Search in sources :

Example 1 with MuleSharedDomainClassLoader

use of org.mule.runtime.deployment.model.internal.domain.MuleSharedDomainClassLoader 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());
}
Also used : File(java.io.File) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor) URL(java.net.URL) LinkedList(java.util.LinkedList) MuleSharedDomainClassLoader(org.mule.runtime.deployment.model.internal.domain.MuleSharedDomainClassLoader) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Before(org.junit.Before)

Aggregations

File (java.io.File)1 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 Before (org.junit.Before)1 ApplicationDescriptor (org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)1 DomainDescriptor (org.mule.runtime.deployment.model.api.domain.DomainDescriptor)1 MuleSharedDomainClassLoader (org.mule.runtime.deployment.model.internal.domain.MuleSharedDomainClassLoader)1 ClassLoaderModel (org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel)1