Search in sources :

Example 1 with AddDependencySetsTask

use of org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask in project maven-plugins by apache.

the class DependencySetAssemblyPhase method execute.

/**
     * {@inheritDoc}
     */
@Override
public void execute(final Assembly assembly, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    Map<DependencySet, Set<Artifact>> resolved = dependencyResolver.resolveDependencySets(assembly, configSource, assembly.getDependencySets());
    for (Map.Entry<DependencySet, Set<Artifact>> dependencySetSetEntry : resolved.entrySet()) {
        final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(dependencySetSetEntry.getKey()), dependencySetSetEntry.getValue(), configSource.getProject(), projectBuilder, getLogger());
        task.execute(archiver, configSource);
    }
}
Also used : Set(java.util.Set) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) Map(java.util.Map) AddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask)

Example 2 with AddDependencySetsTask

use of org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask in project maven-plugins by apache.

the class ModuleSetAssemblyPhase method addModuleBinaries.

void addModuleBinaries(final Assembly assembly, ModuleSet moduleSet, final ModuleBinaries binaries, final Set<MavenProject> projects, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    if (binaries == null) {
        return;
    }
    final Set<MavenProject> moduleProjects = new LinkedHashSet<MavenProject>();
    MavenProjects.select(projects, "pom", log(getLogger()), addTo(moduleProjects));
    final String classifier = binaries.getAttachmentClassifier();
    final Map<MavenProject, Artifact> chosenModuleArtifacts = new HashMap<MavenProject, Artifact>();
    for (final MavenProject project : moduleProjects) {
        Artifact artifact;
        if (classifier == null) {
            getLogger().debug("Processing binary artifact for module project: " + project.getId());
            artifact = project.getArtifact();
        } else {
            getLogger().debug("Processing binary attachment: " + classifier + " for module project: " + project.getId());
            artifact = MavenProjects.findArtifactByClassifier(project, classifier);
            if (artifact == null) {
                throw new InvalidAssemblerConfigurationException("Cannot find attachment with classifier: " + classifier + " in module project: " + project.getId() + ". Please exclude this module from the module-set.");
            }
        }
        chosenModuleArtifacts.put(project, artifact);
        addModuleArtifact(artifact, project, archiver, configSource, binaries);
    }
    final List<DependencySet> depSets = getDependencySets(binaries);
    if (depSets != null) {
        Map<DependencySet, Set<Artifact>> dependencySetSetMap = dependencyResolver.resolveDependencySets(assembly, moduleSet, configSource, depSets);
        for (final DependencySet ds : depSets) {
            // NOTE: Disabling useProjectArtifact flag, since module artifact has already been handled!
            ds.setUseProjectArtifact(false);
        }
        // TODO: The following should be moved into a shared component, cause this
        // test is the same as in maven-enforce rules ReactorModuleConvergence.
        List<MavenProject> validateModuleVersions = validateModuleVersions(moduleProjects);
        if (!validateModuleVersions.isEmpty()) {
            StringBuilder sb = new StringBuilder().append("The current modules seemed to be having different versions.");
            sb.append(LINE_SEPARATOR);
            for (MavenProject mavenProject : validateModuleVersions) {
                sb.append(" --> ");
                sb.append(mavenProject.getId());
                sb.append(LINE_SEPARATOR);
            }
            getLogger().warn(sb.toString());
        }
        for (final MavenProject moduleProject : moduleProjects) {
            getLogger().debug("Processing binary dependencies for module project: " + moduleProject.getId());
            for (Map.Entry<DependencySet, Set<Artifact>> dependencySetSetEntry : dependencySetSetMap.entrySet()) {
                final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(dependencySetSetEntry.getKey()), dependencySetSetEntry.getValue(), moduleProject, projectBuilder, getLogger());
                task.setModuleProject(moduleProject);
                task.setModuleArtifact(chosenModuleArtifacts.get(moduleProject));
                task.setDefaultOutputDirectory(binaries.getOutputDirectory());
                task.setDefaultOutputFileNameMapping(binaries.getOutputFileNameMapping());
                task.execute(archiver, configSource);
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModuleSet(org.apache.maven.plugins.assembly.model.ModuleSet) FileSet(org.apache.maven.plugins.assembly.model.FileSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) HashMap(java.util.HashMap) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) Artifact(org.apache.maven.artifact.Artifact) MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) Map(java.util.Map) AddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask)

Aggregations

Map (java.util.Map)2 Set (java.util.Set)2 AddDependencySetsTask (org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask)2 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)2 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Artifact (org.apache.maven.artifact.Artifact)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 FileSet (org.apache.maven.plugins.assembly.model.FileSet)1 ModuleSet (org.apache.maven.plugins.assembly.model.ModuleSet)1 MavenProject (org.apache.maven.project.MavenProject)1