[Esbox-commits] r845 - trunk/maemosdk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/command/scratchbox
eswartz at garage.maemo.org
eswartz at garage.maemo.org
Wed Oct 8 22:41:08 EEST 2008
Author: eswartz
Date: 2008-10-08 22:41:08 +0300 (Wed, 08 Oct 2008)
New Revision: 845
Modified:
trunk/maemosdk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/command/scratchbox/MaemoCommand.java
Log:
Do not use blocking I/O to read output during maemo AF start/restart/stop.
Modified: trunk/maemosdk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/command/scratchbox/MaemoCommand.java
===================================================================
--- trunk/maemosdk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/command/scratchbox/MaemoCommand.java 2008-10-08 19:16:00 UTC (rev 844)
+++ trunk/maemosdk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/command/scratchbox/MaemoCommand.java 2008-10-08 19:41:08 UTC (rev 845)
@@ -11,7 +11,8 @@
*******************************************************************************/
package org.maemo.esbox.internal.maemosdk.core.command.scratchbox;
-import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.ui.console.*;
import org.maemo.esbox.core.*;
import org.maemo.esbox.core.env.IEnvironmentModifierBlock;
@@ -23,7 +24,6 @@
import org.maemo.esbox.maemosdk.core.MaemoPreferenceConstants;
import org.maemo.esbox.maemosdk.core.scratchbox.ScratchboxException;
-import java.io.*;
import java.util.*;
/**
@@ -49,22 +49,6 @@
}
/*
- * private Properties getVariablesSet() {
- StorableEnvironment env = ESboxEnvironmentVariableManager.fUserSupplier.getWorkspaceEnvironmentCopy();
- ESboxStorableEnvironment esboxEnv = new ESboxStorableEnvironment(env.getVariables(),env.isReadOnly());
- IEnvironmentVariable[] variable = esboxEnv.getVariables();
-
- Properties properties = new Properties();
- for (int i = 0; i < variable.length; i++) {
- IEnvironmentVariable environmentVariable = variable[i];
- properties.put(environmentVariable.getName(), environmentVariable.getValue());
- }
-
- return properties;
- }
- */
-
- /*
* (non-Javadoc)
*
* @see org.maemo.esbox.internal.core.command.ICommand#performCommand(java.util.List)
@@ -85,22 +69,48 @@
IProcessLauncher processLauncher = ProcessLauncherCreator.createProcessLauncher(processLauncherFactory, null,
Collections.singletonList(maemoCommand), envBlock);
-
+
Process process = processLauncher.createProcess();
- // XXX: see why this hangs
- // read the first line to check for error
- InputParser inputParser = new InputParser(process.getInputStream());
- inputParser.run();
-
// spit the consumed output to the console
MessageConsole console = CorePlugin.getDefault().getConsole(
true, sdkTarget, "Running Maemo command (" + params.get(0) + ")");
- try {
- console.newOutputStream().write(inputParser.data().getBytes());
- } catch (IOException e) {
- }
+ console.addPatternMatchListener(new IPatternMatchListener() {
+
+ public int getCompilerFlags() {
+ return 0;
+ }
+
+ public String getLineQualifier() {
+ return null;
+ }
+
+ public String getPattern() {
+ return "ERROR:.*";
+ }
+
+ public void connect(TextConsole console) {
+ }
+
+ public void disconnect() {
+ }
+
+ public void matchFound(PatternMatchEvent event) {
+ TextConsole console = (TextConsole)event.getSource();
+ String content;
+ try {
+ content = console.getDocument().get(event.getOffset(), event.getLength());
+ } catch (BadLocationException e) {
+ content = console.getDocument().get();
+ }
+ ErrorLogger errorLogger = Activator.getErrorLogger();
+ errorLogger.logAndShowError("Error launching maemo",
+ new ESboxException(content));
+ }
+
+ });
+
// emit everything else to the console
processLauncher.redirectToConsole(console);
@@ -155,45 +165,4 @@
private String replaceActions(String command, String action) {
return command.replaceAll("\\$\\{ACTIONS\\}", action);
}
-
- /**
- * Examine the output to ensure the first line is not an error.
- */
- public class InputParser implements Runnable {
-
- boolean firstLine = true;
- private InputStream input;
- private StringBuilder data;
-
- public InputParser(InputStream input) {
- this.input = input;
- this.data = new StringBuilder();
- }
-
- public void run() {
- BufferedReader reader = new BufferedReader(new InputStreamReader(input));
- try {
- String line = "";
- if( (line = reader.readLine()) != null ) {
- // get the rest of the buffered content
- data.append(line);
- while (reader.ready())
- data.append((char)reader.read());
-
- if (line.startsWith("ERROR"))
- throw new ScratchboxInvalidOperationException(line);
- }
- } catch (Exception e) {
- ErrorLogger errorLogger = Activator.getErrorLogger();
- errorLogger.logAndShowError("Error launching maemo", e);
- }
- }
-
- public String data() {
- return data.toString();
- }
-
- }
-
-
}
More information about the Esbox-commits
mailing list