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.ILaunchConfiguration;
014: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
015: import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
016: import org.eclipse.debug.ui.ILaunchConfigurationTab;
017: import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
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.LaunchPluginValidator;
022: import org.eclipse.swt.custom.BusyIndicator;
023: import org.eclipse.swt.widgets.Display;
024:
025: /**
026: * An abstract class subclassed by the Eclipse application and JUnit Plug-in launch
027: * configuration tab groups.
028: * <p>
029: * This class is not intended to be subclassed by clients.
030: * </p>
031: * @since 3.3
032: */
033: public abstract class AbstractPDELaunchConfigurationTabGroup extends
034: AbstractLaunchConfigurationTabGroup {
035:
036: /**
037: * The tab group delegates to all tabs in the group.
038: * Prior to the delegation, it migrates all pre-3.2 launch configurations
039: * to make them 3.2-compliant.
040: *
041: * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
042: */
043: public void initializeFrom(ILaunchConfiguration configuration) {
044: final ILaunchConfiguration config = configuration;
045: final ILaunchConfigurationTab[] tabs = getTabs();
046: BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
047: public void run() {
048: try {
049: if (config instanceof ILaunchConfigurationWorkingCopy) {
050: checkBackwardCompatibility((ILaunchConfigurationWorkingCopy) config);
051: }
052: } catch (CoreException e) {
053: }
054: for (int i = 0; i < tabs.length; i++) {
055: tabs[i].initializeFrom(config);
056: }
057: }
058: });
059: }
060:
061: /**
062: * Checks if the launch configuration is 3.2-compliant and migrates it if it's not.
063: *
064: * @param wc
065: * the launch configuration to be migrated if it's not 3.2-compliant
066: * @throws CoreException
067: * a CoreException is thrown if there was an error retrieving launch
068: * configuration attributes
069: */
070: private void checkBackwardCompatibility(
071: ILaunchConfigurationWorkingCopy wc) throws CoreException {
072: String id = wc
073: .getAttribute(
074: IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
075: (String) null);
076: if (id == null) {
077: wc
078: .setAttribute(
079: IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
080: PDESourcePathProvider.ID);
081: }
082:
083: String value = wc.getAttribute("vmargs", (String) null); //$NON-NLS-1$
084: if (value != null) {
085: wc.setAttribute("vmargs", (String) null); //$NON-NLS-1$
086: wc
087: .setAttribute(
088: IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
089: value);
090: }
091:
092: value = wc.getAttribute("progargs", (String) null); //$NON-NLS-1$
093: if (value != null) {
094: wc.setAttribute("progargs", (String) null); //$NON-NLS-1$
095: wc
096: .setAttribute(
097: IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
098: value);
099: }
100:
101: value = wc.getAttribute(
102: IPDELauncherConstants.LOCATION + "0", (String) null); //$NON-NLS-1$
103: if (value != null) {
104: wc
105: .setAttribute(
106: IPDELauncherConstants.LOCATION + "0", (String) null); //$NON-NLS-1$
107: wc.setAttribute(IPDELauncherConstants.LOCATION, value);
108: }
109:
110: LaunchPluginValidator.checkBackwardCompatibility(wc, false);
111: if (wc.isDirty()) {
112: wc.doSave();
113: }
114: }
115:
116: /**
117: * Delegates to all tabs to set defaults.
118: * It then sets program and VM arguments based on values on the
119: * <b>Plug-in Development > Target Platform > Launching Arguments</b> preference page.
120: *
121: * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
122: */
123: public void setDefaults(
124: ILaunchConfigurationWorkingCopy configuration) {
125: super .setDefaults(configuration);
126: if (TargetPlatformHelper.usesNewApplicationModel())
127: configuration.setAttribute(
128: IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.3"); //$NON-NLS-1$
129: else if (TargetPlatformHelper.getTargetVersion() >= 3.2)
130: configuration.setAttribute(
131: IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.2a"); //$NON-NLS-1$
132:
133: configuration
134: .setAttribute(
135: IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
136: PDESourcePathProvider.ID);
137:
138: // Set Program/VM arguments with preference values
139: String programArgs = LaunchArgumentsHelper
140: .getInitialProgramArguments().trim();
141: if (programArgs.length() > 0)
142: configuration
143: .setAttribute(
144: IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
145: programArgs);
146:
147: String vmArgs = LaunchArgumentsHelper.getInitialVMArguments()
148: .trim();
149: if (vmArgs.length() > 0)
150: configuration
151: .setAttribute(
152: IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
153: vmArgs);
154:
155: configuration.setAttribute(
156: IPDEUIConstants.APPEND_ARGS_EXPLICITLY, true);
157: }
158:
159: }
|