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-ffa450edef68master
@@ -53,7 +53,11 @@ Fixed bugs: | |||||
* MacroDef did not allow attributes named 'description'. Bugzilla Report 27175. | * 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: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -329,13 +329,6 @@ | |||||
<patternset id="teststhatfail"> | <patternset id="teststhatfail"> | ||||
<exclude name="${optional.package}/BeanShellScriptTest.java"/> | <exclude name="${optional.package}/BeanShellScriptTest.java"/> | ||||
<exclude name="${optional.package}/jdepend/JDependTest.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> | </patternset> | ||||
<!-- | <!-- | ||||
@@ -1611,4 +1604,4 @@ | |||||
description="--> creates a minimum distribution in ./dist" | description="--> creates a minimum distribution in ./dist" | ||||
depends="dist-lite"/> | depends="dist-lite"/> | ||||
</project> | |||||
</project> |
@@ -804,6 +804,14 @@ public class ProjectHelper2 extends ProjectHelper { | |||||
// If the name has already been defined ( import for example ) | // If the name has already been defined ( import for example ) | ||||
if (currentTargets.containsKey(name)) { | 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. | // Alter the name. | ||||
if (context.getCurrentProjectName() != null) { | if (context.getCurrentProjectName() != null) { | ||||
String newName = context.getCurrentProjectName() | String newName = context.getCurrentProjectName() | ||||
@@ -206,8 +206,15 @@ public class ProjectTest extends TestCase { | |||||
public void testDuplicateTargets() { | public void testDuplicateTargets() { | ||||
// fail, because buildfile contains two targets with the same name | // 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() { | public void testDuplicateTargetsImport() { | ||||
@@ -265,4 +272,4 @@ public class ProjectTest extends TestCase { | |||||
class DummyTaskPackage extends Task { | class DummyTaskPackage extends Task { | ||||
public DummyTaskPackage() {} | public DummyTaskPackage() {} | ||||
public void execute() {} | public void execute() {} | ||||
} | |||||
} |