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