use of org.mule.runtime.module.artifact.api.classloader.MuleMavenPlugin.MULE_MAVEN_PLUGIN_ARTIFACT_ID 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.classloader.MuleMavenPlugin.MULE_MAVEN_PLUGIN_ARTIFACT_ID in project mule by mulesoft.
the class MavenUtils method addSharedLibraryDependency.
/**
* Adds a shared library to the pom model. If the plugin does not exists yet in the model then it will create it.
*
* @param model the pom model
* @param dependency the descriptor of the dependency
*/
public static void addSharedLibraryDependency(Model model, Dependency dependency) {
Build build = model.getBuild();
if (build == null) {
build = new Build();
model.setBuild(build);
}
List<Plugin> plugins = build.getPlugins();
if (plugins == null) {
plugins = new ArrayList<>();
build.setPlugins(plugins);
}
Optional<Plugin> pluginOptional = plugins.stream().filter(plugin -> plugin.getGroupId().equals(MULE_MAVEN_PLUGIN_GROUP_ID) && plugin.getArtifactId().equals(MULE_MAVEN_PLUGIN_ARTIFACT_ID)).findFirst();
List<Plugin> finalPlugins = plugins;
Plugin plugin = pluginOptional.orElseGet(() -> {
Plugin muleMavenPlugin = new Plugin();
muleMavenPlugin.setGroupId(MULE_MAVEN_PLUGIN_GROUP_ID);
muleMavenPlugin.setArtifactId(MULE_MAVEN_PLUGIN_ARTIFACT_ID);
finalPlugins.add(muleMavenPlugin);
return muleMavenPlugin;
});
Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
if (configuration == null) {
configuration = new Xpp3Dom("configuration");
plugin.setConfiguration(configuration);
}
Xpp3Dom sharedLibrariesDom = configuration.getChild(SHARED_LIBRARIES_ELEMENT);
if (sharedLibrariesDom == null) {
sharedLibrariesDom = new Xpp3Dom(SHARED_LIBRARIES_ELEMENT);
configuration.addChild(sharedLibrariesDom);
}
Xpp3Dom sharedLibraryDom = new Xpp3Dom("sharedLibrary");
sharedLibrariesDom.addChild(sharedLibraryDom);
Xpp3Dom groupIdDom = new Xpp3Dom("groupId");
groupIdDom.setValue(dependency.getGroupId());
sharedLibraryDom.addChild(groupIdDom);
Xpp3Dom artifactIdDom = new Xpp3Dom("artifactId");
artifactIdDom.setValue(dependency.getArtifactId());
sharedLibraryDom.addChild(artifactIdDom);
}
Aggregations