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 @Override
94 protected void doExecute()
95 throws MojoExecutionException
96 {
97 DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact );
98
99 for ( Artifact artifact : dss.getResolvedDependencies() )
100 {
101 File destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType,
102 useSubDirectoryPerArtifact, useRepositoryLayout,
103 stripVersion, outputDirectory, artifact );
104 unpack( artifact, destDir, getIncludes(), getExcludes(), getEncoding(), getFileMappers() );
105 DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory );
106 handler.setMarker();
107 }
108
109 for ( Artifact artifact : dss.getSkippedDependencies() )
110 {
111 getLog().info( artifact.getId() + " already exists in destination." );
112 }
113 }
114
115 @Override
116 protected ArtifactsFilter getMarkedArtifactFilter()
117 {
118 return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer,
119 new DefaultFileMarkerHandler( this.markersDirectory ) );
120 }
121
122
123
124
125 public String getExcludes()
126 {
127 return DependencyUtil.cleanToBeTokenizedString( this.excludes );
128 }
129
130
131
132
133 public void setExcludes( String excludes )
134 {
135 this.excludes = excludes;
136 }
137
138
139
140
141 public String getIncludes()
142 {
143 return DependencyUtil.cleanToBeTokenizedString( this.includes );
144 }
145
146
147
148
149 public void setIncludes( String includes )
150 {
151 this.includes = includes;
152 }
153
154
155
156
157
158 public void setEncoding( String encoding )
159 {
160 this.encoding = encoding;
161 }
162
163
164
165
166
167 public String getEncoding()
168 {
169 return this.encoding;
170 }
171
172
173
174
175
176
177
178 public FileMapper[] getFileMappers()
179 {
180 return this.fileMappers;
181 }
182
183
184
185
186
187
188
189 public void setFileMappers( FileMapper[] fileMappers )
190 {
191 this.fileMappers = fileMappers;
192 }
193 }