Search in sources :

Example 1 with InputRequest

use of org.apache.tools.ant.input.InputRequest 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 2 with InputRequest

use of org.apache.tools.ant.input.InputRequest 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)

Aggregations

InputHandler (org.apache.tools.ant.input.InputHandler)2 InputRequest (org.apache.tools.ant.input.InputRequest)2 MultipleChoiceInputRequest (org.apache.tools.ant.input.MultipleChoiceInputRequest)2 DefaultInputHandler (org.apache.tools.ant.input.DefaultInputHandler)1 GreedyInputHandler (org.apache.tools.ant.input.GreedyInputHandler)1 PropertyFileInputHandler (org.apache.tools.ant.input.PropertyFileInputHandler)1 SecureInputHandler (org.apache.tools.ant.input.SecureInputHandler)1