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