View | Details | Raw Unified | Return to bug 327193 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/Standard11xVMRunner.java (-2 / +11 lines)
Lines 85-98 Link Here
85
			combinedPath[offset] = classPath[i];
85
			combinedPath[offset] = classPath[i];
86
			offset++;
86
			offset++;
87
		}
87
		}
88
		
88
		int cpidx = -1;
89
		if (combinedPath.length > 0) {
89
		if (combinedPath.length > 0) {
90
			cpidx = arguments.size();
90
			arguments.add("-classpath"); //$NON-NLS-1$
91
			arguments.add("-classpath"); //$NON-NLS-1$
91
			arguments.add(convertClassPath(combinedPath));
92
			arguments.add(convertClassPath(combinedPath));
92
		}
93
		}
93
		arguments.add(config.getClassToLaunch());
94
		arguments.add(config.getClassToLaunch());
94
		
95
		
95
		String[] programArgs= config.getProgramArguments();
96
		String[] programArgs= config.getProgramArguments();
97
		
98
		String[] envp = prependJREPath(config.getEnvironment());
99
		String[] newenvp = checkClasspath(arguments, classPath, envp);
100
		if(newenvp != null) {
101
			envp = newenvp;
102
			arguments.remove(cpidx);
103
			arguments.remove(cpidx);
104
		}
96
		addArguments(programArgs, arguments);
105
		addArguments(programArgs, arguments);
97
				
106
				
98
		String[] cmdLine= new String[arguments.size()];
107
		String[] cmdLine= new String[arguments.size()];
Lines 108-114 Link Here
108
		
117
		
109
		Process p= null;
118
		Process p= null;
110
		File workingDir = getWorkingDir(config);
119
		File workingDir = getWorkingDir(config);
111
		p= exec(cmdLine, workingDir);
120
		p= exec(cmdLine, workingDir, envp);
112
		if (p == null) {
121
		if (p == null) {
113
			return;
122
			return;
114
		}
123
		}
(-)a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMDebugger.java (-4 / +12 lines)
Lines 208-230 Link Here
208
		addBootClassPathArguments(arguments, config);
208
		addBootClassPathArguments(arguments, config);
209
		
209
		
210
		String[] cp= config.getClassPath();
210
		String[] cp= config.getClassPath();
211
		int cpidx = -1;
211
		if (cp.length > 0) {
212
		if (cp.length > 0) {
213
			cpidx = arguments.size();
212
			arguments.add("-classpath"); //$NON-NLS-1$
214
			arguments.add("-classpath"); //$NON-NLS-1$
213
			arguments.add(convertClassPath(cp));
215
			arguments.add(convertClassPath(cp));
214
		}
216
		}
215
		
217
		
216
		
217
		
218
		arguments.add(config.getClassToLaunch());
218
		arguments.add(config.getClassToLaunch());
219
		addArguments(config.getProgramArguments(), arguments);
219
		addArguments(config.getProgramArguments(), arguments);
220
		String[] cmdLine= new String[arguments.size()];
221
		arguments.toArray(cmdLine);
222
		
220
		
223
		//With the newer VMs and no backwards compatibility we have to always prepend the current env path (only the runtime one)
221
		//With the newer VMs and no backwards compatibility we have to always prepend the current env path (only the runtime one)
224
		//with a 'corrected' path that points to the location to load the debug dlls from, this location is of the standard JDK installation 
222
		//with a 'corrected' path that points to the location to load the debug dlls from, this location is of the standard JDK installation 
225
		//format: <jdk path>/jre/bin
223
		//format: <jdk path>/jre/bin
226
		String[] envp = prependJREPath(config.getEnvironment(), new Path(program));
224
		String[] envp = prependJREPath(config.getEnvironment(), new Path(program));
227
		
225
		
226
		String[] newenvp = checkClasspath(arguments, cp, envp);
227
		if(newenvp != null) {
228
			envp = newenvp;
229
			arguments.remove(cpidx);
230
			arguments.remove(cpidx);
231
		}
232
		
233
		String[] cmdLine= new String[arguments.size()];
234
		arguments.toArray(cmdLine);
235
		
228
		// check for cancellation
236
		// check for cancellation
