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 lowerClasses.add(type.getName().toLowerCase());
94 }
95
96 String dictionaryDirectory = this.outputDirectory.toString();
97 for (XmlType xmlType : model.getXmlTypes()) {
98 if (lowerClasses.contains(xmlType.getName().toLowerCase())) {
99 lowerClasses.remove(xmlType.getName().toLowerCase());
100 String xmlObject = xmlType.getName();
101 KradDictionaryCreator writer =
102 new KradDictionaryCreator(dictionaryDirectory,
103 model,
104 xmlObject,
105 writeManual,
106 writeGenerated);
107 try {
108
109 writer.write();
110 } catch (Exception e) {
111 log.warn("Generate Failed for: " + xmlObject, e);
112 writer.delete();
113
114 }
115
116 }
117 }
118 if (!lowerClasses.isEmpty()) {
119 StringBuilder buf = new StringBuilder();
120 buf.append(lowerClasses.size());
121 buf.append(" classes were not processed: ");
122 String comma = "";
123 for (String className : lowerClasses) {
124 buf.append(comma);
125 buf.append(className);
126 comma = ", ";
127 }
128 if (throwExceptionIfNotAllFilesProcessed) {
129 throw new MojoExecutionException(buf.toString());
130 }
131 else
132 {
133 log.info(buf.toString());
134 }
135 }
136 }
137 }