use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader in project mule by mulesoft.
the class DefaultDomainFactory method doCreateArtifact.
@Override
protected Domain doCreateArtifact(File domainLocation, Optional<Properties> deploymentProperties) throws IOException {
String domainName = domainLocation.getName();
Domain domain = domainManager.getDomain(domainName);
if (domain != null) {
throw new IllegalArgumentException(format("Domain '%s' already exists", domainName));
}
if (domainName.contains(" ")) {
throw new IllegalArgumentException("Mule domain name may not contain spaces: " + domainName);
}
DomainDescriptor domainDescriptor = findDomain(domainName, domainLocation, deploymentProperties);
List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(emptySet(), domainDescriptor.getPlugins().stream().collect(toList()));
DomainClassLoaderBuilder artifactClassLoaderBuilder = domainClassLoaderBuilderFactory.createArtifactClassLoaderBuilder();
MuleDeployableArtifactClassLoader domainClassLoader = artifactClassLoaderBuilder.addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[resolvedArtifactPluginDescriptors.size()])).setArtifactId(domainDescriptor.getName()).setArtifactDescriptor(domainDescriptor).build();
List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(domainClassLoader, resolvedArtifactPluginDescriptors);
DefaultMuleDomain defaultMuleDomain = new DefaultMuleDomain(domainDescriptor, domainClassLoader, classLoaderRepository, serviceRepository, artifactPlugins, extensionModelLoaderManager);
DomainWrapper domainWrapper = new DomainWrapper(defaultMuleDomain, this);
domainManager.addDomain(domainWrapper);
return domainWrapper;
}
use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader in project mule by mulesoft.
the class PolicyTemplateClassLoaderFactoryTestCase method createsClassLoaderWithPlugins.
@Test
public void createsClassLoaderWithPlugins() throws Exception {
ArtifactClassLoader pluginClassLoader1 = mock(ArtifactClassLoader.class);
ArtifactClassLoader pluginClassLoader2 = mock(ArtifactClassLoader.class);
List<ArtifactClassLoader> artifactPluginClassLoaders = new ArrayList<>();
artifactPluginClassLoaders.add(pluginClassLoader1);
artifactPluginClassLoaders.add(pluginClassLoader2);
final ArtifactClassLoader artifactClassLoader = factory.create(POLICY_ID, parentClassLoader, descriptor, artifactPluginClassLoaders);
final MuleDeployableArtifactClassLoader classLoader = (MuleDeployableArtifactClassLoader) artifactClassLoader.getClassLoader();
assertThat(classLoader.getArtifactPluginClassLoaders(), contains(pluginClassLoader1, pluginClassLoader2));
}
use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader in project mule by mulesoft.
the class DefaultApplicationFactory method createArtifact.
public Application createArtifact(ApplicationDescriptor descriptor) throws IOException {
Domain domain = getApplicationDomain(descriptor);
List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(domain.getDescriptor().getPlugins(), new ArrayList<>(getArtifactPluginDescriptors(descriptor)));
// Refreshes the list of plugins on the descriptor with the resolved from domain and transitive plugin dependencies
Set resolvedArtifactPlugins = new LinkedHashSet<>();
resolvedArtifactPlugins.addAll(resolvedArtifactPluginDescriptors);
descriptor.setPlugins(resolvedArtifactPlugins);
ApplicationClassLoaderBuilder artifactClassLoaderBuilder = applicationClassLoaderBuilderFactory.createArtifactClassLoaderBuilder();
MuleDeployableArtifactClassLoader applicationClassLoader = artifactClassLoaderBuilder.setDomain(domain).addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[0])).setArtifactId(descriptor.getName()).setArtifactDescriptor(descriptor).build();
List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(applicationClassLoader, resolvedArtifactPluginDescriptors);
MuleApplicationPolicyProvider applicationPolicyProvider = new MuleApplicationPolicyProvider(new DefaultPolicyTemplateFactory(policyTemplateClassLoaderBuilderFactory, pluginDependenciesResolver, licenseValidator), new DefaultPolicyInstanceProviderFactory(serviceRepository, classLoaderRepository, extensionModelLoaderRepository));
DefaultMuleApplication delegate = new DefaultMuleApplication(descriptor, applicationClassLoader, artifactPlugins, domainRepository, serviceRepository, extensionModelLoaderRepository, descriptor.getArtifactLocation(), classLoaderRepository, applicationPolicyProvider);
applicationPolicyProvider.setApplication(delegate);
return new ApplicationWrapper(delegate);
}
use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader in project mule by mulesoft.
the class DefaultPolicyTemplateFactoryTestCase method createsPolicyTemplate.
@Test
public void createsPolicyTemplate() throws Exception {
RegionClassLoader regionClassLoader = createRegionClassLoader();
PolicyTemplateClassLoaderBuilder policyTemplateClassLoaderBuilder = createPolicyTemplateClassLoaderBuilder(regionClassLoader);
MuleDeployableArtifactClassLoader policyClassLoader = mock(MuleDeployableArtifactClassLoader.class);
when(policyClassLoader.getArtifactId()).thenReturn(POLICY_ID);
when(policyTemplateClassLoaderBuilder.build()).thenReturn(policyClassLoader);
when(classLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(policyTemplateClassLoaderBuilder);
PolicyTemplate policyTemplate = policyTemplateFactory.createArtifact(createApplication(regionClassLoader), descriptor);
assertThat(policyTemplate.getArtifactClassLoader(), is(policyClassLoader));
assertThat(policyTemplate.getDescriptor(), is(descriptor));
assertThat(policyTemplate.getArtifactId(), is(POLICY_ID));
assertThat(regionClassLoader.getArtifactPluginClassLoaders().size(), equalTo(1));
}
use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader 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;
}
Aggregations