Improved usage of maven-artifact-transfer component:
 o pom.xml
   o Remove maven-model dependency.
   o Added slf4j-api (provided), slf4j-nop in test scope.
 o InstallMojo
   Using ProjectInstaller and using ProjectInstallerRequest instead
   of InstallRequest.


git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1761346 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index dd434d8..ae1e867 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,25 +1,26 @@
 <?xml version='1.0' encoding='UTF-8'?>
 
 <!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
 
   http://www.apache.org/licenses/LICENSE-2.0
 
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
 -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
   <parent>
@@ -68,11 +69,11 @@
       <artifactId>maven-plugin-api</artifactId>
       <version>${mavenVersion}</version>
     </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-model</artifactId>
-      <version>${mavenVersion}</version>
-    </dependency>
+    <!-- <dependency> -->
+    <!-- <groupId>org.apache.maven</groupId> -->
+    <!-- <artifactId>maven-model</artifactId> -->
+    <!-- <version>${mavenVersion}</version> -->
+    <!-- </dependency> -->
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-artifact</artifactId>
@@ -128,7 +129,19 @@
       <version>1.9.5</version>
       <scope>test</scope>
     </dependency>
-    
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.5</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-nop</artifactId>
+      <version>1.7.5</version>
+      <scope>test</scope>
+    </dependency>
+
     <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
diff --git a/src/main/java/org/apache/maven/plugin/install/InstallMojo.java b/src/main/java/org/apache/maven/plugin/install/InstallMojo.java
index f5cc9f7..f6fab8f 100644
--- a/src/main/java/org/apache/maven/plugin/install/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugin/install/InstallMojo.java
@@ -19,23 +19,24 @@
  * under the License.
  */
 
-import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.artifact.ProjectArtifact;
-import org.apache.maven.project.artifact.ProjectArtifactMetadata;
+import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.shared.artifact.install.ArtifactInstallerException;
+import org.apache.maven.shared.project.NoFileAssignedException;
+import org.apache.maven.shared.project.install.ProjectInstaller;
+import org.apache.maven.shared.project.install.ProjectInstallerRequest;
 
 /**
  * Installs the project's main artifact, and any other artifacts attached by other plugins in the lifecycle, to the
@@ -55,8 +56,8 @@
      */
     private static final AtomicInteger READYPROJECTSCOUTNER = new AtomicInteger();
 
-    private static final List<InstallRequest> INSTALLREQUESTS =
-        Collections.synchronizedList( new ArrayList<InstallRequest>() );
+    private static final List<ProjectInstallerRequest> INSTALLREQUESTS =
+        Collections.synchronizedList( new ArrayList<ProjectInstallerRequest>() );
 
     /**
      */
@@ -65,7 +66,7 @@
 
     @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
     private List<MavenProject> reactorProjects;
