Search in sources :

Example 16 with MuleModule

use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.

the class ContainerClassLoaderFactoryTestCase method createClassLoaderExportingBootstrapProperties.

private ContainerClassLoaderFactory createClassLoaderExportingBootstrapProperties() {
    final ModuleRepository moduleRepository = mock(ModuleRepository.class);
    final ContainerClassLoaderFactory factory = new ContainerClassLoaderFactory(moduleRepository);
    final List<MuleModule> modules = new ArrayList<>();
    modules.add(new TestModuleBuilder("module1").exportingResources(BOOTSTRAP_PROPERTIES).build());
    when(moduleRepository.getModules()).thenReturn(modules);
    return factory;
}
Also used : ArrayList(java.util.ArrayList) ModuleRepository(org.mule.runtime.container.api.ModuleRepository) MuleModule(org.mule.runtime.container.api.MuleModule)

Example 17 with MuleModule

use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.

the class ContainerClassLoaderFilterFactoryTestCase method acceptsExportedModulePackages.

@Test
public void acceptsExportedModulePackages() throws Exception {
    final List<MuleModule> muleModules = new ArrayList<>();
    muleModules.add(new TestModuleBuilder("module1").exportingPackages("org.foo1", "org.foo1.bar.").exportingResources("META-INF/foo.txt", "META-INF/docs1/foo.txt").build());
    muleModules.add(new TestModuleBuilder("module2").exportingPackages("org.foo2").exportingResources("META-INF/", "/META-INF/docs2").build());
    final ClassLoaderFilter classLoaderFilter = factory.create(Collections.emptySet(), muleModules);
    assertThat(classLoaderFilter.exportsClass("org.foo1.Foo"), is(true));
    assertThat(classLoaderFilter.exportsClass("org.foo1.bar.Bar"), is(true));
    assertThat(classLoaderFilter.exportsClass("org.foo2.Foo"), is(true));
    assertThat(classLoaderFilter.exportsClass("org.bar.Bar"), is(false));
    assertThat(classLoaderFilter.exportsClass("org.foo2.bar.Bar"), is(false));
    assertThat(classLoaderFilter.exportsResource("META-INF/foo.txt"), is(true));
    assertThat(classLoaderFilter.exportsResource("META-INF/docs1/foo.txt"), is(true));
    assertThat(classLoaderFilter.exportsResource("META-INF/docs2/foo.txt"), is(true));
    assertThat(classLoaderFilter.exportsResource("/META-INF/docs2/foo.txt"), is(true));
    assertThat(classLoaderFilter.exportsResource("/foo.txt"), is(false));
}
Also used : ClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter) ArrayList(java.util.ArrayList) MuleModule(org.mule.runtime.container.api.MuleModule) Test(org.junit.Test)

Example 18 with MuleModule

use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.

the class ClasspathModuleDiscoverer method discover.

