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