View Javadoc

1   package org.apache.maven.plugin.dependency;
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 java.io.File;
23  import java.util.Iterator;
24  import java.util.Set;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.plugin.MojoExecutionException;
28  import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
29  import org.apache.maven.plugin.dependency.utils.DependencyUtil;
30  import org.apache.maven.plugin.dependency.utils.filters.MarkerFileFilter;
31  import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
32  import org.apache.maven.plugin.logging.Log;
33  import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
34  import org.codehaus.plexus.archiver.manager.ArchiverManager;
35  
36  /**
37   * Goal that unpacks the project dependencies from the repository to a defined
38   * location.
39   * 
40   * @goal unpack-dependencies
41   * @requiresDependencyResolution test
42   * @phase process-sources
43   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
44   * @version $Id: UnpackDependenciesMojo.java 728546 2008-12-21 22:56:51Z bentmann $
45   * @since 1.0
46   */
47  public class UnpackDependenciesMojo
48      extends AbstractFromDependenciesMojo
49  {
50  	/**
51       * A comma separated list of file patterns to include when unpacking the
52       * artifact.  i.e.  **\/*.xml,**\/*.properties NOTE: Excludes patterns override the includes. (component code = return isIncluded( name ) AND !isExcluded( name );)
53       * @since 2.0
54       * @parameter expression="${mdep.unpack.includes}"
55       */
56      private String includes;
57  
58      /**
59       * A comma separated list of file patterns to exclude when unpacking the
60       * artifact.  i.e.  **\/*.xml,**\/*.properties. NOTE: Excludes patterns override the includes. (component code = return isIncluded( name ) AND !isExcluded( name );)
61       * @since 2.0
62       * @parameter expression="${mdep.unpack.excludes}"
63       */
64      private String excludes;
65      
66      /**
67       * Main entry into mojo. This method gets the dependencies and iterates
68       * through each one passing it to DependencyUtil.unpackFile().
69       * 
70       * @throws MojoExecutionException
71       *             with a message if an error occurs.
72       * 
73       * @see #getDependencies
74       * @see DependencyUtil#unpackFile(Artifact, File, File, ArchiverManager,
75       *      Log)
76       */
77      public void execute()
78          throws MojoExecutionException
79      {
80          DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact );
81          Set artifacts = dss.getResolvedDependencies();
82  
83          for ( Iterator i = artifacts.iterator(); i.hasNext(); )
84          {
85              Artifact artifact = (Artifact) i.next();
86              File destDir;
87              destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerType, useSubDirectoryPerArtifact,
88                                                                    useRepositoryLayout, stripVersion, outputDirectory,
89                                                                    artifact );
90              unpack( artifact.getFile(), destDir, getIncludes(), getExcludes() );
91              DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory );
92              handler.setMarker();
93          }
94          
95          artifacts = dss.getSkippedDependencies();
96          for ( Iterator i = artifacts.iterator(); i.hasNext(); )
97          {
98              Artifact artifact = (Artifact) i.next();
99              getLog().info( artifact.getFile().getName() + " already exists in destination." );
100         }
101     }
102 
103     protected ArtifactsFilter getMarkedArtifactFilter()
104     {
105         return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer,
106                                      new DefaultFileMarkerHandler( this.markersDirectory ) );
107     }
108     
109     /**
110      * @return Returns a comma separated list of excluded items
111      */
112     public String getExcludes ()
113     {
114         return this.excludes;
115     }
116     
117     /**
118      * @param excludes 
119      * 			A comma separated list of items to exclude 
120      * 			i.e.  **\/*.xml, **\/*.properties
121      */
122     public void setExcludes ( String excludes )
123     {
124         this.excludes = excludes;
125     }
126     
127     /**
128      * @return Returns a comma seperated list of included items
129      */
130     public String getIncludes()
131     {
132     	return this.includes;
133     }
134 
135     /**
136      * @param includes
137      * 			A comma seperated list of items to inmclude 
138      * 			i.e.  **\/*.xml, **\/*.properties
139      */
140     public void setIncludes ( String includes )
141     {
142         this.includes = includes;
143     }
144 }