From 33ac6bc3ceb37259604ae74781ab53913b4079da Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Mon, 26 Apr 2004 17:49:51 +0000 Subject: [PATCH] Add a Location member to oata.Target, with the appropriate settor & gettor. PR: 28599 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276407 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 ++ src/main/org/apache/tools/ant/Target.java | 20 +++++++++++++++++++ .../tools/ant/helper/AntXMLContext.java | 2 ++ .../tools/ant/helper/ProjectHelper2.java | 6 ++---- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index c65fa2b7b..99ef1ef25 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -157,6 +157,8 @@ Other changes: * New attribute "negate" on to invert selection criteria. +* Target now supports a Location member. Bugzilla Report 28599. + Changes from Ant 1.6.0 to Ant 1.6.1 ============================================= diff --git a/src/main/org/apache/tools/ant/Target.java b/src/main/org/apache/tools/ant/Target.java index 27f7e7290..7536b720c 100644 --- a/src/main/org/apache/tools/ant/Target.java +++ b/src/main/org/apache/tools/ant/Target.java @@ -42,6 +42,8 @@ public class Target implements TaskContainer { private List dependencies = null; /** Children of this target (tasks and data types). */ private List children = new ArrayList(); + /** Since Ant 1.6.2 */ + private Location location = Location.UNKNOWN_LOCATION; /** Project this target belongs to. */ private Project project; @@ -73,6 +75,24 @@ public class Target implements TaskContainer { return project; } + /** + * Sets the location of this target's definition. + * + * @param location Location + */ + public void setLocation(Location location) { + this.location = location; + } + + /** + * Get the location of this target's definition. + * + * @return Location + */ + public Location getLocation() { + return location; + } + /** * Sets the list of targets this target is dependent on. * The targets themselves are not resolved at this time. diff --git a/src/main/org/apache/tools/ant/helper/AntXMLContext.java b/src/main/org/apache/tools/ant/helper/AntXMLContext.java index 525db7f0b..ff2d1478e 100644 --- a/src/main/org/apache/tools/ant/helper/AntXMLContext.java +++ b/src/main/org/apache/tools/ant/helper/AntXMLContext.java @@ -29,6 +29,7 @@ import org.xml.sax.Attributes; import org.apache.tools.ant.Project; import org.apache.tools.ant.Target; +import org.apache.tools.ant.Location; import org.apache.tools.ant.RuntimeConfigurable; @@ -109,6 +110,7 @@ public class AntXMLContext { public void setBuildFile(File buildFile) { this.buildFile = buildFile; this.buildFileParent = new File(buildFile.getParent()); + implicitTarget.setLocation(new Location(buildFile.getAbsolutePath())); } /** diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java index 0edb206b0..bcabb421f 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java @@ -757,6 +757,7 @@ public class ProjectHelper2 extends ProjectHelper { Project project = context.getProject(); Target target = new Target(); target.setProject(project); + target.setLocation(new Location(context.getLocator())); context.addTarget(target); for (int i = 0; i < attrs.getLength(); i++) { @@ -805,10 +806,7 @@ public class ProjectHelper2 extends ProjectHelper { 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())); + "Duplicate target '" + name + "'", target.getLocation()); } // Alter the name. if (context.getCurrentProjectName() != null) {