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 | 52 | public class CopyMojo |
42 | |
extends AbstractFromConfigurationMojo |
43 | |
{ |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | 52 | @Parameter( property = "mdep.stripVersion", defaultValue = "false" ) |
49 | |
private boolean stripVersion = false; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
@SuppressWarnings( "unused" ) |
56 | |
@Parameter( property = "artifact" ) |
57 | |
private String artifact; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public void execute() |
69 | |
throws MojoExecutionException, MojoFailureException |
70 | |
{ |
71 | 54 | if ( isSkip() ) |
72 | |
{ |
73 | 2 | return; |
74 | |
} |
75 | |
|
76 | 52 | verifyRequirements(); |
77 | |
|
78 | 52 | List<ArtifactItem> theArtifactItems = getProcessedArtifactItems( this.stripVersion ); |
79 | 46 | for ( ArtifactItem artifactItem : theArtifactItems ) |
80 | |
{ |
81 | 80 | if ( artifactItem.isNeedsProcessing() ) |
82 | |
{ |
83 | 76 | copyArtifact( artifactItem ); |
84 | |
} |
85 | |
else |
86 | |
{ |
87 | 4 | this.getLog().info( artifactItem + " already exists in " + artifactItem.getOutputDirectory() ); |
88 | |
} |
89 | |
} |
90 | 46 | } |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
protected void copyArtifact( ArtifactItem artifactItem ) |
101 | |
throws MojoExecutionException |
102 | |
{ |
103 | 76 | File destFile = new File( artifactItem.getOutputDirectory(), artifactItem.getDestFileName() ); |
104 | |
|
105 | 76 | copyFile( artifactItem.getArtifact().getFile(), destFile ); |
106 | 76 | } |
107 | |
|
108 | |
protected ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item ) |
109 | |
{ |
110 | 84 | ArtifactItemFilter destinationNameOverrideFilter = |
111 | |
new DestFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(), |
112 | |
false, false, false, false, this.stripVersion, item.getOutputDirectory() ); |
113 | 84 | return destinationNameOverrideFilter; |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public boolean isStripVersion() |
120 | |
{ |
121 | 2 | return this.stripVersion; |
122 | |
} |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
public void setStripVersion( boolean stripVersion ) |
128 | |
{ |
129 | 4 | this.stripVersion = stripVersion; |
130 | 4 | } |
131 | |
|
132 | |
} |