From 3e7907c8550f987601c6f3f9ccdd93057393f9bc Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Fri, 27 Feb 2004 11:45:15 +0000 Subject: [PATCH] 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 --- WHATSNEW | 6 +++++- build.xml | 9 +-------- .../org/apache/tools/ant/helper/ProjectHelper2.java | 8 ++++++++ src/testcases/org/apache/tools/ant/ProjectTest.java | 13 ++++++++++--- 4 files changed, 24 insertions(+), 12 deletions(-) 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 +}