use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class ApplicationStartedSplashScreenTestCase method setUp.
@Before
public void setUp() {
splashScreen = new ApplicationStartedSplashScreen();
ClassLoaderModel.ClassLoaderModelBuilder classLoaderModelBuilder = new ClassLoaderModel.ClassLoaderModelBuilder();
runtimeLibs.stream().forEach(classLoaderModelBuilder::containing);
ClassLoaderModel classLoaderModel = classLoaderModelBuilder.build();
ArtifactPluginDescriptor pluginDescriptor = new ArtifactPluginDescriptor(PLUGIN_NAME);
pluginDescriptor.setBundleDescriptor(new BundleDescriptor.Builder().setGroupId(PLUGIN_GROUP_ID).setArtifactId(PLUGIN_ARTIFACT_ID).setVersion(PLUGIN_VERSION).build());
when(descriptor.getName()).thenReturn(APP_NAME);
when(descriptor.getAppProperties()).thenReturn(new HashMap<>());
when(descriptor.getPlugins()).thenReturn(newHashSet(pluginDescriptor));
when(descriptor.getClassLoaderModel()).thenReturn(classLoaderModel);
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class DefaultApplicationFactoryTestCase method createsApplication.
@Test
public void createsApplication() throws Exception {
final ApplicationDescriptor descriptor = new ApplicationDescriptor(APP_NAME);
descriptor.setClassLoaderModel(createClassLoaderModelWithDomain());
final File[] resourceFiles = new File[] { new File("mule-config.xml") };
when(applicationDescriptorFactory.create(any(), any())).thenReturn(descriptor);
final ArtifactPluginDescriptor coreArtifactPluginDescriptor = new ArtifactPluginDescriptor(FAKE_ARTIFACT_PLUGIN);
coreArtifactPluginDescriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().build());
final ArtifactPlugin appPlugin = mock(ArtifactPlugin.class);
final ArtifactClassLoader artifactClassLoader = mock(ArtifactClassLoader.class);
when(appPlugin.getArtifactClassLoader()).thenReturn(artifactClassLoader);
when(artifactClassLoader.getArtifactId()).thenReturn(FAKE_ARTIFACT_PLUGIN);
when(appPlugin.getDescriptor()).thenReturn(coreArtifactPluginDescriptor);
final Domain domain = createDomain(DOMAIN_NAME);
final ClassLoaderLookupPolicy sharedLibLookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(domain.getArtifactClassLoader().getClassLoaderLookupPolicy().extend(anyMap())).thenReturn(sharedLibLookupPolicy);
final MuleApplicationClassLoader applicationArtifactClassLoader = mock(MuleApplicationClassLoader.class);
when(applicationArtifactClassLoader.getArtifactId()).thenReturn(APP_ID);
ApplicationClassLoaderBuilder applicationClassLoaderBuilderMock = mock(ApplicationClassLoaderBuilder.class);
when(applicationClassLoaderBuilderMock.setDomain(any())).thenReturn(applicationClassLoaderBuilderMock);
when(applicationClassLoaderBuilderMock.setArtifactDescriptor(any())).thenReturn(applicationClassLoaderBuilderMock);
when(applicationClassLoaderBuilderMock.setArtifactId(any())).thenReturn(applicationClassLoaderBuilderMock);
when(applicationClassLoaderBuilderMock.addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]))).thenReturn(applicationClassLoaderBuilderMock);
when(applicationClassLoaderBuilderMock.build()).thenReturn(applicationArtifactClassLoader);
when(applicationClassLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(applicationClassLoaderBuilderMock);
List<ArtifactClassLoader> pluginClassLoaders = new ArrayList<>();
pluginClassLoaders.add(artifactClassLoader);
when(applicationArtifactClassLoader.getArtifactPluginClassLoaders()).thenReturn(pluginClassLoaders);
final Application application = applicationFactory.createArtifact(new File(APP_NAME), empty());
assertThat(application.getDomain(), is(domain));
assertThat(application.getArtifactClassLoader(), is(applicationArtifactClassLoader));
assertThat(application.getDescriptor(), is(descriptor));
assertThat(application.getArtifactName(), is(APP_NAME));
assertThat(application.getResourceFiles(), is(resourceFiles));
verify(domainRepository, times(2)).getDomain(DOMAIN_ARTIFACT_FILE_NAME);
verify(applicationClassLoaderBuilderMock).setDomain(domain);
verify(applicationClassLoaderBuilderMock).addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]));
verify(applicationClassLoaderBuilderMock).setArtifactDescriptor(descriptor);
verify(applicationClassLoaderBuilderMock).setArtifactId(APP_NAME);
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor 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));
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class DefaultPolicyTemplateFactory method createArtifact.
@Override
public PolicyTemplate createArtifact(Application application, PolicyTemplateDescriptor descriptor) {
MuleDeployableArtifactClassLoader policyClassLoader;
List<ArtifactPluginDescriptor> resolvedPolicyPluginsDescriptors = resolvePolicyPluginDescriptors(application, descriptor);
try {
policyClassLoader = policyTemplateClassLoaderBuilderFactory.createArtifactClassLoaderBuilder().addArtifactPluginDescriptors(resolvedPolicyPluginsDescriptors.toArray(new ArtifactPluginDescriptor[resolvedPolicyPluginsDescriptors.size()])).setParentClassLoader(application.getRegionClassLoader()).setArtifactDescriptor(descriptor).build();
} catch (IOException e) {
throw new PolicyTemplateCreationException(createPolicyTemplateCreationErrorMessage(descriptor.getName()), e);
}
application.getRegionClassLoader().addClassLoader(policyClassLoader, NULL_CLASSLOADER_FILTER);
List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(policyClassLoader, resolvedPolicyPluginsDescriptors);
validateArtifactLicense(policyClassLoader.getClassLoader(), artifactPlugins, licenseValidator);
DefaultPolicyTemplate policy = new DefaultPolicyTemplate(policyClassLoader.getArtifactId(), descriptor, policyClassLoader, artifactPlugins);
return policy;
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor 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);
}
Aggregations