22
33import java .io .File ;
44import java .util .ArrayList ;
5+ import java .util .HashMap ;
56import java .util .List ;
7+ import java .util .Map ;
68
79import org .eclipse .core .resources .ResourcesPlugin ;
810import org .eclipse .core .runtime .CoreException ;
1416import org .eclipse .debug .core .model .ILaunchConfigurationDelegate ;
1517import org .eclipse .debug .core .model .RuntimeProcess ;
1618import org .eclipse .jface .preference .IPreferenceStore ;
19+ import org .nodeclipse .debug .util .Constants ;
1720import org .nodeclipse .debug .util .NodeDebugUtil ;
21+ import org .nodeclipse .debug .util .VariablesUtil ;
1822import org .nodeclipse .ui .Activator ;
1923import org .nodeclipse .ui .preferences .Dialogs ;
2024import org .nodeclipse .ui .preferences .PreferenceConstants ;
@@ -36,6 +40,7 @@ public class LaunchConfigurationDelegate
3640 //extends org.nodeclipse.debug.launch.LaunchConfigurationDelegate
3741 implements ILaunchConfigurationDelegate {
3842
43+ //@SuppressWarnings("unchecked")
3944 @ Override
4045 public void launch (ILaunchConfiguration configuration , String mode ,
4146 ILaunch launch , IProgressMonitor monitor ) throws CoreException {
@@ -72,16 +77,37 @@ public void launch(ILaunchConfiguration configuration, String mode,
7277 // path is relative, so cannot find it, unless get absolute path
7378 cmdLine .add (filePath );
7479
80+ String workingDirectory = configuration .getAttribute (Constants .ATTR_WORKING_DIRECTORY , "" );
81+ File workingPath = null ;
82+ if (workingDirectory .length () == 0 ) {
83+ workingPath = (new File (filePath )).getParentFile ();
84+ } else {
85+ workingDirectory = VariablesUtil .resolveValue (workingDirectory );
86+ if (workingDirectory == null ) {
87+ workingPath = (new File (filePath )).getParentFile ();
88+ } else {
89+ workingPath = new File (workingDirectory );
90+ }
91+ }
92+
93+ Map <String , String > envm = new HashMap <String , String >();
94+ envm = configuration .getAttribute (Constants .ATTR_ENVIRONMENT_VARIABLES , envm );
95+ String [] envp = new String [envm .size ()];
96+ int idx = 0 ;
97+ for (String key : envm .keySet ()) {
98+ String value = envm .get (key );
99+ envp [idx ++] = key + "=" + value ;
100+ }
101+
75102
76103 for (String s : cmdLine ) NodeclipseConsole .write (s +" " );
77104 NodeclipseConsole .write ("\n " );
78105
79106 String [] cmds = {};
80107 cmds = cmdLine .toArray (cmds );
81- // Launch a process to debug.eg,
82- //TODO Process p = DebugPlugin.exec(cmds, workingPath, envp);
83- Process p = DebugPlugin .exec (cmds , null , null );
84- RuntimeProcess process = (RuntimeProcess )DebugPlugin .newProcess (launch , p , Constants .PROCESS_MESSAGE );
108+ // Launch a process to run or debug
109+ Process p = DebugPlugin .exec (cmds , workingPath , envp );
110+ RuntimeProcess process = (RuntimeProcess )DebugPlugin .newProcess (launch , p , ConstantsPhantomJS .PROCESS_MESSAGE );
85111 if (isDebugMode ) {
86112 int phantomjsDebugPort = preferenceStore .getInt (PreferenceConstants .PHANTOMJS_DEBUG_PORT );
87113 NodeDebugUtil .launch (mode , launch , monitor , phantomjsDebugPort );
0 commit comments