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