Skip to content

Forward errors from gcd.sh #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 16, 2015
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,23 @@ private static class ProcessStreamReader extends Thread {

private final Process process;
private final BufferedReader reader;
private final BufferedReader errorReader;

ProcessStreamReader(Process process, String blockUntil) throws IOException {
ProcessStreamReader(
Process process, String blockUntil, boolean blockOnErrorStream) throws IOException {
super("Local GCD InputStream reader");
setDaemon(true);
this.process = process;
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
if (!Strings.isNullOrEmpty(blockUntil)) {
String line;
do {
line = reader.readLine();
if (blockOnErrorStream) {
line = errorReader.readLine();
} else {
line = reader.readLine();
}
} while (line != null && !line.contains(blockUntil));
}
}
Expand All @@ -205,16 +212,51 @@ void terminate() throws InterruptedException, IOException {
@Override
public void run() {
try {
while (reader.readLine() != null) {
// consume line
boolean readerDone = false;
boolean errorReaderDone = false;
String currentLog = null;
while (!readerDone || !errorReaderDone) {
if (!readerDone && reader.ready()) {
readerDone = reader.readLine() == null;
}
if (!errorReaderDone && errorReader.ready()) {
String errorOutput = errorReader.readLine();
if (errorOutput == null) {
errorReaderDone = true;
} else {
currentLog = processLog(errorOutput, currentLog);
}
}
}
} catch (IOException e) {
// ignore
}
}

public static ProcessStreamReader start(Process process, String blockUntil) throws IOException {
ProcessStreamReader thread = new ProcessStreamReader(process, blockUntil);
private static boolean isNewGcdLog(String line) {
return line.contains("com.google.apphosting.client.serviceapp.BaseApiServlet")
&& !line.trim().startsWith("at ");
}

private static String processLog(String currentLine, String currentLog) {
if (isNewGcdLog(currentLine)) {
if (currentLog != null) {
log.info(currentLog.trim());
}
return "GCD ";
} else if (currentLine.startsWith("SEVERE: ")) {
return null; // Don't show duplicate error messages from gcd.sh

This comment was marked as spam.

} else if (currentLog != null && currentLine.startsWith("INFO: ")) {
return currentLog + currentLine.substring("INFO: ".length()) + "\n";
} else if (currentLog != null && !currentLine.trim().startsWith("at ")) {
return currentLog + currentLine + "\n";
}
return currentLog;
}

public static ProcessStreamReader start(
Process process, String blockUntil, boolean blockOnErrorStream) throws IOException {
ProcessStreamReader thread = new ProcessStreamReader(process, blockUntil, blockOnErrorStream);
thread.start();
return thread;
}
Expand Down Expand Up @@ -396,9 +438,8 @@ private void startGcd(Path executablePath) throws IOException, InterruptedExcept
.command(gcdAbsolutePath.toString(), "start", "--testing", "--allow_remote_shutdown",
"--port=" + Integer.toString(port), projectId)
.directory(gcdPath)
.redirectErrorStream()
.start();
processReader = ProcessStreamReader.start(startProcess, "Dev App Server is now running");
processReader = ProcessStreamReader.start(startProcess, "Dev App Server is now running", true);

This comment was marked as spam.

}

private static String md5(File gcdZipFile) throws IOException {
Expand Down