Search in sources :

Example 1 with ArtifactPluginDescriptor

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor 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;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ExtensionModelLoaderRepository(org.mule.runtime.module.extension.internal.loader.ExtensionModelLoaderRepository) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) Collection(java.util.Collection) Set(java.util.Set) String.format(java.lang.String.format) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) RuntimeExtensionModelProvider(org.mule.runtime.core.api.extension.RuntimeExtensionModelProvider) HashSet(java.util.HashSet) List(java.util.List) LoaderDescriber(org.mule.runtime.deployment.model.api.plugin.LoaderDescriber) Optional(java.util.Optional) Pair(org.mule.runtime.api.util.Pair) DslResolvingContext.getDefault(org.mule.runtime.api.dsl.DslResolvingContext.getDefault) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) Collectors.toSet(java.util.stream.Collectors.toSet) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) LoaderDescriber(org.mule.runtime.deployment.model.api.plugin.LoaderDescriber) Pair(org.mule.runtime.api.util.Pair) HashSet(java.util.HashSet)

Example 2 with ArtifactPluginDescriptor

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.

the class DefaultDomainFactory method doCreateArtifact.

@Override
protected Domain doCreateArtifact(File domainLocation, Optional<Properties> deploymentProperties) throws IOException {
    String domainName = domainLocation.getName();
    Domain domain = domainManager.getDomain(domainName);
    if (domain != null) {
        throw new IllegalArgumentException(format("Domain '%s'  already exists", domainName));
    }
    if (domainName.contains(" ")) {
        throw new IllegalArgumentException("Mule domain name may not contain spaces: " + domainName);
    }
    DomainDescriptor domainDescriptor = findDomain(domainName, domainLocation, deploymentProperties);
    List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(emptySet(), domainDescriptor.getPlugins().stream().collect(toList()));
    DomainClassLoaderBuilder artifactClassLoaderBuilder = domainClassLoaderBuilderFactory.createArtifactClassLoaderBuilder();
    MuleDeployableArtifactClassLoader domainClassLoader = artifactClassLoaderBuilder.addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[resolvedArtifactPluginDescriptors.size()])).setArtifactId(domainDescriptor.getName()).setArtifactDescriptor(domainDescriptor).build();
    List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(domainClassLoader, resolvedArtifactPluginDescriptors);
    DefaultMuleDomain defaultMuleDomain = new DefaultMuleDomain(domainDescriptor, domainClassLoader, classLoaderRepository, serviceRepository, artifactPlugins, extensionModelLoaderManager);
    DomainWrapper domainWrapper = new DomainWrapper(defaultMuleDomain, this);
    domainManager.addDomain(domainWrapper);
    return domainWrapper;
}
Also used : ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) DomainClassLoaderBuilder(org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderBuilder) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor) DefaultArtifactPlugin(org.mule.runtime.module.deployment.impl.internal.plugin.DefaultArtifactPlugin) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Example 3 with ArtifactPluginDescriptor

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor 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 4 with ArtifactPluginDescriptor

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor 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 5 with ArtifactPluginDescriptor

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor 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)

Aggregations

ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)42 Test (org.junit.Test)24 ClassLoaderModelBuilder (org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder)15 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)11 File (java.io.File)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)6 BundleDependency (org.mule.runtime.module.artifact.api.descriptor.BundleDependency)6 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)5 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Optional (java.util.Optional)4 Domain (org.mule.runtime.deployment.model.api.domain.Domain)4 DomainDescriptor (org.mule.runtime.deployment.model.api.domain.DomainDescriptor)4 ArtifactPlugin (org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)4 ArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter)4 Map (java.util.Map)3 Set (java.util.Set)3