ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject cvs commit: ant/src/etc/testcases/taskdefs/import import_same_target.xml same_target.xml
Date Mon, 25 Apr 2005 10:15:11 GMT
peterreilly    2005/04/25 03:15:11

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/helper ProjectHelper2.java
                        AntXMLContext.java
               src/testcases/org/apache/tools/ant/taskdefs ImportTest.java
  Added:       src/etc/testcases/taskdefs/import import_same_target.xml
                        same_target.xml
  Log:
  check for same targets in a source file
  PR: 34566
  
  Revision  Changes    Path
  1.812     +2 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.811
  retrieving revision 1.812
  diff -u -r1.811 -r1.812
  --- WHATSNEW	22 Apr 2005 20:24:37 -0000	1.811
  +++ WHATSNEW	25 Apr 2005 10:15:10 -0000	1.812
  @@ -90,6 +90,8 @@
   
   * JavaTest testcases sometimes fail on windows. Bugzilla Report 34502.
   
  +* Targets with identical name work in imported project. Bugzilla Report 34566.
  +
   Other changes:
   --------------
   
  
  
  
  1.53      +8 -2      ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  
  Index: ProjectHelper2.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- ProjectHelper2.java	6 Jan 2005 12:05:09 -0000	1.52
  +++ ProjectHelper2.java	25 Apr 2005 10:15:11 -0000	1.53
  @@ -24,7 +24,9 @@
   import java.io.IOException;
   import java.io.UnsupportedEncodingException;
   import java.net.URL;
  +import java.util.HashMap;
   import java.util.Hashtable;
  +import java.util.Map;
   import java.util.Stack;
   
   import org.xml.sax.Locator;
  @@ -117,20 +119,24 @@
               context.setIgnoreProjectTag(true);
               Target currentTarget = context.getCurrentTarget();
               Target currentImplicit = context.getImplicitTarget();
  +            Map    currentTargets = context.getCurrentTargets();
               try {
                   Target newCurrent = new Target();
                   newCurrent.setProject(project);
                   newCurrent.setName("");
                   context.setCurrentTarget(newCurrent);
  +                context.setCurrentTargets(new HashMap());
                   context.setImplicitTarget(newCurrent);
                   parse(project, source, new RootHandler(context, mainHandler));
                   newCurrent.execute();
               } finally {
                   context.setCurrentTarget(currentTarget);
                   context.setImplicitTarget(currentImplicit);
  +                context.setCurrentTargets(currentTargets);
               }
           } else {
               // top level file
  +            context.setCurrentTargets(new HashMap());
               parse(project, source, new RootHandler(context, mainHandler));
               // Execute the top-level target
               context.getImplicitTarget().execute();
  @@ -819,8 +825,7 @@
   
               // If the name has already been defined ( import for example )
               if (currentTargets.containsKey(name)) {
  -                if (!context.isIgnoringProjectTag()) {
  -                    // not in an import'ed file
  +                if (context.getCurrentTargets().get(name) != null) {
                       throw new BuildException(
                           "Duplicate target '" + name + "'", target.getLocation());
                   }
  @@ -841,6 +846,7 @@
   
               if (name != null) {
                   target.setName(name);
  +                context.getCurrentTargets().put(name, target);
                   project.addOrReplaceTarget(name, target);
               }
   
  
  
  
  1.11      +21 -1     ant/src/main/org/apache/tools/ant/helper/AntXMLContext.java
  
  Index: AntXMLContext.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/helper/AntXMLContext.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AntXMLContext.java	26 Apr 2004 17:49:51 -0000	1.10
  +++ AntXMLContext.java	25 Apr 2005 10:15:11 -0000	1.11
  @@ -1,5 +1,5 @@
   /*
  - * Copyright  2003-2004 The Apache Software Foundation
  + * Copyright  2003-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -92,6 +92,9 @@
       private Map prefixMapping = new HashMap();
   
   
  +    /** Keeps track of targets in files */
  +    private Map currentTargets = null;
  +
       /**
        * constructor
        * @param project the project to which this antxml context belongs to
  @@ -341,6 +344,23 @@
           }
           return (String) list.get(list.size() - 1);
       }
  +
  +    /**
  +     * Get the targets in the current source file.
  +     * @return the current targets.
  +     */
  +    public Map getCurrentTargets() {
  +        return currentTargets;
  +    }
  +
  +    /**
  +     * Set the map of the targets in the current source file.
  +     * @param currentTargets a map of targets.
  +     */
  +    void setCurrentTargets(Map currentTargets) {
  +        this.currentTargets = currentTargets;
  +    }
  +
   }
   
   
  
  
  
  1.16      +17 -1     ant/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java
  
  Index: ImportTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ImportTest.java	7 Dec 2004 09:10:38 -0000	1.15
  +++ ImportTest.java	25 Apr 2005 10:15:11 -0000	1.16
  @@ -1,5 +1,5 @@
   /*
  - * Copyright  2003-2004 The Apache Software Foundation
  + * Copyright  2003-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -91,6 +91,22 @@
           assertNotNull(getProject().getReference("baz"));
       }
   
  +    public void testImportSameTargets() {
  +        try {
  +            configureProject(
  +                "src/etc/testcases/taskdefs/import/same_target.xml");
  +        } catch (BuildException ex) {
  +            String message = ex.getMessage();
  +            if (message.indexOf("Duplicate target") == -1) {
  +                assertTrue("Did not see 'Duplicate target' in '" + message +"'", false);
  +            }
  +            return;
  +        }
  +        assertTrue(
  +            "Did not see build exception",
  +            false);
  +    }
  +
       public void testImportError() {
           try {
               configureProject(
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/import/import_same_target.xml
  
  Index: import_same_target.xml
  ===================================================================
  <project>
    <target name="t"/>
    <target name="t"/>
  </project>
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/import/same_target.xml
  
  Index: same_target.xml
  ===================================================================
  <project>
    <import file="import_same_target.xml"/>
  </project>
  
  
  

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


Mime
View raw message