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.util.List;
23
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.MojoFailureException;
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 import org.apache.maven.plugins.dependency.utils.filters.ArtifactItemFilter;
30 import org.apache.maven.plugins.dependency.utils.filters.DestFileFilter;
31
32
33
34
35
36
37
38 @Mojo(name = "copy", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true)
39 public class CopyMojo extends AbstractFromConfigurationMojo {
40
41
42
43
44 @Parameter(property = "mdep.stripVersion", defaultValue = "false")
45 private boolean stripVersion = false;
46
47
48
49
50 @Parameter(property = "mdep.stripClassifier", defaultValue = "false")
51 private boolean stripClassifier = false;
52
53
54
55
56
57
58 @Parameter(property = "mdep.prependGroupId", defaultValue = "false")
59 private boolean prependGroupId = false;
60
61
62
63
64
65
66 @Parameter(property = "mdep.useBaseVersion", defaultValue = "false")
67 private boolean useBaseVersion = false;
68
69
70
71
72
73 @SuppressWarnings("unused")
74 @Parameter(property = "artifact")
75 private String artifact;
76
77
78
79
80 @Parameter
81 protected boolean ignorePermissions;
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 copyFile(artifactItem.getArtifact().getFile(), destFile);
118 }
119
120 @Override
121 protected ArtifactItemFilter getMarkedArtifactFilter(ArtifactItem item) {
122 return new DestFileFilter(
123 this.isOverWriteReleases(),
124 this.isOverWriteSnapshots(),
125 this.isOverWriteIfNewer(),
126 false,
127 false,
128 false,
129 false,
130 this.stripVersion,
131 prependGroupId,
132 useBaseVersion,
133 item.getOutputDirectory());
134 }
135
136
137
138
139 public boolean isStripVersion() {
140 return this.stripVersion;
141 }
142
143
144
145
146 public void setStripVersion(boolean stripVersion) {
147 this.stripVersion = stripVersion;
148 }
149
150
151
152
153 public boolean isStripClassifier() {
154 return this.stripClassifier;
155 }
156
157
158
159
160 public void setStripClassifier(boolean stripClassifier) {
161 this.stripClassifier = stripClassifier;
162 }
163
164
165
166
167 public void setUseBaseVersion(boolean useBaseVersion) {
168 this.useBaseVersion = useBaseVersion;
169 }
170 }