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 = getProcessedArtifactItems(
106 new ProcessArtifactItemsRequest( this.stripVersion, this.prependGroupId, this.useBaseVersion, this.stripClassifier ) );
107 for ( ArtifactItem artifactItem : theArtifactItems )
108 {
109 if ( artifactItem.isNeedsProcessing() )
110 {
111 copyArtifact( artifactItem );
112 }
113 else
114 {
115 this.getLog().info( artifactItem + " already exists in " + artifactItem.getOutputDirectory() );
116 }
117 }
118 }
119
120
121
122
123
124
125
126
127
128 protected void copyArtifact( ArtifactItem artifactItem )
129 throws MojoExecutionException
130 {
131 File destFile = new File( artifactItem.getOutputDirectory(), artifactItem.getDestFileName() );
132
133 copyFile( artifactItem.getArtifact().getFile(), destFile );
134 }
135
136 protected ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
137 {
138 ArtifactItemFilter destinationNameOverrideFilter =
139 new DestFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(),
140 false, false, false, false, this.stripVersion, item.getOutputDirectory() );
141 return destinationNameOverrideFilter;
142 }
143
144
145
146
147 public boolean isStripVersion()
148 {
149 return this.stripVersion;
150 }
151
152
153
154
155 public void setStripVersion( boolean stripVersion )
156 {
157 this.stripVersion = stripVersion;
158 }
159
160
161
162
163 public boolean isStripClassifier()
164 {
165 return this.stripClassifier;
166 }
167
168
169
170
171 public void setStripClassifier( boolean stripClassifier )
172 {
173 this.stripClassifier = stripClassifier;
174 }
175
176
177
178
179 public void setUseBaseVersion( boolean useBaseVersion )
180 {
181 this.useBaseVersion = useBaseVersion;
182 }
183 }