1 package org.apache.maven.plugin.assembly.archive.phase;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
24 import org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException;
25 import org.apache.maven.plugin.assembly.archive.ArchiveCreationException;
26 import org.apache.maven.plugin.assembly.archive.task.AddDependencySetsTask;
27 import org.apache.maven.plugin.assembly.artifact.DependencyResolutionException;
28 import org.apache.maven.plugin.assembly.artifact.DependencyResolver;
29 import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
30 import org.apache.maven.plugin.assembly.model.Assembly;
31 import org.apache.maven.plugin.assembly.model.DependencySet;
32 import org.apache.maven.project.MavenProjectBuilder;
33 import org.codehaus.plexus.archiver.Archiver;
34 import org.codehaus.plexus.archiver.manager.ArchiverManager;
35 import org.codehaus.plexus.component.annotations.Component;
36 import org.codehaus.plexus.component.annotations.Requirement;
37 import org.codehaus.plexus.logging.AbstractLogEnabled;
38 import org.codehaus.plexus.logging.Logger;
39
40 import java.util.Collections;
41 import java.util.Map;
42 import java.util.Set;
43
44
45
46
47
48
49 @Component( role = AssemblyArchiverPhase.class, hint = "dependency-sets" )
50 public class DependencySetAssemblyPhase
51 extends AbstractLogEnabled
52 implements AssemblyArchiverPhase, PhaseOrder
53 {
54
55 @Requirement
56 private MavenProjectBuilder projectBuilder;
57
58 @Requirement
59 private ArchiverManager archiverManager;
60
61 @Requirement
62 private DependencyResolver dependencyResolver;
63
64
65
66
67
68 public DependencySetAssemblyPhase()
69 {
70
71 }
72
73
74
75
76
77 public DependencySetAssemblyPhase( final MavenProjectBuilder projectBuilder, DependencyResolver dependencyResolver,
78 final Logger logger )
79 {
80 this.projectBuilder = projectBuilder;
81 this.dependencyResolver = dependencyResolver;
82 enableLogging( logger );
83 }
84
85
86
87
88 public void execute( final Assembly assembly, final Archiver archiver,
89 final AssemblerConfigurationSource configSource )
90 throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException,
91 DependencyResolutionException
92 {
93
94 Map<DependencySet, Set<Artifact>> resolved =
95 dependencyResolver.resolveDependencySets( assembly, configSource, assembly.getDependencySets() );
96 for ( Map.Entry<DependencySet, Set<Artifact>> dependencySetSetEntry : resolved.entrySet() )
97 {
98 final AddDependencySetsTask task =
99 new AddDependencySetsTask( Collections.singletonList( dependencySetSetEntry.getKey() ),
100 dependencySetSetEntry.getValue(), configSource.getProject(), projectBuilder,
101 getLogger() );
102
103 task.execute( archiver, configSource );
104 }
105 }
106
107 public int order()
108 {
109
110 return 40;
111
112 }
113 }