| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package net.sf.antcontrib.walls; |
| 17 |
|
| 18 |
import java.io.File; |
| 19 |
import java.util.StringTokenizer; |
| 20 |
|
| 21 |
import org.apache.tools.ant.BuildException; |
| 22 |
import org.apache.tools.ant.Location; |
| 23 |
import org.apache.tools.ant.Project; |
| 24 |
import org.apache.tools.ant.types.FileSet; |
| 25 |
import org.apache.tools.ant.types.Path; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class Package { |
| 40 |
|
| 41 |
private String name; |
| 42 |
private String pack; |
| 43 |
|
| 44 |
|
| 45 |
private boolean badPackage = false; |
| 46 |
private String failureReason = null; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
private String[] depends; |
| 51 |
|
| 52 |
public void setName(String name) { |
| 53 |
this.name = name; |
| 54 |
} |
| 55 |
public String getName() { |
| 56 |
return name; |
| 57 |
} |
| 58 |
|
| 59 |
public void setPackage(String pack) { |
| 60 |
this.pack = pack; |
| 61 |
} |
| 62 |
public String getPackage() { |
| 63 |
return pack; |
| 64 |
} |
| 65 |
|
| 66 |
public void setDepends(String d) { |
| 67 |
if(d == null) { |
| 68 |
throw new RuntimeException("depends cannot be set to null"); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
StringTokenizer tok = new StringTokenizer(d, ", \t"); |
| 73 |
depends = new String[tok.countTokens()]; |
| 74 |
int i = 0; |
| 75 |
while(tok.hasMoreTokens()) { |
| 76 |
depends[i] = tok.nextToken(); |
| 77 |
i++; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
public String[] getDepends() { |
| 82 |
return depends; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public FileSet getJavaCopyFileSet(Project p, Location l) throws BuildException { |
| 90 |
|
| 91 |
if(failureReason != null) |
| 92 |
throw new BuildException(failureReason, l); |
| 93 |
else if(pack.indexOf("/") != -1 || pack.indexOf("\\") != -1) |
| 94 |
throw new BuildException("A package name cannot contain '\\' or '/' like package="+pack |
| 95 |
+"\nIt must look like biz.xsoftware.* for example", l); |
| 96 |
FileSet set = new FileSet(); |
| 97 |
|
| 98 |
String match = getMatch(p, pack, ".java"); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
set.setIncludes(match); |
| 103 |
|
| 104 |
return set; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public FileSet getClassCopyFileSet(Project p, Location l) throws BuildException { |
| 112 |
FileSet set = new FileSet(); |
| 113 |
set.setIncludes("**/*.class"); |
| 114 |
return set; |
| 115 |
} |
| 116 |
|
| 117 |
public File getBuildSpace(File baseDir) { |
| 118 |
return new File(baseDir, name); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
public Path getSrcPath(File baseDir, Project p) { |
| 125 |
Path path = new Path(p); |
| 126 |
|
| 127 |
path.setLocation(getBuildSpace(baseDir)); |
| 128 |
return path; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public Path getClasspath(File baseDir, Project p) { |
| 135 |
Path path = new Path(p); |
| 136 |
|
| 137 |
if(depends != null) { |
| 138 |
for(int i = 0; i < depends.length; i++) { |
| 139 |
String buildSpace = (String)depends[i]; |
| 140 |
|
| 141 |
File dependsDir = new File(baseDir, buildSpace); |
| 142 |
path.setLocation(dependsDir); |
| 143 |
} |
| 144 |
} |
| 145 |
return path; |
| 146 |
} |
| 147 |
|
| 148 |
private String getMatch(Project p, String pack, String postFix) { |
| 149 |
pack = p.replaceProperties(pack); |
| 150 |
|
| 151 |
|
| 152 |
pack = pack.replace('.', File.separatorChar); |
| 153 |
|
| 154 |
String match; |
| 155 |
String classMatch; |
| 156 |
if(pack.endsWith("**")) { |
| 157 |
match = pack + File.separatorChar+"*"+postFix; |
| 158 |
} |
| 159 |
else if(pack.endsWith("*")) { |
| 160 |
match = pack + postFix; |
| 161 |
} |
| 162 |
else |
| 163 |
throw new RuntimeException("Please report this bug"); |
| 164 |
|
| 165 |
return match; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
public void setFaultReason(String r) { |
| 173 |
failureReason = r; |
| 174 |
} |
| 175 |
} |