Browse Source

fix for Target rewriting for nested "include" only works when "as" is specified, Bugzilla PR 54940

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1481662 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 12 years ago
parent
commit
51ce8fac72
9 changed files with 117 additions and 11 deletions
  1. +8
    -0
      WHATSNEW
  2. +6
    -0
      src/main/org/apache/tools/ant/ProjectHelper.java
  3. +3
    -5
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  4. +5
    -3
      src/main/org/apache/tools/ant/taskdefs/ImportTask.java
  5. +22
    -0
      src/tests/antunit/taskdefs/importtests/w.xml
  6. +22
    -0
      src/tests/antunit/taskdefs/importtests/x.xml
  7. +22
    -0
      src/tests/antunit/taskdefs/importtests/y.xml
  8. +21
    -0
      src/tests/antunit/taskdefs/importtests/z.xml
  9. +8
    -3
      src/tests/antunit/taskdefs/include-test.xml

+ 8
- 0
WHATSNEW View File

@@ -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:
--------------



+ 6
- 0
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -71,6 +71,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.
*


+ 3
- 5
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -732,12 +732,10 @@ public class ProjectHelper2 extends ProjectHelper {
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);
}
}
}


+ 5
- 3
src/main/org/apache/tools/ant/taskdefs/ImportTask.java View File

@@ -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;


+ 22
- 0
src/tests/antunit/taskdefs/importtests/w.xml View File

@@ -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>

+ 22
- 0
src/tests/antunit/taskdefs/importtests/x.xml View File

@@ -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>

+ 22
- 0
src/tests/antunit/taskdefs/importtests/y.xml View File

@@ -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>

+ 21
- 0
src/tests/antunit/taskdefs/importtests/z.xml View File

@@ -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>

+ 8
- 3
src/tests/antunit/taskdefs/include-test.xml View File

@@ -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>

Loading…
Cancel
Save