speedup ant execution from IDEA: use only stderr stream to log ant messages

This commit is contained in:
Eugene Zhuravlev
2011-05-13 13:31:33 +02:00
parent 14c4a5f62b
commit 5ed5dc4179
3 changed files with 34 additions and 26 deletions
@@ -26,7 +26,6 @@ import java.io.PrintWriter;
import java.io.StringWriter;
public final class IdeaAntLogger2 extends DefaultLogger {
static SegmentedOutputStream ourOut;
static SegmentedOutputStream ourErr;
public static final char MESSAGE_CONTENT = 'M';
public static final char EXCEPTION_CONTENT = 'X';
@@ -116,19 +115,16 @@ public final class IdeaAntLogger2 extends DefaultLogger {
}
public static void guardStreams() {
if (ourErr != null && ourOut != null) return;
PrintStream out = System.out;
if (ourErr != null) {
return;
}
PrintStream err = System.err;
ourOut = new SegmentedOutputStream(out);
ourErr = new SegmentedOutputStream(err);
System.setOut(new PrintStream(ourOut));
System.setErr(new PrintStream(ourErr));
ourOut.sendStart();
ourErr.sendStart();
}
private void send(PacketWriter packet) {
packet.sendThrough(ourOut);
packet.sendThrough(ourErr);
}
@@ -30,32 +30,42 @@ import java.util.Vector;
*/
public class IdeaInputHandler implements InputHandler {
public void handleInput(InputRequest request) throws BuildException {
String prompt = request.getPrompt();
if (prompt == null) throw new BuildException("Prompt is null");
SegmentedOutputStream out = IdeaAntLogger2.ourOut;
SegmentedOutputStream err = IdeaAntLogger2.ourErr;
if (out == null || err == null)
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");
PacketWriter packet = PacketFactory.ourInstance.createPacket(IdeaAntLogger2.INPUT_REQUEST);
}
final PacketWriter packet = PacketFactory.ourInstance.createPacket(IdeaAntLogger2.INPUT_REQUEST);
packet.appendLimitedString(prompt);
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++)
for (int i = 0; i < count; i++) {
packet.appendLimitedString((String)choices.elementAt(i));
} else packet.appendLong(0);
} else packet.appendLong(0);
packet.sendThrough(out);
}
}
else {
packet.appendLong(0);
}
}
else {
packet.appendLong(0);
}
packet.sendThrough(err);
try {
byte[] replayLength = readBytes(4);
int length = ((int)replayLength[0] << 24) | ((int)replayLength[1] << 16) | ((int)replayLength[2] << 8) | replayLength[3];
byte[] replay = readBytes(length);
String input = new String(replay);
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);
if (!request.isInputValid()) {
throw new BuildException("Invalid input: " + input);
}
}
catch (IOException e) {
throw new BuildException(e);
@@ -16,7 +16,10 @@
package com.intellij.lang.ant.config.execution;
import com.intellij.execution.junit.JUnitProcessHandler;
import com.intellij.execution.junit2.segments.*;
import com.intellij.execution.junit2.segments.DeferredActionsQueue;
import com.intellij.execution.junit2.segments.DeferredActionsQueueImpl;
import com.intellij.execution.junit2.segments.InputConsumer;
import com.intellij.execution.junit2.segments.SegmentReader;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.lang.ant.config.AntBuildFile;
@@ -85,9 +88,8 @@ final class OutputParser2 extends OutputParser implements PacketProcessor, Input
final AntBuildMessageView errorView,
final ProgressIndicator progress,
final AntBuildFile buildFile) {
OutputParser2 parser = new OutputParser2(myProject, handler, errorView, progress, buildFile.getName());
DeferredActionsQueue queue = new DeferredActionsQueueImpl();
handler.getOut().setPacketDispatcher(parser, queue);
final OutputParser2 parser = new OutputParser2(myProject, handler, errorView, progress, buildFile.getName());
final DeferredActionsQueue queue = new DeferredActionsQueueImpl();
handler.getErr().setPacketDispatcher(parser, queue);
return parser;
}