Search in sources :

Example 6 with DomainDescriptor

use of org.mule.runtime.deployment.model.api.domain.DomainDescriptor in project mule by mulesoft.

the class DefaultPolicyTemplateFactoryTestCase method createApplication.

private Application createApplication(RegionClassLoader regionClassLoader) {
    ApplicationDescriptor appDescriptor = mock(ApplicationDescriptor.class);
    when(appDescriptor.getPlugins()).thenReturn(emptySet());
    Application application = mock(Application.class);
    when(application.getRegionClassLoader()).thenReturn(regionClassLoader);
    when(application.getDescriptor()).thenReturn(appDescriptor);
    final Domain domain = mock(Domain.class);
    when(domain.getDescriptor()).thenReturn(new DomainDescriptor("testDomain"));
    when(application.getDomain()).thenReturn(domain);
    return application;
}
Also used : Domain(org.mule.runtime.deployment.model.api.domain.Domain) Application(org.mule.runtime.deployment.model.api.application.Application) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)

Example 7 with DomainDescriptor

use of org.mule.runtime.deployment.model.api.domain.DomainDescriptor in project mule by mulesoft.

the class DefaultDomainFactoryTestCase method createCustomDomain.

@Test
public void createCustomDomain() throws IOException {
    String domainName = "custom-domain";
    final DomainDescriptor descriptor = new DomainDescriptor(domainName);
    when(domainDescriptorFactory.create(any(), any())).thenReturn(descriptor);
    final MuleApplicationClassLoader domainArtifactClassLoader = mock(MuleApplicationClassLoader.class);
    when(domainArtifactClassLoader.getArtifactId()).thenReturn(domainName);
    DomainClassLoaderBuilder domainClassLoaderBuilderMock = mock(DomainClassLoaderBuilder.class);
    when(domainClassLoaderBuilderMock.setArtifactDescriptor(any())).thenReturn(domainClassLoaderBuilderMock);
    when(domainClassLoaderBuilderMock.setArtifactId(any())).thenReturn(domainClassLoaderBuilderMock);
    when(domainClassLoaderBuilderMock.addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]))).thenReturn(domainClassLoaderBuilderMock);
    when(domainClassLoaderBuilderMock.build()).thenReturn(domainArtifactClassLoader);
    when(domainClassLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(domainClassLoaderBuilderMock);
    Domain domain = domainFactory.createArtifact(new File(domainName), empty());
    assertThat(domain.getArtifactName(), is(domainName));
    assertThat(domain.getDescriptor(), is(descriptor));
    assertThat(domain.getArtifactClassLoader(), is(domainArtifactClassLoader));
}
Also used : ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) DomainClassLoaderBuilder(org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderBuilder) MuleApplicationClassLoader(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor) File(java.io.File) Test(org.junit.Test)

Example 8 with DomainDescriptor

use of org.mule.runtime.deployment.model.api.domain.DomainDescriptor in project mule by mulesoft.

the class ToolingApplicationClassLoaderBuilder method getParentLookupPolicy.

@Override
protected ClassLoaderLookupPolicy getParentLookupPolicy(ArtifactClassLoader parentClassLoader) {
    if (!usesCustomDomain) {
        return super.getParentLookupPolicy(parentClassLoader);
    }
    Map<String, LookupStrategy> lookupStrategies = new HashMap<>();
    DomainDescriptor descriptor = parentClassLoader.getArtifactDescriptor();
    descriptor.getClassLoaderModel().getExportedPackages().forEach(p -> lookupStrategies.put(p, PARENT_FIRST));
    for (ArtifactPluginDescriptor artifactPluginDescriptor : descriptor.getPlugins()) {
        artifactPluginDescriptor.getClassLoaderModel().getExportedPackages().forEach(p -> lookupStrategies.put(p, PARENT_FIRST));
    }
    return parentClassLoader.getClassLoaderLookupPolicy().extend(lookupStrategies);
}
Also used : HashMap(java.util.HashMap) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor)

Example 9 with DomainDescriptor

use of org.mule.runtime.deployment.model.api.domain.DomainDescriptor 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)

Example 10 with DomainDescriptor

use of org.mule.runtime.deployment.model.api.domain.DomainDescriptor in project mule by mulesoft.

the class DomainClassLoaderFactoryTestCase method createClassLoaderUsingDefaultDomain.

@Test
public void createClassLoaderUsingDefaultDomain() {
    createDomainDir(MULE_DOMAIN_FOLDER, DEFAULT_DOMAIN_NAME);
    DomainDescriptor descriptor = getTestDescriptor(DEFAULT_DOMAIN_NAME);
    final String artifactId = getDomainId(DEFAULT_DOMAIN_NAME);
    assertThat(new DomainClassLoaderFactory(getClass().getClassLoader()).create(artifactId, containerClassLoader, descriptor, emptyList()).getArtifactId(), is(artifactId));
}
Also used : DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor) Test(org.junit.Test)

Aggregations

DomainDescriptor (org.mule.runtime.deployment.model.api.domain.DomainDescriptor)12 Test (org.junit.Test)5 Domain (org.mule.runtime.deployment.model.api.domain.Domain)4 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)4 File (java.io.File)3 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)3 HashMap (java.util.HashMap)2 ApplicationDescriptor (org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)2 MuleApplicationClassLoader (org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader)2 DomainClassLoaderBuilder (org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderBuilder)2 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)2 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 Before (org.junit.Before)1 Application (org.mule.runtime.deployment.model.api.application.Application)1 ArtifactPlugin (org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)1 MuleSharedDomainClassLoader (org.mule.runtime.deployment.model.internal.domain.MuleSharedDomainClassLoader)1 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)1 MuleDeployableArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader)1 ClassLoaderModel (org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel)1