use of org.mule.runtime.container.internal.DefaultModuleRepository in project mule by mulesoft.
the class IsolatedClassLoaderFactory method createTestRunnerPlugin.
private void createTestRunnerPlugin(ArtifactsUrlClassification artifactsUrlClassification, Map<String, LookupStrategy> appExportedLookupStrategies, ClassLoaderLookupPolicy childClassLoaderLookupPolicy, RegionClassLoader regionClassLoader, List<ArtifactClassLoader> filteredPluginsArtifactClassLoaders, List<ArtifactClassLoader> pluginsArtifactClassLoaders, List<ArtifactClassLoaderFilter> pluginArtifactClassLoaderFilters, DefaultModuleRepository moduleRepository, TestContainerClassLoaderFactory testContainerClassLoaderFactory, Set<String> parentExportedPackages) {
JarInfo testRunnerJarInfo = getTestRunnerJarInfo(artifactsUrlClassification);
String testRunnerArtifactId = getArtifactPluginId(regionClassLoader.getArtifactId(), "test-runner");
List<String> pluginDependencies = artifactsUrlClassification.getPluginUrlClassifications().stream().map(p -> p.getName()).collect(toList());
PluginUrlClassification testRunnerPluginClassification = new PluginUrlClassification(TEST_RUNNER_ARTIFACT_ID + ":", artifactsUrlClassification.getTestRunnerLibUrls(), emptyList(), pluginDependencies, testRunnerJarInfo.getPackages(), testRunnerJarInfo.getResources(), emptySet(), emptySet());
ClassLoaderLookupPolicy pluginLookupPolicy = extendLookupPolicyForPrivilegedAccess(childClassLoaderLookupPolicy, moduleRepository, testContainerClassLoaderFactory, testRunnerPluginClassification);
pluginLookupPolicy = pluginLookupPolicy.extend(appExportedLookupStrategies);
MuleArtifactClassLoader pluginCL = new MuleArtifactClassLoader(testRunnerArtifactId, new ArtifactDescriptor(testRunnerPluginClassification.getName()), testRunnerPluginClassification.getUrls().toArray(new URL[0]), regionClassLoader, pluginLookupPolicyGenerator.createLookupPolicy(testRunnerPluginClassification, artifactsUrlClassification.getPluginUrlClassifications(), pluginLookupPolicy, pluginsArtifactClassLoaders));
pluginsArtifactClassLoaders.add(pluginCL);
ArtifactClassLoaderFilter filter = createArtifactClassLoaderFilter(testRunnerPluginClassification, parentExportedPackages, childClassLoaderLookupPolicy);
pluginArtifactClassLoaderFilters.add(filter);
filteredPluginsArtifactClassLoaders.add(new FilteringArtifactClassLoader(pluginCL, filter, emptyList()));
logClassLoaderUrls("PLUGIN (" + testRunnerPluginClassification.getName() + ")", testRunnerPluginClassification.getUrls());
}
use of org.mule.runtime.container.internal.DefaultModuleRepository in project mule by mulesoft.
the class IsolatedClassLoaderFactory method createArtifactClassLoader.
/**
* Creates a {@link ArtifactClassLoaderHolder} containing the container, plugins and application {@link ArtifactClassLoader}s
*
* @param extraBootPackages {@link List} of {@link String}s of extra boot packages to be appended to the container
* {@link ClassLoader}
* @param extraPrivilegedArtifacts {@link List} of {@link String}s of extra privileged artifacts. Each value needs to have the
* form groupId:versionId.
* @param artifactsUrlClassification the {@link ArtifactsUrlClassification} that defines the different {@link URL}s for each
* {@link ClassLoader}
* @return a {@link ArtifactClassLoaderHolder} that would be used to run the test
*/
public ArtifactClassLoaderHolder createArtifactClassLoader(List<String> extraBootPackages, Set<String> extraPrivilegedArtifacts, ArtifactsUrlClassification artifactsUrlClassification) {
Map<String, LookupStrategy> appExportedLookupStrategies = new HashMap<>();
JarInfo testJarInfo = getAppSharedPackages(artifactsUrlClassification.getApplicationSharedLibUrls());
testJarInfo.getPackages().stream().forEach(p -> appExportedLookupStrategies.put(p, PARENT_FIRST));
ArtifactClassLoader containerClassLoader;
ClassLoaderLookupPolicy childClassLoaderLookupPolicy;
RegionClassLoader regionClassLoader;
final List<ArtifactClassLoader> filteredPluginsArtifactClassLoaders = new ArrayList<>();
final List<ArtifactClassLoader> pluginsArtifactClassLoaders = new ArrayList<>();
final List<ArtifactClassLoaderFilter> pluginArtifactClassLoaderFilters = new ArrayList<>();
List<ArtifactClassLoader> serviceArtifactClassLoaders;
DefaultModuleRepository moduleRepository = new DefaultModuleRepository(new TestModuleDiscoverer(extraPrivilegedArtifacts, new TestContainerModuleDiscoverer(ContainerClassLoaderFactory.class.getClassLoader())));
try (final TestContainerClassLoaderFactory testContainerClassLoaderFactory = new TestContainerClassLoaderFactory(extraBootPackages, artifactsUrlClassification.getContainerUrls().toArray(new URL[0]), moduleRepository)) {
final Map<String, LookupStrategy> pluginsLookupStrategies = new HashMap<>();
for (PluginUrlClassification pluginUrlClassification : artifactsUrlClassification.getPluginUrlClassifications()) {
pluginUrlClassification.getExportedPackages().forEach(p -> pluginsLookupStrategies.put(p, PARENT_FIRST));
}
containerClassLoader = createContainerArtifactClassLoader(testContainerClassLoaderFactory, artifactsUrlClassification);
childClassLoaderLookupPolicy = testContainerClassLoaderFactory.getContainerClassLoaderLookupPolicy(containerClassLoader.getClassLoader());
final ClassLoaderLookupPolicy appLookupPolicy = childClassLoaderLookupPolicy.extend(pluginsLookupStrategies);
serviceArtifactClassLoaders = createServiceClassLoaders(containerClassLoader.getClassLoader(), childClassLoaderLookupPolicy, artifactsUrlClassification);
regionClassLoader = new RegionClassLoader("Region", new ArtifactDescriptor("Region"), containerClassLoader.getClassLoader(), childClassLoaderLookupPolicy);
if (!artifactsUrlClassification.getPluginUrlClassifications().isEmpty()) {
for (PluginUrlClassification pluginUrlClassification : artifactsUrlClassification.getPluginUrlClassifications()) {
logClassLoaderUrls("PLUGIN (" + pluginUrlClassification.getName() + ")", pluginUrlClassification.getUrls());
String artifactId = getArtifactPluginId(regionClassLoader.getArtifactId(), pluginUrlClassification.getName());
ClassLoaderLookupPolicy pluginLookupPolicy = extendLookupPolicyForPrivilegedAccess(childClassLoaderLookupPolicy, moduleRepository, testContainerClassLoaderFactory, pluginUrlClassification);
pluginLookupPolicy = pluginLookupPolicy.extend(appExportedLookupStrategies);
MuleArtifactClassLoader pluginCL = new MuleArtifactClassLoader(artifactId, new ArtifactDescriptor(pluginUrlClassification.getName()), pluginUrlClassification.getUrls().toArray(new URL[0]), regionClassLoader, pluginLookupPolicyGenerator.createLookupPolicy(pluginUrlClassification, artifactsUrlClassification.getPluginUrlClassifications(), pluginLookupPolicy, pluginsArtifactClassLoaders));
pluginsArtifactClassLoaders.add(pluginCL);
ArtifactClassLoaderFilter filter = createArtifactClassLoaderFilter(pluginUrlClassification, testJarInfo.getPackages(), childClassLoaderLookupPolicy);
pluginArtifactClassLoaderFilters.add(filter);
filteredPluginsArtifactClassLoaders.add(new FilteringArtifactClassLoader(pluginCL, filter, emptyList()));
}
createTestRunnerPlugin(artifactsUrlClassification, appExportedLookupStrategies, childClassLoaderLookupPolicy, regionClassLoader, filteredPluginsArtifactClassLoaders, pluginsArtifactClassLoaders, pluginArtifactClassLoaderFilters, moduleRepository, testContainerClassLoaderFactory, testJarInfo.getPackages());
}
ArtifactClassLoader appClassLoader = createApplicationArtifactClassLoader(regionClassLoader, appLookupPolicy, artifactsUrlClassification, pluginsArtifactClassLoaders);
regionClassLoader.addClassLoader(appClassLoader, new DefaultArtifactClassLoaderFilter(testJarInfo.getPackages(), testJarInfo.getResources()));
for (int i = 0; i < filteredPluginsArtifactClassLoaders.size(); i++) {
final ArtifactClassLoaderFilter classLoaderFilter = pluginArtifactClassLoaderFilters.get(i);
regionClassLoader.addClassLoader(filteredPluginsArtifactClassLoaders.get(i), classLoaderFilter);
}
return new ArtifactClassLoaderHolder(containerClassLoader, serviceArtifactClassLoaders, pluginsArtifactClassLoaders, appClassLoader);
}
}
use of org.mule.runtime.container.internal.DefaultModuleRepository in project mule by mulesoft.
the class AbstractDeploymentTestCase method setUp.
@Before
public void setUp() throws Exception {
if (parallelDeployment) {
setProperty(PARALLEL_DEPLOYMENT_PROPERTY, "");
}
final String tmpDir = getProperty("java.io.tmpdir");
muleHome = new File(new File(tmpDir, "mule_home"), getClass().getSimpleName() + currentTimeMillis());
appsDir = new File(muleHome, "apps");
appsDir.mkdirs();
domainsDir = new File(muleHome, "domains");
domainsDir.mkdirs();
setProperty(MULE_HOME_DIRECTORY_PROPERTY, muleHome.getCanonicalPath());
GlobalConfigLoader.reset();
final File domainFolder = getDomainFolder(DEFAULT_DOMAIN_NAME);
assertThat(domainFolder.mkdirs(), is(true));
services = getServicesFolder();
services.mkdirs();
copyFileToDirectory(buildSchedulerServiceFile(compilerWorkFolder.newFolder("schedulerService")), services);
copyFileToDirectory(buildExpressionLanguageServiceFile(compilerWorkFolder.newFolder("expressionLanguageService")), services);
applicationDeploymentListener = mock(DeploymentListener.class);
testDeploymentListener = new TestDeploymentListener();
domainDeploymentListener = mock(DeploymentListener.class);
domainBundleDeploymentListener = mock(DeploymentListener.class);
moduleDiscoverer = new TestModuleDiscoverer(getPrivilegedArtifactIds());
moduleRepository = new DefaultModuleRepository(moduleDiscoverer);
MuleArtifactResourcesRegistry muleArtifactResourcesRegistry = new MuleArtifactResourcesRegistry.Builder().moduleRepository(moduleRepository).build();
serviceManager = muleArtifactResourcesRegistry.getServiceManager();
containerClassLoader = muleArtifactResourcesRegistry.getContainerClassLoader();
extensionModelLoaderManager = muleArtifactResourcesRegistry.getExtensionModelLoaderManager();
artifactClassLoaderManager = muleArtifactResourcesRegistry.getArtifactClassLoaderManager();
deploymentService = new TestMuleDeploymentService(muleArtifactResourcesRegistry.getDomainFactory(), muleArtifactResourcesRegistry.getApplicationFactory(), () -> findSchedulerService(serviceManager));
deploymentService.addDeploymentListener(applicationDeploymentListener);
deploymentService.addDomainDeploymentListener(domainDeploymentListener);
deploymentService.addDeploymentListener(testDeploymentListener);
deploymentService.addDomainDeploymentListener(testDeploymentListener);
deploymentService.addDomainBundleDeploymentListener(domainBundleDeploymentListener);
policyManager = new TestPolicyManager(deploymentService, new PolicyTemplateDescriptorFactory(muleArtifactResourcesRegistry.getArtifactPluginDescriptorLoader(), createDescriptorLoaderRepository(), ArtifactDescriptorValidatorBuilder.builder()));
// Reset test component state
invocationCount = 0;
policyParametrization = "";
}
use of org.mule.runtime.container.internal.DefaultModuleRepository in project mule by mulesoft.
the class TestModuleDiscoverer method discover.
@Override
public List<MuleModule> discover() {
DefaultModuleRepository containerModuleDiscoverer = new DefaultModuleRepository(delegateModuleDiscoverer);
List<MuleModule> discoveredModules = containerModuleDiscoverer.getModules();
List<MuleModule> updateModules = new ArrayList<>(discoveredModules.size());
for (MuleModule discoveredModule : discoveredModules) {
if (!discoveredModule.getPrivilegedExportedPackages().isEmpty()) {
discoveredModule = updateModuleForTests(discoveredModule);
}
updateModules.add(discoveredModule);
}
return updateModules;
}
Aggregations