use of org.mule.runtime.module.artifact.api.descriptor.BundleDependency 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.api.descriptor.BundleDependency in project mule by mulesoft.
the class AbstractMavenClassLoaderModelLoader method createHeavyPackageClassLoaderModel.
private ClassLoaderModel createHeavyPackageClassLoaderModel(File artifactFile, Map<String, Object> attributes) {
File classLoaderModelDescriptor = getClassLoaderModelDescriptor(artifactFile);
org.mule.tools.api.classloader.model.ClassLoaderModel packagerClassLoaderModel = deserialize(classLoaderModelDescriptor);
File deployableArtifactRepositoryFolder = getDeployableArtifactRepositoryFolder(artifactFile);
final ClassLoaderModel.ClassLoaderModelBuilder classLoaderModelBuilder = new ClassLoaderModel.ClassLoaderModelBuilder();
classLoaderModelBuilder.exportingPackages(new HashSet<>(getAttribute(attributes, EXPORTED_PACKAGES))).exportingPrivilegedPackages(new HashSet<>(getAttribute(attributes, PRIVILEGED_EXPORTED_PACKAGES)), new HashSet<>(getAttribute(attributes, PRIVILEGED_ARTIFACTS_IDS))).exportingResources(new HashSet<>(getAttribute(attributes, EXPORTED_RESOURCES)));
Set<BundleDependency> patchBundleDependencies = getPatchedBundledDependencies(artifactFile, deployableArtifactRepositoryFolder);
Set<BundleDependency> bundleDependencies = packagerClassLoaderModel.getDependencies().stream().map(artifact -> {
Optional<BundleDependency> patchedBundledDependency = patchBundleDependencies.stream().filter(bundleDependency -> bundleDependency.getDescriptor().getGroupId().equals(artifact.getArtifactCoordinates().getGroupId()) && bundleDependency.getDescriptor().getArtifactId().equals(artifact.getArtifactCoordinates().getArtifactId())).findAny();
return patchedBundledDependency.orElse(createBundleDependencyFromPackagerDependency(deployableArtifactRepositoryFolder).apply(artifact));
}).collect(toSet());
loadUrls(artifactFile, classLoaderModelBuilder, bundleDependencies);
classLoaderModelBuilder.dependingOn(bundleDependencies);
return classLoaderModelBuilder.build();
}
use of org.mule.runtime.module.artifact.api.descriptor.BundleDependency in project mule by mulesoft.
the class AbstractMavenClassLoaderModelLoader method getPatchedBundledDependencies.
private Set<BundleDependency> getPatchedBundledDependencies(File artifactFile, File deployableArtifactRepositoryFolder) {
Set<BundleDependency> patchBundleDependencies = new HashSet<>();
File classLoaderModelPatchDescriptor = getClassLoaderModelPatchDescriptor(artifactFile);
if (classLoaderModelPatchDescriptor.exists()) {
org.mule.tools.api.classloader.model.ClassLoaderModel packagerClassLoaderModelPatch = deserialize(classLoaderModelPatchDescriptor);
patchBundleDependencies.addAll(packagerClassLoaderModelPatch.getDependencies().stream().map(artifact -> createBundleDependencyFromPackagerDependency(deployableArtifactRepositoryFolder).apply(artifact)).collect(toSet()));
}
return patchBundleDependencies;
}
use of org.mule.runtime.module.artifact.api.descriptor.BundleDependency in project mule by mulesoft.
the class DeployableMavenClassLoaderModelLoaderTestCase method testPatchedDependency.
private void testPatchedDependency(String application, int totalExpectedDependencies, String patchedArtifactId, String patchedArtifactVersion) throws InvalidDescriptorLoaderException {
DeployableMavenClassLoaderModelLoader deployableMavenClassLoaderModelLoader = new DeployableMavenClassLoaderModelLoader(mockMavenClient, mockLocalRepository);
URL patchedAppUrl = getClass().getClassLoader().getResource(Paths.get(APPS_FOLDER, application).toString());
ClassLoaderModel classLoaderModel = deployableMavenClassLoaderModelLoader.load(FileUtils.toFile(patchedAppUrl), emptyMap(), APP);
Set<BundleDependency> dependencies = classLoaderModel.getDependencies();
assertThat(dependencies, hasSize(totalExpectedDependencies));
List<BundleDependency> connectorsFound = dependencies.stream().filter(bundleDependency -> bundleDependency.getDescriptor().getArtifactId().equals(patchedArtifactId)).collect(Collectors.toList());
assertThat(connectorsFound, hasSize(1));
assertThat(connectorsFound.get(0).getDescriptor().getVersion(), is(patchedArtifactVersion));
}
use of org.mule.runtime.module.artifact.api.descriptor.BundleDependency in project mule by mulesoft.
the class DeployableArtifactDescriptorFactoryTestCase method classLoaderModelWithSingleDependency.
@Test
public void classLoaderModelWithSingleDependency() throws Exception {
D desc = createArtifactDescriptor(getArtifactRootFolder() + "single-dependency");
ClassLoaderModel classLoaderModel = desc.getClassLoaderModel();
assertThat(classLoaderModel.getDependencies(), hasSize(1));
BundleDependency commonsCollectionDependency = classLoaderModel.getDependencies().iterator().next();
assertThat(commonsCollectionDependency, commonsCollectionDependencyMatcher());
assertThat(classLoaderModel.getUrls().length, is(2));
assertThat(asList(classLoaderModel.getUrls()), hasItem(commonsCollectionDependency.getBundleUri().toURL()));
}
Aggregations