~ubuntu-branches/ubuntu/utopic/build-helper-maven-plugin/utopic

« back to all changes in this revision

Viewing changes to src/main/java/org/codehaus/mojo/buildhelper/AttachArtifact.java

  • Committer: Package Import Robot
  • Author(s): tony mancill, Emmanuel Bourg, tony mancill
  • Date: 2013-06-01 20:19:34 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130601201934-hzv7zmdcgazfyupp
Tags: 1.7-1
[ Emmanuel Bourg ]
* Team upload.
* New upstream release
* Set the compiler source/target to 1.5
* Updated Standards-Version to 3.9.4 (no changes)
* debian/copyright:
  - Updated the Format URI to 1.0
  - Removed the duplicate Copyright fields

[ tony mancill ]
* debian/control:
  - Add libmaven-invoker-plugin-java to build-depends-indep.
  - Wrap long lines.
  - Update Vcs-Git URL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.codehaus.mojo.buildhelper;
2
 
 
3
 
/*
4
 
 * The MIT License
5
 
 *
6
 
 * Copyright (c) 2004, The Codehaus
7
 
 *
8
 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
9
 
 * this software and associated documentation files (the "Software"), to deal in
10
 
 * the Software without restriction, including without limitation the rights to
11
 
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12
 
 * of the Software, and to permit persons to whom the Software is furnished to do
13
 
 * so, subject to the following conditions:
14
 
 *
15
 
 * The above copyright notice and this permission notice shall be included in all
16
 
 * copies or substantial portions of the Software.
17
 
 *
18
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
 
 * SOFTWARE.
25
 
 */
26
 
 
27
 
import org.apache.maven.execution.MavenSession;
28
 
import org.apache.maven.plugin.AbstractMojo;
29
 
import org.apache.maven.plugin.MojoExecutionException;
30
 
import org.apache.maven.plugin.MojoFailureException;
31
 
import org.apache.maven.project.MavenProject;
32
 
import org.apache.maven.project.MavenProjectHelper;
33
 
 
34
 
import java.util.HashSet;
35
 
import java.util.Set;
36
 
 
37
 
/**
38
 
 * Attach additional artifacts to be installed and deployed.
39
 
 *
40
 
 * @goal attach-artifact
41
 
 * @phase package
42
 
 * @author <a href="dantran@gmail.com">Dan T. Tran</a>
43
 
 * @version $Id: AttachArtifact.java 11887 2010-02-12 10:13:13Z dennisl $
44
 
 * @since 1.0
45
 
 */
46
 
public class AttachArtifact
47
 
    extends AbstractMojo
48
 
{
49
 
    /**
50
 
     * Attach an array of artifacts to the project.
51
 
     *
52
 
     * @parameter
53
 
     * @required
54
 
     */
55
 
    private Artifact [] artifacts;
56
 
 
57
 
    /**
58
 
     * This project's base directory.
59
 
     *
60
 
     * @parameter expression="${basedir}"
61
 
     * @required
62
 
     * @since 1.5
63
 
     */
64
 
    private String basedir;
65
 
 
66
 
    /**
67
 
     * The Maven Session.
68
 
     *
69
 
     * @parameter expression="${session}"
70
 
     * @readonly
71
 
     * @required
72
 
     * @since 1.5
73
 
     */
74
 
    private MavenSession mavenSession;
75
 
 
76
 
    /**
77
 
     * @parameter expression="${project}"
78
 
     * @required
79
 
     * @readonly
80
 
     */
81
 
    private MavenProject project;
82
 
 
83
 
    /**
84
 
     * Maven ProjectHelper.
85
 
     *
86
 
     * @component
87
 
     * @readonly
88
 
     */
89
 
    private MavenProjectHelper projectHelper;
90
 
 
91
 
    /**
92
 
     * This will cause the execution to be run only at the top of a given module
93
 
     * tree. That is, run in the project contained in the same folder where the
94
 
     * mvn execution was launched.
95
 
     *
96
 
     * @parameter expression="${buildhelper.runOnlyAtExecutionRoot}" default-value="false"
97
 
     * @since 1.5
98
 
     */
99
 
    private boolean runOnlyAtExecutionRoot;
100
 
 
101
 
    public void execute()
102
 
        throws MojoExecutionException, MojoFailureException
103
 
    {
104
 
 
105
 
        // Run only at the execution root
106
 
        if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() )
107
 
        {
108
 
            getLog().info( "Skip attaching artifacts in this project because it's not the Execution Root" );
109
 
        }
110
 
        else
111
 
        {
112
 
            this.validateArtifacts();
113
 
 
114
 
            for ( int i = 0 ; i < this.artifacts.length; ++ i )
115
 
            {
116
 
                projectHelper.attachArtifact( this.project,
117
 
                                              this.artifacts[i].getType(),
118
 
                                              this.artifacts[i].getClassifier(),
119
 
                                              this.artifacts[i].getFile() );
120
 
            }
121
 
        }
122
 
 
123
 
    }
124
 
 
125
 
    /**
126
 
     * Returns <code>true</code> if the current project is located at the
127
 
     * Execution Root Directory (where mvn was launched).
128
 
     *
129
 
     * @return <code>true</code> if the current project is at the Execution Root
130
 
     */
131
 
    private boolean isThisTheExecutionRoot()
132
 
    {
133
 
        getLog().debug( "Root Folder:" + mavenSession.getExecutionRootDirectory() );
134
 
        getLog().debug( "Current Folder:" + basedir );
135
 
        boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase( basedir.toString() );
136
 
        if ( result )
137
 
        {
138
 
            getLog().debug( "This is the execution root." );
139
 
        }
140
 
        else
141
 
        {
142
 
            getLog().debug( "This is NOT the execution root." );
143
 
        }
144
 
        return result;
145
 
    }
146
 
 
147
 
    private void validateArtifacts()
148
 
        throws MojoFailureException
149
 
    {
150
 
        // check unique of types and classifiers
151
 
        Set extensionClassifiers = new HashSet();
152
 
        for ( int i = 0; i < this.artifacts.length; ++i )
153
 
        {
154
 
            Artifact artifact = this.artifacts[i];
155
 
 
156
 
            String extensionClassifier = artifact.getType() + ":" + artifact.getClassifier();
157
 
 
158
 
            if ( !extensionClassifiers.add( extensionClassifier  ) )
159
 
            {
160
 
                throw new MojoFailureException( "The artifact with same type and classifier: "
161
 
                                                + extensionClassifier + " is used more than once." );
162
 
            }
163
 
 
164
 
        }
165
 
    }
166
 
}