| 1 | |
package org.kuali.student.contract.mojo; |
| 2 | |
|
| 3 | |
import java.io.File; |
| 4 | |
import java.util.Collection; |
| 5 | |
import java.util.List; |
| 6 | |
|
| 7 | |
import org.apache.maven.plugin.AbstractMojo; |
| 8 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 9 | |
|
| 10 | |
import org.kuali.student.contract.model.ServiceContractModel; |
| 11 | |
import org.kuali.student.contract.model.impl.ServiceContractModelCache; |
| 12 | |
import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader; |
| 13 | |
import org.kuali.student.contract.model.util.HtmlContractWriter; |
| 14 | |
import org.kuali.student.contract.model.validation.ServiceContractModelValidator; |
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | 0 | public class KSContractDocMojo extends AbstractMojo { |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
private List<String> sourceDirs; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
private File htmlDirectory; |
| 32 | |
|
| 33 | |
public File getHtmlDirectory() { |
| 34 | 0 | return htmlDirectory; |
| 35 | |
} |
| 36 | |
|
| 37 | |
public List<String> getSourceDirs() { |
| 38 | 0 | return sourceDirs; |
| 39 | |
} |
| 40 | |
|
| 41 | |
public void setHtmlDirectory(File htmlDirectory) { |
| 42 | 0 | this.htmlDirectory = htmlDirectory; |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
public void setSourceDirs(List<String> sourceDirs) { |
| 46 | 0 | this.sourceDirs = sourceDirs; |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
private ServiceContractModel getModel() { |
| 50 | 0 | ServiceContractModel instance = new ServiceContractModelQDoxLoader( |
| 51 | |
sourceDirs); |
| 52 | 0 | return new ServiceContractModelCache(instance); |
| 53 | |
|
| 54 | |
} |
| 55 | |
|
| 56 | |
private boolean validate(ServiceContractModel model) { |
| 57 | 0 | Collection<String> errors = new ServiceContractModelValidator(model).validate(); |
| 58 | 0 | if (errors.size() > 0) { |
| 59 | 0 | StringBuilder buf = new StringBuilder(); |
| 60 | 0 | buf.append(errors.size()).append(" errors found while validating the data."); |
| 61 | 0 | return false; |
| 62 | |
|
| 63 | |
|
| 64 | |
} |
| 65 | 0 | return true; |
| 66 | |
} |
| 67 | |
|
| 68 | |
@Override |
| 69 | |
public void execute() throws MojoExecutionException { |
| 70 | 0 | ServiceContractModel model = null; |
| 71 | 0 | HtmlContractWriter writer = null; |
| 72 | 0 | getLog().info("publishing wiki contracts"); |
| 73 | 0 | model = this.getModel(); |
| 74 | 0 | this.validate(model); |
| 75 | 0 | getLog().info("publishing to = " + this.htmlDirectory.toString()); |
| 76 | 0 | writer = new HtmlContractWriter(htmlDirectory.toString(), model); |
| 77 | 0 | writer.write(); |
| 78 | |
|
| 79 | |
|
| 80 | 0 | } |
| 81 | |
} |