Browse Source

Inherit input handlers in <ant*>

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272548 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
01b5ce6c03
2 changed files with 66 additions and 1 deletions
  1. +3
    -1
      src/main/org/apache/tools/ant/taskdefs/Ant.java
  2. +63
    -0
      src/testcases/org/apache/tools/ant/taskdefs/AntTest.java

+ 3
- 1
src/main/org/apache/tools/ant/taskdefs/Ant.java View File

@@ -193,9 +193,11 @@ public class Ant extends Task {
* project, configures a possible logfile, transfers task and
* data-type definitions, transfers properties (either all or just
* the ones specified as user properties to the current project,
* depending on inheritall).
* depending on inheritall), transfers the input handler.
*/
private void initializeProject() {
newProject.setInputHandler(getProject().getInputHandler());

Vector listeners = project.getBuildListeners();
final int count = listeners.size();
for (int i = 0; i < count; i++) {


+ 63
- 0
src/testcases/org/apache/tools/ant/taskdefs/AntTest.java View File

@@ -61,6 +61,8 @@ import junit.framework.AssertionFailedError;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.input.InputHandler;
import org.apache.tools.ant.input.PropertyFileInputHandler;
import org.apache.tools.ant.types.Path;

/**
@@ -237,6 +239,19 @@ public class AntTest extends BuildFileTest {
}
}

public void testInputHandlerInheritance() {
InputHandler ih = new PropertyFileInputHandler();
getProject().setInputHandler(ih);
InputHandlerChecker ic = new InputHandlerChecker(ih);
getProject().addBuildListener(ic);
executeTarget("tripleCall");
AssertionFailedError ae = ic.getError();
if (ae != null) {
throw ae;
}
getProject().removeBuildListener(ic);
}

private class BasedirChecker implements BuildListener {
private String[] expectedBasedirs;
private int calls = 0;
@@ -341,4 +356,52 @@ public class AntTest extends BuildFileTest {

}

private class InputHandlerChecker implements BuildListener {
private InputHandler ih;
private AssertionFailedError error;

InputHandlerChecker(InputHandler value) {
ih = value;
}

public void buildStarted(BuildEvent event) {
check(event);
}
public void buildFinished(BuildEvent event) {
check(event);
}
public void targetFinished(BuildEvent event) {
check(event);
}
public void taskStarted(BuildEvent event) {
check(event);
}
public void taskFinished(BuildEvent event) {
check(event);
}
public void messageLogged(BuildEvent event) {
check(event);
}

public void targetStarted(BuildEvent event) {
check(event);
}

private void check(BuildEvent event) {
if (error == null) {
try {
assertNotNull(event.getProject().getInputHandler());
assertSame(ih, event.getProject().getInputHandler());
} catch (AssertionFailedError e) {
error = e;
}
}
}

AssertionFailedError getError() {
return error;
}

}

}

Loading…
Cancel
Save