Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 147044 | Differences between
and this patch

Collapse All | Expand All

(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java (-82 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-17 Link Here
11
11
12
package org.eclipse.ant.internal.ui.launchConfigurations;
12
package org.eclipse.ant.internal.ui.launchConfigurations;
13
13
14
import org.eclipse.ant.internal.ui.AntUIPlugin;
15
import org.eclipse.ant.internal.ui.IAntUIConstants;
14
import org.eclipse.ant.internal.ui.IAntUIConstants;
16
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
15
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
17
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
16
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
Lines 20-25 Link Here
20
import org.eclipse.debug.core.ILaunchConfiguration;
19
import org.eclipse.debug.core.ILaunchConfiguration;
21
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
20
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
22
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
21
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
22
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;
23
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;
24
import org.eclipse.jdt.internal.debug.ui.jres.JREDescriptor;
24
import org.eclipse.jdt.internal.debug.ui.jres.JREDescriptor;
25
import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock;
25
import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock;
Lines 91-112 Link Here
91
		boolean isDefaultJRE = fJREBlock.isDefaultJRE();
91
		boolean isDefaultJRE = fJREBlock.isDefaultJRE();
92
        fWorkingDirectoryBlock.setEnabled(!isDefaultJRE);
92
        fWorkingDirectoryBlock.setEnabled(!isDefaultJRE);
93
		fVMArgumentsBlock.setEnabled(!isDefaultJRE);
93
		fVMArgumentsBlock.setEnabled(!isDefaultJRE);
94
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, (String)null);
95
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
94
		if (isDefaultJRE) {
96
		if (isDefaultJRE) {
95
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, (String)null);
96
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
97
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
97
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
98
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String)null);
98
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String)null);
99
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
99
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
100
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, false);
100
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, false);
101
		} else {
101
		} else {
102
			super.performApply(configuration);
102
			super.performApply(configuration);
103
			
103
			IVMInstall vm = fJREBlock.getJRE();
104
			if (useDefaultSeparateJRE(configuration)) {
104
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, (vm == null ? false : vm.equals(getDefaultVMInstall(configuration))));
105
				configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, true);
106
			} else {
107
				configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, false);
108
			}
109
			
110
			applySeparateVMAttributes(configuration);
105
			applySeparateVMAttributes(configuration);
111
			fVMArgumentsBlock.performApply(configuration);
106
			fVMArgumentsBlock.performApply(configuration);
112
			fWorkingDirectoryBlock.performApply(configuration);
107
			fWorkingDirectoryBlock.performApply(configuration);
Lines 114-149 Link Here
114
		setLaunchConfigurationWorkingCopy(configuration);
109
		setLaunchConfigurationWorkingCopy(configuration);
115
	}
110
	}
116
	
111
	
117
	private boolean useDefaultSeparateJRE(ILaunchConfigurationWorkingCopy configuration) {
118
		boolean deflt= false;
119
		String vmInstallType= null;
120
        String jreContainerPath= null;
121
		try {
122
			vmInstallType= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
123
            jreContainerPath= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
124
		} catch (CoreException e) {
125
		}
126
		if (vmInstallType != null) {
127
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
128
		}
129
        if (jreContainerPath != null) {
130
            configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
131
        }
132
		IVMInstall defaultVMInstall= getDefaultVMInstall(configuration);
133
		if (defaultVMInstall != null) {
134
			IVMInstall vm= fJREBlock.getJRE();
135
			deflt= defaultVMInstall.equals(vm);
136
		}
137
		
138
		if (vmInstallType != null) {
139
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmInstallType);
140
		}
141
        if (jreContainerPath != null) {
142
            configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jreContainerPath);
143
        }
144
		return deflt;
145
	}
146
	
147
	private void applySeparateVMAttributes(ILaunchConfigurationWorkingCopy configuration) {
112
	private void applySeparateVMAttributes(ILaunchConfigurationWorkingCopy configuration) {
148
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, MAIN_TYPE_NAME);
113
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, MAIN_TYPE_NAME);
149
		//only set to use the remote ant process factory if the user
114
		//only set to use the remote ant process factory if the user
Lines 173-207 Link Here
173
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
138
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
174
	 */
139
	 */
