1 |
|
package org.apache.torque.mojo; |
2 |
|
|
3 |
|
import java.io.File; |
4 |
|
import java.util.List; |
5 |
|
import java.util.Properties; |
6 |
|
import java.util.Set; |
7 |
|
import java.util.TreeSet; |
8 |
|
|
9 |
|
import org.apache.maven.plugin.MojoExecutionException; |
10 |
|
import org.apache.maven.plugin.MojoFailureException; |
11 |
|
import org.apache.tools.ant.DirectoryScanner; |
12 |
|
import org.apache.torque.engine.database.model.Database; |
13 |
|
import org.apache.torque.engine.database.model.Table; |
14 |
|
import org.kuali.core.db.torque.SetUtils; |
15 |
|
import org.kuali.core.db.torque.Utils; |
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
|
|
| 0% |
Uncovered Elements: 80 (80) |
Complexity: 20 |
Complexity Density: 0.34 |
|
26 |
|
public class IdentifyInvalidDataFiles extends BaseMojo { |
27 |
|
private static final String FS = System.getProperty("file.separator"); |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
private String extension; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
private File dataDir; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
private String dataDirIncludes; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
private String dataDirExcludes; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
private String schemaXMLFile; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
private String targetDatabase; |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 3 |
Complexity Density: 0.14 |
|
61 |
0
|
@Override... |
62 |
|
protected void executeMojo() throws MojoExecutionException, MojoFailureException { |
63 |
0
|
Utils utils = new Utils(); |
64 |
0
|
try { |
65 |
0
|
getLog().info("Examining " + dataDir.getAbsolutePath()); |
66 |
0
|
Database db = utils.getDatabase(schemaXMLFile, targetDatabase); |
67 |
0
|
DirectoryScanner ds = getDirectoryScanner(); |
68 |
0
|
Set<File> existing = getExistingFiles(ds); |
69 |
0
|
Set<File> allowed = getDatabaseFiles(db); |
70 |
0
|
Set<File> invalid = SetUtils.difference(existing, allowed); |
71 |
0
|
getLog().info(existing.size() + " data files currently exist"); |
72 |
0
|
getLog().info(invalid.size() + " of those are invalid"); |
73 |
0
|
StringBuilder sb = new StringBuilder(); |
74 |
0
|
int count = 0; |
75 |
0
|
for (File file : invalid) { |
76 |
0
|
if (count != 0) { |
77 |
0
|
sb.append(","); |
78 |
|
} |
79 |
0
|
sb.append("**/src/main/impex/" + file.getName()); |
80 |
0
|
getLog().info("Marked for removal: " + file.getName()); |
81 |
0
|
count++; |
82 |
|
} |
83 |
0
|
Properties properties = getProject().getProperties(); |
84 |
0
|
properties.setProperty("impex.data.invalid", sb.toString()); |
85 |
|
} catch (Exception e) { |
86 |
0
|
throw new MojoExecutionException("Error executing mojo", e); |
87 |
|
} |
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
90 |
0
|
protected Set<File> getDatabaseFiles(Database db) {... |
91 |
0
|
List<?> tables = db.getTables(); |
92 |
0
|
Set<File> files = new TreeSet<File>(); |
93 |
0
|
for (Object object : tables) { |
94 |
0
|
Table table = (Table) object; |
95 |
0
|
String tableName = table.getName(); |
96 |
0
|
String filename = dataDir.getAbsolutePath() + FS + tableName + extension; |
97 |
0
|
File file = new File(filename); |
98 |
0
|
files.add(file); |
99 |
|
} |
100 |
0
|
return files; |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
103 |
0
|
protected Set<File> getExistingFiles(DirectoryScanner ds) {... |
104 |
0
|
ds.scan(); |
105 |
0
|
String[] relativeFilenames = ds.getIncludedFiles(); |
106 |
0
|
Set<File> files = new TreeSet<File>(); |
107 |
0
|
for (int i = 0; i < relativeFilenames.length; i++) { |
108 |
0
|
String filename = ds.getBasedir().getAbsolutePath() + FS + relativeFilenames[i]; |
109 |
0
|
File file = new File(filename); |
110 |
0
|
files.add(file); |
111 |
|
} |
112 |
0
|
return files; |
113 |
|
} |
114 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
115 |
0
|
protected DirectoryScanner getDirectoryScanner() {... |
116 |
0
|
DirectoryScanner ds = new DirectoryScanner(); |
117 |
0
|
ds.setBasedir(dataDir); |
118 |
0
|
ds.setIncludes(new String[] { dataDirIncludes }); |
119 |
0
|
ds.setExcludes(new String[] { dataDirExcludes }); |
120 |
0
|
return ds; |
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
123 |
0
|
protected File getFile(Table table) {... |
124 |
0
|
String tableName = table.getName(); |
125 |
0
|
String filename = dataDir.getAbsolutePath() + FS + tableName + extension; |
126 |
0
|
File file = new File(filename); |
127 |
0
|
return file; |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0
|
public File getDataDir() {... |
131 |
0
|
return dataDir; |
132 |
|
} |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
0
|
public void setDataDir(File dataDir) {... |
135 |
0
|
this.dataDir = dataDir; |
136 |
|
} |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
0
|
public String getDataDirIncludes() {... |
139 |
0
|
return dataDirIncludes; |
140 |
|
} |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
0
|
public void setDataDirIncludes(String dataDirIncludes) {... |
143 |
0
|
this.dataDirIncludes = dataDirIncludes; |
144 |
|
} |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
0
|
public String getDataDirExcludes() {... |
147 |
0
|
return dataDirExcludes; |
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
0
|
public void setDataDirExcludes(String dataDirExcludes) {... |
151 |
0
|
this.dataDirExcludes = dataDirExcludes; |
152 |
|
} |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
154 |
0
|
public String getSchemaXMLFile() {... |
155 |
0
|
return schemaXMLFile; |
156 |
|
} |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
158 |
0
|
public void setSchemaXMLFile(String schemaXMLFile) {... |
159 |
0
|
this.schemaXMLFile = schemaXMLFile; |
160 |
|
} |
161 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
0
|
public String getExtension() {... |
163 |
0
|
return extension; |
164 |
|
} |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
0
|
public void setExtension(String extension) {... |
167 |
0
|
this.extension = extension; |
168 |
|
} |
169 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
170 |
0
|
public String getTargetDatabase() {... |
171 |
0
|
return targetDatabase; |
172 |
|
} |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0
|
public void setTargetDatabase(String targetDatabase) {... |
175 |
0
|
this.targetDatabase = targetDatabase; |
176 |
|
} |
177 |
|
|
178 |
|
} |