Search in sources :

Example 11 with ClassLoaderModel

use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel 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 12 with ClassLoaderModel

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

the class ApplicationStartedSplashScreenTestCase method setUp.

@Before
public void setUp() {
    splashScreen = new ApplicationStartedSplashScreen();
    ClassLoaderModel.ClassLoaderModelBuilder classLoaderModelBuilder = new ClassLoaderModel.ClassLoaderModelBuilder();
    runtimeLibs.stream().forEach(classLoaderModelBuilder::containing);
    ClassLoaderModel classLoaderModel = classLoaderModelBuilder.build();
    ArtifactPluginDescriptor pluginDescriptor = new ArtifactPluginDescriptor(PLUGIN_NAME);
    pluginDescriptor.setBundleDescriptor(new BundleDescriptor.Builder().setGroupId(PLUGIN_GROUP_ID).setArtifactId(PLUGIN_ARTIFACT_ID).setVersion(PLUGIN_VERSION).build());
    when(descriptor.getName()).thenReturn(APP_NAME);
    when(descriptor.getAppProperties()).thenReturn(new HashMap<>());
    when(descriptor.getPlugins()).thenReturn(newHashSet(pluginDescriptor));
    when(descriptor.getClassLoaderModel()).thenReturn(classLoaderModel);
}
Also used : BundleDescriptor(org.mule.runtime.module.artifact.api.descriptor.BundleDescriptor) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Before(org.junit.Before)

Example 13 with ClassLoaderModel

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

the class DeployableArtifactDescriptorFactoryTestCase method classLoaderModelWithIncludeTestDependencies.

@Test
public void classLoaderModelWithIncludeTestDependencies() throws Exception {
    D desc = createArtifactDescriptor(getArtifactRootFolder() + "include-test-dependencies");
    ClassLoaderModel classLoaderModel = desc.getClassLoaderModel();
    assertThat(classLoaderModel.isIncludeTestDependencies(), is(true));
}
Also used : ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Test(org.junit.Test)

Example 14 with ClassLoaderModel

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

the class DeployableArtifactDescriptorFactoryTestCase method classLoaderModelWithPluginDependency.

@Test
public void classLoaderModelWithPluginDependency() throws Exception {
    D desc = createArtifactDescriptor(getArtifactRootFolder() + "plugin-dependency");
    ClassLoaderModel classLoaderModel = desc.getClassLoaderModel();
    assertThat(classLoaderModel.getDependencies().size(), is(1));
    assertThat(classLoaderModel.getDependencies(), hasItem(socketsPluginDependencyMatcher()));
    assertThat(classLoaderModel.getUrls().length, is(1));
    assertThat(asList(classLoaderModel.getUrls()), not(hasItem(classLoaderModel.getDependencies().iterator().next())));
}
Also used : ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Test(org.junit.Test)

Example 15 with ClassLoaderModel

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

the class DeployableArtifactDescriptorFactoryTestCase method classLoaderModelDefaultIncludeTestDependencies.

@Test
public void classLoaderModelDefaultIncludeTestDependencies() throws Exception {
    D desc = createArtifactDescriptor(getArtifactRootFolder() + "custom-config-files");
    ClassLoaderModel classLoaderModel = desc.getClassLoaderModel();
    assertThat(classLoaderModel.isIncludeTestDependencies(), is(false));
}
Also used : 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