01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package org.terracotta.dso.launch;
06:
07: import org.eclipse.core.resources.IFile;
08: import org.eclipse.core.resources.IProject;
09: import org.eclipse.core.resources.ResourcesPlugin;
10: import org.eclipse.core.runtime.CoreException;
11: import org.eclipse.core.variables.IStringVariableManager;
12: import org.eclipse.core.variables.VariablesPlugin;
13: import org.eclipse.debug.core.ILaunchConfiguration;
14: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
15: import org.eclipse.jdt.core.IJavaElement;
16: import org.eclipse.jdt.internal.junit.ui.JUnitPlugin;
17: import org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut;
18: import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
19: import org.terracotta.dso.TcPlugin;
20:
21: public class DSOJUnitLaunchShortcut extends JUnitLaunchShortcut
22: implements IDSOLaunchConfigurationConstants {
23: protected String getLaunchConfigurationTypeId() {
24: return "launch.junitTestConfigurationDelegate";
25: }
26:
27: protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(
28: IJavaElement element) throws CoreException {
29: ILaunchConfigurationWorkingCopy config = super
30: .createLaunchConfiguration(element);
31: ILaunchConfigurationWorkingCopy wc = null;
32: try {
33: wc = config.getWorkingCopy();
34: IFile configFile = TcPlugin.getDefault()
35: .getConfigurationFile(getProject(wc));
36:
37: if (configFile != null) {
38: String arg = configFile.getFullPath().toString();
39: IStringVariableManager variableManager = VariablesPlugin
40: .getDefault().getStringVariableManager();
41: String configSpec = variableManager
42: .generateVariableExpression(
43: "workspace_loc", arg); //$NON-NLS-1$
44: wc.setAttribute(ID_CONFIG_FILE_SPEC, configSpec);
45: }
46: config = wc;
47: } catch (CoreException exception) {
48: JUnitPlugin.log(exception);
49: }
50: return config;
51: }
52:
53: private IProject getProject(ILaunchConfiguration configuration)
54: throws CoreException {
55: String projectName = configuration.getAttribute(
56: IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
57: (String) null);
58: if (projectName != null) {
59: projectName = projectName.trim();
60: if (projectName.length() > 0) {
61: return ResourcesPlugin.getWorkspace().getRoot()
62: .getProject(projectName);
63: }
64: }
65: return null;
66: }
67: }
|