KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > launcher > JUnitWorkbenchShortcut


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /**
34      * Returns the local java launch config type
35      */

36     protected ILaunchConfigurationType getJUnitLaunchConfigType() {
37         ILaunchManager lm= DebugPlugin.getDefault().getLaunchManager();
38         return lm.getLaunchConfigurationType("org.eclipse.pde.ui.JunitLaunchConfig"); //$NON-NLS-1$
39
}
40     
41     protected ILaunchConfiguration createConfiguration(
42         IJavaProject project, String JavaDoc name, String JavaDoc mainType, String JavaDoc container, String JavaDoc testName) {
43         ILaunchConfiguration config = null;
44         try {
45             ILaunchConfigurationType configType= getJUnitLaunchConfigType();
46             String JavaDoc computedName = DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(name);
47             ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, computedName);
48             if (TargetPlatform.isRuntimeRefactored2())
49                 wc.setAttribute("pde.version", "3.2a"); //$NON-NLS-1$ //$NON-NLS-2$
50
else if (TargetPlatform.isRuntimeRefactored1())
51                 wc.setAttribute("pde.version", "3.2"); //$NON-NLS-1$ //$NON-NLS-2$
52
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"); //$NON-NLS-1$
65
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 JavaDoc 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 JavaDoc programArgs = preferences.getString(ICoreConstants.PROGRAM_ARGS);
91         if (programArgs.length() > 0)
92             wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArgs);
93         String JavaDoc 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