Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CopyMojo |
|
| 1.8;1,8 |
1 | package org.apache.maven.plugin.dependency.fromConfiguration; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
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 | * Goal that copies a list of artifacts from the repository to defined locations. | |
34 | * | |
35 | * @author <a href="mailto:brianf@apache.org">Brian Fox</a> | |
36 | * @version $Id: CopyMojo.java 1357251 2012-07-04 13:28:33Z olamy $ | |
37 | * @since 1.0 | |
38 | */ | |
39 | @Mojo( name = "copy", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) | |
40 | 26 | public class CopyMojo |
41 | extends AbstractFromConfigurationMojo | |
42 | { | |
43 | ||
44 | /** | |
45 | * Strip artifact version during copy | |
46 | */ | |
47 | 26 | @Parameter( property = "mdep.stripVersion", defaultValue = "false" ) |
48 | private boolean stripVersion = false; | |
49 | ||
50 | /** | |
51 | * Main entry into mojo. This method gets the ArtifactItems and iterates through each one passing it to | |
52 | * copyArtifact. | |
53 | * | |
54 | * @throws MojoExecutionException with a message if an error occurs. | |
55 | * @see ArtifactItem | |
56 | * @see #getArtifactItems | |
57 | * @see #copyArtifact(ArtifactItem) | |
58 | */ | |
59 | public void execute() | |
60 | throws MojoExecutionException | |
61 | { | |
62 | 27 | if ( isSkip() ) |
63 | { | |
64 | 1 | return; |
65 | } | |
66 | ||
67 | 26 | List<ArtifactItem> theArtifactItems = getProcessedArtifactItems( this.stripVersion ); |
68 | 23 | for ( ArtifactItem artifactItem : theArtifactItems ) |
69 | { | |
70 | 40 | if ( artifactItem.isNeedsProcessing() ) |
71 | { | |
72 | 38 | copyArtifact( artifactItem ); |
73 | } | |
74 | else | |
75 | { | |
76 | 2 | this.getLog().info( artifactItem + " already exists in " + artifactItem.getOutputDirectory() ); |
77 | } | |
78 | } | |
79 | 23 | } |
80 | ||
81 | /** | |
82 | * Resolves the artifact from the repository and copies it to the specified location. | |
83 | * | |
84 | * @param artifactItem containing the information about the Artifact to copy. | |
85 | * @throws MojoExecutionException with a message if an error occurs. | |
86 | * @see DependencyUtil#copyFile(File, File, Log) | |
87 | * @see DependencyUtil#getFormattedFileName(Artifact, boolean) | |
88 | */ | |
89 | protected void copyArtifact( ArtifactItem artifactItem ) | |
90 | throws MojoExecutionException | |
91 | { | |
92 | 38 | File destFile = new File( artifactItem.getOutputDirectory(), artifactItem.getDestFileName() ); |
93 | ||
94 | 38 | copyFile( artifactItem.getArtifact().getFile(), destFile ); |
95 | 38 | } |
96 | ||
97 | protected ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item ) | |
98 | { | |
99 | 42 | ArtifactItemFilter destinationNameOverrideFilter = |
100 | new DestFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(), | |
101 | false, false, false, false, this.stripVersion, item.getOutputDirectory() ); | |
102 | 42 | return destinationNameOverrideFilter; |
103 | } | |
104 | ||
105 | /** | |
106 | * @return Returns the stripVersion. | |
107 | */ | |
108 | public boolean isStripVersion() | |
109 | { | |
110 | 1 | return this.stripVersion; |
111 | } | |
112 | ||
113 | /** | |
114 | * @param stripVersion The stripVersion to set. | |
115 | */ | |
116 | public void setStripVersion( boolean stripVersion ) | |
117 | { | |
118 | 2 | this.stripVersion = stripVersion; |
119 | 2 | } |
120 | ||
121 | } |