peterreilly 2005/01/13 05:43:45 Modified: . WHATSNEW src/main/org/apache/tools/ant/types Reference.java src/etc/testcases/taskdefs ant.xml src/etc/testcases/taskdefs/ant references.xml src/testcases/org/apache/tools/ant/taskdefs AntTest.java Log: Allow references to keep references to the project that they were created in and use that project to deference the reference. PR: 25777 Obtained from: Jesse Glick Revision Changes Path 1.712 +5 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.711 retrieving revision 1.712 diff -u -r1.711 -r1.712 --- WHATSNEW 13 Jan 2005 09:25:26 -0000 1.711 +++ WHATSNEW 13 Jan 2005 13:43:45 -0000 1.712 @@ -16,6 +16,11 @@ it comes to bootclasspath handling), then the bootclasspath of the VM running Ant will be added to the bootclasspath you've specified. +* The Reference class now has a project field that will get + used (if set) in preference to the passed in project, when + dereferencing the reference. + Bugzilla Report 25777. + Fixed bugs: ----------- 1.19 +64 -5 ant/src/main/org/apache/tools/ant/types/Reference.java Index: Reference.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Reference.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- Reference.java 9 Mar 2004 16:48:41 -0000 1.18 +++ Reference.java 13 Jan 2005 13:43:45 -0000 1.19 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2002,2004 The Apache Software Foundation + * Copyright 2000-2002,2004-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,15 +27,31 @@ public class Reference { private String refid; + private Project project; + /** + * @deprecated Please use [EMAIL PROTECTED] Reference#Reference(Project,String)} instead. + */ public Reference() { - super(); } + /** + * @deprecated Please use [EMAIL PROTECTED] Reference#Reference(Project,String)} instead. + */ public Reference(String id) { - this(); setRefId(id); } + + /** + * Create a reference to a named ID in a particular project. + * @param p the project this reference is associated with + * @param id the name of this reference + * @since Ant 1.7 + */ + public Reference(Project p, String id) { + setRefId(id); + setProject(p); + } public void setRefId(String id) { refid = id; @@ -44,16 +60,59 @@ public String getRefId() { return refid; } + + /** + * Set the associated project. Should not normally be necessary; + * use [EMAIL PROTECTED] Reference#Reference(Project,String)}. + * @param p the project to use + * @since Ant 1.7 + */ + public void setProject(Project p) { + this.project = p; + } + + /** + * Get the associated project, if any; may be null. + * @return the associated project + * @since Ant 1.7 + */ + public Project getProject() { + return project; + } - public Object getReferencedObject(Project project) throws BuildException { + /** + * Resolve the reference, using the associated project if + * it set, otherwise use the passed in project. + * @param fallback the fallback project to use if the project attribute of + * reference is not set. + * @return the dereferenced object. + * @throws BuildException if the reference cannot be dereferenced. + */ + public Object getReferencedObject(Project fallback) throws BuildException { if (refid == null) { throw new BuildException("No reference specified"); } - Object o = project.getReference(refid); + + Object o = project == null ? fallback.getReference(refid) : project.getReference(refid); if (o == null) { throw new BuildException("Reference " + refid + " not found."); } return o; } + + /** + * Resolve the reference, looking in the associated project. + * @see Project#getReference + * @return the dereferenced object. + * @throws BuildException if the project is null or the reference cannot be dereferenced + * @since Ant 1.7 + */ + public Object getReferencedObject() throws BuildException { + if (project == null) { + throw new BuildException("No project set on reference to " + refid); + } + return getReferencedObject(project); + } + } 1.16 +14 -0 ant/src/etc/testcases/taskdefs/ant.xml Index: ant.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/ant.xml,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- ant.xml 23 Jul 2004 20:16:29 -0000 1.15 +++ ant.xml 13 Jan 2005 13:43:45 -0000 1.16 @@ -82,6 +82,20 @@ </ant> </target> + <target name="testInheritPath" description="try to pass a reference to a path, which refers itself to a second path"> + <property name="rootdir" location="."/> + <path id="project.classpath"> + <pathelement location="../classes"/> + </path> + <path id="test.classpath"> + <pathelement location="${rootdir}/test/testframework.jar"/> + <path refid="project.classpath"/> + </path> + <ant antfile="ant/references.xml" target="testInheritPath"> + <reference refid="test.classpath"/> + </ant> + </target> + <target name="testLogfilePlacement"> <ant antfile="ant.xml" target="dummy" output="test1.log" inheritall="false" /> 1.2 +7 -1 ant/src/etc/testcases/taskdefs/ant/references.xml Index: references.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/ant/references.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- references.xml 10 Dec 2001 10:10:35 -0000 1.1 +++ references.xml 13 Jan 2005 13:43:45 -0000 1.2 @@ -7,4 +7,10 @@ </target> <target name="dummy" /> -</project> \ No newline at end of file + + <target name="testInheritPath"> + <pathconvert refid="test.classpath" pathsep="${line.separator}" property="myprop"/> + <echo>${myprop}</echo> + </target> + +</project> 1.28 +6 -2 ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java Index: AntTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- AntTest.java 23 Jul 2004 20:16:29 -0000 1.27 +++ AntTest.java 13 Jan 2005 13:43:45 -0000 1.28 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -171,6 +171,10 @@ new boolean[] {false, true}, null); testReference("testRename", new String[] {"newpath", "newpath"}, new boolean[] {false, true}, p); + } + + public void testInheritPath() { + executeTarget("testInheritPath"); } protected void testReference(String target, String[] keys,
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]