Search in sources :

Example 1 with InputHandler

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);
}
Also used : InputHandler(org.apache.tools.ant.input.InputHandler) PropertyFileInputHandler(org.apache.tools.ant.input.PropertyFileInputHandler) PropertyFileInputHandler(org.apache.tools.ant.input.PropertyFileInputHandler) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Example 2 with InputHandler

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;
}
Also used : InputRequest(org.apache.tools.ant.input.InputRequest) MultipleChoiceInputRequest(org.apache.tools.ant.input.MultipleChoiceInputRequest) InputHandler(org.apache.tools.ant.input.InputHandler) MultipleChoiceInputRequest(org.apache.tools.ant.input.MultipleChoiceInputRequest)

Example 3 with InputHandler

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);
    }
}
Also used : InputRequest(org.apache.tools.ant.input.InputRequest) MultipleChoiceInputRequest(org.apache.tools.ant.input.MultipleChoiceInputRequest) InputHandler(org.apache.tools.ant.input.InputHandler) PropertyFileInputHandler(org.apache.tools.ant.input.PropertyFileInputHandler) GreedyInputHandler(org.apache.tools.ant.input.GreedyInputHandler) SecureInputHandler(org.apache.tools.ant.input.SecureInputHandler) DefaultInputHandler(org.apache.tools.ant.input.DefaultInputHandler) MultipleChoiceInputRequest(org.apache.tools.ant.input.MultipleChoiceInputRequest)

Example 4 with InputHandler

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());
}
Also used : InputHandler(org.apache.tools.ant.input.InputHandler) PropertyFileInputHandler(org.apache.tools.ant.input.PropertyFileInputHandler) DefaultInputHandler(org.apache.tools.ant.input.DefaultInputHandler) PropertyFileInputHandler(org.apache.tools.ant.input.PropertyFileInputHandler) DefaultInputHandler(org.apache.tools.ant.input.DefaultInputHandler) Test(org.junit.Test)

Example 5 with InputHandler

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);
}
Also used : InputHandler(org.apache.tools.ant.input.InputHandler) DefaultInputHandler(org.apache.tools.ant.input.DefaultInputHandler) DefaultInputHandler(org.apache.tools.ant.input.DefaultInputHandler)

Aggregations

InputHandler (org.apache.tools.ant.input.InputHandler)6 DefaultInputHandler (org.apache.tools.ant.input.DefaultInputHandler)4 PropertyFileInputHandler (org.apache.tools.ant.input.PropertyFileInputHandler)3 InputRequest (org.apache.tools.ant.input.InputRequest)2 MultipleChoiceInputRequest (org.apache.tools.ant.input.MultipleChoiceInputRequest)2 Test (org.junit.Test)2 AssertionFailedError (junit.framework.AssertionFailedError)1 BuildException (org.apache.tools.ant.BuildException)1 GreedyInputHandler (org.apache.tools.ant.input.GreedyInputHandler)1 SecureInputHandler (org.apache.tools.ant.input.SecureInputHandler)1