You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by an...@apache.org on 2013/05/13 00:37:57 UTC

svn commit: r1481662 - in /ant/core/trunk: ./ src/main/org/apache/tools/ant/ src/main/org/apache/tools/ant/helper/ src/main/org/apache/tools/ant/taskdefs/ src/tests/antunit/taskdefs/ src/tests/antunit/taskdefs/importtests/

Author: antoine
Date: Sun May 12 22:37:56 2013
New Revision: 1481662

URL: http://svn.apache.org/r1481662
Log:
fix for Target rewriting for nested "include" only works when "as" is specified, Bugzilla PR 54940

Added:
    ant/core/trunk/src/tests/antunit/taskdefs/importtests/w.xml   (with props)
    ant/core/trunk/src/tests/antunit/taskdefs/importtests/x.xml   (with props)
    ant/core/trunk/src/tests/antunit/taskdefs/importtests/y.xml   (with props)
    ant/core/trunk/src/tests/antunit/taskdefs/importtests/z.xml   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java
    ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
    ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1481662&r1=1481661&r2=1481662&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Sun May 12 22:37:56 2013
@@ -4,6 +4,9 @@ Changes from Ant 1.9.0 TO current
 Changes that could break older environments:
 -------------------------------------------
 
+ * Users who have their own ProjectHelper implementation will need to change it because the import and include tasks
+   will now default the targetPrefix to ProjectHelper.USE_PROJECT_NAME_AS_TARGET_PREFIX.
+   Users using the default ProjectHelper2 with ant need not worry about this change done to fix Bugzilla Report 54940.
 
 
 Fixed bugs:
@@ -21,6 +24,11 @@ Fixed bugs:
  * Fixed loading of external dependencies in JUnit task.
    Bugzilla Report 54835.
 
+ * Target rewriting for nested "include" only works when "as" is specified.
+   See also "Changes that could break older environments"
+   Bugzilla Report 54940.
+
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java?rev=1481662&r1=1481661&r2=1481662&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java Sun May 12 22:37:56 2013
@@ -72,6 +72,12 @@ public class ProjectHelper {
     public static final String PROJECTHELPER_REFERENCE = MagicNames.REFID_PROJECT_HELPER;
 
     /**
+     * constant to denote use project name as target prefix
+     * @since Ant 1.9.1
+     */
+    public static final String USE_PROJECT_NAME_AS_TARGET_PREFIX = "USE_PROJECT_NAME_AS_TARGET_PREFIX";
+
+    /**
      * Configures the project with the contents of the specified build file.
      *
      * @param project The project to configure. Must not be <code>null</code>.

Modified: ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java?rev=1481662&r1=1481661&r2=1481662&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java Sun May 12 22:37:56 2013
@@ -732,12 +732,10 @@ public class ProjectHelper2 extends Proj
                             project.setName(value);
                             project.addReference(value, project);
                         } else if (isInIncludeMode()) {
-                            if (!"".equals(value)
-                                && (getCurrentTargetPrefix() == null
-                                    || getCurrentTargetPrefix().length() == 0)
-                                ) {
+                            if (!"".equals(value) && getCurrentTargetPrefix()!= null && getCurrentTargetPrefix().endsWith(ProjectHelper.USE_PROJECT_NAME_AS_TARGET_PREFIX))  {
+                                String newTargetPrefix = getCurrentTargetPrefix().replace(ProjectHelper.USE_PROJECT_NAME_AS_TARGET_PREFIX, value);
                                 // help nested include tasks
-                                setCurrentTargetPrefix(value);
+                                setCurrentTargetPrefix(newTargetPrefix);
                             }
                         }
                     }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java?rev=1481662&r1=1481661&r2=1481662&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java Sun May 12 22:37:56 2013
@@ -64,7 +64,7 @@ import java.util.Vector;
 public class ImportTask extends Task {
     private String file;
     private boolean optional;
-    private String targetPrefix;
+    private String targetPrefix = ProjectHelper.USE_PROJECT_NAME_AS_TARGET_PREFIX;
     private String prefixSeparator = ".";
     private final Union resources = new Union();
     private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
@@ -199,7 +199,7 @@ public class ImportTask extends Task {
             return;
         }
 
-        // nested invokations are possible like an imported file
+        // nested invocations are possible like an imported file
         // importing another one
         String oldPrefix = ProjectHelper.getCurrentTargetPrefix();
         boolean oldIncludeMode = ProjectHelper.isInIncludeMode();
@@ -209,7 +209,9 @@ public class ImportTask extends Task {
             if (isInIncludeMode() && oldPrefix != null
                 && targetPrefix != null) {
                 prefix = oldPrefix + oldSep + targetPrefix;
-            } else if (targetPrefix != null) {
+            } else if (isInIncludeMode()) {
+                prefix = targetPrefix;
+            } else if (!ProjectHelper.USE_PROJECT_NAME_AS_TARGET_PREFIX.equals(targetPrefix)) {
                 prefix = targetPrefix;
             } else {
                 prefix = oldPrefix;

Added: ant/core/trunk/src/tests/antunit/taskdefs/importtests/w.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/importtests/w.xml?rev=1481662&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/importtests/w.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/importtests/w.xml Sun May 12 22:37:56 2013
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project name="w">
+    <echo>${ant.file.w}</echo>
+    <include file="x.xml"/>
+    <target name="ww" depends="x.xx, x.y.yy, x.y.z.zz"/>
+</project>

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/importtests/w.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/core/trunk/src/tests/antunit/taskdefs/importtests/x.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/importtests/x.xml?rev=1481662&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/importtests/x.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/importtests/x.xml Sun May 12 22:37:56 2013
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project name="x">
+    <echo>${ant.file.x}</echo>
+    <include file="y.xml"/>
+    <target name="xx" depends="y.yy, y.z.zz"/>
+</project>

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/importtests/x.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/core/trunk/src/tests/antunit/taskdefs/importtests/y.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/importtests/y.xml?rev=1481662&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/importtests/y.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/importtests/y.xml Sun May 12 22:37:56 2013
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project name="y">
+    <echo>${ant.file.y}</echo>
+    <include file="z.xml" as="z"/>
+    <target name="yy" depends="z.zz"/>
+</project>

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/importtests/y.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/core/trunk/src/tests/antunit/taskdefs/importtests/z.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/importtests/z.xml?rev=1481662&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/importtests/z.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/importtests/z.xml Sun May 12 22:37:56 2013
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project name="z">
+    <echo>${ant.file.z}</echo>
+    <target name="zz"/>
+</project>

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/importtests/z.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml?rev=1481662&r1=1481661&r2=1481662&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml Sun May 12 22:37:56 2013
@@ -18,9 +18,9 @@
 <project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
   <import file="../antunit-base.xml" />
 
-  <include>
-    <file file="importtests/a.xml"/>
-  </include>
+ <include>
+  <file file="importtests/a.xml"/>
+</include>
   <include file="importtests/b.xml" as="c"/>
 
   <target name="testNoExplicitPrefix" depends="a.a">
@@ -50,4 +50,9 @@
   <!-- really only tests that the targets have the expected names by
        forcing an exception if the dependencies don't exist -->
   <target name="testNesting" depends="nested.b::b, nested.aa"/>
+  <target name="testNoExplicitPrefixNested">
+    <ant target="x.y.z.zz" antfile="importtests/w.xml"/>
+  </target>
+
+
 </project>