1 package org.apache.maven.plugins.dependency.fromDependencies;
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.MojoExecutionException;
24 import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
25 import org.apache.maven.plugins.dependency.utils.DependencyUtil;
26 import org.apache.maven.plugins.dependency.utils.filters.MarkerFileFilter;
27 import org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler;
28 import org.apache.maven.plugins.annotations.LifecyclePhase;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.plugins.annotations.ResolutionScope;
32 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
33 import org.codehaus.plexus.components.io.filemappers.FileMapper;
34
35 import java.io.File;
36
37
38
39
40
41
42
43
44 @Mojo( name = "unpack-dependencies", requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true )
45
46 public class UnpackDependenciesMojo
47 extends AbstractFromDependenciesMojo
48 {
49
50
51
52
53
54
55
56 @Parameter( property = "mdep.unpack.includes" )
57 private String includes;
58
59
60
61
62
63
64
65
66 @Parameter( property = "mdep.unpack.excludes" )
67 private String excludes;
68
69
70
71
72
73
74 @Parameter( property = "mdep.unpack.encoding" )
75 private String encoding;
76
77
78
79
80
81
82 @Parameter( property = "mdep.unpack.filemappers" )
83 private FileMapper[] fileMappers;
84
85
86
87
88
89
90
91
92
93
94
95 @Override
96 protected void doExecute()
97 throws MojoExecutionException
98 {
99 DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact );
100
101 for ( Artifact artifact : dss.getResolvedDependencies() )
102 {
103 File destDir;
104 destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType,
105 useSubDirectoryPerArtifact, useRepositoryLayout,
106 stripVersion, outputDirectory, artifact );
107 unpack( artifact, destDir, getIncludes(), getExcludes(), getEncoding(), getFileMappers() );
108 DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory );
109 handler.setMarker();
110 }
111
112 for ( Artifact artifact : dss.getSkippedDependencies() )
113 {
114 getLog().info( artifact.getId() + " already exists in destination." );
115 }
116 }
117
118 @Override
119 protected ArtifactsFilter getMarkedArtifactFilter()
120 {
121 return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer,
122 new DefaultFileMarkerHandler( this.markersDirectory ) );
123 }
124
125
126
127
128 public String getExcludes()
129 {
130 return DependencyUtil.cleanToBeTokenizedString( this.excludes );
131 }
132
133
134
135
136 public void setExcludes( String excludes )
137 {
138 this.excludes = excludes;
139 }
140
141
142
143
144 public String getIncludes()
145 {
146 return DependencyUtil.cleanToBeTokenizedString( this.includes );
147 }
148
149
150
151
152 public void setIncludes( String includes )
153 {
154 this.includes = includes;
155 }
156
157
158
159
160
161 public void setEncoding( String encoding )
162 {
163 this.encoding = encoding;
164 }
165
166
167
168
169
170 public String getEncoding()
171 {
172 return this.encoding;
173 }
174
175
176
177
178
179
180
181 public FileMapper[] getFileMappers()
182 {
183 return this.fileMappers;
184 }
185
186
187
188
189
190
191
192 public void setFileMappers( FileMapper[] fileMappers )
193 {
194 this.fileMappers = fileMappers;
195 }
196 }