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
55 @Parameter( property = "mdep.prependGroupId", defaultValue = "false" )
56 private boolean prependGroupId = false;
57
58
59
60
61
62 @Parameter( property = "mdep.useBaseVersion", defaultValue = "false" )
63 private boolean useBaseVersion = false;
64
65
66
67
68
69 @SuppressWarnings( "unused" )
70 @Parameter( property = "artifact" )
71 private String artifact;
72
73
74
75
76
77
78
79
80
81
82 protected void doExecute()
83 throws MojoExecutionException, MojoFailureException
84 {
85 verifyRequirements();
86
87 List<ArtifactItem> theArtifactItems = getProcessedArtifactItems(
88 new ProcessArtifactItemsRequest( this.stripVersion, this.prependGroupId, this.useBaseVersion ) );
89 for ( ArtifactItem artifactItem : theArtifactItems )
90 {
91 if ( artifactItem.isNeedsProcessing() )
92 {
93 copyArtifact( artifactItem );
94 }
95 else
96 {
97 this.getLog().info( artifactItem + " already exists in " + artifactItem.getOutputDirectory() );
98 }
99 }
100 }
101
102
103
104
105
106
107
108
109
110 protected void copyArtifact( ArtifactItem artifactItem )
111 throws MojoExecutionException
112 {
113 File destFile = new File( artifactItem.getOutputDirectory(), artifactItem.getDestFileName() );
114
115 copyFile( artifactItem.getArtifact().getFile(), destFile );
116 }
117
118 protected ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
119 {
120 ArtifactItemFilter destinationNameOverrideFilter =
121 new DestFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(),
122 false, false, false, false, this.stripVersion, item.getOutputDirectory() );
123 return destinationNameOverrideFilter;
124 }
125
126
127
128
129 public boolean isStripVersion()
130 {
131 return this.stripVersion;
132 }
133
134
135
136
137 public void setStripVersion( boolean stripVersion )
138 {
139 this.stripVersion = stripVersion;
140 }
141
142
143
144
145 public void setUseBaseVersion( boolean useBaseVersion )
146 {
147 this.useBaseVersion = useBaseVersion;
148 }
149 }