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