Skip to content

Commit c3241b4

Browse files
committed
Handle missing plug-ins in source-lookup and use List instead of arrays
Fixes #133
1 parent c64a766 commit c3241b4

File tree

7 files changed

+26
-27
lines changed

7 files changed

+26
-27
lines changed

ui/org.eclipse.pde.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %name
44
Bundle-SymbolicName: org.eclipse.pde.core; singleton:=true
5-
Bundle-Version: 3.15.200.qualifier
5+
Bundle-Version: 3.15.300.qualifier
66
Bundle-Activator: org.eclipse.pde.internal.core.PDECore
77
Bundle-Vendor: %provider-name
88
Bundle-Localization: plugin

ui/org.eclipse.pde.core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<relativePath>../../</relativePath>
2020
</parent>
2121
<artifactId>org.eclipse.pde.core</artifactId>
22-
<version>3.15.200-SNAPSHOT</version>
22+
<version>3.15.300-SNAPSHOT</version>
2323
<packaging>eclipse-plugin</packaging>
2424
<properties>
2525
<defaultSigning-excludeInnerJars>true</defaultSigning-excludeInnerJars>

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/sourcelookup/PDESourceLookupDirector.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class PDESourceLookupDirector extends AbstractSourceLookupDirector {
3636
/**
3737
* Cache of source containers by location and id (String & String)
3838
*/
39-
private Map<String, ISourceContainer[]> fSourceContainerMap = new LinkedHashMap<>();
39+
private Map<String, List<ISourceContainer>> fSourceContainerMap = new LinkedHashMap<>();
4040

4141
private ISourceContainer[] fJreSourceContainers;
4242

@@ -84,15 +84,18 @@ public Object[] findSourceElements(Object object) throws CoreException {
8484
return sourceElements;
8585
}
8686

87-
ISourceContainer[] getSourceContainers(String location, String id) throws CoreException {
87+
List<ISourceContainer> getSourceContainers(String location, String id) throws CoreException {
8888

89-
ISourceContainer[] containers = fSourceContainerMap.get(location);
89+
List<ISourceContainer> containers = fSourceContainerMap.get(location);
9090
if (containers != null) {
9191
return containers;
9292
}
9393

94-
ArrayList<IRuntimeClasspathEntry> result = new ArrayList<>();
94+
List<IRuntimeClasspathEntry> result = new ArrayList<>();
9595
ModelEntry entry = PluginRegistry.findEntry(id);
96+
if (entry == null) {
97+
return Collections.emptyList();
98+
}
9699

97100
boolean match = false;
98101

@@ -118,7 +121,7 @@ ISourceContainer[] getSourceContainers(String location, String id) throws CoreEx
118121
// use source container that maps to the library in the linked project.
119122
ISourceContainer container = getArchiveSourceContainer(location);
120123
if (container != null) {
121-
containers = new ISourceContainer[] {container};
124+
containers = List.of(container);
122125
fSourceContainerMap.put(location, containers);
123126
return containers;
124127
}
@@ -139,8 +142,8 @@ ISourceContainer[] getSourceContainers(String location, String id) throws CoreEx
139142
}
140143
}
141144

142-
IRuntimeClasspathEntry[] entries = result.toArray(new IRuntimeClasspathEntry[result.size()]);
143-
containers = JavaRuntime.getSourceContainers(entries);
145+
IRuntimeClasspathEntry[] entries = result.toArray(IRuntimeClasspathEntry[]::new);
146+
containers = List.of(JavaRuntime.getSourceContainers(entries));
144147
fSourceContainerMap.put(location, containers);
145148
return containers;
146149
}
@@ -199,7 +202,7 @@ private ISourceContainer getArchiveSourceContainer(String location) throws JavaM
199202
return null;
200203
}
201204

