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);
}
}
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;
}
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);
}
}
Aggregations