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 (-81 / +24 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 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 13-19 Link Here
13
13
14
import java.util.regex.Pattern;
14
import java.util.regex.Pattern;
15
15
16
import org.eclipse.ant.internal.ui.AntUIPlugin;
17
import org.eclipse.ant.internal.ui.IAntUIConstants;
16
import org.eclipse.ant.internal.ui.IAntUIConstants;
18
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
17
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
19
import org.eclipse.ant.launching.IAntLaunchConstants;
18
import org.eclipse.ant.launching.IAntLaunchConstants;
Lines 25-30 Link Here
25
import org.eclipse.debug.core.ILaunchConfiguration;
24
import org.eclipse.debug.core.ILaunchConfiguration;
26
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
25
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
27
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
26
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
27
import org.eclipse.jdt.core.IJavaProject;
28
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;
28
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;
29
import org.eclipse.jdt.internal.debug.ui.jres.JREDescriptor;
29
import org.eclipse.jdt.internal.debug.ui.jres.JREDescriptor;
30
import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock;
30
import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock;
Lines 96-117 Link Here
96
		boolean isDefaultJRE = fJREBlock.isDefaultJRE();
96
		boolean isDefaultJRE = fJREBlock.isDefaultJRE();
97
        fWorkingDirectoryBlock.setEnabled(!isDefaultJRE);
97
        fWorkingDirectoryBlock.setEnabled(!isDefaultJRE);
98
		fVMArgumentsBlock.setEnabled(!isDefaultJRE);
98
		fVMArgumentsBlock.setEnabled(!isDefaultJRE);
99
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, (String)null);
100
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
99
		if (isDefaultJRE) {
101
		if (isDefaultJRE) {
100
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, (String)null);
101
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
102
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
102
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
103
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String)null);
103
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String)null);
104
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
104
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
105
			configuration.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, false);
105
			configuration.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, false);
106
		} else {
106
		} else {
107
			super.performApply(configuration);
107
			super.performApply(configuration);
108
			
108
			IVMInstall vm = fJREBlock.getJRE();
109
			if (useDefaultSeparateJRE(configuration)) {
109
			configuration.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, (vm == null ? false : vm.equals(getDefaultVMInstall(configuration))));
110
				configuration.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, true);
111
			} else {
112
				configuration.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, false);
113
			}
114
			
115
			applySeparateVMAttributes(configuration);
110
			applySeparateVMAttributes(configuration);
116
			fVMArgumentsBlock.performApply(configuration);
111
			fVMArgumentsBlock.performApply(configuration);
117
			fWorkingDirectoryBlock.performApply(configuration);
112
			fWorkingDirectoryBlock.performApply(configuration);
Lines 119-154 Link Here
119
		setLaunchConfigurationWorkingCopy(configuration);
114
		setLaunchConfigurationWorkingCopy(configuration);
120
	}
115
	}
121
	
116
	
122
	private boolean useDefaultSeparateJRE(ILaunchConfigurationWorkingCopy configuration) {
123
		boolean deflt= false;
124
		String vmInstallType= null;
125
        String jreContainerPath= null;
126
		try {
127
			vmInstallType= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
128
            jreContainerPath= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
129
		} catch (CoreException e) {
130
		}
131
		if (vmInstallType != null) {
132
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
133
		}
134
        if (jreContainerPath != null) {
135
            configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
136
        }
137
		IVMInstall defaultVMInstall= getDefaultVMInstall(configuration);
138
		if (defaultVMInstall != null) {
139
			IVMInstall vm= fJREBlock.getJRE();
140
			deflt= defaultVMInstall.equals(vm);
141
		}
142
		
143
		if (vmInstallType != null) {
144
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmInstallType);
145
		}
146
        if (jreContainerPath != null) {
147
            configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jreContainerPath);
148
        }
149
		return deflt;
150
	}
151
	
152
	private void applySeparateVMAttributes(ILaunchConfigurationWorkingCopy configuration) {
117
	private void applySeparateVMAttributes(ILaunchConfigurationWorkingCopy configuration) {
153
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, MAIN_TYPE_NAME);
118
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, MAIN_TYPE_NAME);
154
		//only set to use the remote ant process factory if the user
119
		//only set to use the remote ant process factory if the user
Lines 189-223 Link Here
189
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
154
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
190
	 */
155
	 */
