Search in sources :

Example 1 with ClassLoaderModelBuilder

use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder 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()))));
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) LoggerFactory(org.slf4j.LoggerFactory) BundleDescriptor(org.mule.runtime.module.artifact.api.descriptor.BundleDescriptor) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Build(org.apache.maven.model.Build) MULE_MAVEN_PLUGIN_ARTIFACT_ID(org.mule.runtime.module.artifact.api.classloader.MuleMavenPlugin.MULE_MAVEN_PLUGIN_ARTIFACT_ID) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Map(java.util.Map) Preconditions.checkState(org.mule.runtime.api.util.Preconditions.checkState) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) DOMAIN(org.mule.runtime.core.api.config.bootstrap.ArtifactType.DOMAIN) POLICY(org.mule.runtime.core.api.config.bootstrap.ArtifactType.POLICY) MULE_LOADER_ID(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.MULE_LOADER_ID) MavenClient(org.mule.maven.client.api.MavenClient) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) INCLUDE_TEST_DEPENDENCIES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.INCLUDE_TEST_DEPENDENCIES) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) AbstractMavenClassLoaderModelLoader(org.mule.runtime.module.deployment.impl.internal.maven.AbstractMavenClassLoaderModelLoader) Set(java.util.Set) LocalRepositorySupplierFactory(org.mule.maven.client.api.LocalRepositorySupplierFactory) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) String.format(java.lang.String.format) File(java.io.File) I18nMessageFactory(org.mule.runtime.api.i18n.I18nMessageFactory) ArtifactType(org.mule.runtime.core.api.config.bootstrap.ArtifactType) List(java.util.List) Plugin(org.apache.maven.model.Plugin) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) MULE_MAVEN_PLUGIN_GROUP_ID(org.mule.runtime.module.artifact.api.classloader.MuleMavenPlugin.MULE_MAVEN_PLUGIN_GROUP_ID) MavenUtils.getPomModelFolder(org.mule.runtime.module.deployment.impl.internal.maven.MavenUtils.getPomModelFolder) Optional(java.util.Optional) ClassLoaderModelBuilder(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) Model(org.apache.maven.model.Model) FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) Build(org.apache.maven.model.Build) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Model(org.apache.maven.model.Model) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Plugin(org.apache.maven.model.Plugin)

Example 2 with ClassLoaderModelBuilder

use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder in project mule by mulesoft.

the class BundlePluginDependenciesResolverTestCase method resolvesPluginDependencyWithCompatibleMinorVersion.

@Test
public void resolvesPluginDependencyWithCompatibleMinorVersion() throws Exception {
    ArtifactPluginDescriptor updatedFooPlugin = new ArtifactPluginDescriptor(FOO_PLUGIN);
    updatedFooPlugin.setBundleDescriptor(createTestBundleDescriptor(FOO_PLUGIN, "1.1"));
    final List<ArtifactPluginDescriptor> pluginDescriptors = createPluginDescriptors(updatedFooPlugin, barPlugin);
    barPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().dependingOn(singleton(createBundleDependency(FOO_BUNDLE_DESCRIPTOR))).build());
    final List<ArtifactPluginDescriptor> resolvedPluginDescriptors = dependenciesResolver.resolve(emptySet(), pluginDescriptors);
    assertResolvedPlugins(resolvedPluginDescriptors, updatedFooPlugin, barPlugin);
}
Also used : ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderModelBuilder(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder) Test(org.junit.Test)

Example 3 with ClassLoaderModelBuilder

use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder in project mule by mulesoft.

the class BundlePluginDependenciesResolverTestCase method sanitizesTransitiveDependantPluginExportedPackages.

