View Javadoc
1   package org.apache.maven.plugin.assembly.archive.phase;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * Handles the top-level <dependencySets/> section of the assembly descriptor.
46   *
47   * @version $Id: DependencySetAssemblyPhase.java 1639422 2014-11-13 18:08:07Z krosenvold $
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       * Default constructor.
67       */
68      public DependencySetAssemblyPhase()
69      {
70          // used for plexus init
71      }
72  
73      /**
74       * @param projectBuilder The Maven Project Builder.
75       * @param logger         The Logger.
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       * {@inheritDoc}
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         return 40;
110     }
111 }