You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by sb...@apache.org on 2001/09/05 09:34:15 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Ant.java
sbailliez 01/09/05 00:34:15
Modified: src/main/org/apache/tools/ant/taskdefs Tag: ANT_14_BRANCH
Ant.java
Log:
Patch from Jason Brittain <ja...@collab.net> to fix an inheritall bug.
System properties were not copied when inheritall was set to false.
We really need to comment source code and write testcases.
I added some comments here and there to make it easier to understand, but
I'm missing the global picture.
Revision Changes Path
No revision
No revision
1.25.2.1 +69 -39 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
Index: Ant.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
retrieving revision 1.25
retrieving revision 1.25.2.1
diff -u -r1.25 -r1.25.2.1
--- Ant.java 2001/08/07 11:43:32 1.25
+++ Ant.java 2001/09/05 07:34:15 1.25.2.1
@@ -79,28 +79,40 @@
*/
public class Ant extends Task {
+ /** the basedir where is executed the build file */
private File dir = null;
+
+ /** the build.xml file (can be absolute) in this case dir will be ignored */
private String antFile = null;
+
+ /** the target to call if any */
private String target = null;
+
+ /** the output */
private String output = null;
+
+ /** should we inherit properties from the parent ? */
private boolean inheritAll = true;
-
- Vector properties = new Vector();
- Project p1;
+
+ /** the properties to pass to the new project */
+ private Vector properties = new Vector();
+
+ /** the temporary project created to run the build file */
+ private Project newProject;
/**
* If true, inherit all properties from parent Project
* If false, inherit only userProperties and those defined
* inside the ant call itself
- **/
- public void setInheritAll(boolean inherit) {
- inheritAll = inherit;
- } //-- setInheritAll
+ */
+ public void setInheritAll(boolean value) {
+ inheritAll = value;
+ }
public void init() {
- p1 = new Project();
- p1.setJavaVersionProperty();
- p1.addTaskDefinition("property",
+ newProject = new Project();
+ newProject.setJavaVersionProperty();
+ newProject.addTaskDefinition("property",
(Class)project.getTaskDefinitions().get("property"));
}
@@ -108,7 +120,7 @@
init();
for (int i=0; i<properties.size(); i++) {
Property p = (Property) properties.elementAt(i);
- Property newP = (Property) p1.createTask("property");
+ Property newP = (Property) newProject.createTask("property");
newP.setName(p.getName());
if (p.getValue() != null) {
newP.setValue(p.getValue());
@@ -126,7 +138,7 @@
private void initializeProject() {
Vector listeners = project.getBuildListeners();
for (int i = 0; i < listeners.size(); i++) {
- p1.addBuildListener((BuildListener)listeners.elementAt(i));
+ newProject.addBuildListener((BuildListener)listeners.elementAt(i));
}
if (output != null) {
@@ -136,7 +148,7 @@
logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setOutputPrintStream(out);
logger.setErrorPrintStream(out);
- p1.addBuildListener(logger);
+ newProject.addBuildListener(logger);
}
catch( IOException ex ) {
log( "Ant: Can't set output to " + output );
@@ -148,7 +160,7 @@
while (et.hasMoreElements()) {
String taskName = (String) et.nextElement();
Class taskClass = (Class) taskdefs.get(taskName);
- p1.addTaskDefinition(taskName, taskClass);
+ newProject.addTaskDefinition(taskName, taskClass);
}
Hashtable typedefs = project.getDataTypeDefinitions();
@@ -156,7 +168,7 @@
while (e.hasMoreElements()) {
String typeName = (String) e.nextElement();
Class typeClass = (Class) typedefs.get(typeName);
- p1.addDataTypeDefinition(typeName, typeClass);
+ newProject.addDataTypeDefinition(typeName, typeClass);
}
// set user-defined or all properties from calling project
@@ -169,23 +181,24 @@
// set Java built-in properties separately,
// b/c we won't inherit them.
- project.setSystemProperties();
+ newProject.setSystemProperties();
}
e = prop1.keys();
while (e.hasMoreElements()) {
String arg = (String) e.nextElement();
String value = (String) prop1.get(arg);
- if (inheritAll == true)
- p1.setProperty(arg, value);
- else
- p1.setUserProperty(arg, value);
+ if (inheritAll == true){
+ newProject.setProperty(arg, value);
+ } else {
+ newProject.setUserProperty(arg, value);
+ }
}
}
protected void handleOutput(String line) {
- if (p1 != null) {
- p1.demuxOutput(line, false);
+ if (newProject != null) {
+ newProject.demuxOutput(line, false);
}
else {
super.handleOutput(line);
@@ -193,8 +206,8 @@
}
protected void handleErrorOutput(String line) {
- if (p1 != null) {
- p1.demuxOutput(line, true);
+ if (newProject != null) {
+ newProject.demuxOutput(line, true);
}
else {
super.handleErrorOutput(line);
@@ -206,17 +219,18 @@
*/
public void execute() throws BuildException {
try {
- if (p1 == null) {
+ if (newProject == null) {
reinit();
}
- if(dir == null)
+ if (dir == null) {
dir = project.getBaseDir();
+ }
initializeProject();
- p1.setBaseDir(dir);
- p1.setUserProperty("basedir" , dir.getAbsolutePath());
+ newProject.setBaseDir(dir);
+ newProject.setUserProperty("basedir" , dir.getAbsolutePath());
// Override with local-defined properties
Enumeration e = properties.elements();
@@ -225,8 +239,9 @@
p.execute();
}
- if (antFile == null)
+ if (antFile == null){
antFile = "build.xml";
+ }
File file = new File(antFile);
if (!file.isAbsolute()) {
@@ -237,37 +252,52 @@
}
}
- p1.setUserProperty( "ant.file" , antFile );
- ProjectHelper.configureProject(p1, new File(antFile));
+ newProject.setUserProperty( "ant.file" , antFile );
+ ProjectHelper.configureProject(newProject, new File(antFile));
if (target == null) {
- target = p1.getDefaultTarget();
+ target = newProject.getDefaultTarget();
}
// Are we trying to call the target in which we are defined?
- if (p1.getBaseDir().equals(project.getBaseDir()) &&
- p1.getProperty("ant.file").equals(project.getProperty("ant.file")) &&
+ if (newProject.getBaseDir().equals(project.getBaseDir()) &&
+ newProject.getProperty("ant.file").equals(project.getProperty("ant.file")) &&
getOwningTarget() != null &&
target.equals(this.getOwningTarget().getName())) {
throw new BuildException("ant task calling its own parent target");
}
- p1.executeTarget(target);
+ newProject.executeTarget(target);
} finally {
// help the gc
- p1 = null;
+ newProject = null;
}
}
+ /**
+ * ...
+ */
public void setDir(File d) {
this.dir = d;
}
+ /**
+ * set the build file, it can be either absolute or relative.
+ * If it is absolute, <tt>dir</tt> will be ignored, if it is
+ * relative it will be resolved relative to <tt>dir</tt>.
+ */
public void setAntfile(String s) {
+ // @note: it is a string and not a file to handle relative/absolute
+ // otherwise a relative file will be resolved based on the current
+ // basedir.
this.antFile = s;
}
+ /**
+ * set the target to execute. If none is defined it will
+ * execute the default target of the build file
+ */
public void setTarget(String s) {
this.target = s;
}
@@ -276,12 +306,12 @@
this.output = s;
}
+ /** create a property to pass to the new project as a 'user property' */
public Property createProperty() {
- if (p1 == null) {
+ if (newProject == null) {
reinit();
}
-
- Property p=(Property)p1.createTask("property");
+ Property p=(Property)newProject.createTask("property");
p.setUserProperty(true);
properties.addElement( p );
return p;