-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathGlobMatchingTask.java
More file actions
101 lines (85 loc) · 2.94 KB
/
GlobMatchingTask.java
File metadata and controls
101 lines (85 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package org.python.util;
import java.io.File;
import java.util.Set;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.GlobPatternMapper;
import org.apache.tools.ant.util.SourceFileScanner;
public abstract class GlobMatchingTask extends MatchingTask {
private Path src;
protected File destDir;
private Set<File> toExpose = Generic.set();
/**
* Set the source directories to find the class files to be exposed.
*/
public void setSrcdir(Path srcDir) {
if (src == null) {
src = srcDir;
} else {
src.append(srcDir);
}
}
/**
* Gets the source dirs to find the class files to be exposed.
*/
public Path getSrcdir() {
return src;
}
/**
* Set the destination directory into which the Java source files should be compiled.
*
* @param destDir
* the destination director
*/
public void setDestdir(File destDir) {
this.destDir = destDir;
}
/**
* Gets the destination directory into which the java source files should be compiled.
*
* @return the destination directory
*/
public File getDestdir() {
return destDir;
}
@Override
public void execute() throws BuildException {
checkParameters();
toExpose.clear();
for (String srcEntry : src.list()) {
File srcDir = getProject().resolveFile(srcEntry);
if (!srcDir.exists()) {
throw new BuildException("srcdir '" + srcDir.getPath() + "' does not exist!",
getLocation());
}
String[] files = getDirectoryScanner(srcDir).getIncludedFiles();
scanDir(srcDir, destDir != null ? destDir : srcDir, files);
}
process(toExpose);
}
protected abstract void process(Set<File> matches);
protected abstract String getFrom();
protected abstract String getTo();
protected void scanDir(File srcDir, File destDir, String[] files) {
GlobPatternMapper m = new GlobPatternMapper();
m.setFrom(getFrom());
m.setTo(getTo());
SourceFileScanner sfs = new SourceFileScanner(this);
for (File file : sfs.restrictAsFiles(files, srcDir, destDir, m)) {
toExpose.add(file);
}
}
/**
* Check that all required attributes have been set and nothing silly has been entered.
*/
protected void checkParameters() throws BuildException {
if (src == null || src.size() == 0) {
throw new BuildException("srcdir attribute must be set!", getLocation());
}
if (destDir != null && !destDir.isDirectory()) {
throw new BuildException("destination directory '" + destDir + "' does not exist "
+ "or is not a directory", getLocation());
}
}
}