Clover Coverage Report - KS Contract Documentation Generator 0.0.1-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
46   160   19   3.07
8   115   0.41   15
15     1.27  
1    
 
  KSDictionaryCreatorMojo       Line # 24 46 0% 19 69 0% 0.0
 
No Tests
 
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    * The plugin entrypoint which is used to generate dictionary files based on the contract
21    * @phase generate-sources
22    * @goal ksdictionarycreator
23    */
 
24    public class KSDictionaryCreatorMojo extends AbstractMojo {
25   
26    /**
27    * @parameter expression=true
28    **/
29    private boolean throwExceptionIfNotAllFilesProcessed;
30    /**
31    * @parameter
32    **/
33    private List<String> sourceDirs;
34    /**
35    * @parameter expression="${outputDirectory}" default-value="${project.build.directory}/generated-sources/datadictionary"
36    */
37    private File outputDirectory;
38    /**
39    * @parameter expression=false
40    */
41    private boolean writeManual;
42    /**
43    * @parameter expression=true
44    */
45    private boolean writeGenerated;
46    /**
47    * @parameter
48    */
49    private List<String> classNames;
50   
 
51  0 toggle public boolean isThrowExceptionIfNotAllFilesProcessed() {
52  0 return throwExceptionIfNotAllFilesProcessed;
53    }
54   
 
55  0 toggle public void setThrowExceptionIfNotAllFilesProcessed(boolean throwExceptionIfNotAllFilesProcessed) {
56  0 this.throwExceptionIfNotAllFilesProcessed = throwExceptionIfNotAllFilesProcessed;
57    }
58   
 
59  0 toggle public File getOutputDirectory() {
60  0 return outputDirectory;
61    }
62   
 
63  0 toggle public List<String> getSourceDirs() {
64  0 return sourceDirs;
65    }
66   
 
67  0 toggle public boolean isWriteManual() {
68  0 return writeManual;
69    }
70   
 
71  0 toggle public boolean isWriteGenerated() {
72  0 return writeGenerated;
73    }
74   
 
75  0 toggle public List<String> getClassNames() {
76  0 return classNames;
77    }
78   
 
79  0 toggle public void setClassNames(List<String> classNames) {
80  0 this.classNames = classNames;
81    }
82   
 
83  0 toggle public void setWriteManual(boolean writeManual) {
84  0 this.writeManual = writeManual;
85    }
86   
 
87  0 toggle public void setWriteGenerated(boolean writeGenerated) {
88  0 this.writeGenerated = writeGenerated;
89    }
90   
 
91  0 toggle public void setOutputDirectory(File htmlDirectory) {
92  0 this.outputDirectory = htmlDirectory;
93    }
94   
 
95  0 toggle public void setSourceDirs(List<String> sourceDirs) {
96  0 this.sourceDirs = sourceDirs;
97    }
98   
 
99  0 toggle private ServiceContractModel getModel() {
100  0 ServiceContractModel instance = new ServiceContractModelQDoxLoader(
101    sourceDirs);
102  0 return new ServiceContractModelCache(instance);
103    }
104   
 
105  0 toggle 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   
 
115  0 toggle @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    }