Browse Source

Make those types that have internal state cloneable in a sensible way,

take advantage of ProjectComponent, simplify a few things.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270135 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
6ef4875d06
8 changed files with 72 additions and 41 deletions
  1. +7
    -0
      src/main/org/apache/tools/ant/Project.java
  2. +1
    -0
      src/main/org/apache/tools/ant/types/FileList.java
  3. +14
    -1
      src/main/org/apache/tools/ant/types/FileSet.java
  4. +10
    -1
      src/main/org/apache/tools/ant/types/FilterSet.java
  5. +8
    -8
      src/main/org/apache/tools/ant/types/Mapper.java
  6. +18
    -25
      src/main/org/apache/tools/ant/types/Path.java
  7. +1
    -1
      src/main/org/apache/tools/ant/types/Reference.java
  8. +13
    -5
      src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java

+ 7
- 0
src/main/org/apache/tools/ant/Project.java View File

@@ -1184,6 +1184,13 @@ public class Project {
return references; return references;
} }


/**
* @return The object with the "id" key.
*/
public Object getReference(String key) {
return references.get(key);
}

/** /**
* send build started event to the listeners * send build started event to the listeners
*/ */


+ 1
- 0
src/main/org/apache/tools/ant/types/FileList.java View File

@@ -86,6 +86,7 @@ public class FileList extends DataType {
protected FileList(FileList filelist) { protected FileList(FileList filelist) {
this.dir = filelist.dir; this.dir = filelist.dir;
this.filenames = filelist.filenames; this.filenames = filelist.filenames;
setProject(filelist.getProject());
} }


/** /**


+ 14
- 1
src/main/org/apache/tools/ant/types/FileSet.java View File

@@ -74,7 +74,7 @@ import java.util.Vector;
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</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 PatternSet defaultPatterns = new PatternSet();
private Vector additionalPatterns = new Vector(); private Vector additionalPatterns = new Vector();
@@ -93,6 +93,7 @@ public class FileSet extends DataType {
this.additionalPatterns = fileset.additionalPatterns; this.additionalPatterns = fileset.additionalPatterns;
this.useDefaultExcludes = fileset.useDefaultExcludes; this.useDefaultExcludes = fileset.useDefaultExcludes;
this.isCaseSensitive = fileset.isCaseSensitive; this.isCaseSensitive = fileset.isCaseSensitive;
setProject(getProject());
} }
@@ -323,4 +324,16 @@ public class FileSet extends DataType {
} }
} }


/**
* 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);
}
}

} }

+ 10
- 1
src/main/org/apache/tools/ant/types/FilterSet.java View File

@@ -77,7 +77,7 @@ import org.apache.tools.ant.Project;
* @author <A href="mailto:gholam@xtra.co.nz"> Michael McCallum </A> * @author <A href="mailto:gholam@xtra.co.nz"> Michael McCallum </A>
* @created 14 March 2001 * @created 14 March 2001
*/ */
public class FilterSet extends DataType {
public class FilterSet extends DataType implements Cloneable {
/** /**
* Individual filter component of filterset * Individual filter component of filterset
@@ -439,6 +439,15 @@ public class FilterSet extends DataType {
public boolean hasFilters() { public boolean hasFilters() {
return getFilters().size() > 0; return getFilters().size() > 0;
} }

public Object clone() throws BuildException {
if (isReference()) {
return new FilterSet(getRef());
} else {
return new FilterSet(this);
}
}

} }




+ 8
- 8
src/main/org/apache/tools/ant/types/Mapper.java View File

@@ -67,14 +67,12 @@ import java.util.Stack;
* *
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/ */
public class Mapper extends DataType {

protected Project p;
public class Mapper extends DataType implements Cloneable {


protected MapperType type = null; protected MapperType type = null;


public Mapper(Project p) { public Mapper(Project p) {
this.p = p;
setProject(p);
} }


/** /**
@@ -123,7 +121,7 @@ public class Mapper extends DataType {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }
if (this.classpath == null) { if (this.classpath == null) {
this.classpath = new Path(p);
this.classpath = new Path(getProject());
} }
return this.classpath.createPath(); return this.classpath.createPath();
} }
@@ -201,7 +199,8 @@ public class Mapper extends DataType {
if (classpath == null) { if (classpath == null) {
c = Class.forName(classname); c = Class.forName(classname);
} else { } else {
AntClassLoader al = new AntClassLoader(p, classpath);
AntClassLoader al = new AntClassLoader(getProject(),
classpath);
c = al.loadClass(classname); c = al.loadClass(classname);
AntClassLoader.initializeClass(c); AntClassLoader.initializeClass(c);
} }
@@ -229,10 +228,10 @@ public class Mapper extends DataType {
if (!checked) { if (!checked) {
Stack stk = new Stack(); Stack stk = new Stack();
stk.push(this); stk.push(this);
dieOnCircularReference(stk, p);
dieOnCircularReference(stk, getProject());
} }
Object o = ref.getReferencedObject(p);
Object o = ref.getReferencedObject(getProject());
if (!(o instanceof Mapper)) { if (!(o instanceof Mapper)) {
String msg = ref.getRefId()+" doesn\'t denote a mapper"; String msg = ref.getRefId()+" doesn\'t denote a mapper";
throw new BuildException(msg); throw new BuildException(msg);
@@ -269,4 +268,5 @@ public class Mapper extends DataType {
return implementations.getProperty(getValue()); return implementations.getProperty(getValue());
} }
} }

} }

+ 18
- 25
src/main/org/apache/tools/ant/types/Path.java View File

@@ -99,7 +99,6 @@ import java.util.Vector;
public class Path extends DataType implements Cloneable { public class Path extends DataType implements Cloneable {


private Vector elements; private Vector elements;
private Project project;


public static Path systemClasspath = public static Path systemClasspath =
new Path(null, System.getProperty("java.class.path")); new Path(null, System.getProperty("java.class.path"));
@@ -116,7 +115,7 @@ public class Path extends DataType implements Cloneable {
} }


public void setPath(String path) { public void setPath(String path) {
parts = Path.translatePath(project, path);
parts = Path.translatePath(getProject(), path);
} }


public String[] getParts() { public String[] getParts() {
@@ -134,15 +133,10 @@ public class Path extends DataType implements Cloneable {
} }


public Path(Project project) { public Path(Project project) {
this.project = project;
setProject(project);
elements = new Vector(); elements = new Vector();
} }


public void setProject(Project p) {
this.project = p;
}
public Project getProject() {return project;}

/** /**
* Adds a element definition to the path. * Adds a element definition to the path.
* @param location the location of the element to add (must not be * @param location the location of the element to add (must not be
@@ -211,7 +205,7 @@ public class Path extends DataType implements Cloneable {
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }
Path p = new Path(project);
Path p = new Path(getProject());
elements.addElement(p); elements.addElement(p);
checked = false; checked = false;
return p; return p;
@@ -240,8 +234,8 @@ public class Path extends DataType implements Cloneable {
String[] list = source.list(); String[] list = source.list();
for (int i=0; i<list.length; i++) { for (int i=0; i<list.length; i++) {
File f = null; File f = null;
if (project != null) {
f = project.resolveFile(list[i]);
if (getProject() != null) {
f = getProject().resolveFile(list[i]);
} }
else { else {
f = new File(list[i]); f = new File(list[i]);
@@ -262,7 +256,7 @@ public class Path extends DataType implements Cloneable {
// make sure we don't have a circular reference here // make sure we don't have a circular reference here
Stack stk = new Stack(); Stack stk = new Stack();
stk.push(this); stk.push(this);
dieOnCircularReference(stk, project);
dieOnCircularReference(stk, getProject());
} }


Vector result = new Vector(2*elements.size()); Vector result = new Vector(2*elements.size());
@@ -270,7 +264,7 @@ public class Path extends DataType implements Cloneable {
Object o = elements.elementAt(i); Object o = elements.elementAt(i);
if (o instanceof Reference) { if (o instanceof Reference) {
Reference r = (Reference) o; Reference r = (Reference) o;
o = r.getReferencedObject(project);
o = r.getReferencedObject(getProject());
// we only support references to paths right now // we only support references to paths right now
if (!(o instanceof Path)) { if (!(o instanceof Path)) {
String msg = r.getRefId()+" doesn\'t denote a path"; String msg = r.getRefId()+" doesn\'t denote a path";
@@ -292,7 +286,7 @@ public class Path extends DataType implements Cloneable {
} else if (o instanceof Path) { } else if (o instanceof Path) {
Path p = (Path) o; Path p = (Path) o;
if (p.getProject() == null) { if (p.getProject() == null) {
p.setProject(project);
p.setProject(getProject());
} }
String[] parts = p.list(); String[] parts = p.list();
for (int j=0; j<parts.length; j++) { for (int j=0; j<parts.length; j++) {
@@ -300,9 +294,9 @@ public class Path extends DataType implements Cloneable {
} }
} else if (o instanceof FileSet) { } else if (o instanceof FileSet) {
FileSet fs = (FileSet) o; FileSet fs = (FileSet) o;
DirectoryScanner ds = fs.getDirectoryScanner(project);
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] s = ds.getIncludedFiles(); String[] s = ds.getIncludedFiles();
File dir = fs.getDir(project);
File dir = fs.getDir(getProject());
for (int j=0; j<s.length; j++) { for (int j=0; j<s.length; j++) {
File f = new File(dir, s[j]); File f = new File(dir, s[j]);
String absolutePath = f.getAbsolutePath(); String absolutePath = f.getAbsolutePath();
@@ -405,7 +399,7 @@ public class Path extends DataType implements Cloneable {
* Return a Path that holds the same elements as this instance. * Return a Path that holds the same elements as this instance.
*/ */
public Object clone() { public Object clone() {
Path p = new Path(project);
Path p = new Path(getProject());
p.append(this); p.append(this);
return p; return p;
} }
@@ -479,11 +473,11 @@ public class Path extends DataType implements Cloneable {
*/ */
public Path concatSystemClasspath(String defValue) { public Path concatSystemClasspath(String defValue) {


Path result = new Path(project);
Path result = new Path(getProject());


String order = defValue; String order = defValue;
if (project != null) {
String o = project.getProperty("build.sysclasspath");
if (getProject() != null) {
String o = getProject().getProperty("build.sysclasspath");
if (o != null) { if (o != null) {
order = o; order = o;
} }
@@ -505,8 +499,8 @@ public class Path extends DataType implements Cloneable {
} else { } else {
// last: don't trust the developer // last: don't trust the developer
if (!order.equals("last")) { 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); result.addExisting(this);
@@ -582,7 +576,7 @@ public class Path extends DataType implements Cloneable {
if (extdirs == null) { if (extdirs == null) {
String extProp = System.getProperty("java.ext.dirs"); String extProp = System.getProperty("java.ext.dirs");
if (extProp != null) { if (extProp != null) {
extdirs = new Path(project, extProp);
extdirs = new Path(getProject(), extProp);
} else { } else {
return; return;
} }
@@ -590,7 +584,7 @@ public class Path extends DataType implements Cloneable {


String[] dirs = extdirs.list(); String[] dirs = extdirs.list();
for (int i=0; i<dirs.length; i++) { 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()) { if (dir.exists() && dir.isDirectory()) {
FileSet fs = new FileSet(); FileSet fs = new FileSet();
fs.setDir(dir); fs.setDir(dir);
@@ -599,5 +593,4 @@ public class Path extends DataType implements Cloneable {
} }
} }
} }

} }

+ 1
- 1
src/main/org/apache/tools/ant/types/Reference.java View File

@@ -88,7 +88,7 @@ public class Reference {
throw new BuildException("No reference specified"); throw new BuildException("No reference specified");
} }
Object o = project.getReferences().get(refid);
Object o = project.getReference(refid);
if (o == null) { if (o == null) {
throw new BuildException("Reference "+refid+" not found."); throw new BuildException("Reference "+refid+" not found.");
} }


+ 13
- 5
src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java View File

@@ -88,17 +88,17 @@ public class ClassfileSet extends FileSet {
} }
} }
protected ClassfileSet(ClassfileSet s) {
super(s);
rootClasses = s.rootClasses;
}

public void setRootClass(String rootClass) public void setRootClass(String rootClass)
throws BuildException throws BuildException
{ {
rootClasses.add(rootClass); rootClasses.add(rootClass);
} }


public void setDir(File dir) throws BuildException {
super.setDir(dir);
}


/** /**
* Return the DirectoryScanner associated with this FileSet. * Return the DirectoryScanner associated with this FileSet.
*/ */
@@ -113,4 +113,12 @@ public class ClassfileSet extends FileSet {
public void addConfiguredRoot(ClassRoot root) { public void addConfiguredRoot(ClassRoot root) {
rootClasses.add(root.getClassname()); rootClasses.add(root.getClassname());
} }

public Object clone() {
if (isReference()) {
return new ClassfileSet((ClassfileSet) getRef(getProject()));
} else {
return new ClassfileSet(this);
}
}
} }

Loading…
Cancel
Save