35
35
/**
36
36
* launch() implements starting Node and passing all parameters.
37
37
* Node is launched as node, coffee, coffee -c, tsc or node-dev(or other monitors)
38
- *
38
+ *
39
39
* @author Lamb, Tomoyuki, Pushkar, Paul Verest
40
40
*/
41
41
public class LaunchConfigurationDelegate implements
42
42
ILaunchConfigurationDelegate {
43
43
private static RuntimeProcess nodeProcess = null ; //since 0.7 it should be debuggable instance
44
44
//@since 0.7. contain all running Node thread, including under debug. Non Thread-safe, as it should be only in GUI thread
45
45
//private static List<RuntimeProcess> nodeRunningProcesses = new LinkedList<RuntimeProcess>();
46
-
46
+
47
47
private boolean warned = false ;
48
-
48
+
49
49
/*
50
50
* (non-Javadoc)
51
- *
51
+ *
52
52
* @see
53
53
* org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.
54
54
* eclipse.debug.core.ILaunchConfiguration, java.lang.String,
@@ -58,30 +58,30 @@ public class LaunchConfigurationDelegate implements
58
58
@ Override
59
59
public void launch (ILaunchConfiguration configuration , String mode ,
60
60
ILaunch launch , IProgressMonitor monitor ) throws CoreException {
61
-
61
+
62
62
IPreferenceStore preferenceStore = Activator .getDefault ().getPreferenceStore ();
63
63
boolean allowedMany = preferenceStore .getBoolean (PreferenceConstants .NODE_ALLOW_MANY );//@since 0.7
64
64
boolean isDebugMode = mode .equals (ILaunchManager .DEBUG_MODE );
65
65
66
66
if (allowedMany ){//@since 0.7
67
- if ( isDebugMode
67
+ if ( isDebugMode
68
68
&& (nodeProcess != null && !nodeProcess .isTerminated ()) ) {
69
69
showErrorDialog ("Only 1 node process can be debugged in 1 Eclipse instance!\n \n " +
70
70
"Open other Eclipse/Enide Studio with different node debug port configurred. " );
71
71
return ;
72
72
}
73
-
74
- }else {
73
+
74
+ }else {
75
75
if (nodeProcess != null && !nodeProcess .isTerminated ()) {
76
76
//throw new CoreException(new Status(IStatus.OK, ChromiumDebugPlugin.PLUGIN_ID, null, null));
77
77
showErrorDialog ("Other node process is running!" );
78
78
return ;
79
79
//TODO suggest to terminate and start new
80
- }
80
+ }
81
81
}
82
82
83
-
84
- // Using configuration to build command line
83
+
84
+ // Using configuration to build command line
85
85
List <String > cmdLine = new ArrayList <String >();
86
86
87
87
if (preferenceStore .getBoolean (PreferenceConstants .NODE_JUST_NODE )){
@@ -96,10 +96,10 @@ public void launch(ILaunchConfiguration configuration, String mode,
96
96
Dialogs .showPreferencesDialog ("Node.js runtime is not correctly configured.\n \n "
97
97
+ "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location" );
98
98
return ;
99
- }
99
+ }
100
100
cmdLine .add (nodePath );
101
101
}
102
-
102
+
103
103
if (isDebugMode ) {
104
104
// -brk says to Node runtime wait until Chromium Debugger starts and connects
105
105
// that is causing "stop on first line" behavior,
@@ -113,24 +113,24 @@ public void launch(ILaunchConfiguration configuration, String mode,
113
113
if (nodeDebugPort ==0 ) { nodeDebugPort =5858 ;};
114
114
cmdLine .add ("--debug" +brk +"=" +nodeDebugPort ); //--debug-brk=5858
115
115
}
116
-
116
+
117
117
//@since 0.9 from Preferences
118
118
String nodeOptions = preferenceStore .getString (PreferenceConstants .NODE_OPTIONS );
119
119
if (!nodeOptions .equals ("" )) {
120
120
String [] sa = nodeOptions .split (" " );
121
121
for (String s : sa ) {
122
122
cmdLine .add (s );
123
- }
123
+ }
124
124
}
125
-
125
+
126
126
String nodeArgs = configuration .getAttribute (Constants .ATTR_NODE_ARGUMENTS , "" );
127
127
if (!nodeArgs .equals ("" )) {
128
128
String [] sa = nodeArgs .split (" " );
129
129
for (String s : sa ) {
130
130
cmdLine .add (s );
131
131
}
132
132
}
133
-
133
+
134
134
String file = configuration .getAttribute (Constants .KEY_FILE_PATH , Constants .BLANK_STRING );
135
135
String extension = null ;
136
136
int i = file .lastIndexOf ('.' );
@@ -142,15 +142,15 @@ public void launch(ILaunchConfiguration configuration, String mode,
142
142
// by default assume
143
143
extension = "js" ;
144
144
}
145
-
145
+
146
146
// #57 running app.js with node-dev, forever, supervisor, nodemon etc
147
147
// https://github.com/Nodeclipse/nodeclipse-1/issues/57
148
148
String nodeMonitor = configuration .getAttribute (Constants .ATTR_NODE_MONITOR , "" );
149
149
if (!nodeMonitor .equals ("" )) { // any value
150
150
//TODO support selection, now only one
151
-
151
+
152
152
String nodeMonitorPath = preferenceStore .getString (PreferenceConstants .NODE_MONITOR_PATH );
153
-
153
+
154
154
// Check if the node monitor location is correctly configured
155
155
File nodeMonitorFile = new File (nodeMonitorPath );
156
156
if (!nodeMonitorFile .exists ()){
@@ -181,7 +181,7 @@ public void launch(ILaunchConfiguration configuration, String mode,
181
181
//String typescriptCompiler = configuration.getAttribute(Constants.ATTR_TYPESCRIPT_COMPILER, "");
182
182
cmdLine .add (preferenceStore .getString (PreferenceConstants .TYPESCRIPT_COMPILER_PATH ));
183
183
}
184
-
184
+
185
185
String filePath = ResourcesPlugin .getWorkspace ().getRoot ().findMember (file ).getLocation ().toOSString ();
186
186
// path is relative, so can not found it.
187
187
cmdLine .add (filePath );
@@ -194,7 +194,7 @@ public void launch(ILaunchConfiguration configuration, String mode,
194
194
cmdLine .add (s );
195
195
}
196
196
}
197
-
197
+
198
198
String programArgs = configuration .getAttribute (Constants .ATTR_PROGRAM_ARGUMENTS , "" );
199
199
if (!programArgs .equals ("" )) {
200
200
String [] sa = programArgs .split (" " );
@@ -216,75 +216,74 @@ public void launch(ILaunchConfiguration configuration, String mode,
216
216
if (workingPath == null ){
217
217
workingPath = (new File (filePath )).getParentFile ();
218
218
}
219
-
219
+
220
220
//env
221
- String [] envp = getEnvironmentVariables (configuration );
222
-
221
+ String [] envp = getEnvironmentVariables (configuration );
222
+
223
223
for (String s : cmdLine ) NodeclipseConsole .write (s +" " );
224
224
NodeclipseConsole .write ("\n " );
225
-
225
+
226
226
String [] cmds = {};
227
227
cmds = cmdLine .toArray (cmds );
228
228
// Launch a process to run/debug. See also #71 (output is less or no output)
229
229
Process p = DebugPlugin .exec (cmds , workingPath , envp );
230
230
// no way to get private p.handle from java.lang.ProcessImpl
231
- RuntimeProcess process = (RuntimeProcess )DebugPlugin .newProcess (launch , p , Constants .PROCESS_MESSAGE );
231
+ RuntimeProcess process = (RuntimeProcess )DebugPlugin .newProcess (launch , p , Constants .PROCESS_MESSAGE );
232
232
if (isDebugMode ) {
233
- if (!process .isTerminated ()) {
233
+ if (!process .isTerminated ()) {
234
234
int nodeDebugPort = preferenceStore .getInt (PreferenceConstants .NODE_DEBUG_PORT );
235
235
NodeDebugUtil .launch (mode , launch , monitor , nodeDebugPort );
236
236
}
237
237
}
238
-
238
+
239
239
if (allowedMany ){ //@since 0.7
240
240
if (isDebugMode ){
241
- nodeProcess = process ;
241
+ nodeProcess = process ;
242
242
}
243
243
//nodeRunningProcesses.add(process);
244
244
}else {
245
- nodeProcess = process ;
245
+ nodeProcess = process ;
246
246
}
247
247
}
248
-
248
+
249
+ public static String [] NODE_ENV_VAR_SET = new String []{"APPDATA" ,"PATH" ,"TEMP" ,"TMP" ,"SystemDrive" }; // #81, #197
250
+
249
251
private String [] getEnvironmentVariables (ILaunchConfiguration configuration ) throws CoreException {
250
252
Map <String , String > envm = new HashMap <String , String >();
251
253
envm = configuration .getAttribute (Constants .ATTR_ENVIRONMENT_VARIABLES , envm );
252
-
253
- int envmSizeDelta = 4 ;
254
+
255
+ int envmSizeDelta = NODE_ENV_VAR_SET . length ;
254
256
Map <String ,String > all = null ;
255
257
IPreferenceStore preferenceStore = Activator .getDefault ().getPreferenceStore ();
256
258
boolean passAllEnvVars = preferenceStore .getBoolean (PreferenceConstants .NODE_PASS_ALL_ENVIRONMENT_VARIABLES );//@since 0.12
257
259
if (passAllEnvVars ){
258
260
all = System .getenv ();
259
261
envmSizeDelta = all .size ();
260
262
}
261
-
263
+
262
264
String [] envp = new String [envm .size ()+envmSizeDelta ]; // see below
263
265
int idx = 0 ;
264
266
for (String key : envm .keySet ()) {
265
267
String value = envm .get (key );
266
268
envp [idx ++] = key + "=" + value ;
267
269
}
268
-
270
+
269
271
if (passAllEnvVars ){
270
272
for (Map .Entry <String , String > entry : all .entrySet ())
271
273
{
272
274
//System.out.println(entry.getKey() + "/" + entry.getValue());
273
275
envp [idx ++] = entry .getKey () + "=" + entry .getValue ();
274
276
}
275
277
}else {
276
- envp [idx ++] = getEnvVariableEqualsString ("APPDATA" ); //#197
277
- //+ #81
278
- envp [idx ++] = getEnvVariableEqualsString ("PATH" );
279
- envp [idx ++] = getEnvVariableEqualsString ("TEMP" );
280
- envp [idx ++] = getEnvVariableEqualsString ("TMP" );
281
- envp [idx ++] = getEnvVariableEqualsString ("SystemDrive" );
278
+ for (String envVarName : NODE_ENV_VAR_SET ){
279
+ envp [idx ++] = getEnvVariableEqualsString (envVarName );
280
+ }
282
281
}
283
282
if (!warned ){
284
283
NodeclipseConsole .write (" These environment variables will be applied automatically to every `node` launch.\n " );
285
284
StringBuilder sb = new StringBuilder (100 );
286
285
for (int i =0 ; i <envp .length ; i ++){
287
- sb .append (" " ).append (envp [i ]).append ('\n' );
286
+ sb .append (" " ).append (envp [i ]).append ('\n' );
288
287
}
289
288
NodeclipseConsole .write (sb .toString ());
290
289
warned = true ;
@@ -295,21 +294,21 @@ private String[] getEnvironmentVariables(ILaunchConfiguration configuration) thr
295
294
protected String getEnvVariableEqualsString (String envvarName ){
296
295
String envvarValue = System .getenv (envvarName );
297
296
if (envvarValue ==null ) envvarValue = "" ;
298
- return envvarName + "=" + envvarValue ;
297
+ return envvarName + "=" + envvarValue ;
299
298
}
300
-
299
+
301
300
private void showErrorDialog (final String message ) {
302
301
Display .getDefault ().syncExec (new Runnable () {
303
302
public void run () {
304
303
Shell shell = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell ();
305
304
306
- MessageDialog dialog = new MessageDialog (shell , "Nodeclipse" , null , message ,
305
+ MessageDialog dialog = new MessageDialog (shell , "Nodeclipse" , null , message ,
307
306
MessageDialog .ERROR , new String [] { "OK" }, 0 );
308
307
dialog .open ();
309
308
}
310
309
});
311
310
}
312
-
311
+
313
312
public static void terminateNodeProcess () {
314
313
if (nodeProcess != null ) {
315
314
try {
0 commit comments