use of org.mule.runtime.module.artifact.api.classloader.ExportedService in project mule by mulesoft.
the class ClasspathModuleDiscoverer method getServicesFromProperty.
private List<ExportedService> getServicesFromProperty(String privilegedExportedPackagesProperty) {
List<ExportedService> exportedServices = new ArrayList<>();
for (String exportedServiceDefinition : privilegedExportedPackagesProperty.split(",")) {
String[] split = exportedServiceDefinition.split(":");
String serviceInterface = split[0];
String serviceImplementation = split[1];
URL resource;
try {
File serviceFile = createTempFile(serviceInterface, "tmp");
stringToFile(serviceFile.getAbsolutePath(), serviceImplementation);
resource = serviceFile.toURI().toURL();
} catch (IOException e) {
throw new IllegalStateException(format("Error creating temporary service provider file for '%s'", serviceInterface), e);
}
exportedServices.add(new ExportedService(serviceInterface, resource));
}
return exportedServices;
}
use of org.mule.runtime.module.artifact.api.classloader.ExportedService in project mule by mulesoft.
the class JreExplorer method exploreJar.
private static void exploreJar(Set<String> packages, Set<String> resources, List<ExportedService> services, File file) throws IOException {
final ZipFile zipFile = new ZipFile(file);
try {
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
final ZipEntry entry = entries.nextElement();
final String name = entry.getName();
final int lastSlash = name.lastIndexOf('/');
if (lastSlash != -1 && name.endsWith(".class")) {
packages.add(name.substring(0, lastSlash).replaceAll("/", "."));
} else if (!entry.isDirectory()) {
if (name.startsWith(META_INF_SERVICES_PATH)) {
String serviceInterface = name.substring(META_INF_SERVICES_PATH.length());
URL resource = getServiceResourceUrl(file.toURI().toURL(), name);
services.add(new ExportedService(serviceInterface, resource));
} else {
resources.add(name);
}
}
}
} finally {
if (zipFile != null)
try {
zipFile.close();
} catch (Throwable ignored) {
}
}
}
use of org.mule.runtime.module.artifact.api.classloader.ExportedService in project mule by mulesoft.
the class JreModuleDiscoverer method discover.
@Override
public List<MuleModule> discover() {
Set<String> packages = new HashSet<>(1024);
Set<String> resources = new HashSet<>(1024);
List<ExportedService> services = new ArrayList<>(128);
exploreJdk(packages, resources, services);
if (logger.isDebugEnabled()) {
logger.debug("Discovered JRE:\npackages: {}\nresources: {}\nservices: {}", packages, resources, services.stream().map(p -> p.getServiceInterface() + ":" + p.getResource().toString()).collect(toList()));
}
MuleModule jdkModule = new MuleModule(JRE_MODULE_NAME, packages, resources, emptySet(), emptySet(), services);
return Collections.singletonList(jdkModule);
}
Aggregations