Lines 10-32
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.pde.internal.ui.launcher; |
11 |
package org.eclipse.pde.internal.ui.launcher; |
12 |
|
12 |
|
|
|
13 |
import java.io.File; |
14 |
import java.util.ArrayList; |
15 |
import java.util.HashMap; |
13 |
import java.util.HashSet; |
16 |
import java.util.HashSet; |
|
|
17 |
import java.util.Iterator; |
18 |
import java.util.Map; |
14 |
import java.util.Set; |
19 |
import java.util.Set; |
15 |
|
20 |
|
|
|
21 |
import org.eclipse.core.resources.IFile; |
22 |
import org.eclipse.core.resources.IProject; |
23 |
import org.eclipse.core.resources.IResource; |
24 |
import org.eclipse.core.resources.IWorkspaceRoot; |
16 |
import org.eclipse.core.runtime.CoreException; |
25 |
import org.eclipse.core.runtime.CoreException; |
|
|
26 |
import org.eclipse.core.runtime.IPath; |
27 |
import org.eclipse.core.runtime.Path; |
17 |
import org.eclipse.core.runtime.SafeRunner; |
28 |
import org.eclipse.core.runtime.SafeRunner; |
18 |
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; |
29 |
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; |
|
|
30 |
import org.eclipse.debug.core.sourcelookup.ISourceContainer; |
19 |
import org.eclipse.debug.core.sourcelookup.ISourceContainerType; |
31 |
import org.eclipse.debug.core.sourcelookup.ISourceContainerType; |
20 |
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant; |
32 |
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant; |
|
|
33 |
import org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer; |
34 |
import org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer; |
21 |
import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; |
35 |
import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; |
22 |
import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer; |
36 |
import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer; |
23 |
import org.eclipse.debug.ui.sourcelookup.WorkingSetSourceContainer; |
37 |
import org.eclipse.debug.ui.sourcelookup.WorkingSetSourceContainer; |
|
|
38 |
import org.eclipse.jdt.core.IClasspathEntry; |
39 |
import org.eclipse.jdt.core.IJavaElement; |
40 |
import org.eclipse.jdt.core.IJavaProject; |
41 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
42 |
import org.eclipse.jdt.core.JavaCore; |
43 |
import org.eclipse.jdt.core.JavaModelException; |
24 |
import org.eclipse.jdt.debug.core.IJavaObject; |
44 |
import org.eclipse.jdt.debug.core.IJavaObject; |
25 |
import org.eclipse.jdt.debug.core.IJavaReferenceType; |
45 |
import org.eclipse.jdt.debug.core.IJavaReferenceType; |
26 |
import org.eclipse.jdt.debug.core.IJavaStackFrame; |
46 |
import org.eclipse.jdt.debug.core.IJavaStackFrame; |
|
|
47 |
import org.eclipse.jdt.launching.IRuntimeClasspathEntry; |
48 |
import org.eclipse.jdt.launching.JavaRuntime; |
27 |
import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant; |
49 |
import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant; |
|
|
50 |
import org.eclipse.pde.core.plugin.IPluginModelBase; |
51 |
import org.eclipse.pde.core.plugin.ModelEntry; |
52 |
import org.eclipse.pde.core.plugin.PluginRegistry; |
53 |
import org.eclipse.pde.internal.core.PDEClasspathContainer; |
54 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
28 |
|
55 |
|
29 |
public class PDESourceLookupDirector extends AbstractSourceLookupDirector { |
56 |
public class PDESourceLookupDirector extends AbstractSourceLookupDirector { |
|
|
57 |
|
58 |
/** |
59 |
* Cache of source containers by location and id (String & String) |
60 |
*/ |
61 |
private Map fSourceContainerMap = new HashMap(); |
62 |
|
63 |
/** |
64 |
* Key for source container - combines two strings |
65 |
*/ |
66 |
private class ContainerKey { |
67 |
private String fA; |
68 |
private String fB; |
69 |
ContainerKey(String a, String b) { |
70 |
fA = a; |
71 |
fB = b; |
72 |
} |
73 |
public boolean equals(Object obj) { |
74 |
if (obj instanceof ContainerKey) { |
75 |
ContainerKey key = (ContainerKey) obj; |
76 |
return key.fA.equals(fA) && key.fB.equals(fB); |
77 |
} |
78 |
return false; |
79 |
} |
80 |
public int hashCode() { |
81 |
return fA.hashCode() + fB.hashCode(); |
82 |
} |
83 |
|
84 |
} |
30 |
|
85 |
|
31 |
private static Set fFilteredTypes; |
86 |
private static Set fFilteredTypes; |
32 |
|
87 |
|
Lines 55-61
Link Here
|
55 |
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector#getSourceElement(java.lang.Object) |
110 |
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector#getSourceElement(java.lang.Object) |
56 |
*/ |
111 |
*/ |
57 |
public Object getSourceElement(Object element) { |
112 |
public Object getSourceElement(Object element) { |
58 |
PDESourceLookupQuery query = new PDESourceLookupQuery(element); |
113 |
PDESourceLookupQuery query = new PDESourceLookupQuery(this, element); |
59 |
SafeRunner.run(query); |
114 |
SafeRunner.run(query); |
60 |
Object result = query.getResult(); |
115 |
Object result = query.getResult(); |
61 |
return result != null ? result : super.getSourceElement(element); |
116 |
return result != null ? result : super.getSourceElement(element); |
Lines 75-78
Link Here
|
75 |
return sourceElements; |
130 |
return sourceElements; |
76 |
} |
131 |
} |
77 |
|
132 |
|
|
|
133 |
ISourceContainer[] getSourceContainers(String location, String id) throws CoreException { |
134 |
|
135 |
ContainerKey key = new ContainerKey(location, id); |
136 |
ISourceContainer[] containers = (ISourceContainer[]) fSourceContainerMap.get(key); |
137 |
if (containers != null) { |
138 |
return containers; |
139 |
} |
140 |
|
141 |
ArrayList result = new ArrayList(); |
142 |
ModelEntry entry = PluginRegistry.findEntry(id); |
143 |
|
144 |
boolean match = false; |
145 |
|
146 |
IPluginModelBase[] models = entry.getWorkspaceModels(); |
147 |
for (int i = 0; i < models.length; i++) { |
148 |
if (isPerfectMatch(models[i], new Path(location))) { |
149 |
IResource resource = models[i].getUnderlyingResource(); |
150 |
// if the plug-in matches a workspace model, |
151 |
// add the project and any libraries not coming via a container |
152 |
// to the list of source containers, in that order |
153 |
if (resource != null) { |
154 |
addProjectSourceContainers(resource.getProject(), result); |
155 |
} |
156 |
match = true; |
157 |
break; |
158 |
} |
159 |
} |
160 |
|
161 |
if (!match) { |
162 |
File file = new File(location); |
163 |
if (file.isFile()) { |
164 |
// in case of linked plug-in projects that map to an external JARd plug-in, |
165 |
// use source container that maps to the library in the linked project. |
166 |
ISourceContainer container = getArchiveSourceContainer(location); |
167 |
if (container != null) { |
168 |
containers = new ISourceContainer[] {container}; |
169 |
fSourceContainerMap.put(key, containers); |
170 |
return containers; |
171 |
} |
172 |
} |
173 |
|
174 |
models = entry.getExternalModels(); |
175 |
for (int i = 0; i < models.length; i++) { |
176 |
if (isPerfectMatch(models[i], new Path(location))) { |
177 |
// try all source zips found in the source code locations |
178 |
IClasspathEntry[] entries = PDEClasspathContainer.getExternalEntries(models[i]); |
179 |
for (int j = 0; j < entries.length; j++) { |
180 |
IRuntimeClasspathEntry rte = convertClasspathEntry(entries[j]); |
181 |
if (rte != null) |
182 |
result.add(rte); |
183 |
} |
184 |
break; |
185 |
} |
186 |
} |
187 |
} |
188 |
|
189 |
IRuntimeClasspathEntry[] entries = (IRuntimeClasspathEntry[]) |
190 |
result.toArray(new IRuntimeClasspathEntry[result.size()]); |
191 |
containers = JavaRuntime.getSourceContainers(entries); |
192 |
fSourceContainerMap.put(key, containers); |
193 |
return containers; |
194 |
} |
195 |
|
196 |
private boolean isPerfectMatch(IPluginModelBase model, IPath path) { |
197 |
return model == null ? false : path.equals(new Path(model.getInstallLocation())); |
198 |
} |
199 |
|
200 |
private IRuntimeClasspathEntry convertClasspathEntry(IClasspathEntry entry) { |
201 |
if (entry == null) |
202 |
return null; |
203 |
|
204 |
IPath srcPath = entry.getSourceAttachmentPath(); |
205 |
if (srcPath != null && srcPath.segmentCount() > 0) { |
206 |
IRuntimeClasspathEntry rte = |
207 |
JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); |
208 |
rte.setSourceAttachmentPath(srcPath); |
209 |
rte.setSourceAttachmentRootPath(entry.getSourceAttachmentRootPath()); |
210 |
return rte; |
211 |
} |
212 |
return null; |
213 |
} |
214 |
|
215 |
private ISourceContainer getArchiveSourceContainer(String location) throws JavaModelException { |
216 |
IWorkspaceRoot root = PDEPlugin.getWorkspace().getRoot(); |
217 |
IFile[] containers = root.findFilesForLocation(new Path(location)); |
218 |
for (int i = 0; i < containers.length; i++) { |
219 |
IJavaElement element = JavaCore.create(containers[i]); |
220 |
if (element instanceof IPackageFragmentRoot) { |
221 |
IPackageFragmentRoot archive = (IPackageFragmentRoot)element; |
222 |
IPath path = archive.getSourceAttachmentPath(); |
223 |
if (path == null || path.segmentCount() == 0) |
224 |
continue; |
225 |
|
226 |
IPath rootPath = archive.getSourceAttachmentRootPath(); |
227 |
boolean detectRootPath = rootPath != null && rootPath.segmentCount() > 0; |
228 |
|
229 |
IFile archiveFile = root.getFile(path); |
230 |
if (archiveFile.exists()) |
231 |
return new ArchiveSourceContainer(archiveFile, detectRootPath); |
232 |
|
233 |
File file = path.toFile(); |
234 |
if (file.exists()) |
235 |
return new ExternalArchiveSourceContainer(file.getAbsolutePath(), detectRootPath); |
236 |
} |
237 |
} |
238 |
return null; |
239 |
} |
240 |
|
241 |
private void addProjectSourceContainers(IProject project, ArrayList result) throws CoreException { |
242 |
if (project == null || !project.hasNature(JavaCore.NATURE_ID)) |
243 |
return; |
244 |
|
245 |
IJavaProject jProject = JavaCore.create(project); |
246 |
result.add(JavaRuntime.newProjectRuntimeClasspathEntry(jProject)); |
247 |
|
248 |
IClasspathEntry[] entries = jProject.getRawClasspath(); |
249 |
for (int i = 0; i < entries.length; i++) { |
250 |
IClasspathEntry entry = entries[i]; |
251 |
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { |
252 |
IRuntimeClasspathEntry rte = convertClasspathEntry(entry); |
253 |
if (rte != null) |
254 |
result.add(rte); |
255 |
} |
256 |
} |
257 |
} |
258 |
|
259 |
/* (non-Javadoc) |
260 |
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector#dispose() |
261 |
*/ |
262 |
public synchronized void dispose() { |
263 |
Iterator iterator = fSourceContainerMap.values().iterator(); |
264 |
while (iterator.hasNext()) { |
265 |
ISourceContainer[] containers = (ISourceContainer[]) iterator.next(); |
266 |
for (int i = 0; i < containers.length; i++) { |
267 |
containers[i].dispose(); |
268 |
} |
269 |
} |
270 |
fSourceContainerMap.clear(); |
271 |
super.dispose(); |
272 |
} |
273 |
|
274 |
|
78 |
} |
275 |
} |