Browse Source

Add IgnoreDependenciesExecutor for weird cases when the user wants to run only the targets explicitly specified.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@521278 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
bbd75a7c27
3 changed files with 114 additions and 18 deletions
  1. +3
    -1
      WHATSNEW
  2. +70
    -0
      src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java
  3. +41
    -17
      src/tests/junit/org/apache/tools/ant/ExecutorTest.java

+ 3
- 1
WHATSNEW View File

@@ -89,7 +89,9 @@ Other changes:

* <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


+ 70
- 0
src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java View File

@@ -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;
}

}

+ 41
- 17
src/tests/junit/org/apache/tools/ant/ExecutorTest.java View File

@@ -20,18 +20,19 @@ package org.apache.tools.ant;

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 class ExecutorTest extends BuildFileTest implements BuildListener {
}

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);
}
}



Loading…
Cancel
Save