git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274561 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -143,4 +143,23 @@ | |||||
| <property name="test" value="5" /> | <property name="test" value="5" /> | ||||
| <echo message="The value of test is ${test}" /> | <echo message="The value of test is ${test}" /> | ||||
| </target> | </target> | ||||
| <target name="test-propertyset"> | |||||
| <property name="test1" value="1"/> | |||||
| <property name="test2" value="2"/> | |||||
| <propertyset id="set"> | |||||
| <propertyref name="test1"/> | |||||
| <mapper type="glob" from="*" to="*.x"/> | |||||
| </propertyset> | |||||
| <ant antfile="ant.xml" target="echo-for-propertyset-test" | |||||
| inheritall="false"> | |||||
| <propertyset refid="set"/> | |||||
| </ant> | |||||
| </target> | |||||
| <target name="echo-for-propertyset-test"> | |||||
| <echo>test1 is ${test1}</echo> | |||||
| <echo>test2 is ${test2}</echo> | |||||
| <echo>test1.x is ${test1.x}</echo> | |||||
| </target> | |||||
| </project> | </project> | ||||
| @@ -69,6 +69,7 @@ import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
| import org.apache.tools.ant.ProjectHelper; | import org.apache.tools.ant.ProjectHelper; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.types.PropertySet; | |||||
| import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
| /** | /** | ||||
| @@ -129,6 +130,9 @@ public class Ant extends Task { | |||||
| /** The stream to which output is to be written. */ | /** The stream to which output is to be written. */ | ||||
| private PrintStream out = null; | private PrintStream out = null; | ||||
| /** the sets of properties to pass to the new project */ | |||||
| private Vector propertySets = new Vector(); | |||||
| /** | /** | ||||
| * If true, pass all properties to the new Ant project. | * If true, pass all properties to the new Ant project. | ||||
| * Defaults to true. | * Defaults to true. | ||||
| @@ -264,23 +268,13 @@ public class Ant extends Task { | |||||
| } else { | } else { | ||||
| // set all properties from calling project | // set all properties from calling project | ||||
| addAlmostAll(getProject().getProperties()); | |||||
| } | |||||
| Hashtable props = getProject().getProperties(); | |||||
| e = props.keys(); | |||||
| while (e.hasMoreElements()) { | |||||
| String arg = e.nextElement().toString(); | |||||
| if ("basedir".equals(arg) || "ant.file".equals(arg)) { | |||||
| // basedir and ant.file get special treatment in execute() | |||||
| continue; | |||||
| } | |||||
| String value = props.get(arg).toString(); | |||||
| // don't re-set user properties, avoid the warning message | |||||
| if (newProject.getProperty(arg) == null){ | |||||
| // no user property | |||||
| newProject.setNewProperty(arg, value); | |||||
| } | |||||
| } | |||||
| e = propertySets.elements(); | |||||
| while (e.hasMoreElements()) { | |||||
| PropertySet ps = (PropertySet) e.nextElement(); | |||||
| addAlmostAll(ps.getProperties()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -550,6 +544,31 @@ public class Ant extends Task { | |||||
| newProject.addReference(newKey, copy); | newProject.addReference(newKey, copy); | ||||
| } | } | ||||
| /** | |||||
| * Copies all properties from the given table to the new project - | |||||
| * ommiting those that have already been set in the new project as | |||||
| * well as properties named basedir or ant.file. | |||||
| * | |||||
| * @since Ant 1.6 | |||||
| */ | |||||
| private void addAlmostAll(Hashtable props) { | |||||
| Enumeration e = props.keys(); | |||||
| while (e.hasMoreElements()) { | |||||
| String key = e.nextElement().toString(); | |||||
| if ("basedir".equals(key) || "ant.file".equals(key)) { | |||||
| // basedir and ant.file get special treatment in execute() | |||||
| continue; | |||||
| } | |||||
| String value = props.get(key).toString(); | |||||
| // don't re-set user properties, avoid the warning message | |||||
| if (newProject.getProperty(key) == null){ | |||||
| // no user property | |||||
| newProject.setNewProperty(key, value); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * The directory to use as a base directory for the new Ant project. | * The directory to use as a base directory for the new Ant project. | ||||
| * Defaults to the current project's basedir, unless inheritall | * Defaults to the current project's basedir, unless inheritall | ||||
| @@ -617,6 +636,15 @@ public class Ant extends Task { | |||||
| references.addElement(r); | references.addElement(r); | ||||
| } | } | ||||
| /** | |||||
| * Set of properties to pass to the new project. | |||||
| * | |||||
| * @since Ant 1.6 | |||||
| */ | |||||
| public void addPropertyset(PropertySet ps) { | |||||
| propertySets.addElement(ps); | |||||
| } | |||||
| /** | /** | ||||
| * Helper class that implements the nested <reference> | * Helper class that implements the nested <reference> | ||||
| * element of <ant> and <antcall>. | * element of <ant> and <antcall>. | ||||
| @@ -166,6 +166,18 @@ public class CallTarget extends Task { | |||||
| callee.addReference(r); | callee.addReference(r); | ||||
| } | } | ||||
| /** | |||||
| * Set of properties to pass to the new project. | |||||
| * | |||||
| * @since Ant 1.6 | |||||
| */ | |||||
| public void addPropertyset(org.apache.tools.ant.types.PropertySet ps) { | |||||
| if (callee == null) { | |||||
| init(); | |||||
| } | |||||
| callee.addPropertyset(ps); | |||||
| } | |||||
| /** | /** | ||||
| * Target to execute, required. | * Target to execute, required. | ||||
| */ | */ | ||||
| @@ -68,6 +68,7 @@ import org.apache.tools.ant.types.Path; | |||||
| import org.apache.tools.ant.types.DirSet; | import org.apache.tools.ant.types.DirSet; | ||||
| import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
| import org.apache.tools.ant.types.FileList; | import org.apache.tools.ant.types.FileList; | ||||
| import org.apache.tools.ant.types.PropertySet; | |||||
| import org.apache.tools.ant.types.Reference; | import org.apache.tools.ant.types.Reference; | ||||
| import org.apache.tools.ant.taskdefs.Ant; | import org.apache.tools.ant.taskdefs.Ant; | ||||
| @@ -97,6 +98,7 @@ public class SubAnt | |||||
| private Vector properties = new Vector(); | private Vector properties = new Vector(); | ||||
| private Vector references = new Vector(); | private Vector references = new Vector(); | ||||
| private Vector propertySets = new Vector(); | |||||
| /** | /** | ||||
| * Runs the various sub-builds. | * Runs the various sub-builds. | ||||
| @@ -238,6 +240,14 @@ public class SubAnt | |||||
| references.addElement(r); | references.addElement(r); | ||||
| } | } | ||||
| /** | |||||
| * Corresponds to <code><ant></code>'s | |||||
| * nested <code><propertyset></code> element. | |||||
| */ | |||||
| public void addPropertyset(PropertySet ps) { | |||||
| propertySets.addElement(ps); | |||||
| } | |||||
| /** | /** | ||||
| * Adds a directory set to the implicit build path. | * Adds a directory set to the implicit build path. | ||||
| * <p> | * <p> | ||||
| @@ -345,6 +355,10 @@ public class SubAnt | |||||
| copyProperty(ant.createProperty(), (Property) i.nextElement()); | copyProperty(ant.createProperty(), (Property) i.nextElement()); | ||||
| } | } | ||||
| for (Enumeration i = propertySets.elements(); i.hasMoreElements();) { | |||||
| ant.addPropertyset((PropertySet) i.nextElement()); | |||||
| } | |||||
| ant.setInheritRefs(inheritRefs); | ant.setInheritRefs(inheritRefs); | ||||
| for (Enumeration i = references.elements(); i.hasMoreElements();) { | for (Enumeration i = references.elements(); i.hasMoreElements();) { | ||||
| ant.addReference((Ant.Reference) i.nextElement()); | ant.addReference((Ant.Reference) i.nextElement()); | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
| * | * | ||||
| * Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
| * Copyright (c) 2000-2003 The Apache Software Foundation. All rights | |||||
| * reserved. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
| @@ -295,6 +295,13 @@ public class AntTest extends BuildFileTest { | |||||
| "The value of test is 4"); | "The value of test is 4"); | ||||
| } | } | ||||
| public void testPropertySet() { | |||||
| executeTarget("test-propertyset"); | |||||
| assertTrue(getLog().indexOf("test1 is ${test1}") > -1); | |||||
| assertTrue(getLog().indexOf("test2 is ${test2}") > -1); | |||||
| assertTrue(getLog().indexOf("test1.x is 1") > -1); | |||||
| } | |||||
| private class BasedirChecker implements BuildListener { | private class BasedirChecker implements BuildListener { | ||||
| private String[] expectedBasedirs; | private String[] expectedBasedirs; | ||||
| private int calls = 0; | private int calls = 0; | ||||