Wrong partition length raises exception.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPStartApacheAction.java
index 8a6b5e2..a87c8a1 100644 (file)
@@ -6,74 +6,79 @@ which accompanies this distribution, and is available at
 http://www.eclipse.org/legal/cpl-v10.html
 
 Contributors:
-    IBM Corporation - Initial implementation
-    Klaus Hartlage - www.eclipseproject.de
+               IBM Corporation - Initial implementation
+               www.phpeclipse.de
 **********************************************************************/
 package net.sourceforge.phpeclipse.actions;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.text.MessageFormat;
 
+import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil;
+import net.sourceforge.phpeclipse.PHPConsole;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-import net.sourceforge.phpeclipse.views.PHPConsole;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
+import net.sourceforge.phpeclipse.ui.WebUI;
+
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import sun.security.krb5.internal.crypto.e;
 
 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
   protected IWorkbenchWindow activeWindow = null;
 
   public void run(IAction action) {
-    final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
-    String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
+    final IPreferenceStore store =
+      PHPeclipsePlugin.getDefault().getPreferenceStore();
+    String documentRoot = store.getString(WebUI.PHP_DOCUMENTROOT_PREF);
     // replace backslash with slash in the DocumentRoot under Windows
     documentRoot = documentRoot.replace('\\', '/');
     String[] arguments = { documentRoot };
-    MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
-    execute(form.format(arguments), "Start Apache: ");
+    MessageFormat form =
+      new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
+    execute(
+      "apache_start",
+      store.getString(PHPeclipsePlugin.APACHE_RUN_PREF),
+      form.format(arguments),
+      store.getBoolean(PHPeclipsePlugin.APACHE_START_BACKGROUND));
   }
 
-  public void execute(String command, String consoleMessage) {
-    //         MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
-    try {
-      PHPConsole.write(consoleMessage+command+"\n");
-      Runtime runtime = Runtime.getRuntime();
-
-          // runs the command
-      Process p = runtime.exec(command);
-
-      // gets the input stream to have the post-compile-time information
-      InputStream stream = p.getInputStream();
-
-      // and get the string from it
-      String compilerOutput = PHPConsole.getStringFromStream(stream);
-
-      // prints out the information
-      PHPConsole.write(compilerOutput);
-
-      // parse the buffer to find the errors and create markers
-    //  createMarkers(compilerOutput, fileToCompile);
-
-    } catch (IOException e) {
-      // @todo should throw the exception again
-      System.err.println("Problem");
-      e.printStackTrace();
-//    } catch (CoreException e) {
-//      e.printStackTrace();
-//      // @todo do something here !
+  /**
+        * Executes an external progam and saves the LaunchConfiguration under external tools 
+        * @param command external tools command name
+        * @param executable executable path i.e.c:\apache\apache.exe
+        * @param arguments arguments for this configuration
+        * @param background run this configuration in background mode
+        */
+  public static void execute(
+    String command,
+    String executable,
+    String arguments,
+    boolean background) {
+    PHPConsole console = new PHPConsole();
+    String consoleMessage;
+    if (background) {
+      consoleMessage =
+        "run in background mode-"
+          + command
+          + ": "
+          + executable
+          + " "
+          + arguments;
+    } else {
+      consoleMessage =
+        "run in foreground mode-"
+          + command
+          + ": "
+          + executable
+          + " "
+          + arguments;
     }
-  }
+    console.println(consoleMessage);
 
+    ExternalToolsUtil.execute(command, executable, arguments, background);
+  }
+  
   public void selectionChanged(IAction action, ISelection selection) {
 
   }
@@ -85,4 +90,5 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
   public void dispose() {
 
   }
+
 }