1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.torque.mojo;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.util.List;
21
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.torque.util.SimpleScanner;
26 import org.codehaus.plexus.util.StringUtils;
27
28
29
30
31
32
33
34 public class MetaInfMojo extends AbstractMojo {
35
36
37
38
39
40
41
42 private String include;
43
44
45
46
47
48
49 private String exclude;
50
51
52
53
54
55
56
57 private File baseDir;
58
59
60
61
62
63
64
65 private File outputFile;
66
67
68
69
70
71
72 private String prefix;
73
74 @Override
75 public void execute() throws MojoExecutionException {
76 try {
77 getLog().info("Examining - " + baseDir.getAbsolutePath());
78 getLog().info("Include - " + include);
79 getLog().info("Exclude - " + exclude);
80 SimpleScanner scanner = new SimpleScanner(baseDir, include, exclude);
81 List<File> files = scanner.getFiles();
82 getLog().info("Located " + files.size() + " files");
83 String content = getLocations(baseDir, files, prefix);
84 getLog().info("Creating " + outputFile);
85 FileUtils.writeStringToFile(outputFile, content);
86 } catch (Exception e) {
87 throw new MojoExecutionException("Unexpected error", e);
88 }
89 }
90
91 protected String getLocations(File baseDir, List<File> files, String prefix) throws IOException {
92 StringBuilder sb = new StringBuilder();
93 for (int i = 0; i < files.size(); i++) {
94 if (i != 0) {
95 sb.append("\n");
96 }
97 sb.append(getLocation(baseDir, files.get(i), prefix));
98 }
99 return sb.toString();
100 }
101
102 protected String getLocation(File baseDir, File file, String prefix) throws IOException {
103 String dir = baseDir.getCanonicalPath();
104 String path = file.getCanonicalPath();
105 int pos = dir.length() + 1;
106 return prefix + StringUtils.substring(path, pos);
107 }
108
109 public String getInclude() {
110 return include;
111 }
112
113 public void setInclude(String include) {
114 this.include = include;
115 }
116
117 public String getExclude() {
118 return exclude;
119 }
120
121 public void setExclude(String exclude) {
122 this.exclude = exclude;
123 }
124
125 public File getBaseDir() {
126 return baseDir;
127 }
128
129 public void setBaseDir(File baseDir) {
130 this.baseDir = baseDir;
131 }
132
133 public File getOutputFile() {
134 return outputFile;
135 }
136
137 public void setOutputFile(File outputFile) {
138 this.outputFile = outputFile;
139 }
140
141 public String getPrefix() {
142 return prefix;
143 }
144
145 public void setPrefix(String prefix) {
146 this.prefix = prefix;
147 }
148
149 }