From b7258ab797862fb2e9f07b881f2568ae6691b386 Mon Sep 17 00:00:00 2001 From: Costin Manolache Date: Wed, 23 Feb 2000 20:46:53 +0000 Subject: [PATCH] - added "deep" properties to - you can now set properties for the called antfile - build.xml: read ~/.ant.properties if exist, it will allow override of local properties ( you don't have to type -Dfoo=bar each time you run ant ) - changed dist.dir to ant.dist.dir ( to allow users to set the destinations per project in ant.properties ) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267612 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 54 +++++++++--------- src/main/org/apache/tools/ant/Project.java | 2 +- .../org/apache/tools/ant/taskdefs/Ant.java | 55 ++++++++++++++++--- .../apache/tools/ant/taskdefs/Property.java | 32 +++++++++-- 4 files changed, 103 insertions(+), 40 deletions(-) diff --git a/build.xml b/build.xml index 59609a816..dc09bcc97 100644 --- a/build.xml +++ b/build.xml @@ -20,13 +20,17 @@ - + + + + @@ -93,41 +97,41 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + - + @@ -136,7 +140,7 @@ - + diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 3d5cf1966..5ef7a8794 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -179,7 +179,7 @@ public class Project { } public void setUserProperty(String name, String value) { - log("Setting project property: " + name + " -> " + + log("Setting ro project property: " + name + " -> " + value, MSG_VERBOSE); userProperties.put(name, value); properties.put(name, value); diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java index acddb5440..86e774d9a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ant.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java @@ -61,6 +61,20 @@ import java.util.*; /** * Call Ant in a sub-project * + *
+ *    
+ *    
+ *      
+ *      
+ *     
+ *  
+ *
+ * 
+ *    
+ * 
+ * 
+ * + * * @author costin@dnt.ro */ public class Ant extends Task { @@ -69,11 +83,11 @@ public class Ant extends Task { private String antFile = null; private String target = null; - /** - * Do the execution. - */ - public void execute() throws BuildException { - Project p1 = new Project(project.getOutput(), project.getOutputLevel()); + Vector properties=new Vector(); + Project p1; + + public void init() { + p1 = new Project(project.getOutput(), project.getOutputLevel()); // set user-define properties Hashtable prop1 = project.getProperties(); @@ -81,12 +95,29 @@ public class Ant extends Task { while (e.hasMoreElements()) { String arg = (String) e.nextElement(); String value = (String) prop1.get(arg); - p1.setUserProperty(arg, value); + p1.setProperty(arg, value); } + } + + /** + * Do the execution. + */ + public void execute() throws BuildException { + if( antFile==null) throw new BuildException( "ant required antFile property "); - p1.setBasedir(dir); + if( dir==null) dir="."; + p1.setBasedir(dir); p1.setUserProperty("basedir" , dir); - if (antFile == null) antFile = dir + "/build.xml"; + + // Override with local-defined properties + Enumeration e = properties.elements(); + while (e.hasMoreElements()) { + Property p=(Property) e.nextElement(); + // System.out.println("Setting " + p.getName()+ " " + p.getValue()); + p.init(); + } + + if (antFile == null) antFile = dir + "/build.xml"; ProjectHelper.configureProject(p1, new File(antFile)); if (target == null) { @@ -107,4 +138,12 @@ public class Ant extends Task { public void setTarget(String s) { this.target = s; } + + // XXX replace with createProperty!! + public Task addProperty() { + Property p=(Property)p1.createTask("property"); + p.setUserProperty(true); + properties.addElement( p ); + return p; + } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Property.java b/src/main/org/apache/tools/ant/taskdefs/Property.java index 0c2cbd9d9..6c4e58c9d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Property.java +++ b/src/main/org/apache/tools/ant/taskdefs/Property.java @@ -65,19 +65,29 @@ import java.util.*; */ public class Property extends Task { - private String name; - private String value; - private String file; - private String resource; + String name; + String value; + String file; + String resource; + + boolean userProperty=false; // set read-only properties public void setName(String name) { this.name = name; } + public String getName() { + return name; + } + public void setValue(String value) { this.value = value; } + public String getValue() { + return value; + } + public void setFile(String file) { this.file = file; } @@ -90,7 +100,10 @@ public class Property extends Task { try { if ((name != null) && (value != null)) { String v = ProjectHelper.replaceProperties(value, project.getProperties()); - project.setProperty(name, v); + if( userProperty ) + project.setUserProperty(name, v); + else + project.setProperty(name, v); } if (file != null) loadFile(file); @@ -135,7 +148,14 @@ public class Property extends Task { String name = (String) e.nextElement(); String value = (String) props.getProperty(name); String v = ProjectHelper.replaceProperties(value, project.getProperties()); - project.setProperty(name, v); + if( userProperty ) + project.setUserProperty(name, v); + else + project.setProperty(name, v); } } + + public void setUserProperty( boolean userP ) { + userProperty=userP; + } }