Browse Source

Restore the ability to define properties and taskdefs outside the scope

of any target.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267645 13f79535-47bb-0310-9956-ffa450edef68
master
Sam Ruby 25 years ago
parent
commit
4461e98f84
2 changed files with 60 additions and 38 deletions
  1. +32
    -29
      build.xml
  2. +28
    -9
      src/main/org/apache/tools/ant/ProjectHelper.java

+ 32
- 29
build.xml View File

@@ -6,47 +6,50 @@


<project name="Ant" default="main" basedir="."> <project name="Ant" default="main" basedir=".">


<target name="init">
<property name="Name" value="Ant"/>
<property name="name" value="ant"/>
<property name="version" value="1.0-rc1"/>

<property name="ant.home" value="."/>
<property name="bin.dir" value="bin"/>
<property name="src.bin.dir" value="src/bin"/>
<property name="src.dir" value="${basedir}/src/main"/>
<property name="lib.dir" value="lib"/>
<property name="docs.dir" value="docs"/>
<property name="build.dir" value="build"/>
<property name="build.classes" value="build/classes"/>
<property name="build.javadocs" value="build/javadocs"/>
<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"/>
<property name="Name" value="Ant"/>
<property name="name" value="ant"/>
<property name="version" value="1.0-rc1"/>


<property name="ant.home" value="."/>
<property name="bin.dir" value="bin"/>
<property name="src.bin.dir" value="src/bin"/>
<property name="src.dir" value="${basedir}/src/main"/>
<property name="lib.dir" value="lib"/>
<property name="docs.dir" value="docs"/>
<property name="build.dir" value="build"/>
<property name="build.classes" value="build/classes"/>
<property name="build.javadocs" value="build/javadocs"/>
<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" />

<!-- =================================================================== -->
<!-- Check to see what optional dependencies are available -->
<!-- =================================================================== -->
<target name="check_for_optional_packages">
<available property="bsf.present" classname="com.ibm.bsf.BSFManager" /> <available property="bsf.present" classname="com.ibm.bsf.BSFManager" />
<available property="netrexx.present" classname="netrexx.lang.Rexx" /> <available property="netrexx.present" classname="netrexx.lang.Rexx" />

<!-- 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> </target>


<!-- =================================================================== --> <!-- =================================================================== -->
<!-- Prepares the build directory --> <!-- Prepares the build directory -->
<!-- =================================================================== --> <!-- =================================================================== -->
<target name="prepare" depends="init">
<target name="prepare">
<mkdir dir="${build.dir}"/> <mkdir dir="${build.dir}"/>
</target> </target>


<!-- =================================================================== --> <!-- =================================================================== -->
<!-- Compiles the source code --> <!-- Compiles the source code -->
<!-- =================================================================== --> <!-- =================================================================== -->
<target name="compile" depends="prepare">
<target name="compile" depends="prepare,check_for_optional_packages">
<mkdir dir="${build.classes}"/> <mkdir dir="${build.classes}"/>
<javac srcdir="${src.dir}" <javac srcdir="${src.dir}"
destdir="${build.classes}" destdir="${build.classes}"
@@ -143,7 +146,7 @@
<!-- =================================================================== --> <!-- =================================================================== -->
<!-- Cleans up generated stuff --> <!-- Cleans up generated stuff -->
<!-- =================================================================== --> <!-- =================================================================== -->
<target name="clean" depends="init">
<target name="clean">
<deltree dir="${build.dir}"/> <deltree dir="${build.dir}"/>
<deltree dir="${ant.dist.dir}"/> <deltree dir="${ant.dist.dir}"/>
</target> </target>
@@ -161,7 +164,7 @@


<!-- in progress ! (may not work) --> <!-- in progress ! (may not work) -->


<target name="get.snapshot" depends="init">
<target name="get.snapshot">
<get src="http://jakarta.apache.org/build/tmp/ant/ant.src.zip" dest="ant-src.zip" /> <get src="http://jakarta.apache.org/build/tmp/ant/ant.src.zip" dest="ant-src.zip" />
<expand src="ant-src.zip" dest="." /> <expand src="ant-src.zip" dest="." />
</target> </target>


+ 28
- 9
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -61,6 +61,7 @@ import java.lang.reflect.*;
import java.util.*; import java.util.*;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.w3c.dom.*; import org.w3c.dom.*;
import org.apache.tools.ant.taskdefs.*;


/** /**
* Configures a Project (complete with Targets and Tasks) based on * Configures a Project (complete with Targets and Tasks) based on
@@ -129,15 +130,33 @@ public class ProjectHelper {


// configureTaskDefs(project, root); // configureTaskDefs(project, root);


// set up the targets into the project
configureTargets(project, root);
// set up the taskdefs, properties, and targets into the project
configureProject(project, root);
} }


private static void configureTargets(Project project, Element root)
private static void configureProject(Project project, Element root)
throws BuildException throws BuildException
{ {
// configure taskdefs
NodeList list = root.getElementsByTagName("taskdef");
for (int i = 0; i < list.getLength(); i++) {
Taskdef taskdef = new Taskdef();
configure(project, taskdef, (Element)list.item(i));
taskdef.setProject(project);
taskdef.init();
}

// configure properties
list = root.getElementsByTagName("property");
for (int i = 0; i < list.getLength(); i++) {
Property property = new Property();
configure(project, property, (Element)list.item(i));
property.setProject(project);
property.init();
}

// configure targets // configure targets
NodeList list = root.getElementsByTagName("target");
list = root.getElementsByTagName("target");
for (int i = 0; i < list.getLength(); i++) { for (int i = 0; i < list.getLength(); i++) {
Element element = (Element)list.item(i); Element element = (Element)list.item(i);
String targetName = element.getAttribute("name"); String targetName = element.getAttribute("name");
@@ -199,8 +218,7 @@ public class ProjectHelper {
// get the attributes of this element and reflect them // get the attributes of this element and reflect them
// into the task // into the task


NamedNodeMap nodeMap = element.getAttributes();
configure(project, task, nodeMap);
configure(project, task, element);
task.init(); task.init();
task.setTarget(target); task.setTarget(target);
target.addTask(task); target.addTask(task);
@@ -253,8 +271,7 @@ public class ProjectHelper {
targetClass.getMethod(methodName, new Class[]{}); targetClass.getMethod(methodName, new Class[]{});
Object child = addProp.invoke(target, new Object[] {}); Object child = addProp.invoke(target, new Object[] {});


NamedNodeMap nodeMap = element.getAttributes();
configure(project, child, nodeMap);
configure(project, child, element);


processNestedProperties(project, child, element); processNestedProperties(project, child, element);
} catch (NoSuchMethodException nsme) { } catch (NoSuchMethodException nsme) {
@@ -272,9 +289,11 @@ public class ProjectHelper {


private static void configure(Project project, private static void configure(Project project,
Object target, Object target,
NamedNodeMap nodeMap)
Element element)
throws BuildException throws BuildException
{ {
NamedNodeMap nodeMap = element.getAttributes();

if( target instanceof TaskAdapter ) if( target instanceof TaskAdapter )
target=((TaskAdapter)target).getProxy(); target=((TaskAdapter)target).getProxy();




Loading…
Cancel
Save