1 |
|
package org.kuali.student.contract.mojo; |
2 |
|
|
3 |
|
import java.io.File; |
4 |
|
import java.util.Collection; |
5 |
|
import java.util.HashSet; |
6 |
|
import java.util.List; |
7 |
|
import java.util.Set; |
8 |
|
|
9 |
|
import org.apache.maven.plugin.AbstractMojo; |
10 |
|
import org.apache.maven.plugin.MojoExecutionException; |
11 |
|
|
12 |
|
import org.kuali.student.contract.model.ServiceContractModel; |
13 |
|
import org.kuali.student.contract.model.XmlType; |
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.KradDictionaryCreator; |
17 |
|
import org.kuali.student.contract.model.validation.ServiceContractModelValidator; |
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
|
|
| 0% |
Uncovered Elements: 61 (61) |
Complexity: 16 |
Complexity Density: 0.38 |
|
24 |
|
public class KSDictionaryCreatorMojo extends AbstractMojo { |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
private List<String> sourceDirs; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
private File outputDirectory; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
private boolean writeManual; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
private boolean writeGenerated; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private List<String> classNames; |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
0
|
public File getOutputDirectory() {... |
48 |
0
|
return outputDirectory; |
49 |
|
} |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
0
|
public List<String> getSourceDirs() {... |
52 |
0
|
return sourceDirs; |
53 |
|
} |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0
|
public boolean isWriteManual() {... |
56 |
0
|
return writeManual; |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
0
|
public boolean isWriteGenerated() {... |
60 |
0
|
return writeGenerated; |
61 |
|
} |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0
|
public List<String> getClassNames() {... |
64 |
0
|
return classNames; |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0
|
public void setClassNames(List<String> classNames) {... |
68 |
0
|
this.classNames = classNames; |
69 |
|
} |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0
|
public void setWriteManual(boolean writeManual) {... |
72 |
0
|
this.writeManual = writeManual; |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0
|
public void setWriteGenerated(boolean writeGenerated) {... |
76 |
0
|
this.writeGenerated = writeGenerated; |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0
|
public void setOutputDirectory(File htmlDirectory) {... |
80 |
0
|
this.outputDirectory = htmlDirectory; |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0
|
public void setSourceDirs(List<String> sourceDirs) {... |
84 |
0
|
this.sourceDirs = sourceDirs; |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
87 |
0
|
private ServiceContractModel getModel() {... |
88 |
0
|
ServiceContractModel instance = new ServiceContractModelQDoxLoader( |
89 |
|
sourceDirs); |
90 |
0
|
return new ServiceContractModelCache(instance); |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
93 |
0
|
private boolean validate(ServiceContractModel model) {... |
94 |
0
|
Collection<String> errors = new ServiceContractModelValidator(model).validate(); |
95 |
0
|
if (errors.size() > 0) { |
96 |
0
|
StringBuilder buf = new StringBuilder(); |
97 |
0
|
buf.append(errors.size()).append(" errors found while validating the data."); |
98 |
0
|
return false; |
99 |
|
} |
100 |
0
|
return true; |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 3 |
Complexity Density: 0.12 |
|
103 |
0
|
@Override... |
104 |
|
public void execute() throws MojoExecutionException { |
105 |
0
|
getLog().info("generating ks-XXX-dictionary.xml files=" + this.writeManual); |
106 |
0
|
getLog().info("generating ks-XXX-dictionary-generated.xml files=" + this.writeGenerated); |
107 |
0
|
ServiceContractModel model = this.getModel(); |
108 |
0
|
this.validate(model); |
109 |
|
|
110 |
0
|
Set<String> lowerClasses = new HashSet(); |
111 |
0
|
for (String className : classNames) { |
112 |
0
|
lowerClasses.add(className.toLowerCase()); |
113 |
|
} |
114 |
|
|
115 |
0
|
String dictionaryDirectory = this.outputDirectory.toString(); |
116 |
0
|
for (XmlType xmlType : model.getXmlTypes()) { |
117 |
0
|
if (lowerClasses.contains(xmlType.getName().toLowerCase())) { |
118 |
0
|
lowerClasses.remove(xmlType.getName().toLowerCase()); |
119 |
0
|
String xmlObject = xmlType.getName(); |
120 |
0
|
KradDictionaryCreator writer = |
121 |
|
new KradDictionaryCreator(dictionaryDirectory, |
122 |
|
model, |
123 |
|
xmlObject, |
124 |
|
writeManual, |
125 |
|
writeGenerated); |
126 |
0
|
writer.write(); |
127 |
|
} |
128 |
|
} |
129 |
0
|
if (!lowerClasses.isEmpty()) { |
130 |
0
|
StringBuilder buf = new StringBuilder(); |
131 |
0
|
buf.append(lowerClasses.size()); |
132 |
0
|
buf.append(" classes were not processed: "); |
133 |
0
|
String comma = ""; |
134 |
0
|
for (String className : lowerClasses) { |
135 |
0
|
buf.append(comma); |
136 |
0
|
buf.append(className); |
137 |
0
|
comma = ", "; |
138 |
|
} |
139 |
0
|
throw new MojoExecutionException(buf.toString()); |
140 |
|
} |
141 |
|
} |
142 |
|
} |