You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/12/13 12:53:44 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/types/optional/depend ClassfileSet.java
bodewig 01/12/13 03:53:44
Modified: src/main/org/apache/tools/ant Project.java
src/main/org/apache/tools/ant/types FileList.java
FileSet.java FilterSet.java Mapper.java Path.java
Reference.java
src/main/org/apache/tools/ant/types/optional/depend
ClassfileSet.java
Log:
Make those types that have internal state cloneable in a sensible way,
take advantage of ProjectComponent, simplify a few things.
Revision Changes Path
1.88 +7 -0 jakarta-ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -r1.87 -r1.88
--- Project.java 2001/12/12 09:17:36 1.87
+++ Project.java 2001/12/13 11:53:43 1.88
@@ -1185,6 +1185,13 @@
}
/**
+ * @return The object with the "id" key.
+ */
+ public Object getReference(String key) {
+ return references.get(key);
+ }
+
+ /**
* send build started event to the listeners
*/
protected void fireBuildStarted() {
1.3 +2 -1 jakarta-ant/src/main/org/apache/tools/ant/types/FileList.java
Index: FileList.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/FileList.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FileList.java 2001/10/28 21:27:19 1.2
+++ FileList.java 2001/12/13 11:53:43 1.3
@@ -72,7 +72,7 @@
* exists in the file system.
*
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
- * @version $Revision: 1.2 $ $Date: 2001/10/28 21:27:19 $
+ * @version $Revision: 1.3 $ $Date: 2001/12/13 11:53:43 $
*/
public class FileList extends DataType {
@@ -86,6 +86,7 @@
protected FileList(FileList filelist) {
this.dir = filelist.dir;
this.filenames = filelist.filenames;
+ setProject(filelist.getProject());
}
/**
1.19 +14 -1 jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java
Index: FileSet.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- FileSet.java 2001/09/30 13:21:54 1.18
+++ FileSet.java 2001/12/13 11:53:43 1.19
@@ -74,7 +74,7 @@
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a>
*/
-public class FileSet extends DataType {
+public class FileSet extends DataType implements Cloneable {
private PatternSet defaultPatterns = new PatternSet();
private Vector additionalPatterns = new Vector();
@@ -93,6 +93,7 @@
this.additionalPatterns = fileset.additionalPatterns;
this.useDefaultExcludes = fileset.useDefaultExcludes;
this.isCaseSensitive = fileset.isCaseSensitive;
+ setProject(getProject());
}
@@ -320,6 +321,18 @@
throw new BuildException(msg);
} else {
return (FileSet) o;
+ }
+ }
+
+ /**
+ * Return a FileSet that has the same basedir and same patternsets
+ * as this one.
+ */
+ public Object clone() {
+ if (isReference()) {
+ return new FileSet(getRef(getProject()));
+ } else {
+ return new FileSet(this);
}
}
1.7 +10 -1 jakarta-ant/src/main/org/apache/tools/ant/types/FilterSet.java
Index: FilterSet.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/FilterSet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FilterSet.java 2001/11/13 14:58:01 1.6
+++ FilterSet.java 2001/12/13 11:53:43 1.7
@@ -77,7 +77,7 @@
* @author <A href="mailto:gholam@xtra.co.nz"> Michael McCallum </A>
* @created 14 March 2001
*/
-public class FilterSet extends DataType {
+public class FilterSet extends DataType implements Cloneable {
/**
* Individual filter component of filterset
@@ -439,6 +439,15 @@
public boolean hasFilters() {
return getFilters().size() > 0;
}
+
+ public Object clone() throws BuildException {
+ if (isReference()) {
+ return new FilterSet(getRef());
+ } else {
+ return new FilterSet(this);
+ }
+ }
+
}
1.7 +8 -8 jakarta-ant/src/main/org/apache/tools/ant/types/Mapper.java
Index: Mapper.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Mapper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Mapper.java 2001/10/28 21:27:19 1.6
+++ Mapper.java 2001/12/13 11:53:43 1.7
@@ -67,14 +67,12 @@
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
-public class Mapper extends DataType {
+public class Mapper extends DataType implements Cloneable {
- protected Project p;
-
protected MapperType type = null;
public Mapper(Project p) {
- this.p = p;
+ setProject(p);
}
/**
@@ -123,7 +121,7 @@
throw noChildrenAllowed();
}
if (this.classpath == null) {
- this.classpath = new Path(p);
+ this.classpath = new Path(getProject());
}
return this.classpath.createPath();
}
@@ -201,7 +199,8 @@
if (classpath == null) {
c = Class.forName(classname);
} else {
- AntClassLoader al = new AntClassLoader(p, classpath);
+ AntClassLoader al = new AntClassLoader(getProject(),
+ classpath);
c = al.loadClass(classname);
AntClassLoader.initializeClass(c);
}
@@ -229,10 +228,10 @@
if (!checked) {
Stack stk = new Stack();
stk.push(this);
- dieOnCircularReference(stk, p);
+ dieOnCircularReference(stk, getProject());
}
- Object o = ref.getReferencedObject(p);
+ Object o = ref.getReferencedObject(getProject());
if (!(o instanceof Mapper)) {
String msg = ref.getRefId()+" doesn\'t denote a mapper";
throw new BuildException(msg);
@@ -269,4 +268,5 @@
return implementations.getProperty(getValue());
}
}
+
}
1.26 +18 -25 jakarta-ant/src/main/org/apache/tools/ant/types/Path.java
Index: Path.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Path.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Path.java 2001/11/06 10:47:34 1.25
+++ Path.java 2001/12/13 11:53:43 1.26
@@ -99,7 +99,6 @@
public class Path extends DataType implements Cloneable {
private Vector elements;
- private Project project;
public static Path systemClasspath =
new Path(null, System.getProperty("java.class.path"));
@@ -116,7 +115,7 @@
}
public void setPath(String path) {
- parts = Path.translatePath(project, path);
+ parts = Path.translatePath(getProject(), path);
}
public String[] getParts() {
@@ -134,15 +133,10 @@
}
public Path(Project project) {
- this.project = project;
+ setProject(project);
elements = new Vector();
}
- public void setProject(Project p) {
- this.project = p;
- }
- public Project getProject() {return project;}
-
/**
* Adds a element definition to the path.
* @param location the location of the element to add (must not be
@@ -211,7 +205,7 @@
if (isReference()) {
throw noChildrenAllowed();
}
- Path p = new Path(project);
+ Path p = new Path(getProject());
elements.addElement(p);
checked = false;
return p;
@@ -240,8 +234,8 @@
String[] list = source.list();
for (int i=0; i<list.length; i++) {
File f = null;
- if (project != null) {
- f = project.resolveFile(list[i]);
+ if (getProject() != null) {
+ f = getProject().resolveFile(list[i]);
}
else {
f = new File(list[i]);
@@ -262,7 +256,7 @@
// make sure we don't have a circular reference here
Stack stk = new Stack();
stk.push(this);
- dieOnCircularReference(stk, project);
+ dieOnCircularReference(stk, getProject());
}
Vector result = new Vector(2*elements.size());
@@ -270,7 +264,7 @@
Object o = elements.elementAt(i);
if (o instanceof Reference) {
Reference r = (Reference) o;
- o = r.getReferencedObject(project);
+ o = r.getReferencedObject(getProject());
// we only support references to paths right now
if (!(o instanceof Path)) {
String msg = r.getRefId()+" doesn\'t denote a path";
@@ -292,7 +286,7 @@
} else if (o instanceof Path) {
Path p = (Path) o;
if (p.getProject() == null) {
- p.setProject(project);
+ p.setProject(getProject());
}
String[] parts = p.list();
for (int j=0; j<parts.length; j++) {
@@ -300,9 +294,9 @@
}
} else if (o instanceof FileSet) {
FileSet fs = (FileSet) o;
- DirectoryScanner ds = fs.getDirectoryScanner(project);
+ DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] s = ds.getIncludedFiles();
- File dir = fs.getDir(project);
+ File dir = fs.getDir(getProject());
for (int j=0; j<s.length; j++) {
File f = new File(dir, s[j]);
String absolutePath = f.getAbsolutePath();
@@ -405,7 +399,7 @@
* Return a Path that holds the same elements as this instance.
*/
public Object clone() {
- Path p = new Path(project);
+ Path p = new Path(getProject());
p.append(this);
return p;
}
@@ -479,11 +473,11 @@
*/
public Path concatSystemClasspath(String defValue) {
- Path result = new Path(project);
+ Path result = new Path(getProject());
String order = defValue;
- if (project != null) {
- String o = project.getProperty("build.sysclasspath");
+ if (getProject() != null) {
+ String o = getProject().getProperty("build.sysclasspath");
if (o != null) {
order = o;
}
@@ -505,8 +499,8 @@
} else {
// last: don't trust the developer
if (!order.equals("last")) {
- project.log("invalid value for build.sysclasspath: " + order,
- Project.MSG_WARN);
+ log("invalid value for build.sysclasspath: " + order,
+ Project.MSG_WARN);
}
result.addExisting(this);
@@ -582,7 +576,7 @@
if (extdirs == null) {
String extProp = System.getProperty("java.ext.dirs");
if (extProp != null) {
- extdirs = new Path(project, extProp);
+ extdirs = new Path(getProject(), extProp);
} else {
return;
}
@@ -590,7 +584,7 @@
String[] dirs = extdirs.list();
for (int i=0; i<dirs.length; i++) {
- File dir = project.resolveFile(dirs[i]);
+ File dir = getProject().resolveFile(dirs[i]);
if (dir.exists() && dir.isDirectory()) {
FileSet fs = new FileSet();
fs.setDir(dir);
@@ -599,5 +593,4 @@
}
}
}
-
}
1.6 +1 -1 jakarta-ant/src/main/org/apache/tools/ant/types/Reference.java
Index: Reference.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Reference.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Reference.java 2001/05/23 16:58:19 1.5
+++ Reference.java 2001/12/13 11:53:44 1.6
@@ -88,7 +88,7 @@
throw new BuildException("No reference specified");
}
- Object o = project.getReferences().get(refid);
+ Object o = project.getReference(refid);
if (o == null) {
throw new BuildException("Reference "+refid+" not found.");
}
1.3 +13 -5 jakarta-ant/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java
Index: ClassfileSet.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ClassfileSet.java 2001/11/29 13:47:38 1.2
+++ ClassfileSet.java 2001/12/13 11:53:44 1.3
@@ -88,17 +88,17 @@
}
}
+ protected ClassfileSet(ClassfileSet s) {
+ super(s);
+ rootClasses = s.rootClasses;
+ }
+
public void setRootClass(String rootClass)
throws BuildException
{
rootClasses.add(rootClass);
}
- public void setDir(File dir) throws BuildException {
- super.setDir(dir);
- }
-
-
/**
* Return the DirectoryScanner associated with this FileSet.
*/
@@ -112,5 +112,13 @@
public void addConfiguredRoot(ClassRoot root) {
rootClasses.add(root.getClassname());
+ }
+
+ public Object clone() {
+ if (isReference()) {
+ return new ClassfileSet((ClassfileSet) getRef(getProject()));
+ } else {
+ return new ClassfileSet(this);
+ }
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>