Search in sources :

Example 1 with EXPORTED_PACKAGES

use of org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.EXPORTED_PACKAGES 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 2 with EXPORTED_PACKAGES

use of org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.EXPORTED_PACKAGES 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)2 File (java.io.File)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 Paths (java.nio.file.Paths)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Optional.of (java.util.Optional.of)2 Optional.ofNullable (java.util.Optional.ofNullable)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Supplier (java.util.function.Supplier)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 FileUtils.deleteQuietly (org.apache.commons.io.FileUtils.deleteQuietly)2 Model (org.apache.maven.model.Model)2