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
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
27 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
28 import org.apache.maven.plugin.dependency.utils.filters.MarkerFileFilter;
29 import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
30 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
31
32 /**
33 * Goal that unpacks the project dependencies from the repository to a defined
34 * location.
35 *
36 * @goal unpack-dependencies
37 * @requiresDependencyResolution test
38 * @phase process-sources
39 * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
40 * @version $Id: UnpackDependenciesMojo.java 1085777 2011-03-26 18:13:19Z hboutemy $
41 * @since 1.0
42 */
43 public class UnpackDependenciesMojo
44 extends AbstractFromDependenciesMojo
45 {
46 /**
47 * A comma separated list of file patterns to include when unpacking the
48 * artifact. i.e. <code>**\/*.xml,**\/*.properties</code>
49 * NOTE: Excludes patterns override the includes.
50 * (component code = <code>return isIncluded( name ) AND !isExcluded( name );</code>)
51 * @since 2.0
52 * @parameter expression="${mdep.unpack.includes}"
53 */
54 private String includes;
55
56 /**
57 * A comma separated list of file patterns to exclude when unpacking the
58 * artifact. i.e. <code>**\/*.xml,**\/*.properties</code>
59 * NOTE: Excludes patterns override the includes.
60 * (component code = <code>return isIncluded( name ) AND !isExcluded( name );</code>)
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
82 for ( Artifact artifact : dss.getResolvedDependencies() )
83 {
84 File destDir;
85 destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, useSubDirectoryPerArtifact,
86 useRepositoryLayout, stripVersion, outputDirectory,
87 artifact );
88 unpack( artifact.getFile(), destDir, getIncludes(), getExcludes() );
89 DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory );
90 handler.setMarker();
91 }
92
93 for ( Artifact artifact : dss.getSkippedDependencies() )
94 {
95 getLog().info( artifact.getFile().getName() + " already exists in destination." );
96 }
97 }
98
99 protected ArtifactsFilter getMarkedArtifactFilter()
100 {
101 return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer,
102 new DefaultFileMarkerHandler( this.markersDirectory ) );
103 }
104
105 /**
106 * @return Returns a comma separated list of excluded items
107 */
108 public String getExcludes()
109 {
110 return DependencyUtil.cleanToBeTokenizedString( this.excludes );
111 }
112
113 /**
114 * @param excludes
115 * A comma separated list of items to exclude
116 * i.e. <code>**\/*.xml, **\/*.properties</code>
117 */
118 public void setExcludes( String excludes )
119 {
120 this.excludes = excludes;
121 }
122
123 /**
124 * @return Returns a comma separated list of included items
125 */
126 public String getIncludes()
127 {
128 return DependencyUtil.cleanToBeTokenizedString( this.includes );
129 }
130
131 /**
132 * @param includes
133 * A comma separated list of items to include
134 * i.e. <code>**\/*.xml, **\/*.properties</code>
135 */
136 public void setIncludes( String includes )
137 {
138 this.includes = includes;
139 }
140 }