You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@locus.apache.org on 2000/02/23 21:46:53 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Ant.java Property.java
costin 00/02/23 12:46:53
Modified: . build.xml
src/main/org/apache/tools/ant Project.java
src/main/org/apache/tools/ant/taskdefs Ant.java
Property.java
Log:
- added "deep" properties to <ant> - 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 )
Revision Changes Path
1.11 +29 -25 jakarta-ant/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/build.xml,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- build.xml 2000/02/12 16:59:25 1.10
+++ build.xml 2000/02/23 20:46:52 1.11
@@ -20,13 +20,17 @@
<property name="build.dir" value="build"/>
<property name="build.classes" value="build/classes"/>
<property name="build.javadocs" value="build/javadocs"/>
- <property name="dist.dir" value="dist"/>
+ <property name="ant.dist.dir" value="dist"/>
<property name="classpath" value="lib/xml.jar"/>
<property name="packages" value="org.apache.tools.*"/>
<property name="manifest" value="src/etc/manifest"/>
<property name="build.compiler" value="classic"/>
+
+ <!-- Give user a chance to override without editing this file
+ (and without typing -D each time it compiles it -->
+ <property file="${user.home}/.ant.properties" />
</target>
<!-- =================================================================== -->
@@ -93,41 +97,41 @@
<!-- Creates the distribution -->
<!-- =================================================================== -->
<target name="dist" depends="jar,javadocs">
- <mkdir dir="${dist.dir}"/>
- <mkdir dir="${dist.dir}/bin"/>
- <mkdir dir="${dist.dir}/lib"/>
- <mkdir dir="${dist.dir}/docs"/>
- <mkdir dir="${dist.dir}/docs/api"/>
- <mkdir dir="${dist.dir}/src"/>
-
- <copydir src="${src.dir}" dest="${dist.dir}/src"/>
- <copydir src="${lib.dir}" dest="${dist.dir}/lib"/>
-
- <copyfile src="build.xml" dest="${dist.dir}/lib/build.xml"/>
- <copydir src="src/bin" dest="${dist.dir}/bin"/>
- <copydir src="${docs.dir}" dest="${dist.dir}/docs"/>
- <copydir src="${build.javadocs}" dest="${dist.dir}/docs/api"/>
-
- <chmod perm="+x" src="${dist.dir}/bin/ant"/>
- <chmod perm="+x" src="${dist.dir}/bin/antRun"/>
-
- <copyfile src="README" dest="${dist.dir}/README"/>
- <copyfile src="TODO" dest="${dist.dir}/TODO"/>
- <copyfile src="LICENSE" dest="${dist.dir}/LICENSE"/>
+ <mkdir dir="${ant.dist.dir}"/>
+ <mkdir dir="${ant.dist.dir}/bin"/>
+ <mkdir dir="${ant.dist.dir}/lib"/>
+ <mkdir dir="${ant.dist.dir}/docs"/>
+ <mkdir dir="${ant.dist.dir}/docs/api"/>
+ <mkdir dir="${ant.dist.dir}/src"/>
+
+ <copydir src="${src.dir}" dest="${ant.dist.dir}/src"/>
+ <copydir src="${lib.dir}" dest="${ant.dist.dir}/lib"/>
+
+ <copyfile src="build.xml" dest="${ant.dist.dir}/lib/build.xml"/>
+ <copydir src="src/bin" dest="${ant.dist.dir}/bin"/>
+ <copydir src="${docs.dir}" dest="${ant.dist.dir}/docs"/>
+ <copydir src="${build.javadocs}" dest="${ant.dist.dir}/docs/api"/>
+
+ <chmod perm="+x" src="${ant.dist.dir}/bin/ant"/>
+ <chmod perm="+x" src="${ant.dist.dir}/bin/antRun"/>
+
+ <copyfile src="README" dest="${ant.dist.dir}/README"/>
+ <copyfile src="TODO" dest="${ant.dist.dir}/TODO"/>
+ <copyfile src="LICENSE" dest="${ant.dist.dir}/LICENSE"/>
</target>
<!-- =================================================================== -->
<!-- Packages the distribution with ZIP -->
<!-- =================================================================== -->
<target name="dist-zip" depends="dist">
- <zip zipfile="${Name}-${version}.zip" basedir="${dist.dir}" includes="**"/>
+ <zip zipfile="${Name}-${version}.zip" basedir="${ant.dist.dir}" includes="**"/>
</target>
<!-- =================================================================== -->
<!-- Packages the distribution with TAR-GZIP -->
<!-- =================================================================== -->
<target name="dist-tgz" depends="dist">
- <tar tarfile="${Name}-${version}.tar" basedir="${dist.dir}" includes="**"/>
+ <tar tarfile="${Name}-${version}.tar" basedir="${ant.dist.dir}" includes="**"/>
<gzip zipfile="${Name}-${version}.tar.gz" src="${Name}-${version}.tar"/>
</target>
@@ -136,7 +140,7 @@
<!-- =================================================================== -->
<target name="clean" depends="init">
<deltree dir="${build.dir}"/>
- <deltree dir="${dist.dir}"/>
+ <deltree dir="${ant.dist.dir}"/>
</target>
<!-- =================================================================== -->
1.10 +1 -1 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Project.java 2000/02/14 12:19:26 1.9
+++ Project.java 2000/02/23 20:46:53 1.10
@@ -179,7 +179,7 @@
}
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);
1.3 +47 -8 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Ant.java 2000/01/24 00:15:08 1.2
+++ Ant.java 2000/02/23 20:46:53 1.3
@@ -61,6 +61,20 @@
/**
* Call Ant in a sub-project
*
+ * <pre>
+ * <target name="foo" depends="init">
+ * <ant antfile="build.xml" target="bar" >
+ * <property name="property1" value="aaaaa" />
+ * <property name="foo" value="baz" />
+ * </ant>
+ * </target>
+ *
+ * <target name="bar" depends="init">
+ * <echo message="prop is ${property1} ${foo}" />
+ * </target>
+ * </pre>
+ *
+ *
* @author costin@dnt.ro
*/
public class Ant extends Task {
@@ -69,11 +83,11 @@
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 @@
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) {
@@ -106,5 +137,13 @@
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;
}
}
1.4 +26 -6 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java
Index: Property.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Property.java 2000/02/11 01:31:24 1.3
+++ Property.java 2000/02/23 20:46:53 1.4
@@ -65,19 +65,29 @@
*/
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 @@
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 @@
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;
}
}