Search in sources :

Example 1 with MultipleChoiceInputRequest

use of org.apache.tools.ant.input.MultipleChoiceInputRequest in project intellij-community by JetBrains.

the class IdeaInputHandler method handleInput.

public void handleInput(InputRequest request) throws BuildException {
    final String prompt = request.getPrompt();
    if (prompt == null) {
        throw new BuildException("Prompt is null");
    }
    final SegmentedOutputStream err = IdeaAntLogger2.ourErr;
    if (err == null) {
        throw new BuildException("Selected InputHandler should be used by Intellij IDEA");
    }
    final PacketWriter packet = PacketFactory.ourInstance.createPacket(IdeaAntLogger2.INPUT_REQUEST);
    packet.appendLimitedString(prompt);
    packet.appendLimitedString(request.getDefaultValue());
    if (request instanceof MultipleChoiceInputRequest) {
        Vector choices = ((MultipleChoiceInputRequest) request).getChoices();
        if (choices != null && choices.size() > 0) {
            int count = choices.size();
            packet.appendLong(count);
            for (int i = 0; i < count; i++) {
                packet.appendLimitedString((String) choices.elementAt(i));
            }
        } else {
            packet.appendLong(0);
        }
    } else {
        packet.appendLong(0);
    }
    packet.sendThrough(err);
    try {
        final byte[] replayLength = readBytes(4);
        final int length = ((int) replayLength[0] << 24) | ((int) replayLength[1] << 16) | ((int) replayLength[2] << 8) | replayLength[3];
        final byte[] replay = readBytes(length);
        final String input = new String(replay);
        request.setInput(input);
        if (!request.isInputValid()) {
            throw new BuildException("Invalid input: " + input);
        }
    } catch (IOException e) {
        throw new BuildException(e);
    }
}
Also used : MultipleChoiceInputRequest(org.apache.tools.ant.input.MultipleChoiceInputRequest) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) Vector(java.util.Vector)

Example 2 with MultipleChoiceInputRequest

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

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

MultipleChoiceInputRequest (org.apache.tools.ant.input.MultipleChoiceInputRequest)3 InputHandler (org.apache.tools.ant.input.InputHandler)2 InputRequest (org.apache.tools.ant.input.InputRequest)2 IOException (java.io.IOException)1 Vector (java.util.Vector)1 BuildException (org.apache.tools.ant.BuildException)1 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