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