use of org.mule.runtime.module.artifact.internal.util.JarInfo in project mule by mulesoft.
the class DeployableMavenClassLoaderModelLoader method exportSharedLibrariesResourcesAndPackages.
private void exportSharedLibrariesResourcesAndPackages(File applicationFolder, ClassLoaderModelBuilder classLoaderModelBuilder, Set<BundleDependency> dependencies) {
Model model = loadPomModel(applicationFolder);
Build build = model.getBuild();
if (build != null) {
List<Plugin> plugins = build.getPlugins();
if (plugins != null) {
Optional<Plugin> packagingPluginOptional = plugins.stream().filter(plugin -> plugin.getArtifactId().equals(MULE_MAVEN_PLUGIN_ARTIFACT_ID) && plugin.getGroupId().equals(MULE_MAVEN_PLUGIN_GROUP_ID)).findFirst();
packagingPluginOptional.ifPresent(packagingPlugin -> {
Object configuration = packagingPlugin.getConfiguration();
if (configuration != null) {
Xpp3Dom sharedLibrariesDom = ((Xpp3Dom) configuration).getChild("sharedLibraries");
if (sharedLibrariesDom != null) {
Xpp3Dom[] sharedLibraries = sharedLibrariesDom.getChildren("sharedLibrary");
if (sharedLibraries != null) {
FileJarExplorer fileJarExplorer = new FileJarExplorer();
for (Xpp3Dom sharedLibrary : sharedLibraries) {
String groupId = getSharedLibraryAttribute(applicationFolder, sharedLibrary, "groupId");
String artifactId = getSharedLibraryAttribute(applicationFolder, sharedLibrary, "artifactId");
Optional<BundleDependency> bundleDependencyOptional = dependencies.stream().filter(bundleDependency -> bundleDependency.getDescriptor().getArtifactId().equals(artifactId) && bundleDependency.getDescriptor().getGroupId().equals(groupId)).findFirst();
bundleDependencyOptional.map(bundleDependency -> {
JarInfo jarInfo = fileJarExplorer.explore(bundleDependency.getBundleUri());
classLoaderModelBuilder.exportingPackages(jarInfo.getPackages());
classLoaderModelBuilder.exportingResources(jarInfo.getResources());
return bundleDependency;
}).orElseThrow(() -> new MuleRuntimeException(I18nMessageFactory.createStaticMessage(format("Dependency %s:%s could not be found within the artifact %s. It must be declared within the maven dependencies of the artifact.", groupId, artifactId, applicationFolder.getName()))));
}
}
}
}
});
}
}
}
use of org.mule.runtime.module.artifact.internal.util.JarInfo 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.module.artifact.internal.util.JarInfo in project mule by mulesoft.
the class IsolatedClassLoaderFactory method getTestJarInfo.
/**
* Creates the {@link JarInfo} for the {@link ArtifactsUrlClassification}.
*
* @param artifactsUrlClassification the {@link ArtifactsUrlClassification} that defines the different {@link URL}s for each
* {@link ClassLoader}
* @return {@link JarInfo} for the classification
*/
private JarInfo getTestJarInfo(ArtifactsUrlClassification artifactsUrlClassification) {
URL testCodeUrl = artifactsUrlClassification.getTestRunnerLibUrls().get(0);
// sometimes the test-classes URL is the second one.
if (!toFile(testCodeUrl).getPath().contains("test-classes") && artifactsUrlClassification.getTestRunnerLibUrls().size() > 1) {
testCodeUrl = artifactsUrlClassification.getTestRunnerLibUrls().get(1);
}
Set<String> productionPackages = getProductionCodePackages(testCodeUrl);
JarInfo testJarInfo = getTestCodePackages(testCodeUrl);
Set<String> testPackages = sanitizeTestExportedPackages(productionPackages, testJarInfo.getPackages());
return new JarInfo(testPackages, testJarInfo.getResources());
}
use of org.mule.runtime.module.artifact.internal.util.JarInfo in project mule by mulesoft.
the class IsolatedClassLoaderFactory method getTestRunnerJarInfo.
private JarInfo getTestRunnerJarInfo(ArtifactsUrlClassification artifactsUrlClassification) {
JarInfo testJarInfo = getTestJarInfo(artifactsUrlClassification);
Set<String> exportedPackages = testJarInfo.getPackages();
Set<String> exportedResources = testJarInfo.getResources();
artifactsUrlClassification.getTestRunnerExportedLibUrls().forEach(url -> {
JarInfo jarInfo = getTestCodePackages(url);
exportedPackages.addAll(jarInfo.getPackages());
exportedResources.addAll(jarInfo.getResources());
});
return new JarInfo(exportedPackages, exportedResources);
}
use of org.mule.runtime.module.artifact.internal.util.JarInfo in project mule by mulesoft.
the class IsolatedClassLoaderFactory method getLibraryPackages.
private JarInfo getLibraryPackages(List<URL> libraries) {
Set<String> packages = new HashSet<>();
Set<String> resources = new HashSet<>();
final JarExplorer jarExplorer = new FileJarExplorer();
for (URL library : libraries) {
try {
JarInfo jarInfo = jarExplorer.explore(library.toURI());
packages.addAll(jarInfo.getPackages());
resources.addAll(jarInfo.getResources());
} catch (URISyntaxException e) {
throw new MuleRuntimeException(e);
}
}
return new JarInfo(packages, resources);
}
Aggregations