1 11 package org.eclipse.pde.ui.launcher; 12 13 import java.io.File ; 14 import java.util.ArrayList ; 15 import java.util.Map ; 16 17 import org.eclipse.core.resources.IProject; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.SubProgressMonitor; 23 import org.eclipse.debug.core.DebugPlugin; 24 import org.eclipse.debug.core.ILaunch; 25 import org.eclipse.debug.core.ILaunchConfiguration; 26 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 27 import org.eclipse.debug.core.model.LaunchConfigurationDelegate; 28 import org.eclipse.jdt.launching.ExecutionArguments; 29 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 30 import org.eclipse.jdt.launching.IVMInstall; 31 import org.eclipse.jdt.launching.IVMRunner; 32 import org.eclipse.jdt.launching.VMRunnerConfiguration; 33 import org.eclipse.jface.dialogs.MessageDialog; 34 import org.eclipse.pde.core.plugin.TargetPlatform; 35 import org.eclipse.pde.internal.core.TargetPlatformHelper; 36 import org.eclipse.pde.internal.ui.IPDEUIConstants; 37 import org.eclipse.pde.internal.ui.PDEPlugin; 38 import org.eclipse.pde.internal.ui.PDEUIMessages; 39 import org.eclipse.pde.internal.ui.launcher.EclipsePluginValidationOperation; 40 import org.eclipse.pde.internal.ui.launcher.LaunchArgumentsHelper; 41 import org.eclipse.pde.internal.ui.launcher.LaunchConfigurationHelper; 42 import org.eclipse.pde.internal.ui.launcher.LaunchPluginValidator; 43 import org.eclipse.pde.internal.ui.launcher.LauncherUtils; 44 import org.eclipse.pde.internal.ui.launcher.VMHelper; 45 46 53 public abstract class AbstractPDELaunchConfiguration extends LaunchConfigurationDelegate { 54 55 protected File fConfigDir = null; 56 57 61 public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, 62 IProgressMonitor monitor) throws CoreException { 63 try { 64 fConfigDir = null; 65 monitor.beginTask("", 4); try { 67 preLaunchCheck(configuration, launch, new SubProgressMonitor(monitor, 2)); 68 } catch (CoreException e) { 69 if (e.getStatus().getSeverity() == IStatus.CANCEL) { 70 monitor.setCanceled(true); 71 return; 72 } 73 throw e; 74 } 75 VMRunnerConfiguration runnerConfig = new VMRunnerConfiguration( 76 getMainClass(), getClasspath(configuration)); 77 runnerConfig.setVMArguments(getVMArguments(configuration)); 78 runnerConfig.setProgramArguments(getProgramArguments(configuration)); 79 runnerConfig.setWorkingDirectory(getWorkingDirectory(configuration).getAbsolutePath()); 80 runnerConfig.setEnvironment(getEnvironment(configuration)); 81 runnerConfig.setVMSpecificAttributesMap(getVMSpecificAttributesMap(configuration)); 82 83 monitor.worked(1); 84 85 setDefaultSourceLocator(configuration); 86 manageLaunch(launch); 87 IVMRunner runner = getVMRunner(configuration, mode); 88 if (runner != null) 89 runner.run(runnerConfig, launch, monitor); 90 else 91 monitor.setCanceled(true); 92 monitor.done(); 93 } catch (final CoreException e) { 94 monitor.setCanceled(true); 95 LauncherUtils.getDisplay().syncExec(new Runnable () { 96 public void run() { 97 MessageDialog.openError(LauncherUtils.getActiveShell(), 98 PDEUIMessages.Launcher_error_title, 99 e.getMessage()); 100 } 101 }); 102 } 103 } 104 105 114 public IVMRunner getVMRunner(ILaunchConfiguration configuration, String mode) throws CoreException { 115 IVMInstall launcher = VMHelper.createLauncher(configuration); 116 return launcher.getVMRunner(mode); 117 } 118 119 129 protected void setDefaultSourceLocator(ILaunchConfiguration configuration) throws CoreException { 130 ILaunchConfigurationWorkingCopy wc = null; 131 if (configuration.isWorkingCopy()) { 132 wc = (ILaunchConfigurationWorkingCopy) configuration; 133 } else { 134 wc = configuration.getWorkingCopy(); 135 } 136 String id = configuration.getAttribute( 137 IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, 138 (String ) null); 139 if (!PDESourcePathProvider.ID.equals(id)) { 140 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, 141 PDESourcePathProvider.ID); 142 wc.doSave(); 143 } 144 } 145 146 157 public String [] getClasspath(ILaunchConfiguration configuration) throws CoreException { 158 String [] classpath = LaunchArgumentsHelper.constructClasspath(configuration); 159 if (classpath == null) { 160 String message = PDEUIMessages.WorkbenchLauncherConfigurationDelegate_noStartup; 161 throw new CoreException(LauncherUtils.createErrorStatus(message)); 162 } 163 return classpath; 164 } 165 166 174 public String [] getEnvironment(ILaunchConfiguration configuration) throws CoreException { 175 return DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration); 176 } 177 178 189 public File getWorkingDirectory(ILaunchConfiguration configuration) throws CoreException { 190 return LaunchArgumentsHelper.getWorkingDirectory(configuration); 191 } 192 193 203 public Map getVMSpecificAttributesMap(ILaunchConfiguration configuration) throws CoreException { 204 return LaunchArgumentsHelper.getVMSpecificAttributesMap(configuration); 205 } 206 207 218 public String [] getVMArguments(ILaunchConfiguration configuration) throws CoreException { 219 return new ExecutionArguments(LaunchArgumentsHelper.getUserVMArguments(configuration), "").getVMArgumentsArray(); } 221 222 236 public String [] getProgramArguments(ILaunchConfiguration configuration) throws CoreException { 237 ArrayList programArgs = new ArrayList (); 238 239 if (configuration.getAttribute(IPDELauncherConstants.TRACING, false) 241 && !IPDELauncherConstants.TRACING_NONE.equals(configuration.getAttribute(IPDELauncherConstants.TRACING_CHECKED, (String ) null))) { 242 programArgs.add("-debug"); programArgs.add( 244 LaunchArgumentsHelper.getTracingFileArgument( 245 configuration, 246 getConfigDir(configuration).toString() + IPath.SEPARATOR + ".options")); } 248 249 String [] userArgs = LaunchArgumentsHelper.getUserProgramArgumentArray(configuration); 251 ArrayList userDefined = new ArrayList (); 252 for (int i = 0; i < userArgs.length; i++) { 253 if (userArgs[i].equals("-debug") && programArgs.contains("-debug")) continue; 257 userDefined.add(userArgs[i]); 258 } 259 260 if (!configuration.getAttribute(IPDEUIConstants.APPEND_ARGS_EXPLICITLY, false)) { 261 262 if (!userDefined.contains("-os")) { programArgs.add("-os"); programArgs.add(TargetPlatform.getOS()); 265 } 266 if (!userDefined.contains("-ws")) { programArgs.add("-ws"); programArgs.add(TargetPlatform.getWS()); 269 } 270 if (!userDefined.contains("-arch")) { programArgs.add("-arch"); programArgs.add(TargetPlatform.getOSArch()); 273 } 274 } 275 276 if (userDefined.size() > 0) { 277 programArgs.addAll(userDefined); 278 } 279 280 return (String [])programArgs.toArray(new String [programArgs.size()]); 281 } 282 283 295 protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) 296 throws CoreException { 297 boolean autoValidate = configuration.getAttribute(IPDELauncherConstants.AUTOMATIC_VALIDATE, false); 298 monitor.beginTask("", autoValidate ? 3 : 4); if (autoValidate) 300 validatePluginDependencies(configuration, new SubProgressMonitor(monitor, 1)); 301 validateProjectDependencies(configuration, new SubProgressMonitor(monitor, 1)); 302 clear(configuration, new SubProgressMonitor(monitor, 1)); 303 launch.setAttribute(IPDELauncherConstants.CONFIG_LOCATION, getConfigDir(configuration).toString()); 304 synchronizeManifests(configuration, new SubProgressMonitor(monitor, 1)); 305 } 306 307 316 protected File getConfigDir(ILaunchConfiguration configuration) { 317 if (fConfigDir == null) 318 fConfigDir = LaunchConfigurationHelper.getConfigurationArea(configuration); 319 return fConfigDir; 320 } 321 322 326 protected IProject[] getBuildOrder(ILaunchConfiguration configuration, 327 String mode) throws CoreException { 328 return computeBuildOrder(LaunchPluginValidator.getAffectedProjects(configuration)); 329 } 330 331 335 protected IProject[] getProjectsForProblemSearch( 336 ILaunchConfiguration configuration, String mode) 337 throws CoreException { 338 return LaunchPluginValidator.getAffectedProjects(configuration); 339 } 340 341 347 public String getMainClass() { 348 if (TargetPlatformHelper.getTargetVersion() >= 3.3) 349 return "org.eclipse.equinox.launcher.Main"; return "org.eclipse.core.launcher.Main"; } 352 353 362 protected void manageLaunch(ILaunch launch) { 363 PDEPlugin.getDefault().getLaunchListener().manage(launch); 364 } 365 366 378 protected void synchronizeManifests(ILaunchConfiguration configuration, IProgressMonitor monitor) { 379 LaunchConfigurationHelper.synchronizeManifests(configuration, getConfigDir(configuration)); 380 monitor.done(); 381 } 382 383 394 protected void validateProjectDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) { 395 LauncherUtils.validateProjectDependencies(configuration, monitor); 396 } 397 398 409 protected void clear(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { 410 } 411 412 422 protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { 423 EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration); 424 LaunchPluginValidator.runValidationOperation(op, monitor); 425 } 426 427 } 428 | Popular Tags |