3131import org .nodeclipse .ui .Activator ;
3232import org .nodeclipse .ui .preferences .PreferenceConstants ;
3333
34+ /**
35+ * launch() implements starting Node and passing all parameters
36+ *
37+ * @author Lamb, Tomoyuki, Pushkar, Paul Vverest
38+ */
3439public class LaunchConfigurationDelegate implements
3540 ILaunchConfigurationDelegate {
3641 private static RuntimeProcess nodeProcess = null ;
@@ -58,15 +63,21 @@ public void launch(ILaunchConfiguration configuration, String mode,
5863 File nodeFile = new File (nodePath );
5964 if (!nodeFile .exists ()){
6065 // If the location is not valid than show a dialog which prompts the user to goto the preferences page
61- showPreferencesDialog ();
66+ showPreferencesDialog ("Node.js runtime is not correctly configured.\n \n "
67+ + "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location" );
6268 return ;
6369 }
6470
6571 List <String > cmdLine = new ArrayList <String >();
6672 // Application path should be stored in preference.
6773 cmdLine .add (nodePath );
6874 if (mode .equals (ILaunchManager .DEBUG_MODE )) {
69- cmdLine .add ("--debug-brk=5858" );
75+ // -brk says to Node runtime wait until Chromium Debugger starts and connects
76+ // that is causing "stop on first line" behavior,
77+ // otherwise small apps or first line can be undebuggable.
78+ // TODO flexible debugging port, instead of hard-coded 5858
79+ // #61 https://github.com/Nodeclipse/nodeclipse-1/issues/61
80+ cmdLine .add ("--debug-brk=5858" );
7081 }
7182
7283 String nodeArgs = configuration .getAttribute (Constants .ATTR_NODE_ARGUMENTS , "" );
@@ -77,17 +88,38 @@ public void launch(ILaunchConfiguration configuration, String mode,
7788 }
7889 }
7990
80- String file =
81- configuration .getAttribute (Constants .KEY_FILE_PATH , Constants .BLANK_STRING );
91+ String file = configuration .getAttribute (Constants .KEY_FILE_PATH , Constants .BLANK_STRING );
8292 String extension = null ;
8393 int i = file .lastIndexOf ('.' );
8494 if (i > 0 ) {
8595 extension = file .substring (i +1 );
8696 } else {
87- throw new CoreException (new Status (IStatus .OK , ChromiumDebugPlugin .PLUGIN_ID , "Target file does not have extension: " + file , null ));
97+ throw new CoreException (new Status (IStatus .OK , ChromiumDebugPlugin .PLUGIN_ID ,
98+ "Target file does not have extension: " + file , null ));
8899 }
89- if ("coffee" .equals (extension )) {
90- cmdLine .add (Activator .getDefault ().getPreferenceStore ().getString (PreferenceConstants .COFFEE_PATH ));
100+
101+ // #57 running app.js with node-dev, forever, supervisor, nodemon etc
102+ // https://github.com/Nodeclipse/nodeclipse-1/issues/57
103+ String nodeMonitor = configuration .getAttribute (Constants .ATTR_NODE_MONITOR , "" );
104+ if (!nodeMonitor .equals ("" )) { // any value
105+ //TODO support selection, now only one
106+
107+ String nodeMonitorPath = Activator .getDefault ().getPreferenceStore ().getString (PreferenceConstants .NODE_MONITOR_PATH );
108+
109+ // Check if the node monitor location is correctly configured
110+ File nodeMonitorFile = new File (nodeMonitorPath );
111+ if (!nodeMonitorFile .exists ()){
112+ // If the location is not valid than show a dialog which prompts the user to goto the preferences page
113+ showPreferencesDialog ("Node.js monitor is not correctly configured.\n "
114+ + "Select path to installed util: forever, node-dev, nodemon or superviser.\n \n "
115+ + "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location" );
116+ return ;
117+ }
118+ cmdLine .add (nodeMonitorPath );
119+ } else {
120+ if ("coffee" .equals (extension )) {
121+ cmdLine .add (Activator .getDefault ().getPreferenceStore ().getString (PreferenceConstants .COFFEE_PATH ));
122+ }
91123 }
92124
93125 String filePath =
@@ -138,16 +170,17 @@ public void launch(ILaunchConfiguration configuration, String mode,
138170 nodeProcess = process ;
139171 }
140172
141- private void showPreferencesDialog () {
173+ private void showPreferencesDialog (final String message ) {
142174 Display .getDefault ().syncExec (new Runnable () {
143175 public void run () {
144176 Shell shell = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell ();
145177
146- MessageDialog dialog = new MessageDialog (shell , "Nodeclipse" , null , "Node.js runtime is not correctly configured. \n \n "
147- + "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location" , MessageDialog .ERROR , new String [] { "Open Prefrences ..." , "Cancel" }, 0 );
178+ MessageDialog dialog = new MessageDialog (shell , "Nodeclipse" , null , message ,
179+ MessageDialog .ERROR , new String [] { "Open Prefrences ..." , "Cancel" }, 0 );
148180 int result = dialog .open ();
149181 if (result == 0 ) {
150- PreferenceDialog pref = PreferencesUtil .createPreferenceDialogOn (shell , PreferenceConstants .PREFERENCES_PAGE , null , null );
182+ PreferenceDialog pref = PreferencesUtil .createPreferenceDialogOn (shell ,
183+ PreferenceConstants .PREFERENCES_PAGE , null , null );
151184 if (pref != null )
152185 pref .open ();
153186 }
0 commit comments