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.io.FileNotFoundException; |
20 |
|
import java.io.FileOutputStream; |
21 |
|
import java.io.OutputStream; |
22 |
|
import java.io.PrintStream; |
23 |
|
import java.net.MalformedURLException; |
24 |
|
import java.net.URL; |
25 |
|
import java.net.URLClassLoader; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.LinkedHashSet; |
28 |
|
import java.util.List; |
29 |
|
import java.util.Map; |
30 |
|
import java.util.Set; |
31 |
|
import org.apache.maven.artifact.DependencyResolutionRequiredException; |
32 |
|
import org.apache.maven.plugin.AbstractMojo; |
33 |
|
import org.apache.maven.plugin.MojoExecutionException; |
34 |
|
import org.apache.maven.project.MavenProject; |
35 |
|
import org.kuali.rice.krad.datadictionary.DataObjectEntry; |
36 |
|
import org.kuali.student.datadictionary.util.DictionaryFormatter; |
37 |
|
import org.kuali.student.datadictionary.util.DictionaryTesterHelper; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 0% |
Uncovered Elements: 70 (70) |
Complexity: 16 |
Complexity Density: 0.31 |
|
45 |
|
public class KSDictionaryDocMojo extends AbstractMojo { |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private MavenProject project; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private List<String> inputFiles; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
private List<String> supportFiles = new ArrayList(); |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
private File htmlDirectory; |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0
|
public void setHtmlDirectory(File htmlDirectory) {... |
67 |
0
|
this.htmlDirectory = htmlDirectory; |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0
|
public File getHtmlDirectory() {... |
71 |
0
|
return htmlDirectory; |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
0
|
public List<String> getInputFiles() {... |
75 |
0
|
return inputFiles; |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
0
|
public MavenProject getProject() {... |
79 |
0
|
return project; |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0
|
public void setInputFiles(List<String> inputFiles) {... |
83 |
0
|
this.inputFiles = inputFiles; |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0
|
public List<String> getSupportFiles() {... |
87 |
0
|
return supportFiles; |
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
0
|
public void setSupportFiles(List<String> supportFiles) {... |
91 |
0
|
this.supportFiles = supportFiles; |
92 |
|
} |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 55 (55) |
Complexity: 9 |
Complexity Density: 0.2 |
|
94 |
0
|
@Override... |
95 |
|
public void execute() |
96 |
|
throws MojoExecutionException { |
97 |
0
|
this.getLog().info("generating dictionary documentation"); |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
0
|
if (project != null) { |
102 |
0
|
this.getLog().info("adding current project's classpath to plugin class loader"); |
103 |
0
|
List runtimeClasspathElements; |
104 |
0
|
try { |
105 |
0
|
runtimeClasspathElements = project.getRuntimeClasspathElements(); |
106 |
|
} catch (DependencyResolutionRequiredException ex) { |
107 |
0
|
throw new MojoExecutionException("got error", ex); |
108 |
|
} |
109 |
0
|
URL[] runtimeUrls = new URL[runtimeClasspathElements.size()]; |
110 |
0
|
for (int i = 0; i < runtimeClasspathElements.size(); i++) { |
111 |
0
|
String element = (String) runtimeClasspathElements.get(i); |
112 |
0
|
try { |
113 |
0
|
runtimeUrls[i] = new File(element).toURI().toURL(); |
114 |
|
} catch (MalformedURLException ex) { |
115 |
0
|
throw new MojoExecutionException(element, ex); |
116 |
|
} |
117 |
|
} |
118 |
0
|
URLClassLoader newLoader = new URLClassLoader(runtimeUrls, |
119 |
|
Thread.currentThread().getContextClassLoader()); |
120 |
0
|
Thread.currentThread().setContextClassLoader(newLoader); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
0
|
if (!htmlDirectory.exists()) { |
126 |
0
|
if (!htmlDirectory.mkdirs()) { |
127 |
|
|
128 |
0
|
throw new IllegalArgumentException("Could not create directory " |
129 |
|
+ this.htmlDirectory.getPath()); |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
0
|
Set<String> inpFiles = new LinkedHashSet(this.inputFiles.size()); |
134 |
0
|
for (String dictFileName : this.inputFiles) { |
135 |
0
|
if (dictFileName.endsWith(".xml")) { |
136 |
0
|
inpFiles.add(dictFileName); |
137 |
|
} |
138 |
|
} |
139 |
|
|
140 |
0
|
Set<String> configFiles = new LinkedHashSet(this.inputFiles.size() + supportFiles.size()); |
141 |
0
|
configFiles.addAll(inpFiles); |
142 |
0
|
configFiles.addAll(this.supportFiles); |
143 |
|
|
144 |
0
|
String outputDir = this.htmlDirectory.getAbsolutePath(); |
145 |
0
|
DictionaryTesterHelper tester = new DictionaryTesterHelper(outputDir, configFiles); |
146 |
0
|
List<String> outputFileNames = tester.doTest(); |
147 |
|
|
148 |
|
|
149 |
0
|
String indexFileName = this.htmlDirectory.getPath() + "/" + "index.html"; |
150 |
0
|
File indexFile = new File(indexFileName); |
151 |
0
|
OutputStream outputStream; |
152 |
0
|
try { |
153 |
0
|
outputStream = new FileOutputStream(indexFile, false); |
154 |
|
} catch (FileNotFoundException ex) { |
155 |
|
|
156 |
0
|
throw new IllegalArgumentException(indexFileName, ex); |
157 |
|
} |
158 |
0
|
PrintStream out = new PrintStream(outputStream); |
159 |
0
|
DictionaryFormatter.writeHeader(out, "Data Dictionary Index"); |
160 |
0
|
out.println("<h1>Data Dictionary Index</h1>"); |
161 |
0
|
String endUL = ""; |
162 |
0
|
Map<String, DataObjectEntry> beansOfType = tester.getDataObjectEntryBeans(); |
163 |
0
|
for (String beanId : beansOfType.keySet()) { |
164 |
0
|
String outputFileName = beanId + ".html"; |
165 |
0
|
out.println("<li><a href=\"" + outputFileName + "\">" + beanId + "</a>"); |
166 |
|
} |
167 |
0
|
out.println("</ul>"); |
168 |
0
|
DictionaryFormatter.writeFooter(out); |
169 |
0
|
this.getLog().info("finished generating dictionary documentation"); |
170 |
|
} |
171 |
|
} |