Search in sources :

Example 1 with INCLUDE_TEST_DEPENDENCIES

use of org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.INCLUDE_TEST_DEPENDENCIES 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)

Aggregations

Files.createTempDir (com.google.common.io.Files.createTempDir)1 File (java.io.File)1 Boolean.getBoolean (java.lang.Boolean.getBoolean)1 Boolean.valueOf (java.lang.Boolean.valueOf)1 String.format (java.lang.String.format)1 MalformedURLException (java.net.MalformedURLException)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.of (java.util.Optional.of)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 FileUtils.deleteQuietly (org.apache.commons.io.FileUtils.deleteQuietly)1 Model (org.apache.maven.model.Model)1