191
	public void initializeFrom(ILaunchConfiguration configuration) {
156
	public void initializeFrom(ILaunchConfiguration configuration) {
192
		try {
193
			 boolean isDefaultVMInstall= configuration.getAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, false);
194
			 if (isDefaultVMInstall) {
195
			 	ILaunchConfigurationWorkingCopy copy = null;
196
			 	if (configuration instanceof ILaunchConfigurationWorkingCopy) {
197
			 		copy= (ILaunchConfigurationWorkingCopy) configuration;
198
			 	} else {
199
			 		copy= configuration.getWorkingCopy();
200
			 	}
201
			 	
202
			 	//null out the vm type and jre container path to get the default vm install from JavaRuntime
203
			 	copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
204
			 	copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
205
			 	IVMInstall defaultVMInstall= getDefaultVMInstall(copy);
206
			 	if (defaultVMInstall != null) {
207
			 		//update if required
208
			 		setDefaultVMInstallAttributes(defaultVMInstall, copy);
209
			 	}
210
				if (copy.isDirty() && !copy.isReadOnly()) {
211
					configuration= copy.doSave();
212
				}
213
			 }
214
        } catch (CoreException ce) {
215
        	AntUIPlugin.log(ce);
216
        }
217
		super.initializeFrom(configuration);
157
		super.initializeFrom(configuration);
218
		fVMArgumentsBlock.initializeFrom(configuration);
158
		fVMArgumentsBlock.initializeFrom(configuration);
219
		fWorkingDirectoryBlock.initializeFrom(configuration);
159
		fWorkingDirectoryBlock.initializeFrom(configuration);
220
		boolean separateVM= !fJREBlock.isDefaultJRE();
160
		boolean separateVM = !fJREBlock.isDefaultJRE();
221
		fWorkingDirectoryBlock.setEnabled(separateVM);
161
		fWorkingDirectoryBlock.setEnabled(separateVM);
222
		fVMArgumentsBlock.setEnabled(separateVM);
162
		fVMArgumentsBlock.setEnabled(separateVM);
223
	}
163
	}
Lines 276-308 Link Here
276
		IVMInstall defaultVMInstall= getDefaultVMInstall(config);
216
		IVMInstall defaultVMInstall= getDefaultVMInstall(config);
277
		if (defaultVMInstall != null) {
217
		if (defaultVMInstall != null) {
278
			config.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, true);
218
			config.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, true);
279
			setDefaultVMInstallAttributes(defaultVMInstall, config);
219
			//setDefaultVMInstallAttributes(defaultVMInstall, config);
280
			applySeparateVMAttributes(config);
220
			applySeparateVMAttributes(config);
281
		}
221
		}
282
		
222
		
283
	}
223
	}
284
224
225
	/**
226
	 * Returns the default {@link IVMInstall} for the given {@link ILaunchConfiguration}, which resolves
227
	 * to the {@link IVMInstall} for the backing {@link IJavaProject} as specified by the project
228
	 * attribute in the configuration. If there is no project attribute the workspace default
229
	 * {@link IVMInstall} is returned.
230
	 * 
231
	 * @param config
232
	 * @return the default {@link IVMInstall} for the given {@link ILaunchConfiguration}
233
	 */
285
	private IVMInstall getDefaultVMInstall(ILaunchConfiguration config) {
234
	private IVMInstall getDefaultVMInstall(ILaunchConfiguration config) {
286
		IVMInstall defaultVMInstall;
287
		try {
235
		try {
288
			defaultVMInstall = JavaRuntime.computeVMInstall(config);
236
			IJavaProject project = JavaRuntime.getJavaProject(config);
237
			if(project != null) {
238
				return JavaRuntime.getVMInstall(project);
239
			}
240
			return JavaRuntime.getDefaultVMInstall();
289
		} catch (CoreException e) {
241
		} catch (CoreException e) {
290
			//core exception thrown for non-Java project
242
			//core exception thrown for non-Java project
291
			defaultVMInstall= JavaRuntime.getDefaultVMInstall();
243
			return JavaRuntime.getDefaultVMInstall();
292
		}
244
		}
293
		return defaultVMInstall;
294
	}
245
	}
295
246
296
	private void setDefaultVMInstallAttributes(IVMInstall defaultVMInstall, ILaunchConfigurationWorkingCopy config) {
297
		String vmName = defaultVMInstall.getName();
298
		String vmTypeID = defaultVMInstall.getVMInstallType().getId();
299
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, vmName);
300
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmTypeID);
301
	}
302
	
303
	/* (non-Javadoc)
247
	/* (non-Javadoc)
304
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
248
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
305
	 */
249
	 */
306
	public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
250
	public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {}
307
	}
308
}
251
}

Return to bug 147044