01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.launch;
05:
06: import org.eclipse.core.resources.IFile;
07: import org.eclipse.core.resources.IProject;
08: import org.eclipse.core.resources.ResourcesPlugin;
09: import org.eclipse.core.runtime.CoreException;
10: import org.eclipse.core.variables.IStringVariableManager;
11: import org.eclipse.core.variables.VariablesPlugin;
12: import org.eclipse.debug.core.ILaunchConfiguration;
13: import org.eclipse.debug.core.ILaunchConfigurationType;
14: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
15: import org.eclipse.jdt.core.IType;
16: import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
17: import org.terracotta.dso.TcPlugin;
18:
19: public class LaunchShortcut
20: extends
21: org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut
22: implements IDSOLaunchConfigurationConstants {
23: /**
24: * Renamed to getConfigurationType in 3.2
25: */
26: protected ILaunchConfigurationType getJavaLaunchConfigType() {
27: return internalGetJavaLaunchConfigType();
28: }
29:
30: /**
31: * Renamed from getJavaLaunchConfigType in 3.1
32: */
33: protected ILaunchConfigurationType getConfigurationType() {
34: return internalGetJavaLaunchConfigType();
35: }
36:
37: /**
38: * Bridge to span renaming of getJavaLaunchConfigType -> getConfigurationType in 3.2
39: */
40: private ILaunchConfigurationType internalGetJavaLaunchConfigType() {
41: return getLaunchManager().getLaunchConfigurationType(
42: "launch.configurationDelegate");
43: }
44:
45: protected ILaunchConfiguration createConfiguration(IType type) {
46: ILaunchConfiguration config = super .createConfiguration(type);
47: ILaunchConfigurationWorkingCopy wc = null;
48: try {
49: wc = config.getWorkingCopy();
50: IFile configFile = TcPlugin.getDefault()
51: .getConfigurationFile(getProject(wc));
52:
53: if (configFile != null) {
54: String arg = configFile.getFullPath().toString();
55: IStringVariableManager variableManager = VariablesPlugin
56: .getDefault().getStringVariableManager();
57: String configSpec = variableManager
58: .generateVariableExpression(
59: "workspace_loc", arg); //$NON-NLS-1$
60: wc.setAttribute(ID_CONFIG_FILE_SPEC, configSpec);
61: }
62: config = wc.doSave();
63: } catch (CoreException exception) {
64: reportErorr(exception);
65: }
66: return config;
67: }
68:
69: private IProject getProject(ILaunchConfiguration configuration)
70: throws CoreException {
71: String projectName = configuration.getAttribute(
72: IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
73: (String) null);
74: if (projectName != null) {
75: projectName = projectName.trim();
76: if (projectName.length() > 0) {
77: return ResourcesPlugin.getWorkspace().getRoot()
78: .getProject(projectName);
79: }
80: }
81: return null;
82: }
83: }
|