Search in sources :

Example 1 with ExportedService

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;
}
Also used : ExportedService(org.mule.runtime.module.artifact.api.classloader.ExportedService) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File.createTempFile(java.io.File.createTempFile) File(java.io.File) FileUtils.stringToFile(org.mule.runtime.core.api.util.FileUtils.stringToFile) URL(java.net.URL)

Example 2 with ExportedService

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) {
            }
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ExportedService(org.mule.runtime.module.artifact.api.classloader.ExportedService) ZipEntry(java.util.zip.ZipEntry) URL(java.net.URL)

Example 3 with ExportedService

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);
}
Also used : ExportedService(org.mule.runtime.module.artifact.api.classloader.ExportedService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MuleModule(org.mule.runtime.container.api.MuleModule)

Aggregations

ExportedService (org.mule.runtime.module.artifact.api.classloader.ExportedService)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 File (java.io.File)1 File.createTempFile (java.io.File.createTempFile)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 MuleModule (org.mule.runtime.container.api.MuleModule)1 FileUtils.stringToFile (org.mule.runtime.core.api.util.FileUtils.stringToFile)1