202-
private void addProjectSourceContainers(IProject project, ArrayList<IRuntimeClasspathEntry> result) throws CoreException {
205+
private void addProjectSourceContainers(IProject project, List<IRuntimeClasspathEntry> result) throws CoreException {
203206
if (project == null || !project.hasNature(JavaCore.NATURE_ID))
204207
return;
205208

@@ -224,13 +227,7 @@ private void addProjectSourceContainers(IProject project, ArrayList<IRuntimeClas
224227

225228
@Override
226229
public synchronized void dispose() {
227-
Iterator<ISourceContainer[]> iterator = fSourceContainerMap.values().iterator();
228-
while (iterator.hasNext()) {
229-
ISourceContainer[] containers = iterator.next();
230-
for (ISourceContainer container : containers) {
231-
container.dispose();
232-
}
233-
}
230+
fSourceContainerMap.values().stream().flatMap(List::stream).forEach(ISourceContainer::dispose);
234231
fSourceContainerMap.clear();
235232
super.dispose();
236233
}

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/sourcelookup/PDESourceLookupQuery.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import com.sun.jdi.VMDisconnectedException;
1818
import java.io.File;
19+
import java.util.Arrays;
20+
import java.util.List;
1921
import org.eclipse.core.runtime.CoreException;
2022
import org.eclipse.core.runtime.ISafeRunnable;
2123
import org.eclipse.debug.core.DebugException;
@@ -304,11 +306,11 @@ private Object getSourceElement(String location, String id, String typeName, boo
304306
}
305307

306308
private Object findJreSourceElement(String sourcePath) throws CoreException {
307-
ISourceContainer[] jreSourceContainers = fDirector.getJreSourceContainers();
309+
List<ISourceContainer> jreSourceContainers = Arrays.asList(fDirector.getJreSourceContainers());
308310
return findSourceElement(jreSourceContainers, sourcePath);
309311
}
310312

311-
private Object findSourceElement(ISourceContainer[] containers, String typeName) throws CoreException {
313+
private Object findSourceElement(List<ISourceContainer> containers, String typeName) throws CoreException {
312314
for (ISourceContainer container : containers) {
313315
Object[] result = container.findSourceElements(typeName);
314316
if (result.length > 0)
@@ -317,7 +319,7 @@ private Object findSourceElement(ISourceContainer[] containers, String typeName)
317319
return null;
318320
}
319321

320-
protected ISourceContainer[] getSourceContainers(String location, String id) throws CoreException {
322+
protected List<ISourceContainer> getSourceContainers(String location, String id) throws CoreException {
321323
return fDirector.getSourceContainers(location, id);
322324
}
323325

ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: PDE JUnit Tests
44
Bundle-SymbolicName: org.eclipse.pde.ui.tests; singleton:=true
5-
Bundle-Version: 3.11.800.qualifier
5+
Bundle-Version: 3.11.900.qualifier
66
Bundle-ClassPath: tests.jar
77
Bundle-Activator: org.eclipse.pde.ui.tests.PDETestsPlugin
88
Bundle-Vendor: Eclipse.org

ui/org.eclipse.pde.ui.tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<relativePath>../../</relativePath>
1919
</parent>
2020
<artifactId>org.eclipse.pde.ui.tests</artifactId>
21-
<version>3.11.800-SNAPSHOT</version>
21+
<version>3.11.900-SNAPSHOT</version>
2222
<packaging>eclipse-test-plugin</packaging>
2323

2424
<properties>

ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathresolver/ClasspathResolverTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public _PDESourceLookupQuery(PDESourceLookupDirector director, Object object) {
104104
}
105105

106106
@Override // Make super.getSourceContainers() visible
107-
public ISourceContainer[] getSourceContainers(String location, String id) throws CoreException {
107+
public List<ISourceContainer> getSourceContainers(String location, String id) throws CoreException {
108108
return super.getSourceContainers(location, id);
109109
}
110110
}
@@ -137,12 +137,12 @@ public void testSourceLookupPath() throws Exception {
137137
PDESourceLookupDirector d = new PDESourceLookupDirector();
138138
_PDESourceLookupQuery q = new _PDESourceLookupQuery(d, project);
139139

140-
ISourceContainer[] containers = q.getSourceContainers(project.getLocation().toOSString(), bundleName);
140+
List<ISourceContainer> containers = q.getSourceContainers(project.getLocation().toOSString(), bundleName);
141141

142-
assertEquals(2, containers.length);
143-
assertEquals(JavaCore.create(project), ((JavaProjectSourceContainer) containers[0]).getJavaProject());
142+
assertEquals(2, containers.size());
143+
assertEquals(JavaCore.create(project), ((JavaProjectSourceContainer) containers.get(0)).getJavaProject());
144144
assertEquals(project.getFolder("cpe").getLocation().toFile(),
145-
((DirectorySourceContainer) containers[1]).getDirectory());
145+
((DirectorySourceContainer) containers.get(1)).getDirectory());
146146
}
147147

148148
@Test

0 commit comments

Comments
 (0)