001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.ui.launcher;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
014: import org.eclipse.jdt.core.IJavaElement;
015: import org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut;
016: import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
017: import org.eclipse.pde.core.plugin.TargetPlatform;
018: import org.eclipse.pde.internal.core.TargetPlatformHelper;
019: import org.eclipse.pde.internal.ui.IPDEUIConstants;
020: import org.eclipse.pde.internal.ui.launcher.LaunchArgumentsHelper;
021: import org.eclipse.pde.internal.ui.launcher.LauncherUtils;
022:
023: /**
024: * A launch shortcut capable of launching a Plug-in JUnit test.
025: * <p>
026: * This class may be substantiated or subclassed by clients.
027: * </p>
028: * @since 3.3
029: */
030: public class JUnitWorkbenchLaunchShortcut extends JUnitLaunchShortcut {
031:
032: /* (non-Javadoc)
033: * @see org.eclipse.jdt.junit.JUnitLaunchShortcut#getLaunchConfigurationTypeId()
034: */
035: protected String getLaunchConfigurationTypeId() {
036: return "org.eclipse.pde.ui.JunitLaunchConfig"; //$NON-NLS-1$
037: }
038:
039: /* (non-Javadoc)
040: * @see org.eclipse.jdt.junit.JUnitLaunchShortcut#createLaunchConfiguration(org.eclipse.jdt.core.IJavaElement)
041: */
042: protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(
043: IJavaElement element) throws CoreException {
044: ILaunchConfigurationWorkingCopy configuration = super
045: .createLaunchConfiguration(element);
046: if (TargetPlatformHelper.usesNewApplicationModel())
047: configuration.setAttribute(
048: IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.3"); //$NON-NLS-1$
049: else if (TargetPlatformHelper.getTargetVersion() >= 3.2)
050: configuration.setAttribute(
051: IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.2a"); //$NON-NLS-1$
052: configuration.setAttribute(IPDELauncherConstants.LOCATION,
053: LaunchArgumentsHelper
054: .getDefaultJUnitWorkspaceLocation());
055: configuration.setAttribute(IPDELauncherConstants.DOCLEAR, true);
056: configuration.setAttribute(IPDELauncherConstants.ASKCLEAR,
057: false);
058: configuration.setAttribute(
059: IPDEUIConstants.APPEND_ARGS_EXPLICITLY, true);
060:
061: // Program to launch
062: if (LauncherUtils.requiresUI(configuration)) {
063: String product = TargetPlatform.getDefaultProduct();
064: if (product != null) {
065: configuration.setAttribute(
066: IPDELauncherConstants.USE_PRODUCT, true);
067: configuration.setAttribute(
068: IPDELauncherConstants.PRODUCT, product);
069: }
070: } else {
071: configuration.setAttribute(
072: IPDELauncherConstants.APPLICATION,
073: IPDEUIConstants.CORE_TEST_APPLICATION);
074: }
075:
076: // Plug-ins to launch
077: configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT,
078: true);
079:
080: // Program arguments
081: String programArgs = LaunchArgumentsHelper
082: .getInitialProgramArguments();
083: if (programArgs.length() > 0)
084: configuration
085: .setAttribute(
086: IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
087: programArgs);
088:
089: // VM arguments
090: String vmArgs = LaunchArgumentsHelper.getInitialVMArguments();
091: if (vmArgs.length() > 0)
092: configuration
093: .setAttribute(
094: IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
095: vmArgs);
096:
097: // configuration attributes
098: configuration.setAttribute(
099: IPDELauncherConstants.CONFIG_GENERATE_DEFAULT, true);
100: configuration.setAttribute(
101: IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, false);
102: configuration.setAttribute(
103: IPDELauncherConstants.CONFIG_LOCATION,
104: LaunchArgumentsHelper
105: .getDefaultJUnitConfigurationLocation());
106: configuration.setAttribute(
107: IPDELauncherConstants.CONFIG_CLEAR_AREA, true);
108:
109: // tracing option
110: configuration.setAttribute(
111: IPDELauncherConstants.TRACING_CHECKED,
112: IPDELauncherConstants.TRACING_NONE);
113:
114: // source path provider
115: configuration
116: .setAttribute(
117: IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
118: PDESourcePathProvider.ID);
119:
120: return configuration;
121: }
122:
123: }
|