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