Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,23 @@ protected Enumeration<URL> findResources(String name) throws IOException {
List<SPIMapping> spis = mappings.computeIfAbsent(name, spi -> {
List<SPIMapping> list = new ArrayList<>();
for (Bundle other : bundles) {
URL entry = other.getEntry(name);
if (entry != null) {
try {
list.add(new SPIMapping(other.loadClass(serviceName), other, entry));
} catch (ClassNotFoundException e) {
// should not happen
try {
Enumeration<URL> resources = other.getResources(name);
if (resources != null) {
list.add(new SPIMapping(other.loadClass(serviceName), other, Collections.list(resources)));
}
} catch (ClassNotFoundException e) {
// should not happen
} catch (IOException e) {
//can't be used then
}
}
return list;
});
Bundle caller = Caller.getBundle(junitVersion);
for (SPIMapping mapping : spis) {
if (mapping.isCompatible(caller)) {
result.add(mapping.getUrl());
result.addAll(mapping.getUrls());
}
}
return Collections.enumeration(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashSet;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;

import org.osgi.framework.Bundle;

Expand All @@ -28,23 +28,27 @@ final class SPIMapping {
private final Class<?> serviceClass;
private final Bundle bundle;
private final Set<String> classes;
private final URL url;
private final Collection<URL> urls;

SPIMapping(Class<?> serviceClass, Bundle bundle, URL url) {
SPIMapping(Class<?> serviceClass, Bundle bundle, Collection<URL> urls) {
this.serviceClass = serviceClass;
this.bundle = bundle;
this.url = url;
this.classes = readClasses(url);
this.urls = urls;
this.classes = readClasses(urls);
}

private Set<String> readClasses(URL entry) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(entry.openStream()))) {
return reader.lines().collect(Collectors.toSet());
} catch (IOException e) {
return new HashSet<>();
private static Set<String> readClasses(Collection<URL> urls) {
Set<String> result = new LinkedHashSet<>();
for (URL url : urls) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
reader.lines().forEach(result::add);
} catch (IOException e) {
}
}
return result;
}


boolean isCompatible(Bundle other) {
try {
return other.loadClass(serviceClass.getName()) == serviceClass;
Expand All @@ -53,8 +57,8 @@ boolean isCompatible(Bundle other) {
}
}

URL getUrl() {
return url;
Collection<URL> getUrls() {
return urls;
}

boolean hasService(String implementation) {
Expand Down
Loading