229
		if (monitor.isCanceled()) {
237
		if (monitor.isCanceled()) {
230
			return;
238
			return;
(-)a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java (-3 / +80 lines)
Lines 208-214 Link Here
208
		if (fileExists(exe)) {
208
		if (fileExists(exe)) {
209
			return exe.getAbsolutePath(); 
209
			return exe.getAbsolutePath(); 
210
		}		
210
		}		
211
212
		
211
		
213
		// not found
212
		// not found
214
		abort(NLS.bind(LaunchingMessages.StandardVMRunner_Specified_executable__0__does_not_exist_for__1__4, new String[]{command, fVMInstance.getName()}), null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); 
213
		abort(NLS.bind(LaunchingMessages.StandardVMRunner_Specified_executable__0__does_not_exist_for__1__4, new String[]{command, fVMInstance.getName()}), null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); 
Lines 297-303 Link Here
297
		addBootClassPathArguments(arguments, config);
296
		addBootClassPathArguments(arguments, config);
298
		
297
		
299
		String[] cp= config.getClassPath();
298
		String[] cp= config.getClassPath();
299
		int cpidx = -1;
300
		if (cp.length > 0) {
300
		if (cp.length > 0) {
301
			cpidx = arguments.size();
301
			arguments.add("-classpath"); //$NON-NLS-1$
302
			arguments.add("-classpath"); //$NON-NLS-1$
302
			arguments.add(convertClassPath(cp));
303
			arguments.add(convertClassPath(cp));
303
		}
304
		}
Lines 306-315 Link Here
306
		String[] programArgs= config.getProgramArguments();
307
		String[] programArgs= config.getProgramArguments();
307
		addArguments(programArgs, arguments);
308
		addArguments(programArgs, arguments);
308
				
309
				
310
		String[] envp = prependJREPath(config.getEnvironment());
311
		
312
		String[] newenvp = checkClasspath(arguments, cp, envp);
313
		if(newenvp != null) {
314
			envp = newenvp;
315
			arguments.remove(cpidx);
316
			arguments.remove(cpidx);
317
		}
318
		
309
		String[] cmdLine= new String[arguments.size()];
319
		String[] cmdLine= new String[arguments.size()];
310
		arguments.toArray(cmdLine);
320
		arguments.toArray(cmdLine);
311
		
312
		String[] envp = prependJREPath(config.getEnvironment());
313
		
321
		
314
		subMonitor.worked(1);
322
		subMonitor.worked(1);
315
323
Lines 356-361 Link Here
356
	}
364
	}
357
	
365
	
358
	/**
366
	/**
367
	 * Returns the index in the given array for the CLASSPATH variable
368
	 * @param env the environment array or <code>null</code>
369
	 * @return -1 or the index of the CLASSPATH variable
370
	 * @since 3.6.200
371
	 */
372
	int getCPIndex(String[] env) {
373
		if(env != null) {
374
			for (int i = 0; i < env.length; i++) {
375
				if(env[i].startsWith("CLASSPATH")) { //$NON-NLS-1$
376
					return i;
377
				}
378
			}
379
		}
380
		return -1;
381
	}
382
	
383
	/**
384
	 * Checks to see if the command / classpath needs to be shortened for Windows. Returns the modified
385
	 * environment or <code>null</code> if no changes are needed.
386
	 * 
387
	 * @param args the raw arguments from the runner
388
	 * @param cp the raw classpath from the runner configuration
389
	 * @param env the current environment
390
	 * @return the modified environment or <code>null</code> if no changes were made
391
	 * @sine 3.6.200
392
	 */
393
	String[] checkClasspath(List<String> args, String[] cp, String[] env) { 
394
		if(Platform.getOS().equals(Platform.OS_WIN32)) {
395
			//count the complete command length
396
			int size = 0;
397
			for (String arg : args) {
398
				if(arg != null) {
399
					size += arg.length();
400
				}
401
			}
402
			//greater than 32768 is a no-go
403
			//see http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
404
			if(size > 32768) {
405
				StringBuffer newcp = new StringBuffer();
406
				for (int i = 0; i < cp.length; i++) {
407
					newcp.append(cp[i]);
408
					newcp.append(';');
409
				}
410
				int index = getCPIndex(env);
411
				if(index < 0) {
412
					newcp.insert(0, "CLASSPATH="); //$NON-NLS-1$
413
					if(env == null) {
414
						String[] newenv = new String[1];
415
						newenv[0] = newcp.toString(); 
416
						return newenv;
417
					}
418
					String[] newenv = new String[env.length+1];
419
					System.arraycopy(env, 0, newenv, 0, env.length);
420
					newenv[env.length] = newcp.toString();  
421
					return newenv;
422
				}
423
				String oldcp = env[index];
424
				if(!oldcp.endsWith(";")) { //$NON-NLS-1$
425
					oldcp += ';';
426
				}
427
				newcp.insert(0, oldcp);
428
				env[index] = newcp.toString();
429
				return env;
430
			}
431
		}
432
		return null;
433
	}
434
	
435
	/**
359
	 * Prepends the correct java version variable state to the environment path for Mac VMs
436
	 * Prepends the correct java version variable state to the environment path for Mac VMs
360
	 * 
437
	 * 
361
	 * @param env the current array of environment variables to run with
438
	 * @param env the current array of environment variables to run with

Return to bug 327193