Search in sources :

Example 1 with ClassLoaderModel

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

the class PolicyTemplateDescriptorTestCase method verifiesPolicyTemplateDoesNotExportResources.

@Test
public void verifiesPolicyTemplateDoesNotExportResources() throws Exception {
    PolicyTemplateDescriptor policyTemplateDescriptor = new PolicyTemplateDescriptor(POLICY_NAME);
    ClassLoaderModel classLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder().exportingResources(Collections.singleton("META-INF/foo.xml")).build();
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage(POLICY_EXPORTED_RESOURCE_ERROR);
    policyTemplateDescriptor.setClassLoaderModel(classLoaderModel);
}
Also used : ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with ClassLoaderModel

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

the class PolicyTemplateDescriptorTestCase method verifiesPolicyTemplateDoesNotExportPackages.

@Test
public void verifiesPolicyTemplateDoesNotExportPackages() throws Exception {
    PolicyTemplateDescriptor policyTemplateDescriptor = new PolicyTemplateDescriptor(POLICY_NAME);
    ClassLoaderModel classLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder().exportingPackages(Collections.singleton("org.foo")).build();
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage(POLICY_EXPORTED_PACKAGES_ERROR);
    policyTemplateDescriptor.setClassLoaderModel(classLoaderModel);
}
Also used : ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with ClassLoaderModel

use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel 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();
}
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) Optional(java.util.Optional) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) File(java.io.File) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) HashSet(java.util.HashSet)

Example 4 with ClassLoaderModel

use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel 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));
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) MavenClient(org.mule.maven.client.api.MavenClient) URL(java.net.URL) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) Set(java.util.Set) LocalRepositorySupplierFactory(org.mule.maven.client.api.LocalRepositorySupplierFactory) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Rule(org.junit.Rule) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Paths(java.nio.file.Paths) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) Is.is(org.hamcrest.core.Is.is) Matchers.hasSize(org.hamcrest.Matchers.hasSize) InvalidDescriptorLoaderException(org.mule.runtime.module.artifact.api.descriptor.InvalidDescriptorLoaderException) TemporaryFolder(org.junit.rules.TemporaryFolder) Mockito.mock(org.mockito.Mockito.mock) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) URL(java.net.URL) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel)

Example 5 with ClassLoaderModel

use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel 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()));
}
Also used : BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Test(org.junit.Test)

Aggregations

ClassLoaderModel (org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel)21 Test (org.junit.Test)15 File (java.io.File)7 BundleDependency (org.mule.runtime.module.artifact.api.descriptor.BundleDependency)5 URL (java.net.URL)3 Paths (java.nio.file.Paths)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 LocalRepositorySupplierFactory (org.mule.maven.client.api.LocalRepositorySupplierFactory)3 MavenClient (org.mule.maven.client.api.MavenClient)3 Files.createTempDir (com.google.common.io.Files.createTempDir)2 Boolean.getBoolean (java.lang.Boolean.getBoolean)2 Boolean.valueOf (java.lang.Boolean.valueOf)2 String.format (java.lang.String.format)2 MalformedURLException (java.net.MalformedURLException)2 Optional (java.util.Optional)2 Optional.of (java.util.Optional.of)2