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.dependency.utils.filters.ArtifactItemFilter;
24 import org.apache.maven.plugin.dependency.utils.filters.DestFileFilter;
25 import org.apache.maven.plugins.annotations.LifecyclePhase;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.Parameter;
28
29 import java.io.File;
30 import java.util.List;
31
32
33
34
35
36
37
38
39 @Mojo( name = "copy", defaultPhase = LifecyclePhase.PROCESS_SOURCES )
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
54
55
56
57
58
59 public void execute()
60 throws MojoExecutionException
61 {
62 if ( isSkip() )
63 {
64 return;
65 }
66
67 List<ArtifactItem> theArtifactItems = getProcessedArtifactItems( this.stripVersion );
68 for ( ArtifactItem artifactItem : theArtifactItems )
69 {
70 if ( artifactItem.isNeedsProcessing() )
71 {
72 copyArtifact( artifactItem );
73 }
74 else
75 {
76 this.getLog().info( artifactItem + " already exists in " + artifactItem.getOutputDirectory() );
77 }
78 }
79 }
80
81
82
83
84
85
86
87
88
89 protected void copyArtifact( ArtifactItem artifactItem )
90 throws MojoExecutionException
91 {
92 File destFile = new File( artifactItem.getOutputDirectory(), artifactItem.getDestFileName() );
93
94 copyFile( artifactItem.getArtifact().getFile(), destFile );
95 }
96
97 protected ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
98 {
99 ArtifactItemFilter destinationNameOverrideFilter =
100 new DestFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(),
101 false, false, false, false, this.stripVersion, item.getOutputDirectory() );
102 return destinationNameOverrideFilter;
103 }
104
105
106
107
108 public boolean isStripVersion()
109 {
110 return this.stripVersion;
111 }
112
113
114
115
116 public void setStripVersion( boolean stripVersion )
117 {
118 this.stripVersion = stripVersion;
119 }
120
121 }