Search in sources :

Example 6 with BundleDependency

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

the class DefaultApplicationFactoryTestCase method createClassLoaderModelWithDomain.

private ClassLoaderModel createClassLoaderModelWithDomain() {
    BundleDescriptor domainDescriptor = new BundleDescriptor.Builder().setArtifactId(DOMAIN_NAME).setGroupId("test").setVersion("1.0.0").setClassifier(MULE_DOMAIN_CLASSIFIER).build();
    Set<BundleDependency> domainDependency = Collections.singleton(new BundleDependency.Builder().setDescriptor(domainDescriptor).build());
    return new ClassLoaderModel.ClassLoaderModelBuilder().dependingOn(domainDependency).build();
}
Also used : BundleDescriptor(org.mule.runtime.module.artifact.api.descriptor.BundleDescriptor) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency)

Example 7 with BundleDependency

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

the class AbstractDeployableDescriptorFactory method createArtifactPluginDescriptors.

private Set<ArtifactPluginDescriptor> createArtifactPluginDescriptors(ClassLoaderModel classLoaderModel) throws IOException {
    Set<ArtifactPluginDescriptor> pluginDescriptors = new HashSet<>();
    for (BundleDependency bundleDependency : classLoaderModel.getDependencies()) {
        if (bundleDependency.getDescriptor().isPlugin()) {
            File pluginFile = new File(bundleDependency.getBundleUri());
            pluginDescriptors.add(artifactPluginDescriptorLoader.load(pluginFile));
        }
    }
    return pluginDescriptors;
}
Also used : ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) File(java.io.File) HashSet(java.util.HashSet)

Example 8 with BundleDependency

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

the class AbstractMavenClassLoaderModelLoader method createLightPackageClassLoaderModel.

private ClassLoaderModel createLightPackageClassLoaderModel(File artifactFile, Map<String, Object> attributes, ArtifactType artifactType) {
    File containerRepository;
    if (isStandalone() && !getBoolean("mule.mode.embedded")) {
        containerRepository = new File(getMuleHomeFolder(), "repository");
        if (!containerRepository.exists()) {
            if (!containerRepository.mkdirs()) {
                // check again since it may have been created already.
                if (!containerRepository.exists()) {
                    throw new MuleRuntimeException(I18nMessageFactory.createStaticMessage("Failure creating repository folder in MULE_HOME folder " + containerRepository.getAbsolutePath()));
                }
            }
        }
    }
    File localMavenRepositoryLocation = mavenClient.getMavenConfiguration().getLocalMavenRepositoryLocation();
    Supplier<File> compositeRepoLocationSupplier = localRepositorySupplierFactory.composeSuppliers(localRepositorySupplierFactory.artifactFolderRepositorySupplier(artifactFile, localMavenRepositoryLocation), localRepositorySupplierFactory.fixedFolderSupplier(localMavenRepositoryLocation));
    File mavenRepository = compositeRepoLocationSupplier.get();
    File temporaryDirectory = createTempDir();
    try {
        List<org.mule.maven.client.api.model.BundleDependency> dependencies = mavenClient.resolveArtifactDependencies(artifactFile, includeTestDependencies(attributes), includeProvidedDependencies(artifactType), of(mavenRepository), ofNullable((MavenReactorResolver) attributes.get(CLASSLOADER_MODEL_MAVEN_REACTOR_RESOLVER)), of(temporaryDirectory));
        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))).includeTestDependencies(valueOf(getSimpleAttribute(attributes, INCLUDE_TEST_DEPENDENCIES, "false")));
        Set<BundleDependency> bundleDependencies = dependencies.stream().filter(mavenClientDependency -> !mavenClientDependency.getScope().equals(PROVIDED)).map(mavenClientDependency -> convertBundleDependency(mavenClientDependency)).collect(toSet());
        loadUrls(artifactFile, classLoaderModelBuilder, bundleDependencies);
        Set<BundleDependency> allBundleDependencies = dependencies.stream().map(mavenClientDependency -> convertBundleDependency(mavenClientDependency)).collect(toSet());
        classLoaderModelBuilder.dependingOn(allBundleDependencies);
        return classLoaderModelBuilder.build();
    } finally {
        deleteQuietly(temporaryDirectory);
    }
}
Also used : PRIVILEGED_EXPORTED_PACKAGES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.PRIVILEGED_EXPORTED_PACKAGES) Optional.of(java.util.Optional.of) LoggerFactory(org.slf4j.LoggerFactory) MULE_PLUGIN_CLASSIFIER(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor.MULE_PLUGIN_CLASSIFIER) Map(java.util.Map) InvalidDescriptorLoaderException(org.mule.runtime.module.artifact.api.descriptor.InvalidDescriptorLoaderException) Collectors.toSet(java.util.stream.Collectors.toSet) ArtifactDescriptorConstants(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants) MULE_LOADER_ID(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.MULE_LOADER_ID) Artifact(org.mule.tools.api.classloader.model.Artifact) Files.createTempDir(com.google.common.io.Files.createTempDir) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) PROVIDED(org.mule.maven.client.api.model.BundleScope.PROVIDED) Set(java.util.Set) LocalRepositorySupplierFactory(org.mule.maven.client.api.LocalRepositorySupplierFactory) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Boolean.getBoolean(java.lang.Boolean.getBoolean) String.format(java.lang.String.format) I18nMessageFactory(org.mule.runtime.api.i18n.I18nMessageFactory) ClassLoaderModelJsonSerializer.deserialize(org.mule.tools.api.classloader.ClassLoaderModelJsonSerializer.deserialize) List(java.util.List) Optional(java.util.Optional) FileUtils.deleteQuietly(org.apache.commons.io.FileUtils.deleteQuietly) Model(org.apache.maven.model.Model) MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) EXPORTED_RESOURCES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.EXPORTED_RESOURCES) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) BundleDescriptor(org.mule.runtime.module.artifact.api.descriptor.BundleDescriptor) BundleScope(org.mule.runtime.module.artifact.api.descriptor.BundleScope) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) MavenClient(org.mule.maven.client.api.MavenClient) PRIVILEGED_ARTIFACTS_IDS(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.PRIVILEGED_ARTIFACTS_IDS) MuleFoldersUtil.getMuleHomeFolder(org.mule.runtime.container.api.MuleFoldersUtil.getMuleHomeFolder) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Optional.ofNullable(java.util.Optional.ofNullable) INCLUDE_TEST_DEPENDENCIES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.INCLUDE_TEST_DEPENDENCIES) REPOSITORY_FOLDER(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor.REPOSITORY_FOLDER) Boolean.valueOf(java.lang.Boolean.valueOf) MavenReactorResolver(org.mule.maven.client.api.MavenReactorResolver) File(java.io.File) EXPORTED_PACKAGES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.EXPORTED_PACKAGES) ArtifactType(org.mule.runtime.core.api.config.bootstrap.ArtifactType) ClassLoaderModelLoader(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModelLoader) Paths(java.nio.file.Paths) MuleContainerBootstrapUtils.isStandalone(org.mule.runtime.module.reboot.api.MuleContainerBootstrapUtils.isStandalone) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) File(java.io.File) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) MavenReactorResolver(org.mule.maven.client.api.MavenReactorResolver) HashSet(java.util.HashSet)

