misc
[phpeclipse.git] / net.sourceforge.phpeclipse.launching / src / net / sourceforge / phpdt / internal / launching / PHPLaunchConfigurationDelegate.java
1 /**********************************************************************
2  Copyright (c) 2000, 2002 IBM Corp. and others.
3  All rights reserved. This program and the accompanying materials
4  are made available under the terms of the Common Public License v1.0
5  which accompanies this distribution, and is available at
6  http://www.eclipse.org/legal/cpl-v10.html
7  
8  Contributors:
9  IBM Corporation - Initial implementation
10  Vicente Fernando - www.alfersoft.com.ar
11  **********************************************************************/
12 package net.sourceforge.phpdt.internal.launching;
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.debug.core.DebugPlugin;
19 import org.eclipse.debug.core.ILaunch;
20 import org.eclipse.debug.core.ILaunchConfiguration;
21 import org.eclipse.debug.core.ILaunchManager;
22 import org.eclipse.debug.core.Launch;
23 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
24 import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
25
26 public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate {
27         
28         protected static final InterpreterRunner interpreterRunner;
29         protected static final DebuggerRunner debuggerRunner;
30         
31         static {
32                 interpreterRunner  = new InterpreterRunner();
33                 debuggerRunner = new DebuggerRunner();
34         }
35
36         /** (non-Javadoc)
37          * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate2#getLaunch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
38          */
39         public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) 
40         throws CoreException {
41                 PHPSourceLocator locator = new PHPSourceLocator();
42                 locator.initializeDefaults(configuration);
43                 return new Launch(configuration, mode, locator);
44         }
45         
46         /**
47          * @see ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
48          */
49         public void 
50         launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
51                 if (PHPRuntime.getDefault().getSelectedInterpreter() == null) {
52                         String pid = PHPLaunchingPlugin.PLUGIN_ID;
53                         String msg = "You must define an interpreter before running PHP.";
54                         IStatus s = new Status(IStatus.ERROR, pid, IStatus.OK, msg, null);
55                         throw new CoreException(s);
56                 }
57                 
58                 InterpreterRunnerConfiguration conf = new 
59                         InterpreterRunnerConfiguration(configuration);
60                 ILaunchManager m = DebugPlugin.getDefault().getLaunchManager();
61                 conf.setEnvironment(m.getEnvironment(configuration));
62                 if (mode.equals("debug")) {
63                         debuggerRunner.run(conf, launch);
64                 } else {
65                         interpreterRunner.run(conf, launch);
66                 }               
67         }
68 }