1 11 12 package org.eclipse.ant.internal.ui.launchConfigurations; 13 14 import org.eclipse.ant.internal.ui.AntUIPlugin; 15 import org.eclipse.ant.internal.ui.IAntUIConstants; 16 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.ILaunchConfiguration; 20 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 21 import org.eclipse.debug.ui.ILaunchConfigurationDialog; 22 import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab; 23 import org.eclipse.jdt.internal.debug.ui.jres.JREDescriptor; 24 import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock; 25 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 26 import org.eclipse.jdt.launching.IVMInstall; 27 import org.eclipse.jdt.launching.JavaRuntime; 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.ui.PlatformUI; 32 import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil; 33 34 public class AntJRETab extends JavaJRETab { 35 36 private static final String MAIN_TYPE_NAME= "org.eclipse.ant.internal.ui.antsupport.InternalAntRunner"; 38 private VMArgumentsBlock fVMArgumentsBlock= new VMArgumentsBlock(); 39 private AntWorkingDirectoryBlock fWorkingDirectoryBlock= new AntWorkingDirectoryBlock(); 40 41 44 public void createControl(Composite parent) { 45 super.createControl(parent); 46 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IAntUIHelpContextIds.ANT_JRE_TAB); 47 Composite comp= (Composite)fJREBlock.getControl(); 48 ((GridData)comp.getLayoutData()).grabExcessVerticalSpace= true; 49 ((GridData)comp.getLayoutData()).verticalAlignment= SWT.FILL; 50 51 fVMArgumentsBlock.createControl(comp); 52 ((GridData)fVMArgumentsBlock.getControl().getLayoutData()).horizontalSpan= 2; 53 54 fWorkingDirectoryBlock.createControl(comp); 55 ((GridData)fWorkingDirectoryBlock.getControl().getLayoutData()).horizontalSpan= 2; 56 } 57 58 61 protected JREDescriptor getDefaultJREDescriptor() { 62 return new JREDescriptor() { 63 66 public String getDescription() { 67 return AntLaunchConfigurationMessages.AntJRETab_2; 68 } 69 }; 70 } 71 72 75 protected JREDescriptor getSpecificJREDescriptor() { 76 return new JREDescriptor() { 77 80 public String getDescription() { 81 return AntLaunchConfigurationMessages.AntJRETab_3; 82 } 83 }; 84 } 85 86 89 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 90 boolean isDefaultJRE = fJREBlock.isDefaultJRE(); 91 fWorkingDirectoryBlock.setEnabled(!isDefaultJRE); 92 fVMArgumentsBlock.setEnabled(!isDefaultJRE); 93 if (isDefaultJRE) { 94 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, (String )null); 95 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String )null); 96 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String )null); 97 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String )null); 98 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String )null); 99 configuration.setAttribute(IAntUIConstants.ATTR_DEFAULT_VM_INSTALL, false); 100 } else { 101 super.performApply(configuration); 102 103 if (useDefaultSeparateJRE(configuration)) { 104 configuration.setAttribute(IAntUIConstants.ATTR_DEFAULT_VM_INSTALL, true); 105 } else { 106 configuration.setAttribute(IAntUIConstants.ATTR_DEFAULT_VM_INSTALL, false); 107 } 108 109 applySeparateVMAttributes(configuration); 110 fVMArgumentsBlock.performApply(configuration); 111 fWorkingDirectoryBlock.performApply(configuration); 112 } 113 setLaunchConfigurationWorkingCopy(configuration); 114 } 115 116 private boolean useDefaultSeparateJRE(ILaunchConfigurationWorkingCopy configuration) { 117 boolean deflt= false; 118 String vmInstallType= null; 119 String jreContainerPath= null; 120 try { 121 vmInstallType= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String )null); 122 jreContainerPath= configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String )null); 123 } catch (CoreException e) { 124 } 125 if (vmInstallType != null) { 126 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String )null); 127 } 128 if (jreContainerPath != null) { 129 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String )null); 130 } 131 IVMInstall defaultVMInstall= getDefaultVMInstall(configuration); 132 if (defaultVMInstall != null) { 133 IVMInstall vm= fJREBlock.getJRE(); 134 deflt= defaultVMInstall.equals(vm); 135 } 136 137 if (vmInstallType != null) { 138 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmInstallType); 139 } 140 if (jreContainerPath != null) { 141 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jreContainerPath); 142 } 143 return deflt; 144 } 145 146 private void applySeparateVMAttributes(ILaunchConfigurationWorkingCopy configuration) { 147 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, MAIN_TYPE_NAME); 148 boolean userLogger= false; 151 try { 152 String [] arguments = ExternalToolsUtil.getArguments(configuration); 153 if (arguments != null) { 154 for (int i = 0; i < arguments.length; i++) { 155 String arg = arguments[i]; 156 if (arg.equals("-logger")) { userLogger= true; 158 break; 159 } 160 } 161 } 162 } catch (CoreException e) { 163 } 164 if (userLogger) { 165 configuration.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, (String ) null); 166 } else { 167 configuration.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, IAntUIConstants.REMOTE_ANT_PROCESS_FACTORY_ID); 168 } 169 } 170 171 174 public void initializeFrom(ILaunchConfiguration configuration) { 175 try { 176 boolean isDefaultVMInstall= configuration.getAttribute(IAntUIConstants.ATTR_DEFAULT_VM_INSTALL, false); 177 if (isDefaultVMInstall) { 178 ILaunchConfigurationWorkingCopy copy = null; 179 if (configuration instanceof ILaunchConfigurationWorkingCopy) { 180 copy= (ILaunchConfigurationWorkingCopy) configuration; 181 } else { 182 copy= configuration.getWorkingCopy(); 183 } 184 185 copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String )null); 187 copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String )null); 188 IVMInstall defaultVMInstall= getDefaultVMInstall(copy); 189 if (defaultVMInstall != null) { 190 setDefaultVMInstallAttributes(defaultVMInstall, copy); 192 } 193 if (copy.isDirty() && !copy.isReadOnly()) { 194 configuration= copy.doSave(); 195 } 196 } 197 } catch (CoreException ce) { 198 AntUIPlugin.log(ce); 199 } 200 super.initializeFrom(configuration); 201 fVMArgumentsBlock.initializeFrom(configuration); 202 fWorkingDirectoryBlock.initializeFrom(configuration); 203 boolean separateVM= !fJREBlock.isDefaultJRE(); 204 fWorkingDirectoryBlock.setEnabled(separateVM); 205 fVMArgumentsBlock.setEnabled(separateVM); 206 } 207 208 211 public boolean isValid(ILaunchConfiguration config) { 212 return super.isValid(config) && fWorkingDirectoryBlock.isValid(config); 213 } 214 215 218 public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) { 219 super.setLaunchConfigurationDialog(dialog); 220 fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog); 221 fVMArgumentsBlock.setLaunchConfigurationDialog(dialog); 222 } 223 224 227 public String getErrorMessage() { 228 String m = super.getErrorMessage(); 229 if (m == null) { 230 return fWorkingDirectoryBlock.getErrorMessage(); 231 } 232 return m; 233 } 234 235 238 public String getMessage() { 239 String m = super.getMessage(); 240 if (m == null) { 241 return fWorkingDirectoryBlock.getMessage(); 242 } 243 return m; 244 } 245 246 249 public void activated(ILaunchConfigurationWorkingCopy workingCopy) { 250 setLaunchConfigurationWorkingCopy(workingCopy); 251 } 252 253 256 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 257 super.setDefaults(config); 258 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); IVMInstall defaultVMInstall= getDefaultVMInstall(config); 260 if (defaultVMInstall != null) { 261 config.setAttribute(IAntUIConstants.ATTR_DEFAULT_VM_INSTALL, true); 262 setDefaultVMInstallAttributes(defaultVMInstall, config); 263 applySeparateVMAttributes(config); 264 } 265 266 } 267 268 private IVMInstall getDefaultVMInstall(ILaunchConfiguration config) { 269 IVMInstall defaultVMInstall; 270 try { 271 defaultVMInstall = JavaRuntime.computeVMInstall(config); 272 } catch (CoreException e) { 273 defaultVMInstall= JavaRuntime.getDefaultVMInstall(); 275 } 276 return defaultVMInstall; 277 } 278 279 private void setDefaultVMInstallAttributes(IVMInstall defaultVMInstall, ILaunchConfigurationWorkingCopy config) { 280 String vmName = defaultVMInstall.getName(); 281 String vmTypeID = defaultVMInstall.getVMInstallType().getId(); 282 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, vmName); 283 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmTypeID); 284 } 285 286 289 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { 290 } 291 } 292 | Popular Tags |