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-ffa450edef68master
@@ -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> | |||
<!-- =================================================================== --> | |||
@@ -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); | |||
@@ -61,6 +61,20 @@ import java.util.*; | |||
/** | |||
* 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 @@ 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; | |||
} | |||
} |
@@ -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; | |||
} | |||
} |