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
42   142   16   3.23
6   102   0.38   13
13     1.23  
1    
 
  KSDictionaryCreatorMojo       Line # 24 42 0% 16 61 0% 0.0
 
No Tests
 
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    * 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
28    **/
29    private List<String> sourceDirs;
30    /**
31    * @parameter expression="${outputDirectory}" default-value="${project.build.directory}/classes"
32    */
33    private File outputDirectory;
34    /**
35    * @parameter expression=false
36    */
37    private boolean writeManual;
38    /**
39    * @parameter expression=true
40    */
41    private boolean writeGenerated;
42    /**
43    * @parameter
44    */
45    private List<String> classNames;
46   
 
47  0 toggle public File getOutputDirectory() {
48  0 return outputDirectory;
49    }
50   
 
51  0 toggle public List<String> getSourceDirs() {
52  0 return sourceDirs;
53    }
54   
 
55  0 toggle public boolean isWriteManual() {
56  0 return writeManual;
57    }
58   
 
59  0 toggle public boolean isWriteGenerated() {
60  0 return writeGenerated;
61    }
62   
 
63  0 toggle public List<String> getClassNames() {
64  0 return classNames;
65    }
66   
 
67  0 toggle public void setClassNames(List<String> classNames) {
68  0 this.classNames = classNames;
69    }
70   
 
71  0 toggle public void setWriteManual(boolean writeManual) {
72  0 this.writeManual = writeManual;
73    }
74   
 
75  0 toggle public void setWriteGenerated(boolean writeGenerated) {
76  0 this.writeGenerated = writeGenerated;
77    }
78   
 
79  0 toggle public void setOutputDirectory(File htmlDirectory) {
80  0 this.outputDirectory = htmlDirectory;
81    }
82   
 
83  0 toggle public void setSourceDirs(List<String> sourceDirs) {
84  0 this.sourceDirs = sourceDirs;
85    }
86   
 
87  0 toggle private ServiceContractModel getModel() {
88  0 ServiceContractModel instance = new ServiceContractModelQDoxLoader(
89    sourceDirs);
90  0 return new ServiceContractModelCache(instance);
91    }
92   
 
93  0 toggle 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   
 
103  0 toggle @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    }