use of org.apache.tools.ant.input.InputHandler in project ant by apache.
the class AntTest method testInputHandlerInheritance.
@Test
public void testInputHandlerInheritance() {
InputHandler ih = new PropertyFileInputHandler();
buildRule.getProject().setInputHandler(ih);
InputHandlerChecker ic = new InputHandlerChecker(ih);
buildRule.getProject().addBuildListener(ic);
buildRule.executeTarget("tripleCall");
AssertionFailedError ae = ic.getError();
if (ae != null) {
throw ae;
}
buildRule.getProject().removeBuildListener(ic);
}
use of org.apache.tools.ant.input.InputHandler in project freeplane by freeplane.
the class TaskUtils method multipleChoice.
@SuppressWarnings("unchecked")
static String multipleChoice(Project project, String message, String validValues, String defaultValue) {
InputRequest request = null;
if (validValues != null) {
Vector<String> accept = StringUtils.split(validValues, ',');
request = new MultipleChoiceInputRequest(message, accept);
} else {
request = new InputRequest(message);
}
InputHandler handler = project.getInputHandler();
handler.handleInput(request);
final String value = request.getInput();
if ((value == null || value.trim().length() == 0) && defaultValue != null) {
return defaultValue;
}
return value;
}
use of org.apache.tools.ant.input.InputHandler in project ant by apache.
the class Input method execute.
/**
* Actual method executed by ant.
* @throws BuildException on error
*/
@Override
public void execute() throws BuildException {
if (addproperty != null && getProject().getProperty(addproperty) != null) {
log("skipping " + getTaskName() + " as property " + addproperty + " has already been set.");
return;
}
InputRequest request = null;
if (validargs != null) {
final List<String> accept = StringUtils.split(validargs, ',');
request = new MultipleChoiceInputRequest(message, accept);
} else {
request = new InputRequest(message);
}
request.setDefaultValue(defaultvalue);
final InputHandler h = handler == null ? getProject().getInputHandler() : handler.getInputHandler();
h.handleInput(request);
String value = request.getInput();
if ((value == null || value.trim().isEmpty()) && defaultvalue != null) {
value = defaultvalue;
}
if (addproperty != null && value != null) {
getProject().setNewProperty(addproperty, value);
}
}
use of org.apache.tools.ant.input.InputHandler in project ant by apache.
the class ProjectTest method testInputHandler.
@Test
public void testInputHandler() {
InputHandler ih = p.getInputHandler();
assertNotNull(ih);
assertTrue(ih instanceof DefaultInputHandler);
InputHandler pfih = new PropertyFileInputHandler();
p.setInputHandler(pfih);
assertSame(pfih, p.getInputHandler());
}
use of org.apache.tools.ant.input.InputHandler in project ant by apache.
the class Main method addInputHandler.
/**
* Creates the InputHandler and adds it to the project.
*
* @param project the project instance.
*
* @exception BuildException if a specified InputHandler
* implementation could not be loaded.
*/
private void addInputHandler(final Project project) throws BuildException {
InputHandler handler = null;
if (inputHandlerClassname == null) {
handler = new DefaultInputHandler();
} else {
handler = ClasspathUtils.newInstance(inputHandlerClassname, Main.class.getClassLoader(), InputHandler.class);
project.setProjectReference(handler);
}
project.setInputHandler(handler);
}
Aggregations