Skip to content

Commit 53de627

Browse files
Paul VerestPaul Verest
authored andcommitted
close #198 ArrayIndexOutOfBound because of newly added APPDATA in #197
was not tested
1 parent f6c0cc6 commit 53de627

File tree

2 files changed

+69
-71
lines changed

2 files changed

+69
-71
lines changed

org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@
3535
/**
3636
* launch() implements starting Node and passing all parameters.
3737
* Node is launched as node, coffee, coffee -c, tsc or node-dev(or other monitors)
38-
*
38+
*
3939
* @author Lamb, Tomoyuki, Pushkar, Paul Verest
4040
*/
4141
public class LaunchConfigurationDelegate implements
4242
ILaunchConfigurationDelegate {
4343
private static RuntimeProcess nodeProcess = null; //since 0.7 it should be debuggable instance
4444
//@since 0.7. contain all running Node thread, including under debug. Non Thread-safe, as it should be only in GUI thread
4545
//private static List<RuntimeProcess> nodeRunningProcesses = new LinkedList<RuntimeProcess>();
46-
46+
4747
private boolean warned = false;
48-
48+
4949
/*
5050
* (non-Javadoc)
51-
*
51+
*
5252
* @see
5353
* org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.
5454
* eclipse.debug.core.ILaunchConfiguration, java.lang.String,
@@ -58,30 +58,30 @@ public class LaunchConfigurationDelegate implements
5858
@Override
5959
public void launch(ILaunchConfiguration configuration, String mode,
6060
ILaunch launch, IProgressMonitor monitor) throws CoreException {
61-
61+
6262
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
6363
boolean allowedMany = preferenceStore.getBoolean(PreferenceConstants.NODE_ALLOW_MANY);//@since 0.7
6464
boolean isDebugMode = mode.equals(ILaunchManager.DEBUG_MODE);
6565

6666
if (allowedMany){//@since 0.7
67-
if ( isDebugMode
67+
if ( isDebugMode
6868
&& (nodeProcess != null && !nodeProcess.isTerminated()) ) {
6969
showErrorDialog("Only 1 node process can be debugged in 1 Eclipse instance!\n\n"+
7070
"Open other Eclipse/Enide Studio with different node debug port configurred. ");
7171
return;
7272
}
73-
74-
}else{
73+
74+
}else{
7575
if(nodeProcess != null && !nodeProcess.isTerminated()) {
7676
//throw new CoreException(new Status(IStatus.OK, ChromiumDebugPlugin.PLUGIN_ID, null, null));
7777
showErrorDialog("Other node process is running!");
7878
return;
7979
//TODO suggest to terminate and start new
80-
}
80+
}
8181
}
8282

83-
84-
// Using configuration to build command line
83+
84+
// Using configuration to build command line
8585
List<String> cmdLine = new ArrayList<String>();
8686

8787
if (preferenceStore.getBoolean(PreferenceConstants.NODE_JUST_NODE)){
@@ -96,10 +96,10 @@ public void launch(ILaunchConfiguration configuration, String mode,
9696
Dialogs.showPreferencesDialog("Node.js runtime is not correctly configured.\n\n"
9797
+ "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location");
9898
return;
99-
}
99+
}
100100
cmdLine.add(nodePath);
101101
}
102-
102+
103103
if (isDebugMode) {
104104
// -brk says to Node runtime wait until Chromium Debugger starts and connects
105105
// that is causing "stop on first line" behavior,
@@ -113,24 +113,24 @@ public void launch(ILaunchConfiguration configuration, String mode,
113113
if (nodeDebugPort==0) { nodeDebugPort=5858;};
114114
cmdLine.add("--debug"+brk+"="+nodeDebugPort); //--debug-brk=5858
115115
}
116-
116+
117117
//@since 0.9 from Preferences
118118
String nodeOptions= preferenceStore.getString(PreferenceConstants.NODE_OPTIONS);
119119
if(!nodeOptions.equals("")) {
120120
String[] sa = nodeOptions.split(" ");
121121
for(String s : sa) {
122122
cmdLine.add(s);
123-
}
123+
}
124124
}
125-
125+
126126
String nodeArgs = configuration.getAttribute(Constants.ATTR_NODE_ARGUMENTS, "");
127127
if(!nodeArgs.equals("")) {
128128
String[] sa = nodeArgs.split(" ");
129129
for(String s : sa) {
130130
cmdLine.add(s);
131131
}
132132
}
133-
133+
134134
String file = configuration.getAttribute(Constants.KEY_FILE_PATH, Constants.BLANK_STRING);
135135
String extension = null;
136136
int i = file.lastIndexOf('.');
@@ -142,15 +142,15 @@ public void launch(ILaunchConfiguration configuration, String mode,
142142
// by default assume
143143
extension = "js";
144144
}
145-
145+
146146
// #57 running app.js with node-dev, forever, supervisor, nodemon etc
147147
// https://github.com/Nodeclipse/nodeclipse-1/issues/57
148148
String nodeMonitor = configuration.getAttribute(Constants.ATTR_NODE_MONITOR, "");
149149
if(!nodeMonitor.equals("")) { // any value
150150
//TODO support selection, now only one
151-
151+
152152
String nodeMonitorPath= preferenceStore.getString(PreferenceConstants.NODE_MONITOR_PATH);
153-
153+
154154
// Check if the node monitor location is correctly configured
155155
File nodeMonitorFile = new File(nodeMonitorPath);
156156
if(!nodeMonitorFile.exists()){
@@ -181,7 +181,7 @@ public void launch(ILaunchConfiguration configuration, String mode,
181181
//String typescriptCompiler = configuration.getAttribute(Constants.ATTR_TYPESCRIPT_COMPILER, "");
182182
cmdLine.add(preferenceStore.getString(PreferenceConstants.TYPESCRIPT_COMPILER_PATH));
183183
}
184-
184+
185185
String filePath = ResourcesPlugin.getWorkspace().getRoot().findMember(file).getLocation().toOSString();
186186
// path is relative, so can not found it.
187187
cmdLine.add(filePath);
@@ -194,7 +194,7 @@ public void launch(ILaunchConfiguration configuration, String mode,
194194
cmdLine.add(s);
195195
}
196196
}
197-
197+
198198
String programArgs = configuration.getAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, "");
199199
if(!programArgs.equals("")) {
200200
String[] sa = programArgs.split(" ");
@@ -216,75 +216,74 @@ public void launch(ILaunchConfiguration configuration, String mode,
216216
if (workingPath == null){
217217
workingPath = (new File(filePath)).getParentFile();
218218
}
219-
219+
220220
//env
221-
String[] envp = getEnvironmentVariables(configuration);
222-
221+
String[] envp = getEnvironmentVariables(configuration);
222+
223223
for(String s : cmdLine) NodeclipseConsole.write(s+" ");
224224
NodeclipseConsole.write("\n");
225-
225+
226226
String[] cmds = {};
227227
cmds = cmdLine.toArray(cmds);
228228
// Launch a process to run/debug. See also #71 (output is less or no output)
229229
Process p = DebugPlugin.exec(cmds, workingPath, envp);
230230
// 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);
232232
if (isDebugMode) {
233-
if(!process.isTerminated()) {
233+
if(!process.isTerminated()) {
234234
int nodeDebugPort = preferenceStore.getInt(PreferenceConstants.NODE_DEBUG_PORT);
235235
NodeDebugUtil.launch(mode, launch, monitor, nodeDebugPort);
236236
}
237237
}
238-
238+
239239
if (allowedMany){ //@since 0.7
240240
if (isDebugMode){
241-
nodeProcess = process;
241+
nodeProcess = process;
242242
}
243243
//nodeRunningProcesses.add(process);
244244
}else{
245-
nodeProcess = process;
245+
nodeProcess = process;
246246
}
247247
}
248-
248+
249+
public static String[] NODE_ENV_VAR_SET = new String[]{"APPDATA","PATH","TEMP","TMP","SystemDrive"}; // #81, #197
250+
249251
private String[] getEnvironmentVariables(ILaunchConfiguration configuration) throws CoreException {
250252
Map<String, String> envm = new HashMap<String, String>();
251253
envm = configuration.getAttribute(Constants.ATTR_ENVIRONMENT_VARIABLES, envm);
252-
253-
int envmSizeDelta = 4;
254+
255+
int envmSizeDelta = NODE_ENV_VAR_SET.length;
254256
Map<String,String> all = null;
255257
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
256258
boolean passAllEnvVars = preferenceStore.getBoolean(PreferenceConstants.NODE_PASS_ALL_ENVIRONMENT_VARIABLES);//@since 0.12
257259
if (passAllEnvVars){
258260
all = System.getenv();
259261
envmSizeDelta = all.size();
260262
}
261-
263+
262264
String[] envp = new String[envm.size()+envmSizeDelta]; // see below
263265
int idx = 0;
264266
for(String key : envm.keySet()) {
265267
String value = envm.get(key);
266268
envp[idx++] = key + "=" + value;
267269
}
268-
270+
269271
if (passAllEnvVars){
270272
for (Map.Entry<String, String> entry : all.entrySet())
271273
{
272274
//System.out.println(entry.getKey() + "/" + entry.getValue());
273275
envp[idx++] = entry.getKey() + "=" + entry.getValue();
274276
}
275277
}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+
}
282281
}
283282
if (!warned ){
284283
NodeclipseConsole.write(" These environment variables will be applied automatically to every `node` launch.\n");
285284
StringBuilder sb = new StringBuilder(100);
286285
for(int i=0; i<envp.length; i++){
287-
sb.append(" ").append(envp[i]).append('\n');
286+
sb.append(" ").append(envp[i]).append('\n');
288287
}
289288
NodeclipseConsole.write(sb.toString());
290289
warned = true;
@@ -295,21 +294,21 @@ private String[] getEnvironmentVariables(ILaunchConfiguration configuration) thr
295294
protected String getEnvVariableEqualsString(String envvarName){
296295
String envvarValue = System.getenv(envvarName);
297296
if (envvarValue==null) envvarValue = "";
298-
return envvarName + "=" + envvarValue;
297+
return envvarName + "=" + envvarValue;
299298
}
300-
299+
301300
private void showErrorDialog(final String message) {
302301
Display.getDefault().syncExec(new Runnable() {
303302
public void run() {
304303
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
305304

306-
MessageDialog dialog = new MessageDialog(shell, "Nodeclipse", null, message,
305+
MessageDialog dialog = new MessageDialog(shell, "Nodeclipse", null, message,
307306
MessageDialog.ERROR, new String[] { "OK" }, 0);
308307
dialog.open();
309308
}
310309
});
311310
}
312-
311+
313312
public static void terminateNodeProcess() {
314313
if(nodeProcess != null) {
315314
try {

org.nodeclipse.ui/src/org/nodeclipse/ui/npm/LaunchConfigurationDelegate.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import org.nodeclipse.ui.util.OSUtils;
2222

2323
public class LaunchConfigurationDelegate implements ILaunchConfigurationDelegate {
24-
24+
2525
private boolean warned = false;
2626

2727
/*
2828
* (non-Javadoc)
29-
*
29+
*
3030
* @see
3131
* org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.
3232
* eclipse.debug.core.ILaunchConfiguration, java.lang.String,
@@ -39,20 +39,20 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
3939
List<String> cmdLine = new ArrayList<String>();
4040
String nodePath = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.NODE_PATH);
4141
cmdLine.add(findNpm(nodePath));
42-
42+
4343
String goal = configuration.getAttribute(Constants.KEY_GOAL, Constants.BLANK_STRING);
4444
cmdLine.add(goal);
4545
String file = configuration.getAttribute(Constants.KEY_FILE_PATH, Constants.BLANK_STRING);
4646
String filePath = ResourcesPlugin.getWorkspace().getRoot().findMember(file).getLocation().toOSString();
4747

4848
File workingPath = (new File(filePath)).getParentFile();
49-
49+
5050
//env
51-
String[] envp = getEnvironmentVariables(configuration);
52-
51+
String[] envp = getEnvironmentVariables(configuration);
52+
5353
String[] cmds = {};
5454
cmds = cmdLine.toArray(cmds);
55-
55+
5656
// Process p = null;
5757
// if(OSUtils.isMacOS()) {
5858
// String[] env = {"PATH=" + nodePath.substring(0, nodePath.lastIndexOf(File.separator))};
@@ -63,47 +63,46 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
6363
Process p = DebugPlugin.exec(cmds, workingPath, envp);
6464
DebugPlugin.newProcess(launch, p, Constants.NPM_PROCESS_MESSAGE + goal);
6565
}
66-
67-
// copied from org.nodeclipse.debug.launch.LaunchConfigurationDelegate
66+
67+
// copied from org.nodeclipse.debug.launch.LaunchConfigurationDelegate {
68+
public static String[] NODE_ENV_VAR_SET = new String[]{"APPDATA","PATH","TEMP","TMP","SystemDrive"}; // #81, #197
69+
6870
private String[] getEnvironmentVariables(ILaunchConfiguration configuration) throws CoreException {
6971
Map<String, String> envm = new HashMap<String, String>();
7072
envm = configuration.getAttribute(Constants.ATTR_ENVIRONMENT_VARIABLES, envm);
71-
72-
int envmSizeDelta = 4;
73+
74+
int envmSizeDelta = NODE_ENV_VAR_SET.length;
7375
Map<String,String> all = null;
7476
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
7577
boolean passAllEnvVars = preferenceStore.getBoolean(PreferenceConstants.NODE_PASS_ALL_ENVIRONMENT_VARIABLES);//@since 0.12
7678
if (passAllEnvVars){
7779
all = System.getenv();
7880
envmSizeDelta = all.size();
7981
}
80-
82+
8183
String[] envp = new String[envm.size()+envmSizeDelta]; // see below
8284
int idx = 0;
8385
for(String key : envm.keySet()) {
8486
String value = envm.get(key);
8587
envp[idx++] = key + "=" + value;
8688
}
87-
89+
8890
if (passAllEnvVars){
8991
for (Map.Entry<String, String> entry : all.entrySet())
9092
{
9193
//System.out.println(entry.getKey() + "/" + entry.getValue());
9294
envp[idx++] = entry.getKey() + "=" + entry.getValue();
9395
}
9496
}else{
95-
envp[idx++] = getEnvVariableEqualsString("APPDATA"); //#197
96-
//+ #81
97-
envp[idx++] = getEnvVariableEqualsString("PATH");
98-
envp[idx++] = getEnvVariableEqualsString("TEMP");
99-
envp[idx++] = getEnvVariableEqualsString("TMP");
100-
envp[idx++] = getEnvVariableEqualsString("SystemDrive");
97+
for (String envVarName : NODE_ENV_VAR_SET){
98+
envp[idx++] = getEnvVariableEqualsString(envVarName);
99+
}
101100
}
102101
if (!warned ){
103102
NodeclipseConsole.write(" These environment variables will be applied automatically to every `node` launch.\n");
104103
StringBuilder sb = new StringBuilder(100);
105104
for(int i=0; i<envp.length; i++){
106-
sb.append(" ").append(envp[i]).append('\n');
105+
sb.append(" ").append(envp[i]).append('\n');
107106
}
108107
NodeclipseConsole.write(sb.toString());
109108
warned = true;
@@ -114,10 +113,10 @@ private String[] getEnvironmentVariables(ILaunchConfiguration configuration) thr
114113
protected String getEnvVariableEqualsString(String envvarName){
115114
String envvarValue = System.getenv(envvarName);
116115
if (envvarValue==null) envvarValue = "";
117-
return envvarName + "=" + envvarValue;
116+
return envvarName + "=" + envvarValue;
118117
}
119-
120-
118+
//}
119+
121120
private static String findNpm(String nodePath) {
122121
//TODO npm application path should be stored in preference.
123122
String npmFileName = getNpmFileName();
@@ -126,7 +125,7 @@ private static String findNpm(String nodePath) {
126125
if(npmFile.exists()) {
127126
return npmFile.getAbsolutePath();
128127
}
129-
128+
130129
String path = System.getenv("PATH");
131130
String[] paths = path.split("" + File.pathSeparatorChar, 0);
132131
List<String> directories = new ArrayList<String>();

0 commit comments

Comments
 (0)