@Test
public void sanitizesTransitiveDependantPluginExportedPackages() throws Exception {
    fooPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().exportingPackages(getFooExportedPackages()).build());
    bazPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().exportingPackages(getBazExportedPackages()).dependingOn(singleton(FOO_PLUGIN_DESCRIPTOR)).build());
    barPlugin.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().exportingPackages(getBarExportedPackages()).dependingOn(singleton(BAZ_PLUGIN_DESCRIPTOR)).build());
    final List<ArtifactPluginDescriptor> pluginDescriptors = createPluginDescriptors(fooPlugin, barPlugin, bazPlugin);
    final List<ArtifactPluginDescriptor> resolvedPluginDescriptors = dependenciesResolver.resolve(emptySet(), pluginDescriptors);
    assertResolvedPlugins(resolvedPluginDescriptors, fooPlugin, bazPlugin, barPlugin);
    assertPluginExportedPackages(fooPlugin, "org.foo", "org.foo.mule");
    assertPluginExportedPackages(bazPlugin, "org.baz");
    assertPluginExportedPackages(barPlugin, "org.bar", "org.bar.mule");
}
Also used : ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderModelBuilder(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder) Test(org.junit.Test)

Example 4 with ClassLoaderModelBuilder

use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder in project mule by mulesoft.

the class BundlePluginDependenciesResolverTestCase method resolvesPluginWithNewestVersionOnDependency.

@Test
public void resolvesPluginWithNewestVersionOnDependency() throws Exception {
    final List<ArtifactPluginDescriptor> pluginDescriptors = createPluginDescriptors(barPlugin, bazPlugin, fooPlugin);
    barPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().dependingOn(singleton(LATEST_BAZ_PLUGIN_DESCRIPTOR)).build());
    bazPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().dependingOn(singleton(FOO_PLUGIN_DESCRIPTOR)).build());
    latestBazPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().dependingOn(singleton(FOO_PLUGIN_DESCRIPTOR)).build());
    when(artifactDescriptorFactory.create(argThat(hasProperty("absolutePath", endsWith(latestBazPlugin.getBundleDescriptor().getArtifactFileName()))), any(Optional.class))).thenReturn(latestBazPlugin);
    final List<ArtifactPluginDescriptor> resolvedPluginDescriptors = dependenciesResolver.resolve(emptySet(), pluginDescriptors);
    assertResolvedPlugins(resolvedPluginDescriptors, fooPlugin, bazPlugin, barPlugin);
}
Also used : Optional(java.util.Optional) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderModelBuilder(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder) Test(org.junit.Test)

Example 5 with ClassLoaderModelBuilder

use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder in project mule by mulesoft.

the class BundlePluginDependenciesResolverTestCase method sanitizesDependantPluginExportedPackages.

@Test
public void sanitizesDependantPluginExportedPackages() throws Exception {
    fooPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().exportingPackages(getFooExportedPackages()).build());
    barPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().dependingOn(singleton(FOO_PLUGIN_DESCRIPTOR)).exportingPackages(getBarExportedPackages()).build());
    final List<ArtifactPluginDescriptor> pluginDescriptors = createPluginDescriptors(fooPlugin, barPlugin);
    final List<ArtifactPluginDescriptor> resolvedPluginDescriptors = dependenciesResolver.resolve(emptySet(), pluginDescriptors);
    assertResolvedPlugins(resolvedPluginDescriptors, fooPlugin, barPlugin);
    assertPluginExportedPackages(fooPlugin, "org.foo", "org.foo.mule");
    assertPluginExportedPackages(barPlugin, "org.bar", "org.baz", "org.bar.mule");
}
Also used : ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderModelBuilder(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder) Test(org.junit.Test)

Aggregations

ClassLoaderModelBuilder (org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder)16 Test (org.junit.Test)15 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)15 List (java.util.List)2 Optional (java.util.Optional)2 BundleDescriptor (org.mule.runtime.module.artifact.api.descriptor.BundleDescriptor)2 File (java.io.File)1 String.format (java.lang.String.format)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 StringUtils.isEmpty (org.apache.commons.lang3.StringUtils.isEmpty)1 Build (org.apache.maven.model.Build)1 Model (org.apache.maven.model.Model)1 Plugin (org.apache.maven.model.Plugin)1 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)1 LocalRepositorySupplierFactory (org.mule.maven.client.api.LocalRepositorySupplierFactory)1