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;
}
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));
}
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;
}
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);
}
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);
}
Aggregations