Browse Source

Fix for duplicate targets in the build file.

In ant 1.5 these were not allowed.
In ant 1.6, with import file's targets being allowed to
be overridden, duplicate targets where incorrectly allowed
in normal build files.
The fix just checks if the duplicate target is defined
in an imported file or in a "main" file.
Reported by: Dominique Devienne
See: http://marc.theaimsgroup.com/?t=107705039100004&r=1&w=2


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276165 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
3e7907c855
4 changed files with 24 additions and 12 deletions
  1. +5
    -1
      WHATSNEW
  2. +1
    -8
      build.xml
  3. +8
    -0
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  4. +10
    -3
      src/testcases/org/apache/tools/ant/ProjectTest.java

+ 5
- 1
WHATSNEW View File

@@ -53,7 +53,11 @@ Fixed bugs:

* MacroDef did not allow attributes named 'description'. Bugzilla Report 27175.

* Throw build exception if name attribute missing from patternset. Bugzilla Report 25982.
* Throw build exception if name attribute missing from patternset#NameEntry.
Bugzilla Report 25982.

* Throw build exception if target repeated in build file, but allow targets
to be repeated in imported files.

Other changes:
--------------


+ 1
- 8
build.xml View File

@@ -329,13 +329,6 @@
<patternset id="teststhatfail">
<exclude name="${optional.package}/BeanShellScriptTest.java"/>
<exclude name="${optional.package}/jdepend/JDependTest.java"/>
<!-- The org.apache.tools.ant.ProjectTest.testDuplicateTargets fails.
This is a known problem. It was noticed that duplicate targets were
not detected in ant 1.6.*, so a test was put in. But no code was put in
to fix the problem!
see http://marc.theaimsgroup.com/?l=ant-dev&m=107756336622453&w=2
-->
<exclude name="${ant.package}/ProjectTest.java"/>
</patternset>

<!--
@@ -1611,4 +1604,4 @@
description="--> creates a minimum distribution in ./dist"
depends="dist-lite"/>

</project>
</project>

+ 8
- 0
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -804,6 +804,14 @@ public class ProjectHelper2 extends ProjectHelper {

// If the name has already been defined ( import for example )
if (currentTargets.containsKey(name)) {
if (!context.isIgnoringProjectTag()) {
// not in an import'ed file
throw new BuildException(
"Duplicate target '" + name + "'",
new Location(context.getLocator().getSystemId(),
context.getLocator().getLineNumber(),
context.getLocator().getColumnNumber()));
}
// Alter the name.
if (context.getCurrentProjectName() != null) {
String newName = context.getCurrentProjectName()


+ 10
- 3
src/testcases/org/apache/tools/ant/ProjectTest.java View File

@@ -206,8 +206,15 @@ public class ProjectTest extends TestCase {

public void testDuplicateTargets() {
// fail, because buildfile contains two targets with the same name
BFT bft = new BFT("", "core/duplicate-target.xml");
bft.expectBuildException("twice", "Duplicate target");
try {
BFT bft = new BFT("", "core/duplicate-target.xml");
} catch (BuildException ex) {
assertEquals("specific message",
"Duplicate target 'twice'",
ex.getMessage());
return;
}
fail("Should throw BuildException about duplicate target");
}

public void testDuplicateTargetsImport() {
@@ -265,4 +272,4 @@ public class ProjectTest extends TestCase {
class DummyTaskPackage extends Task {
public DummyTaskPackage() {}
public void execute() {}
}
}

Loading…
Cancel
Save