ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@yahoo.com>
Subject Re: [Bug 28444] - Import: Target Handling Bug
Date Thu, 12 May 2005 15:46:04 GMT
Here's my comment from the bug since Stefan wants to
be on-list:  :)

<quote>
I also support fixing this.  However, instead of
cloning the entire target,
couldn't we:

a) unconditionally rename the imported target
b) if the target has NOT been overridden, create a new
target that depends on
the imported target

?
-Matt
</quote>

The only issue with this is logging.  I guess it
really doesn't matter; the cloning approach shouldn't
be much heavier since it's as shallow as it is...

:)

--- Peter Reilly <peterreilly@apache.org> wrote:

> Stefan Bodewig wrote:
> 
> >>Be that as it may, the current behaviour is a bit
> silly -
> >>i.e. inconsistent.
> >>    
> >>
> >
> >big +1
> >
> >But we should discuss it here instead of in
> bugzilla - nobody's going
> >to follow it there.  I know that I don't.
> >  
> >
> No problem.
> 
> The bug is :
>
http://issues.apache.org/bugzilla/show_bug.cgi?id=28444
> The example given is:
> 
> <project name="A">
>    <target name="x"/>
> </project>
> 
> <project name="B">
>    <import file="A.xml"/>
>    <target name="x" depends="A.x"/>
> </project>
> 
> <project name="C">
>    <import file="A.xml"/>
>    <import file="B.xml"/>
> </project>
> 
> Succeeds:
>    ant -f A.xml x
>    ant -f B.xml x
> 
> Fails:
>    ant -f C.xml x
> 
> BUILD FAILED
> 
> 
> Target `A.x' does not exist in this project. It is
> used from target `B.x'.
> 
> 
> My comment is:
> 
> I never liked the target renaming stuff - it seems a
> bit strange.
> Be that as it may, the current behaviour is a bit
> silly - i.e. inconsistent.
> The target gets renamed if there another target of
> the same name, but
> not otherwise - how can one write a proper reusable
> import file using the
> rename feature in this case?
> 
> The fix will have a small overhead - the target
> object needs to be
> cloned and given a a new name, whereas the current
> code just renames the
> target object.
> 
> The changes to ant for this is:
> Index: src/main/org/apache/tools/ant/Target.java
>
===================================================================
> RCS file:
>
/home/cvs/ant/src/main/org/apache/tools/ant/Target.java,v
> retrieving revision 1.58
> diff -u -3 -p -r1.58 Target.java
> --- src/main/org/apache/tools/ant/Target.java   10
> Mar 2005 12:50:57 -0000      1.58
> +++ src/main/org/apache/tools/ant/Target.java   12
> May 2005 14:41:25 -0000
> @@ -52,12 +52,28 @@ public class Target implements
> TaskConta
>      /** Description of this target, if any. */
>      private String description = null;
> 
> -    /** Sole constructor. */
> +    /** Default constructor. */
>      public Target() {
>          //empty
>      }
> 
>      /**
> +     * Cloning constructor.
> +     * @param other the Target to clone.
> +     */
> +    public Target(Target other) {
> +        this.name = other.name;
> +        this.ifCondition = other.ifCondition;
> +        this.unlessCondition =
> other.unlessCondition;
> +        this.dependencies = other.dependencies;
> +        this.location = other.location;
> +        this.project = other.project;
> +        this.description = other.description;
> +        // The children are added to after this
> cloning
> +        this.children = other.children;
> +    }
> +
> +    /**
>       * Sets the project this target belongs to.
>       *
>       * @param project The project this target
> belongs to.
> Index:
>
src/main/org/apache/tools/ant/helper/ProjectHelper2.java
>
===================================================================
> RCS file:
>
/home/cvs/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v
> retrieving revision 1.54
> diff -u -3 -p -r1.54 ProjectHelper2.java
> ---
>
src/main/org/apache/tools/ant/helper/ProjectHelper2.java
>    26 Apr 2005 11:55:18 -0000    1.54
> +++
>
src/main/org/apache/tools/ant/helper/ProjectHelper2.java
>    12 May 2005 14:41:26 -0000
> @@ -815,38 +815,39 @@ public class ProjectHelper2
> extends Proj
>                      + "a name attribute",
> context.getLocator());
>              }
> 
> -            Hashtable currentTargets =
> project.getTargets();
> +            // Check if this target is in the
> current build file
> +            if
> (context.getCurrentTargets().get(name) != null) {
> +                throw new BuildException(
> +                    "Duplicate target '" + name +
> "'", target.getLocation());
> +            }
> 
> -            // If the name has already been defined
> ( import for example )
> -            if (currentTargets.containsKey(name)) {
> -                if
> (context.getCurrentTargets().get(name) != null) {
> -                    throw new BuildException(
> -                        "Duplicate target '" + name
> + "'", target.getLocation());
> -                }
> -                // Alter the name.
> -                if (context.getCurrentProjectName()
> != null) {
> -                    String newName =
> context.getCurrentProjectName()
> -                        + "." + name;
> -                    project.log("Already defined in
> main or a previous import, "
> -                        + "define " + name + " as "
> + newName,
> -                               
> Project.MSG_VERBOSE);
> -                    name = newName;
> -                } else {
> -                    project.log("Already defined in
> main or a previous import, "
> -                        + "ignore " + name,
> Project.MSG_VERBOSE);
> -                    name = null;
> -                }
> +            if (depends.length() > 0) {
> +                target.setDepends(depends);
>              }
> 
> -            if (name != null) {
> +            Hashtable projectTargets =
> project.getTargets();
> +            boolean   usedTarget = false;
> +            // If the name has not already been
> defined define it
> +            if (projectTargets.containsKey(name)) {
> +                project.log("Already defined in
> main or a previous import, "
> +                            + "ignore " + name,
> Project.MSG_VERBOSE);
> +            } else {
>                  target.setName(name);
>                 
> context.getCurrentTargets().put(name, target);
>                  project.addOrReplaceTarget(name,
> target);
> +                usedTarget = true;
>              }
> 
> -            // take care of dependencies
> -            if (depends.length() > 0) {
> -                target.setDepends(depends);
> +            if (context.isIgnoringProjectTag() &&
> context.getCurrentProjectName() != null
> +                &&
> context.getCurrentProjectName().length() 
=== message truncated ===



		
Discover Yahoo! 
Stay in touch with email, IM, photo sharing and more. Check it out! 
http://discover.yahoo.com/stayintouch.html

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message