use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class DefaultRegionPluginClassLoadersFactoryTestCase method createsPluginWithPrivilegedPluginAccess.
@Test
public void createsPluginWithPrivilegedPluginAccess() throws Exception {
ClassLoaderModel plugin1ClassLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder().exportingPrivilegedPackages(singleton(PRIVILEGED_PACKAGE), singleton(PLUGIN_ARTIFACT_ID2)).build();
plugin1Descriptor.setClassLoaderModel(plugin1ClassLoaderModel);
BundleDependency pluginDependency = new BundleDependency.Builder().setScope(BundleScope.COMPILE).setDescriptor(PLUGIN1_BUNDLE_DESCRIPTOR).setBundleUri(new File("test").toURI()).build();
plugin2Descriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().dependingOn(singleton(pluginDependency)).build());
List<ArtifactPluginDescriptor> artifactPluginDescriptors = new ArrayList<>();
artifactPluginDescriptors.add(plugin1Descriptor);
artifactPluginDescriptors.add(plugin2Descriptor);
ArgumentCaptor<Map> argumentCaptor = forClass(Map.class);
when(regionOwnerLookupPolicy.extend(argumentCaptor.capture())).thenReturn(pluginLookupPolicy);
List<ArtifactClassLoader> pluginClassLoaders = factory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionOwnerLookupPolicy);
assertThat(pluginClassLoaders, contains(pluginClassLoader1, pluginClassLoader2));
assertThat((Map<String, LookupStrategy>) argumentCaptor.getAllValues().get(0), not(hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(DelegateOnlyLookupStrategy.class))));
assertThat((Map<String, LookupStrategy>) argumentCaptor.getAllValues().get(1), hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(DelegateOnlyLookupStrategy.class)));
}
use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class MuleApplicationClassLoaderTestCase method createAppClassLoader.
@Before
public void createAppClassLoader() throws Exception {
// Create directories structure
previousMuleHome = System.setProperty(MULE_HOME_DIRECTORY_PROPERTY, tempMuleHome.getRoot().getAbsolutePath());
final List<URL> urls = new LinkedList<>();
appFolder = getAppFolder(APP_NAME);
assertThat(appFolder.mkdirs(), is(true));
// Add isolated resources in classes dir
FileUtils.stringToFile(new File(appFolder, RESOURCE_IN_CLASSES_AND_JAR).getAbsolutePath(), "Some text");
FileUtils.stringToFile(new File(appFolder, RESOURCE_JUST_IN_CLASSES).getAbsolutePath(), "Some text");
urls.add(appFolder.toURI().toURL());
// Add jar file with resources in lib dir
File libDir = getAppLibFolder(APP_NAME);
assertThat(libDir.mkdirs(), is(true));
URL resourceSrcJarFile = currentThread().getContextClassLoader().getResource("test-jar-with-resources.jar");
assertNotNull(resourceSrcJarFile);
File srcJarFile = new File(resourceSrcJarFile.toURI());
jarFile = new File(libDir, "test-jar-with-resources.jar");
FileUtils.copyFile(srcJarFile, jarFile, false);
urls.add(jarFile.toURI().toURL());
// Add isolated resources in domain dir
domainDir = MuleFoldersUtil.getDomainFolder(DOMAIN_NAME);
assertThat(domainDir.mkdirs(), is(true));
FileUtils.stringToFile(new File(domainDir, RESOURCE_JUST_IN_DOMAIN).getAbsolutePath(), "Some text");
mockStatic(MuleArtifactClassLoader.class);
// Create app class loader
domainCL = new MuleSharedDomainClassLoader(new DomainDescriptor(DOMAIN_NAME), currentThread().getContextClassLoader(), mock(ClassLoaderLookupPolicy.class), emptyList(), emptyList());
final ApplicationDescriptor applicationDescriptor = new ApplicationDescriptor(APP_NAME);
ClassLoaderModel classLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder(applicationDescriptor.getClassLoaderModel()).containing(getAppFolder(APP_NAME).toURI().toURL()).build();
applicationDescriptor.setClassLoaderModel(classLoaderModel);
appCL = new MuleApplicationClassLoader(APP_NAME, applicationDescriptor, domainCL, null, urls, mock(ClassLoaderLookupPolicy.class), emptyList());
}
use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class BundlePluginDependenciesResolver method sanitizeExportedPackages.
private void sanitizeExportedPackages(ArtifactPluginDescriptor pluginDescriptor, List<ArtifactPluginDescriptor> resolvedPlugins) {
final Set<String> packagesExportedByDependencies = findDependencyPackageClosure(pluginDescriptor.getClassLoaderModel().getDependencies(), resolvedPlugins);
ClassLoaderModel originalClassLoaderModel = pluginDescriptor.getClassLoaderModel();
final Set<String> exportedClassPackages = new HashSet<>(originalClassLoaderModel.getExportedPackages());
exportedClassPackages.removeAll(packagesExportedByDependencies);
pluginDescriptor.setClassLoaderModel(createBuilderWithoutExportedPackages(originalClassLoaderModel).exportingPackages(exportedClassPackages).build());
}
use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class LibFolderClassLoaderModelLoaderTestCase method addsArtifactFolderToClassLoader.
@Test
public void addsArtifactFolderToClassLoader() throws Exception {
ClassLoaderModel classLoaderModel = classLoaderModelLoader.load(serviceFolder.getRoot(), emptyMap(), SERVICE);
assertThat(classLoaderModel.getUrls(), hasItemInArray(serviceFolder.getRoot().toURI().toURL()));
}
use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class LibFolderClassLoaderModelLoaderTestCase method addJarsFromLibFolderToClassLoader.
@Test
public void addJarsFromLibFolderToClassLoader() throws Exception {
File libFolder = serviceFolder.newFolder(LIB_FOLDER);
File jarFile = new File(libFolder, "dummy.jar");
jarFile.createNewFile();
ClassLoaderModel classLoaderModel = classLoaderModelLoader.load(serviceFolder.getRoot(), emptyMap(), SERVICE);
assertThat(classLoaderModel.getUrls(), hasItemInArray(jarFile.toURI().toURL()));
}
Aggregations