1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.assembly.archive.phase;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.Collections;
26 import java.util.Map;
27 import java.util.Set;
28
29 import org.apache.maven.artifact.Artifact;
30 import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
31 import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
32 import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
33 import org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask;
34 import org.apache.maven.plugins.assembly.artifact.DependencyResolutionException;
35 import org.apache.maven.plugins.assembly.artifact.DependencyResolver;
36 import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
37 import org.apache.maven.plugins.assembly.model.Assembly;
38 import org.apache.maven.plugins.assembly.model.DependencySet;
39 import org.apache.maven.project.ProjectBuilder;
40 import org.codehaus.plexus.archiver.Archiver;
41
42 import static java.util.Objects.requireNonNull;
43
44
45
46
47
48
49 @Singleton
50 @Named("dependency-sets")
51 public class DependencySetAssemblyPhase implements AssemblyArchiverPhase, PhaseOrder {
52 private final ProjectBuilder projectBuilder;
53
54 private final DependencyResolver dependencyResolver;
55
56
57
58
59 @Inject
60 public DependencySetAssemblyPhase(
61 final ProjectBuilder projectBuilder, final DependencyResolver dependencyResolver) {
62 this.projectBuilder = requireNonNull(projectBuilder);
63 this.dependencyResolver = requireNonNull(dependencyResolver);
64 }
65
66
67
68
69 @Override
70 public void execute(
71 final Assembly assembly, final Archiver archiver, final AssemblerConfigurationSource configSource)
72 throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException,
73 DependencyResolutionException {
74
75 Map<DependencySet, Set<Artifact>> resolved =
76 dependencyResolver.resolveDependencySets(assembly, configSource, assembly.getDependencySets());
77 for (Map.Entry<DependencySet, Set<Artifact>> dependencySetSetEntry : resolved.entrySet()) {
78 final AddDependencySetsTask task = new AddDependencySetsTask(
79 Collections.singletonList(dependencySetSetEntry.getKey()),
80 dependencySetSetEntry.getValue(),
81 configSource.getProject(),
82 projectBuilder);
83
84 task.execute(archiver, configSource);
85 }
86 }
87
88 @Override
89 public int order() {
90
91 return 40;
92
93 }
94 }