1 package org.apache.maven.plugin.dependency.fromConfiguration;
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.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.MojoFailureException;
24 import org.apache.maven.plugin.dependency.utils.filters.ArtifactItemFilter;
25 import org.apache.maven.plugin.dependency.utils.filters.DestFileFilter;
26 import org.apache.maven.plugins.annotations.LifecyclePhase;
27 import org.apache.maven.plugins.annotations.Mojo;
28 import org.apache.maven.plugins.annotations.Parameter;
29
30 import java.io.File;
31 import java.util.List;
32
33
34
35
36
37
38
39
40 @Mojo( name = "copy", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true )
41 public class CopyMojo
42 extends AbstractFromConfigurationMojo
43 {
44
45
46
47
48 @Parameter( property = "mdep.stripVersion", defaultValue = "false" )
49 private boolean stripVersion = false;
50
51
52
53
54 @Parameter( property = "mdep.stripClassifier", defaultValue = "false" )
55 private boolean stripClassifier = false;
56
57
58
59
60
61 @Parameter( property = "mdep.prependGroupId", defaultValue = "false" )
62 private boolean prependGroupId = false;
63
64
65
66
67
68 @Parameter( property = "mdep.useBaseVersion", defaultValue = "false" )
69 private boolean useBaseVersion = false;
70
71
72
73
74
75 @SuppressWarnings( "unused" )
76 @Parameter( property = "artifact" )
77 private String artifact;
78
79
80
81
82 @Parameter
83 protected boolean useJvmChmod = true;
84
85
86
87
88 @Parameter
89 protected boolean ignorePermissions;
90
91
92
93
94
95
96
97
98
99
100 protected void doExecute()
101 throws MojoExecutionException, MojoFailureException
102 {
103 verifyRequirements();
104
105 List<ArtifactItem> theArtifactItems =
106 getProcessedArtifactItems( new ProcessArtifactItemsRequest( stripVersion, prependGroupId,
107 useBaseVersion, stripClassifier ) );
108 for ( ArtifactItem artifactItem : theArtifactItems )
109 {
110 if ( artifactItem.isNeedsProcessing() )
111 {
112 copyArtifact( artifactItem );
113 }
114 else
115 {
116 this.getLog().info( artifactItem + " already exists in " + artifactItem.getOutputDirectory() );
117 }
118 }
119 }
120
121
122
123
124
125
126
127
128
129 protected void copyArtifact( ArtifactItem artifactItem )
130 throws MojoExecutionException
131 {
132 File destFile = new File( artifactItem.getOutputDirectory(), artifactItem.getDestFileName() );
133
134 copyFile( artifactItem.getArtifact().getFile(), destFile );
135 }
136
137 protected ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
138 {
139 ArtifactItemFilter destinationNameOverrideFilter =
140 new DestFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(),
141 false, false, false, false, this.stripVersion, item.getOutputDirectory() );
142 return destinationNameOverrideFilter;
143 }
144
145
146
147
148 public boolean isStripVersion()
149 {
150 return this.stripVersion;
151 }
152
153
154
155
156 public void setStripVersion( boolean stripVersion )
157 {
158 this.stripVersion = stripVersion;
159 }
160
161
162
163
164 public boolean isStripClassifier()
165 {
166 return this.stripClassifier;
167 }
168
169
170
171
172 public void setStripClassifier( boolean stripClassifier )
173 {
174 this.stripClassifier = stripClassifier;
175 }
176
177
178
179
180 public void setUseBaseVersion( boolean useBaseVersion )
181 {
182 this.useBaseVersion = useBaseVersion;
183 }
184 }