View Javadoc

1   package org.apache.maven.plugin.coreit;
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.artifact.Artifact;
23  import org.apache.maven.artifact.installer.ArtifactInstaller;
24  import org.apache.maven.plugin.MojoExecutionException;
25  
26  import java.util.Iterator;
27  
28  /**
29   * Installs the project artifacts into the local repository. This is the essence of the Maven Install Plugin.
30   * 
31   * @goal install
32   * @phase install
33   * 
34   * @author Benjamin Bentmann
35   * @version $Id: InstallMojo.java 995270 2010-09-08 22:38:20Z bentmann $
36   */
37  public class InstallMojo
38      extends AbstractRepoMojo
39  {
40  
41      /**
42       * The artifact installer.
43       * 
44       * @component
45       */
46      private ArtifactInstaller installer;
47  
48      /**
49       * Runs this mojo.
50       * 
51       * @throws MojoExecutionException If any artifact could not be installed.
52       */
53      public void execute()
54          throws MojoExecutionException
55      {
56          getLog().info( "[MAVEN-CORE-IT-LOG] Installing project artifacts" );
57  
58          try
59          {
60              if ( isPomArtifact() )
61              {
62                  installer.install( pomFile, mainArtifact, localRepository );
63              }
64              else
65              {
66                  installer.install( mainArtifact.getFile(), mainArtifact, localRepository );
67              }
68  
69              if ( attachedArtifacts != null )
70              {
71                  for ( Iterator it = attachedArtifacts.iterator(); it.hasNext(); )
72                  {
73                      Artifact attachedArtifact = (Artifact) it.next();
74                      installer.install( attachedArtifact.getFile(), attachedArtifact, localRepository );
75                  }
76              }
77          }
78          catch ( Exception e )
79          {
80              throw new MojoExecutionException( "Failed to install artifacts", e );
81          }
82      }
83  
84  }