KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > ui > launcher > JUnitWorkbenchLaunchShortcut


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.ui.launcher;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
15 import org.eclipse.jdt.core.IJavaElement;
16 import org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut;
17 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
18 import org.eclipse.pde.core.plugin.TargetPlatform;
19 import org.eclipse.pde.internal.core.TargetPlatformHelper;
20 import org.eclipse.pde.internal.ui.IPDEUIConstants;
21 import org.eclipse.pde.internal.ui.launcher.LaunchArgumentsHelper;
22 import org.eclipse.pde.internal.ui.launcher.LauncherUtils;
23
24 /**
25  * A launch shortcut capable of launching a Plug-in JUnit test.
26  * <p>
27  * This class may be substantiated or subclassed by clients.
28  * </p>
29  * @since 3.3
30  */

31 public class JUnitWorkbenchLaunchShortcut extends JUnitLaunchShortcut {
32         
33     /* (non-Javadoc)
34      * @see org.eclipse.jdt.junit.JUnitLaunchShortcut#getLaunchConfigurationTypeId()
35      */

36     protected String JavaDoc getLaunchConfigurationTypeId() {
37         return "org.eclipse.pde.ui.JunitLaunchConfig"; //$NON-NLS-1$
38
}
39     
40     /* (non-Javadoc)
41      * @see org.eclipse.jdt.junit.JUnitLaunchShortcut#createLaunchConfiguration(org.eclipse.jdt.core.IJavaElement)
42      */

43     protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement element) throws CoreException {
44         ILaunchConfigurationWorkingCopy configuration = super.createLaunchConfiguration(element);
45         if (TargetPlatformHelper.usesNewApplicationModel())
46             configuration.setAttribute(IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.3"); //$NON-NLS-1$
47
else if (TargetPlatformHelper.getTargetVersion() >= 3.2)
48             configuration.setAttribute(IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.2a"); //$NON-NLS-1$
49
configuration.setAttribute(IPDELauncherConstants.LOCATION, LaunchArgumentsHelper.getDefaultJUnitWorkspaceLocation());
50         configuration.setAttribute(IPDELauncherConstants.DOCLEAR, true);
51         configuration.setAttribute(IPDELauncherConstants.ASKCLEAR, false);
52         configuration.setAttribute(IPDEUIConstants.APPEND_ARGS_EXPLICITLY, true);
53
54         // Program to launch
55
if (LauncherUtils.requiresUI(configuration)) {
56             String JavaDoc product = TargetPlatform.getDefaultProduct();
57             if (product != null) {
58                 configuration.setAttribute(IPDELauncherConstants.USE_PRODUCT, true);
59                 configuration.setAttribute(IPDELauncherConstants.PRODUCT, product);
60             }
61         } else {
62             configuration.setAttribute(IPDELauncherConstants.APPLICATION, IPDEUIConstants.CORE_TEST_APPLICATION);
63         }
64         
65         // Plug-ins to launch
66
configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT, true);
67
68         // Program arguments
69
String JavaDoc programArgs = LaunchArgumentsHelper.getInitialProgramArguments();
70         if (programArgs.length() > 0)
71             configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArgs);
72
73         // VM arguments
74
String JavaDoc vmArgs = LaunchArgumentsHelper.getInitialVMArguments();
75         if (vmArgs.length() > 0)
76             configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs);
77
78         
79         // configuration attributes
80
configuration.setAttribute(IPDELauncherConstants.CONFIG_GENERATE_DEFAULT, true);
81         configuration.setAttribute(IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, false);
82         configuration.setAttribute(IPDELauncherConstants.CONFIG_LOCATION, LaunchArgumentsHelper.getDefaultJUnitConfigurationLocation());
83         configuration.setAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, true);
84         
85         // tracing option
86
configuration.setAttribute(IPDELauncherConstants.TRACING_CHECKED, IPDELauncherConstants.TRACING_NONE);
87
88         // source path provider
89
configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
90                 PDESourcePathProvider.ID);
91         
92         return configuration;
93     }
94     
95 }
96
Popular Tags