use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class ExtensionModelDiscoverer method discoverPluginsExtensionModels.
/**
* For each artifactPlugin discovers the {@link ExtensionModel}.
*
* @param loaderRepository {@link ExtensionModelLoaderRepository} with the available extension loaders.
* @param artifactPlugins {@link Pair} of {@link ArtifactPluginDescriptor} and {@link ArtifactClassLoader} for artifact plugins
* deployed inside the artifact. Non null.
* @param parentArtifactExtensions {@link Set} of {@link ExtensionModel} to also take into account when parsing extensions
* @return {@link Set} of {@link Pair} carrying the {@link ArtifactPluginDescriptor} and it's corresponding
* {@link ExtensionModel}.
*/
public Set<Pair<ArtifactPluginDescriptor, ExtensionModel>> discoverPluginsExtensionModels(ExtensionModelLoaderRepository loaderRepository, List<Pair<ArtifactPluginDescriptor, ArtifactClassLoader>> artifactPlugins, Set<ExtensionModel> parentArtifactExtensions) {
final Set<Pair<ArtifactPluginDescriptor, ExtensionModel>> descriptorsWithExtensions = new HashSet<>();
artifactPlugins.forEach(artifactPlugin -> {
Set<ExtensionModel> extensions = descriptorsWithExtensions.stream().map(Pair::getSecond).collect(toSet());
extensions.addAll(parentArtifactExtensions);
final ArtifactPluginDescriptor artifactPluginDescriptor = artifactPlugin.getFirst();
Optional<LoaderDescriber> loaderDescriber = artifactPluginDescriptor.getExtensionModelDescriptorProperty();
ClassLoader artifactClassloader = artifactPlugin.getSecond().getClassLoader();
String artifactName = artifactPluginDescriptor.getName();
ExtensionModel extension = loaderDescriber.map(describer -> discoverExtensionThroughJsonDescriber(loaderRepository, describer, extensions, artifactClassloader, artifactName)).orElse(null);
if (extension != null) {
descriptorsWithExtensions.add(new Pair<>(artifactPluginDescriptor, extension));
}
});
return descriptorsWithExtensions;
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class ContainerClassLoaderFactoryTestCase method doesNotFindAnyResources.
@Test
public void doesNotFindAnyResources() throws Exception {
final ContainerClassLoaderFactory factory = createClassLoaderExportingBootstrapProperties();
final ArtifactClassLoader containerClassLoader = factory.createContainerClassLoader(this.getClass().getClassLoader());
final Enumeration<URL> resources = containerClassLoader.findResources(BOOTSTRAP_PROPERTIES);
assertThat(resources.hasMoreElements(), is(false));
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class ContainerClassLoaderFactoryTestCase method getResourcesFromParent.
@Test
public void getResourcesFromParent() throws Exception {
final ContainerClassLoaderFactory factory = createClassLoaderExportingBootstrapProperties();
final ArtifactClassLoader containerClassLoader = factory.createContainerClassLoader(this.getClass().getClassLoader());
final Enumeration<URL> resources = containerClassLoader.getClassLoader().getResources(BOOTSTRAP_PROPERTIES);
assertThat(resources.hasMoreElements(), is(true));
Set<String> items = new HashSet<>();
int size = 0;
while (resources.hasMoreElements()) {
final String url = resources.nextElement().toString();
items.add(url);
size++;
}
assertThat(size, equalTo(items.size()));
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class ContainerClassLoaderFactoryTestCase method doesNotFindAnyResource.
@Test
public void doesNotFindAnyResource() throws Exception {
final ContainerClassLoaderFactory factory = createClassLoaderExportingBootstrapProperties();
final ArtifactClassLoader containerClassLoader = factory.createContainerClassLoader(this.getClass().getClassLoader());
final URL resource = containerClassLoader.findResource(BOOTSTRAP_PROPERTIES);
assertThat(resource, is(nullValue()));
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class DomainDeploymentTestCase method refreshDomainClassloaderAfterRedeployment.
@Ignore("MULE-6926: flaky test")
@Test
public void refreshDomainClassloaderAfterRedeployment() throws Exception {
startDeployment();
// Deploy domain and apps and wait until success
addPackedDomainFromBuilder(sharedDomainFileBuilder);
addPackedAppFromBuilder(sharedAAppFileBuilder);
addPackedAppFromBuilder(sharedBAppFileBuilder);
assertDeploymentSuccess(domainDeploymentListener, sharedDomainFileBuilder.getId());
assertDeploymentSuccess(applicationDeploymentListener, sharedAAppFileBuilder.getId());
assertDeploymentSuccess(applicationDeploymentListener, sharedBAppFileBuilder.getId());
// Ensure resources are registered at domain's registry
Domain domain = findADomain(sharedDomainFileBuilder.getId());
assertThat(domain.getRegistry().lookupByName("http-listener-config").isPresent(), is(true));
ArtifactClassLoader initialArtifactClassLoader = domain.getArtifactClassLoader();
reset(domainDeploymentListener);
reset(applicationDeploymentListener);
// Force redeployment by touching the domain's config file
File domainFolder = new File(domainsDir.getPath(), sharedDomainFileBuilder.getId());
File configFile = new File(domainFolder, sharedDomainFileBuilder.getConfigFile());
long firstFileTimestamp = configFile.lastModified();
touch(configFile);
alterTimestampIfNeeded(configFile, firstFileTimestamp);
assertUndeploymentSuccess(applicationDeploymentListener, sharedAAppFileBuilder.getId());
assertUndeploymentSuccess(applicationDeploymentListener, sharedBAppFileBuilder.getId());
assertUndeploymentSuccess(domainDeploymentListener, sharedDomainFileBuilder.getId());
assertDeploymentSuccess(domainDeploymentListener, sharedDomainFileBuilder.getId());
assertDeploymentSuccess(applicationDeploymentListener, sharedAAppFileBuilder.getId());
assertDeploymentSuccess(applicationDeploymentListener, sharedBAppFileBuilder.getId());
domain = findADomain(sharedDomainFileBuilder.getId());
ArtifactClassLoader artifactClassLoaderAfterRedeployment = domain.getArtifactClassLoader();
// Ensure that after redeployment the domain's class loader has changed
assertThat(artifactClassLoaderAfterRedeployment, not(sameInstance(initialArtifactClassLoader)));
// Undeploy domain and apps
removeAppAnchorFile(sharedAAppFileBuilder.getId());
removeAppAnchorFile(sharedBAppFileBuilder.getId());
removeDomainAnchorFile(sharedDomainFileBuilder.getId());
assertUndeploymentSuccess(applicationDeploymentListener, sharedAAppFileBuilder.getId());
assertUndeploymentSuccess(applicationDeploymentListener, sharedBAppFileBuilder.getId());
assertUndeploymentSuccess(domainDeploymentListener, sharedDomainFileBuilder.getId());
}
Aggregations