@Override
public List<MuleModule> discover() {
    List<MuleModule> modules = new LinkedList<>();
    Set<String> moduleNames = new HashSet<>();
    try {
        for (Properties moduleProperties : discoverProperties(classLoader, getModulePropertiesFileName())) {
            final MuleModule module = createModule(moduleProperties);
            if (moduleNames.contains(module.getName())) {
                logger.warn(format("Ignoring duplicated module '%s'", module.getName()));
            } else {
                moduleNames.add(module.getName());
                modules.add(module);
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("Cannot discover mule modules", e);
    }
    return modules;
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) PropertiesUtils.discoverProperties(org.mule.runtime.core.api.util.PropertiesUtils.discoverProperties) LinkedList(java.util.LinkedList) MuleModule(org.mule.runtime.container.api.MuleModule) HashSet(java.util.HashSet)

Example 19 with MuleModule

use of org.mule.runtime.container.api.MuleModule 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)

Example 20 with MuleModule

use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.

the class DefaultRegionPluginClassLoadersFactory method createPluginLookupPolicy.

private ClassLoaderLookupPolicy createPluginLookupPolicy(List<ArtifactClassLoader> classLoaders, ArtifactPluginDescriptor descriptor, ClassLoaderLookupPolicy baseLookupPolicy, List<ArtifactPluginDescriptor> artifactPluginDescriptors) {
    Map<String, LookupStrategy> pluginsLookupPolicies = new HashMap<>();
    List<ArtifactPluginDescriptor> pluginDescriptors = getPluginDescriptors(descriptor, artifactPluginDescriptors);
    for (ArtifactPluginDescriptor dependencyPluginDescriptor : pluginDescriptors) {
        if (dependencyPluginDescriptor.getName().equals(descriptor.getName())) {
            continue;
        }
        LookupStrategy lookupStrategy = getClassLoaderLookupStrategy(descriptor, dependencyPluginDescriptor);
        for (String exportedPackage : dependencyPluginDescriptor.getClassLoaderModel().getExportedPackages()) {
            pluginsLookupPolicies.put(exportedPackage, lookupStrategy);
        }
        if (isPrivilegedPluginDependency(descriptor, dependencyPluginDescriptor)) {
            Optional<ArtifactClassLoader> pluginClassLoader = classLoaders.stream().filter(c -> c.getArtifactDescriptor().getBundleDescriptor().getArtifactId().equals(dependencyPluginDescriptor.getBundleDescriptor().getArtifactId())).findFirst();
            if (!pluginClassLoader.isPresent()) {
                throw new IllegalStateException("Cannot find classloader for plugin: " + dependencyPluginDescriptor.getBundleDescriptor().getArtifactId());
            }
            lookupStrategy = new DelegateOnlyLookupStrategy(pluginClassLoader.get().getClassLoader());
            for (String exportedPackage : dependencyPluginDescriptor.getClassLoaderModel().getPrivilegedExportedPackages()) {
                pluginsLookupPolicies.put(exportedPackage, lookupStrategy);
            }
        }
    }
    ContainerOnlyLookupStrategy containerOnlyLookupStrategy = new ContainerOnlyLookupStrategy(this.getClass().getClassLoader());
    for (MuleModule module : moduleRepository.getModules()) {
        if (module.getPrivilegedArtifacts().contains(descriptor.getBundleDescriptor().getGroupId() + ":" + descriptor.getBundleDescriptor().getArtifactId())) {
            for (String packageName : module.getPrivilegedExportedPackages()) {
                pluginsLookupPolicies.put(packageName, containerOnlyLookupStrategy);
            }
        }
    }
    return baseLookupPolicy.extend(pluginsLookupPolicies);
}
Also used : ModuleRepository(org.mule.runtime.container.api.ModuleRepository) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) CHILD_ONLY(org.mule.runtime.module.artifact.api.classloader.ChildOnlyLookupStrategy.CHILD_ONLY) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) Set(java.util.Set) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) HashMap(java.util.HashMap) PARENT_FIRST(org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST) MuleModule(org.mule.runtime.container.api.MuleModule) Collectors.toList(java.util.stream.Collectors.toList) MULE_PLUGIN_CLASSIFIER(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor.MULE_PLUGIN_CLASSIFIER) List(java.util.List) ArtifactClassLoaderFactory(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFactory) Map(java.util.Map) Optional(java.util.Optional) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) LinkedList(java.util.LinkedList) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) HashMap(java.util.HashMap) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) MuleModule(org.mule.runtime.container.api.MuleModule) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)

Aggregations

MuleModule (org.mule.runtime.container.api.MuleModule)21 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)11 URL (java.net.URL)5 EnumerationAdapter (org.mule.runtime.core.internal.util.EnumerationAdapter)5 SmallTest (org.mule.tck.size.SmallTest)5 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)4 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)4 HashMap (java.util.HashMap)3 ModuleRepository (org.mule.runtime.container.api.ModuleRepository)3 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)3 ClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter)3 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)2 DelegateOnlyLookupStrategy (org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy)2 ArtifactDescriptor (org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor)2 IOException (java.io.IOException)1