ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r521278 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java src/tests/junit/org/apache/tools/ant/ExecutorTest.java
Date Thu, 22 Mar 2007 14:12:22 GMT
Author: mbenson
Date: Thu Mar 22 07:12:20 2007
New Revision: 521278

URL: http://svn.apache.org/viewvc?view=rev&rev=521278
Log:
Add IgnoreDependenciesExecutor for weird cases when the user wants to run only the targets
explicitly specified.

Added:
    ant/core/trunk/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java  
(with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/ExecutorTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=521278&r1=521277&r2=521278
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Mar 22 07:12:20 2007
@@ -89,7 +89,9 @@
 
 * <junitreport> xsl stylesheets allow setting the title used in <title> and <h1>
tags by
   using <report><param> element.  Bugzilla 41742.
-  
+
+* Add IgnoreDependenciesExecutor for weird cases when the user wants to run
+  only the targets explicitly specified.
   
 
 Changes from Ant 1.6.5 to Ant 1.7.0

Added: ant/core/trunk/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java?view=auto&rev=521278
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java Thu
Mar 22 07:12:20 2007
@@ -0,0 +1,70 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.helper;
+
+import java.util.Hashtable;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Executor;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Target;
+
+/**
+ * Target executor implementation that ignores dependencies. Runs each
+ * target by calling <code>target.performTasks()</code> directly. If an
+ * error occurs, behavior is determined by the Project's "keep-going" mode.
+ * To be used when you know what you're doing.
+ *
+ * @since Ant 1.7.1
+ */
+public class IgnoreDependenciesExecutor implements Executor {
+
+    private static final SingleCheckExecutor SUB_EXECUTOR = new SingleCheckExecutor();
+
+    /** {@inheritDoc}. */
+    public void executeTargets(Project project, String[] targetNames)
+        throws BuildException {
+        Hashtable targets = project.getTargets();
+        BuildException thrownException = null;
+        for (int i = 0; i < targetNames.length; i++) {
+            try {
+                Target t = (Target) targets.get(targetNames[i]);
+                if (t == null) {
+                  throw new BuildException("Unknown target " + targetNames[i]);
+                }
+                t.performTasks();
+            } catch (BuildException ex) {
+                if (project.isKeepGoingMode()) {
+                    thrownException = ex;
+                } else {
+                    throw ex;
+                }
+            }
+        }
+        if (thrownException != null) {
+            throw thrownException;
+        }
+    }
+
+    /** {@inheritDoc}. */
+    public Executor getSubProjectExecutor() {
+        return SUB_EXECUTOR;
+    }
+
+}

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/ExecutorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/ExecutorTest.java?view=diff&rev=521278&r1=521277&r2=521278
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/ExecutorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/ExecutorTest.java Thu Mar 22 07:12:20
2007
@@ -20,18 +20,19 @@
 
 import java.util.Vector;
 
-
 /**
  * Executor tests
  */
 public class ExecutorTest extends BuildFileTest implements BuildListener {
     private static final String SINGLE_CHECK
         = "org.apache.tools.ant.helper.SingleCheckExecutor";
-    private static final Vector targetNames;
+    private static final String IGNORE_DEPS
+        = "org.apache.tools.ant.helper.IgnoreDependenciesExecutor";
+    private static final Vector TARGET_NAMES;
     static {
-        targetNames = new Vector();
-        targetNames.add("a");
-        targetNames.add("b");
+        TARGET_NAMES = new Vector();
+        TARGET_NAMES.add("a");
+        TARGET_NAMES.add("b");
     }
 
     private int targetCount;
@@ -76,52 +77,75 @@
     }
 
     public void testDefaultExecutor() {
-        getProject().executeTargets(targetNames);
-        assertEquals(targetCount, 4);
+        getProject().executeTargets(TARGET_NAMES);
+        assertEquals(4, targetCount);
     }
 
     public void testSingleCheckExecutor() {
-        getProject(SINGLE_CHECK).executeTargets(targetNames);
-        assertEquals(targetCount, 3);
+        getProject(SINGLE_CHECK).executeTargets(TARGET_NAMES);
+        assertEquals(3, targetCount);
+    }
+
+    public void testIgnoreDependenciesExecutor() {
+        getProject(IGNORE_DEPS).executeTargets(TARGET_NAMES);
+        assertEquals(2, targetCount);
     }
 
     public void testDefaultFailure() {
         try {
-            getProject(null, true).executeTargets(targetNames);
+            getProject(null, true).executeTargets(TARGET_NAMES);
             fail("should fail");
         } catch (BuildException e) {
             assertTrue(e.getMessage().equals("failfoo"));
-            assertEquals(targetCount, 1);
+            assertEquals(1, targetCount);
         }
     }
 
     public void testSingleCheckFailure() {
         try {
-            getProject(SINGLE_CHECK, true).executeTargets(targetNames);
+            getProject(SINGLE_CHECK, true).executeTargets(TARGET_NAMES);
             fail("should fail");
         } catch (BuildException e) {
             assertTrue(e.getMessage().equals("failfoo"));
-            assertEquals(targetCount, 1);
+            assertEquals(1, targetCount);
         }
     }
 
+    public void testIgnoreDependenciesFailure() {
+        //no foo failure; foo is never executed as dependencies are ignored!
+        getProject(IGNORE_DEPS, true).executeTargets(TARGET_NAMES);
+    }
+
     public void testKeepGoingDefault() {
         try {
-            getProject(null, true, true).executeTargets(targetNames);
+            getProject(null, true, true).executeTargets(TARGET_NAMES);
             fail("should fail");
         } catch (BuildException e) {
             assertTrue(e.getMessage().equals("failfoo"));
-            assertEquals(targetCount, 2);
+            assertEquals(2, targetCount);
         }
     }
 
     public void testKeepGoingSingleCheck() {
         try {
-            getProject(SINGLE_CHECK, true, true).executeTargets(targetNames);
+            getProject(SINGLE_CHECK, true, true).executeTargets(TARGET_NAMES);
+            fail("should fail");
+        } catch (BuildException e) {
+            assertTrue(e.getMessage().equals("failfoo"));
+            assertEquals(1, targetCount);
+        }
+    }
+
+    public void testKeepGoingIgnoreDependencies() {
+        try {
+            //explicitly add foo for failure
+            Vector targetNames = new Vector(TARGET_NAMES);
+            targetNames.add(0, "foo");
+            getProject(IGNORE_DEPS, true, true).executeTargets(targetNames);
             fail("should fail");
         } catch (BuildException e) {
             assertTrue(e.getMessage().equals("failfoo"));
-            assertEquals(targetCount, 1);
+            assertEquals(3, targetCount);
         }
     }
 



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


Mime
View raw message