Example 9 with BundleDependency

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

the class DefaultRegionPluginClassLoadersFactoryTestCase method createsDependantPlugins.

@Test
public void createsDependantPlugins() throws Exception {
    BundleDependency pluginDependency = new BundleDependency.Builder().setScope(BundleScope.COMPILE).setDescriptor(PLUGIN1_BUNDLE_DESCRIPTOR).setBundleUri(new File("test").toURI()).build();
    plugin2Descriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().dependingOn(singleton(pluginDependency)).build());
    List<ArtifactPluginDescriptor> artifactPluginDescriptors = new ArrayList<>();
    artifactPluginDescriptors.add(plugin1Descriptor);
    artifactPluginDescriptors.add(plugin2Descriptor);
    when(regionOwnerLookupPolicy.extend(argThat(any(Map.class)))).thenReturn(pluginLookupPolicy);
    List<ArtifactClassLoader> pluginClassLoaders = factory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionOwnerLookupPolicy);
    assertThat(pluginClassLoaders, contains(pluginClassLoader1, pluginClassLoader2));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) ArrayList(java.util.ArrayList) File(java.io.File) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Test(org.junit.Test)

Example 10 with BundleDependency

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

the class DefaultRegionPluginClassLoadersFactoryTestCase method createsPluginWithPrivilegedPluginAccess.

@Test
public void createsPluginWithPrivilegedPluginAccess() throws Exception {
    ClassLoaderModel plugin1ClassLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder().exportingPrivilegedPackages(singleton(PRIVILEGED_PACKAGE), singleton(PLUGIN_ARTIFACT_ID2)).build();
    plugin1Descriptor.setClassLoaderModel(plugin1ClassLoaderModel);
    BundleDependency pluginDependency = new BundleDependency.Builder().setScope(BundleScope.COMPILE).setDescriptor(PLUGIN1_BUNDLE_DESCRIPTOR).setBundleUri(new File("test").toURI()).build();
    plugin2Descriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().dependingOn(singleton(pluginDependency)).build());
    List<ArtifactPluginDescriptor> artifactPluginDescriptors = new ArrayList<>();
    artifactPluginDescriptors.add(plugin1Descriptor);
    artifactPluginDescriptors.add(plugin2Descriptor);
    ArgumentCaptor<Map> argumentCaptor = forClass(Map.class);
    when(regionOwnerLookupPolicy.extend(argumentCaptor.capture())).thenReturn(pluginLookupPolicy);
    List<ArtifactClassLoader> pluginClassLoaders = factory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionOwnerLookupPolicy);
    assertThat(pluginClassLoaders, contains(pluginClassLoader1, pluginClassLoader2));
    assertThat((Map<String, LookupStrategy>) argumentCaptor.getAllValues().get(0), not(hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(DelegateOnlyLookupStrategy.class))));
    assertThat((Map<String, LookupStrategy>) argumentCaptor.getAllValues().get(1), hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(DelegateOnlyLookupStrategy.class)));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) ArrayList(java.util.ArrayList) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) File(java.io.File) Map(java.util.Map) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Test(org.junit.Test)

Aggregations

BundleDependency (org.mule.runtime.module.artifact.api.descriptor.BundleDependency)13 File (java.io.File)7 ClassLoaderModel (org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel)7 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)5 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 Test (org.junit.Test)4 LocalRepositorySupplierFactory (org.mule.maven.client.api.LocalRepositorySupplierFactory)4 MavenClient (org.mule.maven.client.api.MavenClient)4 String.format (java.lang.String.format)3 MalformedURLException (java.net.MalformedURLException)3 Paths (java.nio.file.Paths)3 Optional (java.util.Optional)3 Model (org.apache.maven.model.Model)3 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)3 I18nMessageFactory (org.mule.runtime.api.i18n.I18nMessageFactory)3 ArtifactType (org.mule.runtime.core.api.config.bootstrap.ArtifactType)3