blob: 275f5d84529241d4c5c8c870311772e36d3f9c52 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*******************************************************************************
* Copyright (c) 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.internal.ui.launcher;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.pde.ui.launcher.OSGiLaunchConfiguration;
public class OSGiSourceLookupDirector implements IPersistableSourceLocator {
IPersistableSourceLocator fLocator;
public String getMemento() throws CoreException {
if (fLocator != null)
return fLocator.getMemento();
return null;
}
public void initializeDefaults(ILaunchConfiguration configuration)
throws CoreException {
String id = configuration.getAttribute(OSGiLaunchConfiguration.OSGI_ENV_ID, (String)null);
if (id == null)
id = EquinoxLauncher.ID;
String locatorId = null;
locatorId = getFrameworkSourceLocator(id);
if (locatorId == null)
locatorId = "org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"; //$NON-NLS-1$
Object obj = getClass(locatorId);
fLocator = (IPersistableSourceLocator)obj;
if (fLocator != null)
fLocator.initializeDefaults(configuration);
}
private String getFrameworkSourceLocator(String id) {
if (id != null) {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiLaunchers"); //$NON-NLS-1$
for (int i = 0; i < elements.length; i++) {
if (elements[i].getAttribute("id").equals(id)) { //$NON-NLS-1$
String attr = elements[i].getAttribute("sourceLocatorId"); //$NON-NLS-1$
if (attr != null)
return attr;
}
}
}
return null;
}
private IPersistableSourceLocator getClass(String locatorId) {
IPersistableSourceLocator javaLocator = null;
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.debug.core.sourceLocators"); //$NON-NLS-1$
for (int i = 0; i < elements.length; i++) {
try {
if (elements[i].getAttribute("id").equals(locatorId)) { //$NON-NLS-1$
Object o = elements[i].createExecutableExtension("class"); //$NON-NLS-1$
if (o instanceof IPersistableSourceLocator)
return (IPersistableSourceLocator)o;
}
if (elements[i].getAttribute("id").equals("org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector")) //$NON-NLS-1$ //$NON-NLS-2$
javaLocator = (IPersistableSourceLocator)elements[i].createExecutableExtension("class"); //$NON-NLS-1$
} catch (CoreException e) {
}
}
return javaLocator;
}
public void initializeFromMemento(String memento) throws CoreException {
if (fLocator != null)
fLocator.initializeFromMemento(memento);
}
public Object getSourceElement(IStackFrame stackFrame) {
if (fLocator != null)
return fLocator.getSourceElement(stackFrame);
return null;
}
}
|