diff --git a/WHATSNEW b/WHATSNEW index 5ef2fc380..428697723 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -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: -------------- diff --git a/build.xml b/build.xml index d78498f92..eb5654549 100644 --- a/build.xml +++ b/build.xml @@ -329,13 +329,6 @@ - - creates a minimum distribution in ./dist" depends="dist-lite"/> - \ No newline at end of file + diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java index dab946b1f..f949f8570 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java @@ -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() diff --git a/src/testcases/org/apache/tools/ant/ProjectTest.java b/src/testcases/org/apache/tools/ant/ProjectTest.java index 605d40412..6fda82295 100644 --- a/src/testcases/org/apache/tools/ant/ProjectTest.java +++ b/src/testcases/org/apache/tools/ant/ProjectTest.java @@ -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() {} -} \ No newline at end of file +}