[Esbox-commits] r146 - in trunk/org.indt.esbox.core/src/org/indt/esbox: core internal/core/command/scratchbox

raul at garage.maemo.org raul at garage.maemo.org
Tue Oct 16 00:49:18 EEST 2007


Author: raul
Date: 2007-10-16 00:49:18 +0300 (Tue, 16 Oct 2007)
New Revision: 146

Modified:
   trunk/org.indt.esbox.core/src/org/indt/esbox/core/ESboxScriptLauncher.java
   trunk/org.indt.esbox.core/src/org/indt/esbox/internal/core/command/scratchbox/MaemoCommand.java
Log:


Modified: trunk/org.indt.esbox.core/src/org/indt/esbox/core/ESboxScriptLauncher.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/core/ESboxScriptLauncher.java	2007-10-15 21:18:45 UTC (rev 145)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/core/ESboxScriptLauncher.java	2007-10-15 21:49:18 UTC (rev 146)
@@ -10,7 +10,10 @@
 
 package org.indt.esbox.core;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.util.StringTokenizer;
@@ -438,7 +441,41 @@
 	}
 	
 	public boolean isXServerStarted() {
-		return xServerStarted;
+		boolean isXServerRunning = false;
+		
+		// get preferences from SbCorePlugin
+		Preferences prefs = CoreActivator.getDefault().getPluginPreferences();
+		String server = prefs.getString(ESboxPreferenceConstants.DISPLAY_X_COMMAND.toString());
+		
+		// standard command launcher from CDT
+		CommandLauncher launcher = new CommandLauncher();
+
+		IPath wd = new Path(".");
+
+		IPath cmdPS = new Path("ps");
+		String[] args = new String[1];
+		args[0] = "-aux";
+		
+		Process p = launcher.execute(cmdPS, args, new String[] {}, wd);		
+		BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));		
+		int count = 0;
+		String line = "";
+		try {
+			while( (line = input.readLine()) != null ) {
+				if(line.contains(server))
+					count++;
+			}
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
+		isXServerRunning = count > 0;
+		
+		if (isMaemoStarted() & !isXServerRunning)
+			setMaemoStarted(false);
+		
+		return xServerStarted & isXServerRunning;
 	}
 	
 	public void setMaemoStarted(boolean isMaemoStarted) {

Modified: trunk/org.indt.esbox.core/src/org/indt/esbox/internal/core/command/scratchbox/MaemoCommand.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/internal/core/command/scratchbox/MaemoCommand.java	2007-10-15 21:18:45 UTC (rev 145)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/internal/core/command/scratchbox/MaemoCommand.java	2007-10-15 21:49:18 UTC (rev 146)
@@ -10,7 +10,10 @@
  *******************************************************************************/
 package org.indt.esbox.internal.core.command.scratchbox;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -18,6 +21,7 @@
 import org.indt.esbox.core.CoreActivator;
 import org.indt.esbox.core.ESboxPreferenceConstants;
 import org.indt.esbox.core.ESboxScriptLauncher;
+import org.indt.esbox.core.ErrorLogger;
 import org.indt.esbox.core.StreamMonitor;
 import org.indt.esbox.core.scratchbox.ScratchboxCommandLauncher;
 import org.indt.esbox.core.scratchbox.ScratchboxException;
@@ -27,6 +31,10 @@
  */
 public class MaemoCommand extends ScratchboxCommand {
 
+	private boolean errorOccured;
+	
+	private Process process;
+	
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -57,14 +65,8 @@
 		ScratchboxCommandLauncher commandLauncher = new ScratchboxCommandLauncher();
 		Process process = commandLauncher.execInsideSbox(maemoCommand);
 		
-//		try {
-//			String errorLine = getErrorInputFromProcess(process);
-//			if (errorLine.trim().startsWith("ERROR")) {
-//				throw new ScratchboxInvalidOperationException(errorLine);
-//			}
-//		} catch (IOException e) {
-//			throw new ScratchboxException(e.getMessage());
-//		}
+		CoreActivator.getDefault().getWorkbench()
+						.getDisplay().syncExec(new InputParser(process.getInputStream()));
 		
 		// print all output to console
 		new StreamMonitor(process.getInputStream(), true, new String("Running Maemo command (" + params.get(0) + ")"));
@@ -83,9 +85,10 @@
 		
 		List<String> params = getParamList(ESboxPreferenceConstants.MAEMO_START_ACTION
 				.toString());
+				
 		Object result = performCommand(params);
 		
-		if (result != null)
+		if (result != null && !errorOccured)
 			ESboxScriptLauncher.getInstance().setMaemoStarted(true);
 		
 		return result;
@@ -101,9 +104,11 @@
 		List<String> params = getParamList(ESboxPreferenceConstants.MAEMO_STOP_ACTION
 				.toString());
 		
+		errorOccured = false;
+		
 		Object result = performCommand(params);
 		
-		if (result != null)
+		if (result != null && !errorOccured)
 			ESboxScriptLauncher.getInstance().setMaemoStarted(false);
 		
 		return result;
@@ -131,5 +136,35 @@
 	private String replaceActions(String command, String action) {
 		return command.replaceAll("\\$\\{ACTIONS\\}", action);
 	}
+	
+	/**
+	 * 
+	 * 
+	 *
+	 */
+	public class InputParser implements Runnable {
 
+		private InputStream input;
+		
+		public InputParser(InputStream input) {
+			this.input = input;
+		}
+		
+		public void run() {
+			BufferedReader reader = new BufferedReader(new InputStreamReader(input));
+			try {
+				String line = "";
+				if( (line = reader.readLine()) != null ) {
+					if (line.startsWith("ERROR"))
+						throw new ScratchboxInvalidOperationException(line);
+				}
+			} catch (Exception e) {
+				errorOccured = true;
+				ErrorLogger errorLogger = CoreActivator.getDefault().getErrorLogger();
+				errorLogger.logAndShowError("Scratchbox error", e);
+			}
+		}
+		
+	}
+
 }



More information about the Esbox-commits mailing list