Issue #2602 Don't try to load classes from uninstalled bundles.

Former-commit-id: 0c4fc0dd01 [formerly 30ca0135046851884e4a07b36559fce086ccd3f2]
Former-commit-id: 3187754736
This commit is contained in:
Ben Steffensmeier 2014-01-22 15:46:51 -06:00
parent 786f3d1978
commit d1dbd0c9b6
2 changed files with 25 additions and 6 deletions

View file

@ -20,6 +20,7 @@
package com.raytheon.uf.viz.core.reflect;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@ -45,6 +46,7 @@ import org.reflections.util.ConfigurationBuilder;
* Date Ticket# Engineer Description
* ------------- -------- ----------- --------------------------
* Oct 21, 2013 2491 bsteffen Initial creation
* Jan 22, 2014 2062 bsteffen Handle bundles with no wiring.
*
* </pre>
*
@ -54,19 +56,28 @@ import org.reflections.util.ConfigurationBuilder;
public class BundleReflections {
private Reflections reflections;
private final Reflections reflections;
public BundleReflections(Bundle bundle, Scanner scanner) throws IOException {
ConfigurationBuilder cb = new ConfigurationBuilder();
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
cb.addClassLoader(bundleWiring.getClassLoader());
cb.addUrls(FileLocator.getBundleFile(bundle).toURI().toURL());
cb.setScanners(scanner);
reflections = cb.build();
if (bundleWiring != null) {
cb.addClassLoader(bundleWiring.getClassLoader());
cb.addUrls(FileLocator.getBundleFile(bundle).toURI().toURL());
cb.setScanners(scanner);
reflections = cb.build();
} else {
reflections = null;
}
}
public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) {
return reflections.getSubTypesOf(type);
if (reflections == null) {
return Collections.emptySet();
} else {
return reflections.getSubTypesOf(type);
}
}
public Set<Class<?>> getSubTypesOf(Class<?>... types) {

View file

@ -145,6 +145,14 @@ public class SubClassLocator implements ISubClassLocator {
*/
return Collections.emptySet();
}
if(bundle.getState() == Bundle.UNINSTALLED){
/*
* We won't be able to get a class loader for uninstalled bundles so
* don't process them.
*/
return Collections.emptySet();
}
if (includeRequiredSubclasses) {
/* Short circut if we already did this. */