1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.datadictionary.mojo;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25
26 import org.apache.maven.plugin.AbstractMojo;
27 import org.apache.maven.plugin.MojoExecutionException;
28
29 import org.kuali.student.common.mojo.AbstractKSMojo;
30 import org.kuali.student.contract.model.ServiceContractModel;
31 import org.kuali.student.contract.model.XmlType;
32 import org.kuali.student.contract.model.impl.ServiceContractModelCache;
33 import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
34 import org.kuali.student.datadictionary.util.KradDictionaryCreator;
35 import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39
40
41
42
43
44 public class KSDictionaryCreatorMojo extends AbstractKSMojo {
45
46 private static final Logger log = LoggerFactory.getLogger(KSDictionaryCreatorMojo.class);
47
48
49
50
51 private boolean throwExceptionIfNotAllFilesProcessed;
52
53
54
55
56 private File outputDirectory;
57
58
59
60 private boolean writeManual;
61
62
63
64 private boolean writeGenerated;
65
66
67
68
69 private Map<String, String>typeOverrides;
70
71 public boolean isThrowExceptionIfNotAllFilesProcessed() {
72 return throwExceptionIfNotAllFilesProcessed;
73 }
74
75 public void setThrowExceptionIfNotAllFilesProcessed(boolean throwExceptionIfNotAllFilesProcessed) {
76 this.throwExceptionIfNotAllFilesProcessed = throwExceptionIfNotAllFilesProcessed;
77 }
78
79 public File getOutputDirectory() {
80 return outputDirectory;
81 }
82
83
84 public boolean isWriteManual() {
85 return writeManual;
86 }
87
88 public boolean isWriteGenerated() {
89 return writeGenerated;
90 }
91
92 public void setWriteManual(boolean writeManual) {
93 this.writeManual = writeManual;
94 }
95
96 public void setWriteGenerated(boolean writeGenerated) {
97 this.writeGenerated = writeGenerated;
98 }
99
100 public void setOutputDirectory(File htmlDirectory) {
101 this.outputDirectory = htmlDirectory;
102 }
103
104 @Override
105 public void execute() throws MojoExecutionException {
106 getLog().info("generating ks-XXX-dictionary.xml files=" + this.writeManual);
107 getLog().info("generating ks-XXX-dictionary-generated.xml files=" + this.writeGenerated);
108 ServiceContractModel model = this.getModel();
109 this.validate(model);
110
111
112 Set<String> lowerClasses = new HashSet<String>();
113
114 for (XmlType type : model.getXmlTypes()) {
115
116 String className = type.getName().toLowerCase();
117
118
119 if (!className.endsWith("info") || className.matches("\\.r1\\."))
120 continue;
121
122
123 if (this.localPackages.contains(type.getJavaPackage())) {
124 lowerClasses.add(className);
125 }
126 }
127
128 String dictionaryDirectory = this.outputDirectory.toString();
129
130
131 for (XmlType xmlType : model.getXmlTypes()) {
132 if (lowerClasses.contains(xmlType.getName().toLowerCase())) {
133 lowerClasses.remove(xmlType.getName().toLowerCase());
134 String xmlObject = xmlType.getName();
135 KradDictionaryCreator writer =
136 new KradDictionaryCreator(dictionaryDirectory,
137 model,
138 xmlObject,
139 writeManual,
140 writeGenerated,
141 typeOverrides);
142 try {
143
144 writer.write();
145 } catch (Exception e) {
146 log.warn("Generate Failed for: " + xmlObject, e);
147 writer.delete();
148
149 }
150
151 }
152 }
153 if (!lowerClasses.isEmpty()) {
154 StringBuilder buf = new StringBuilder();
155 buf.append(lowerClasses.size());
156 buf.append(" classes were not processed: ");
157 String comma = "";
158 for (String className : lowerClasses) {
159 buf.append(comma);
160 buf.append(className);
161 comma = ", ";
162 }
163 if (throwExceptionIfNotAllFilesProcessed) {
164 throw new MojoExecutionException(buf.toString());
165 }
166 else
167 {
168 log.info(buf.toString());
169 }
170 }
171 }
172 }