ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 5270] - Ant task - allow multiple targets
Date Wed, 10 Apr 2002 18:37:22 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5270>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5270

Ant task - allow multiple targets





------- Additional Comments From bdeweese@yahoo.com  2002-04-10 18:37 -------
Good question.  The original would throw a BuildException stating that the 
target '' could not be found.  This exception is thrown by Project.executeTarget
(String).

The patched version would go merrily along its way ignoring the fact that you 
hadn't specified any targets.  It calls Project.executeTargets(Vector) which 
doesn't do any error checking.  I've supplied a patch for Project.java as well 
as Ant.java that does throw a BuildException() if no target(s) are provided.


--- Ant.java.orig	Thu Oct 11 23:58:28 2001
+++ Ant.java	Wed Apr 10 11:57:21 2002
@@ -254,16 +254,40 @@
                 target = newProject.getDefaultTarget();
             }
 
+            Vector targets = new Vector();
+            StringTokenizer tok =
+                new StringTokenizer(target, ",", true);
+            while (tok.hasMoreTokens()) {
+                String token = tok.nextToken().trim();
+
+                //Make sure the target is not empty string
+                if (token.equals("") || token.equals(","))
+                  continue;
+
+                  targets.addElement(token);
+
+                //Make sure that target attribute does not
+                //end in a ,
+                if (tok.hasMoreTokens()) {
+                    token = tok.nextToken();
+                    if (!tok.hasMoreTokens() || !token.equals(",")) {
+                        throw new BuildException( "Syntax Error: Target 
attribute " +
+                                                  "for task \"" + getTaskName
() +
+                                                  "\" ends with a , 
character" );
+                    }
+                }
+            }
+
             // Are we trying to call the target in which we are defined?
             if (newProject.getBaseDir().equals(project.getBaseDir()) &&
                 newProject.getProperty("ant.file").equals(project.getProperty
("ant.file")) &&
                 getOwningTarget() != null &&
-                target.equals(this.getOwningTarget().getName())) { 
+                targets.contains(this.getOwningTarget().getName())) {
 
                 throw new BuildException("ant task calling its own parent 
target");
             }
 
-            newProject.executeTarget(target);
+            newProject.executeTargets(targets);
         } finally {
             // help the gc
             newProject = null;

--- Project.java.orig	Thu Oct 11 23:58:28 2001
+++ Project.java	Wed Apr 10 11:57:15 2002
@@ -556,6 +556,11 @@
     public void executeTargets(Vector targetNames) throws BuildException {
         Throwable error = null;
 
+        if (targetNames == null || targetNames.size() == 0) {
+            String msg = "No target(s) specified";
+            throw new BuildException(msg);
+        }
+
         for (int i = 0; i < targetNames.size(); i++) {
             executeTarget((String)targetNames.elementAt(i));
         }

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


Mime
View raw message