-    
+
     /**
      * Whether every project should be installed during its own install-phase or at the end of the multimodule build. If
      * set to {@code true} and the build fails, none of the reactor projects is installed.
@@ -85,8 +86,11 @@
     @Parameter( property = "maven.install.skip", defaultValue = "false" )
     private boolean skip;
 
+    @Component
+    private ProjectInstaller installer;
+
     public void execute()
-        throws MojoExecutionException
+        throws MojoExecutionException, MojoFailureException
     {
         boolean addedInstallRequest = false;
         if ( skip )
@@ -96,17 +100,17 @@
         else
         {
             // CHECKSTYLE_OFF: LineLength
-            InstallRequest currentExecutionInstallRequest =
-                new InstallRequest().setProject( project ).setCreateChecksum( createChecksum ).setUpdateReleaseInfo( updateReleaseInfo );
+            ProjectInstallerRequest projectInstallerRequest =
+                new ProjectInstallerRequest().setProject( project ).setCreateChecksum( createChecksum ).setUpdateReleaseInfo( updateReleaseInfo );
             // CHECKSTYLE_ON: LineLength
 
             if ( !installAtEnd )
             {
-                installProject( currentExecutionInstallRequest );
+                installProject( session.getProjectBuildingRequest(), projectInstallerRequest );
             }
             else
             {
-                INSTALLREQUESTS.add( currentExecutionInstallRequest );
+                INSTALLREQUESTS.add( projectInstallerRequest );
                 addedInstallRequest = true;
             }
         }
@@ -118,96 +122,38 @@
             {
                 while ( !INSTALLREQUESTS.isEmpty() )
                 {
-                    installProject( INSTALLREQUESTS.remove( 0 ) );
+                    installProject( session.getProjectBuildingRequest(), INSTALLREQUESTS.remove( 0 ) );
                 }
             }
         }
         else if ( addedInstallRequest )
         {
             getLog().info( "Installing " + project.getGroupId() + ":" + project.getArtifactId() + ":"
-                               + project.getVersion() + " at end" );
+                + project.getVersion() + " at end" );
         }
     }
 
-    private void installProject( InstallRequest request )
-        throws MojoExecutionException
+    private void installProject( ProjectBuildingRequest pbr, ProjectInstallerRequest pir )
+        throws MojoFailureException, MojoExecutionException
     {
-        MavenProject project = request.getProject();
-        boolean createChecksum = request.isCreateChecksum();
-        boolean updateReleaseInfo = request.isUpdateReleaseInfo();
-
-        Artifact artifact = project.getArtifact();
-        String packaging = project.getPackaging();
-        File pomFile = project.getFile();
-
-        List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
-
-        // TODO: push into transformation
-        boolean isPomArtifact = "pom".equals( packaging );
-
-        ProjectArtifactMetadata metadata;
-
-        if ( updateReleaseInfo )
-        {
-            artifact.setRelease( true );
-        }
-
         try
         {
-            Collection<File> metadataFiles = new LinkedHashSet<File>();
-
-            if ( isPomArtifact )
-            {
-//                installer.install( pomFile, artifact, localRepository );
-                installer.install( session.getProjectBuildingRequest(),
-                                   Collections.<Artifact>singletonList( new ProjectArtifact( project ) ) );
-                installChecksums( artifact, createChecksum );
-                addMetaDataFilesForArtifact( artifact, metadataFiles, createChecksum );
-            }
-            else
-            {
-                metadata = new ProjectArtifactMetadata( artifact, pomFile );
-                artifact.addMetadata( metadata );
-
-                File file = artifact.getFile();
-
-                // Here, we have a temporary solution to MINSTALL-3 (isDirectory() is true if it went through compile
-                // but not package). We are designing in a proper solution for Maven 2.1
-                if ( file != null && file.isFile() )
-                {
-//                    installer.install( file, artifact, localRepository );
-                    installer.install( session.getProjectBuildingRequest(), Collections.singletonList( artifact ) );
-                    installChecksums( artifact, createChecksum );
-                    addMetaDataFilesForArtifact( artifact, metadataFiles, createChecksum );
-                }
-                else if ( !attachedArtifacts.isEmpty() )
-                {
-                    throw new MojoExecutionException( "The packaging plugin for this project did not assign "
-                                   + "a main file to the project but it has attachments. Change packaging to 'pom'." );
-                }
-                else
-                {
-                    // CHECKSTYLE_OFF: LineLength
-                    throw new MojoExecutionException(
-                                                      "The packaging for this project did not assign a file to the build artifact" );
-                    // CHECKSTYLE_ON: LineLength
-                }
-            }
-
-            for ( Artifact attached : attachedArtifacts )
-            {
-//                installer.install( attached.getFile(), attached, localRepository );
-                installer.install( session.getProjectBuildingRequest(), Collections.singletonList( attached ) );
-                installChecksums( attached, createChecksum );
-                addMetaDataFilesForArtifact( attached, metadataFiles, createChecksum );
-            }
-
-            installChecksums( metadataFiles );
+            installer.installProject( session.getProjectBuildingRequest(), pir,
+                                      localRepository );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoFailureException( "IOException", e );
         }
         catch ( ArtifactInstallerException e )
         {
-            throw new MojoExecutionException( e.getMessage(), e );
+            throw new MojoExecutionException( "ArtifactInstallerException", e );
         }
+        catch ( NoFileAssignedException e )
+        {
+            throw new MojoExecutionException( "NoFileAssignedException", e );
+        }
+
     }
 
     public void setSkip( boolean skip )
diff --git a/src/main/java/org/apache/maven/plugin/install/InstallRequest.java b/src/main/java/org/apache/maven/plugin/install/InstallRequest.java
deleted file mode 100644
index 4234d4c..0000000
--- a/src/main/java/org/apache/maven/plugin/install/InstallRequest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.apache.maven.plugin.install;

-

-/*

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements.  See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership.  The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License.  You may obtain a copy of the License at

- *

- *  http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied.  See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-import org.apache.maven.project.MavenProject;

-

-/**

- * 

- * @author Robert Scholte

- * @since 2.5.1

- */

-public class InstallRequest

-{

-    // From AbstractInstallMojo

-    

-    private boolean createChecksum;

-    

-    private boolean updateReleaseInfo;

-    

-    // From InstallMojo

-    

-    private MavenProject project;

-    

-    /**

-     * @return the createChecksum

-     */

-    public boolean isCreateChecksum()

-    {

-        return createChecksum;

-    }

-

-    /**

-     * @param createChecksum the createChecksum to set

-     */

-    public InstallRequest setCreateChecksum( boolean createChecksum )

-    {

-        this.createChecksum = createChecksum;

-        return this;

-    }

-

-    /**

-     * @return the updateReleaseInfo

-     */

-    public boolean isUpdateReleaseInfo()

-    {

-        return updateReleaseInfo;

-    }

-

-    /**

-     * @param updateReleaseInfo the updateReleaseInfo to set

-     */

-    public InstallRequest setUpdateReleaseInfo( boolean updateReleaseInfo )

-    {

-        this.updateReleaseInfo = updateReleaseInfo;

-        return this;

-    }

-

-    /**

-     * @return the project

-     */

-    public MavenProject getProject()

-    {

-        return project;

-    }

-

-    /**

-     * @param project the project to set

-     */

-    public InstallRequest setProject( MavenProject project )

-    {

-        this.project = project;

-        return this;

-    }

-

-}

diff --git a/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java b/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
index 5a53f85..9c717d5 100644
--- a/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
+++ b/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
@@ -26,6 +26,7 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.execution.MavenSession;
@@ -127,7 +128,7 @@
         setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
         setVariableValueToObject( mojo, "session", createMavenSession() );
 
-        List attachedArtifacts = project.getAttachedArtifacts();
+        List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
 
         mojo.execute();