1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.Preferences; 15 import org.eclipse.debug.core.DebugPlugin; 16 import org.eclipse.debug.core.ILaunchConfiguration; 17 import org.eclipse.debug.core.ILaunchConfigurationType; 18 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 19 import org.eclipse.debug.core.ILaunchManager; 20 import org.eclipse.jdt.core.IJavaProject; 21 import org.eclipse.jdt.internal.junit.launcher.AssertionVMArg; 22 import org.eclipse.jdt.internal.junit.launcher.JUnitBaseLaunchConfiguration; 23 import org.eclipse.jdt.internal.junit.launcher.JUnitLaunchShortcut; 24 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 25 import org.eclipse.pde.internal.core.ICoreConstants; 26 import org.eclipse.pde.internal.core.PDECore; 27 import org.eclipse.pde.internal.core.TargetPlatform; 28 import org.eclipse.pde.internal.ui.PDEPlugin; 29 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 30 31 public class JUnitWorkbenchShortcut extends JUnitLaunchShortcut { 32 33 36 protected ILaunchConfigurationType getJUnitLaunchConfigType() { 37 ILaunchManager lm= DebugPlugin.getDefault().getLaunchManager(); 38 return lm.getLaunchConfigurationType("org.eclipse.pde.ui.JunitLaunchConfig"); } 40 41 protected ILaunchConfiguration createConfiguration( 42 IJavaProject project, String name, String mainType, String container, String testName) { 43 ILaunchConfiguration config = null; 44 try { 45 ILaunchConfigurationType configType= getJUnitLaunchConfigType(); 46 String computedName = DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(name); 47 ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, computedName); 48 if (TargetPlatform.isRuntimeRefactored2()) 49 wc.setAttribute("pde.version", "3.2a"); else if (TargetPlatform.isRuntimeRefactored1()) 51 wc.setAttribute("pde.version", "3.2"); wc.setAttribute(IPDELauncherConstants.LOCATION, LaunchArgumentsHelper.getDefaultJUnitWorkspaceLocation()); 53 setJavaArguments(wc); 54 wc.setAttribute(IPDELauncherConstants.USE_DEFAULT, true); 55 wc.setAttribute(IPDELauncherConstants.DOCLEAR, true); 56 wc.setAttribute(IPDELauncherConstants.ASKCLEAR, false); 57 wc.setAttribute(IPDELauncherConstants.TRACING_CHECKED, IPDELauncherConstants.TRACING_NONE); 58 wc.setAttribute(IPDELauncherConstants.CONFIG_GENERATE_DEFAULT, true); 59 wc.setAttribute(IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, false); 60 wc.setAttribute(IPDELauncherConstants.CONFIG_LOCATION, LaunchArgumentsHelper.getDefaultJUnitConfigurationLocation()); 61 wc.setAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, true); 62 wc.setAttribute( 63 IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, 64 "org.eclipse.pde.ui.workbenchClasspathProvider"); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getElementName()); 66 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainType); 67 wc.setAttribute(JUnitBaseLaunchConfiguration.ATTR_KEEPRUNNING, false); 68 wc.setAttribute(JUnitBaseLaunchConfiguration.LAUNCH_CONTAINER_ATTR, container); 69 if (testName.length() > 0) 70 wc.setAttribute(JUnitBaseLaunchConfiguration.TESTNAME_ATTR, testName); 71 if (JUnitLaunchConfiguration.requiresUI(wc)) { 72 String product = TargetPlatform.getDefaultProduct(); 73 if (product != null) { 74 wc.setAttribute(IPDELauncherConstants.USE_PRODUCT, true); 75 wc.setAttribute(IPDELauncherConstants.PRODUCT, product); 76 } 77 } else { 78 wc.setAttribute(IPDELauncherConstants.APPLICATION, JUnitLaunchConfiguration.CORE_APPLICATION); 79 } 80 AssertionVMArg.setArgDefault(wc); 81 config= wc.doSave(); 82 } catch (CoreException ce) { 83 PDEPlugin.log(ce); 84 } 85 return config; 86 } 87 88 private void setJavaArguments(ILaunchConfigurationWorkingCopy wc) { 89 Preferences preferences = PDECore.getDefault().getPluginPreferences(); 90 String programArgs = preferences.getString(ICoreConstants.PROGRAM_ARGS); 91 if (programArgs.length() > 0) 92 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArgs); 93 String vmArgs = preferences.getString(ICoreConstants.VM_ARGS); 94 if (vmArgs.length() > 0) 95 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs); 96 } 97 98 } 99 | Popular Tags |