Issue #2602 Don't try to load classes from uninstalled bundles.
Former-commit-id:3187754736
[formerly 30ca0135046851884e4a07b36559fce086ccd3f2] Former-commit-id:0c4fc0dd01
This commit is contained in:
parent
737ed09ade
commit
c7357863b9
2 changed files with 25 additions and 6 deletions
|
@ -20,6 +20,7 @@
|
||||||
package com.raytheon.uf.viz.core.reflect;
|
package com.raytheon.uf.viz.core.reflect;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ import org.reflections.util.ConfigurationBuilder;
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------- -------- ----------- --------------------------
|
* ------------- -------- ----------- --------------------------
|
||||||
* Oct 21, 2013 2491 bsteffen Initial creation
|
* Oct 21, 2013 2491 bsteffen Initial creation
|
||||||
|
* Jan 22, 2014 2062 bsteffen Handle bundles with no wiring.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -54,20 +56,29 @@ import org.reflections.util.ConfigurationBuilder;
|
||||||
|
|
||||||
public class BundleReflections {
|
public class BundleReflections {
|
||||||
|
|
||||||
private Reflections reflections;
|
private final Reflections reflections;
|
||||||
|
|
||||||
public BundleReflections(Bundle bundle, Scanner scanner) throws IOException {
|
public BundleReflections(Bundle bundle, Scanner scanner) throws IOException {
|
||||||
ConfigurationBuilder cb = new ConfigurationBuilder();
|
ConfigurationBuilder cb = new ConfigurationBuilder();
|
||||||
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
|
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
|
||||||
|
if (bundleWiring != null) {
|
||||||
cb.addClassLoader(bundleWiring.getClassLoader());
|
cb.addClassLoader(bundleWiring.getClassLoader());
|
||||||
cb.addUrls(FileLocator.getBundleFile(bundle).toURI().toURL());
|
cb.addUrls(FileLocator.getBundleFile(bundle).toURI().toURL());
|
||||||
cb.setScanners(scanner);
|
cb.setScanners(scanner);
|
||||||
reflections = cb.build();
|
reflections = cb.build();
|
||||||
|
} else {
|
||||||
|
reflections = null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) {
|
public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) {
|
||||||
|
if (reflections == null) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
} else {
|
||||||
return reflections.getSubTypesOf(type);
|
return reflections.getSubTypesOf(type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Set<Class<?>> getSubTypesOf(Class<?>... types) {
|
public Set<Class<?>> getSubTypesOf(Class<?>... types) {
|
||||||
Set<Class<?>> subTypes = new HashSet<Class<?>>();
|
Set<Class<?>> subTypes = new HashSet<Class<?>>();
|
||||||
|
|
|
@ -146,6 +146,14 @@ public class SubClassLocator implements ISubClassLocator {
|
||||||
return Collections.emptySet();
|
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) {
|
if (includeRequiredSubclasses) {
|
||||||
/* Short circut if we already did this. */
|
/* Short circut if we already did this. */
|
||||||
Set<Class<?>> result = recursiveClasses.get(bundleName);
|
Set<Class<?>> result = recursiveClasses.get(bundleName);
|
||||||
|
|
Loading…
Add table
Reference in a new issue