175
	public void initializeFrom(ILaunchConfiguration configuration) {
140
	public void initializeFrom(ILaunchConfiguration configuration) {
176
		try {
177
			 boolean isDefaultVMInstall= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, false);
178
			 if (isDefaultVMInstall) {
179
			 	ILaunchConfigurationWorkingCopy copy = null;
180
			 	if (configuration instanceof ILaunchConfigurationWorkingCopy) {
181
			 		copy= (ILaunchConfigurationWorkingCopy) configuration;
182
			 	} else {
183
			 		copy= configuration.getWorkingCopy();
184
			 	}
185
			 	
186
			 	//null out the vm type and jre container path to get the default vm install from JavaRuntime
187
			 	copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
188
			 	copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
189
			 	IVMInstall defaultVMInstall= getDefaultVMInstall(copy);
190
			 	if (defaultVMInstall != null) {
191
			 		//update if required
192
			 		setDefaultVMInstallAttributes(defaultVMInstall, copy);
193
			 	}
194
				if (copy.isDirty() && !copy.isReadOnly()) {
195
					configuration= copy.doSave();
196
				}
197
			 }
198
        } catch (CoreException ce) {
199
        	AntUIPlugin.log(ce);
200
        }
201
		super.initializeFrom(configuration);
141
		super.initializeFrom(configuration);
202
		fVMArgumentsBlock.initializeFrom(configuration);
142
		fVMArgumentsBlock.initializeFrom(configuration);
203
		fWorkingDirectoryBlock.initializeFrom(configuration);
143
		fWorkingDirectoryBlock.initializeFrom(configuration);
204
		boolean separateVM= !fJREBlock.isDefaultJRE();
144
		boolean separateVM = !fJREBlock.isDefaultJRE();
205
		fWorkingDirectoryBlock.setEnabled(separateVM);
145
		fWorkingDirectoryBlock.setEnabled(separateVM);
206
		fVMArgumentsBlock.setEnabled(separateVM);
146
		fVMArgumentsBlock.setEnabled(separateVM);
207
	}
147
	}
Lines 257-292 Link Here
257
	public void setDefaults(ILaunchConfigurationWorkingCopy config) {
197
	public void setDefaults(ILaunchConfigurationWorkingCopy config) {
258
		super.setDefaults(config);
198
		super.setDefaults(config);
259
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); //$NON-NLS-1$
199
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); //$NON-NLS-1$
260
		IVMInstall defaultVMInstall= getDefaultVMInstall(config);
200
		IVMInstall defaultVMInstall = getDefaultVMInstall(config);
261
		if (defaultVMInstall != null) {
201
		if (defaultVMInstall != null) {
262
			config.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, true);
202
			config.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, true);
263
			setDefaultVMInstallAttributes(defaultVMInstall, config);
203
			//setDefaultVMInstallAttributes(defaultVMInstall, config);
264
			applySeparateVMAttributes(config);
204
			applySeparateVMAttributes(config);
265
		}
205
		}
266
		
206
		
267
	}
207
	}
268
208
209
	/**
210
	 * Returns the default {@link IVMInstall} for the given {@link ILaunchConfiguration}, which resolves
211
	 * to the {@link IVMInstall} for the backing {@link IJavaProject} as specified by the project
212
	 * attribute in the configuration. If there is no project attribute the workspace default
213
	 * {@link IVMInstall} is returned.
214
	 * 
215
	 * @param config
216
	 * @return the default {@link IVMInstall} for the given {@link ILaunchConfiguration}
217
	 */
269
	private IVMInstall getDefaultVMInstall(ILaunchConfiguration config) {
218
	private IVMInstall getDefaultVMInstall(ILaunchConfiguration config) {
270
		IVMInstall defaultVMInstall;
271
		try {
219
		try {
272
			defaultVMInstall = JavaRuntime.computeVMInstall(config);
220
			IJavaProject project = JavaRuntime.getJavaProject(config);
221
			if(project != null) {
222
				return JavaRuntime.getVMInstall(project);
223
			}
224
			return JavaRuntime.getDefaultVMInstall();
273
		} catch (CoreException e) {
225
		} catch (CoreException e) {
274
			//core exception thrown for non-Java project
226
			//core exception thrown for non-Java project
275
			defaultVMInstall= JavaRuntime.getDefaultVMInstall();
227
			return JavaRuntime.getDefaultVMInstall();
276
		}
228
		}
277
		return defaultVMInstall;
278
	}
279
280
	private void setDefaultVMInstallAttributes(IVMInstall defaultVMInstall, ILaunchConfigurationWorkingCopy config) {
281
		String vmName = defaultVMInstall.getName();
282
		String vmTypeID = defaultVMInstall.getVMInstallType().getId();
283
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, vmName);
284
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmTypeID);
285
	}
229
	}
286
	
230
	
287
	/* (non-Javadoc)
231
	/* (non-Javadoc)
288
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
232
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
289
	 */
233
	 */
290
	public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
234
	public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {}
291
	}
292
}
235
}

Return to bug 147044