You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/05/10 11:30:29 UTC

svn commit: r655034 - in /maven/plugins/trunk/maven-invoker-plugin: ./ src/main/java/org/apache/maven/plugin/invoker/ src/site/apt/ src/site/apt/examples/

Author: bentmann
Date: Sat May 10 02:30:28 2008
New Revision: 655034

URL: http://svn.apache.org/viewvc?rev=655034&view=rev
Log:
[MINVOKER-22] Add feature to install plugin to a local repository.

o Refactored functionality into distinct mojo

Added:
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java   (with props)
Modified:
    maven/plugins/trunk/maven-invoker-plugin/pom.xml
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
    maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/install-artifacts.apt
    maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt

Modified: maven/plugins/trunk/maven-invoker-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/pom.xml?rev=655034&r1=655033&r2=655034&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-invoker-plugin/pom.xml Sat May 10 02:30:28 2008
@@ -71,6 +71,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-settings</artifactId>
       <version>2.0</version>
     </dependency>

Added: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java?rev=655034&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java Sat May 10 02:30:28 2008
@@ -0,0 +1,176 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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 java.io.File;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.installer.ArtifactInstallationException;
+import org.apache.maven.artifact.installer.ArtifactInstaller;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Installs the project artifacts into the local repository as a preparation to run the integration tests.
+ * 
+ * @goal install
+ * @phase pre-integration-test
+ * @since 1.2
+ * 
+ * @author Paul Gier
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class InstallMojo
+    extends AbstractMojo
+{
+
+    /**
+     * Maven artifact install component to copy artifacts to the local repository.
+     * 
+     * @component
+     */
+    private ArtifactInstaller installer;
+
+    /**
+     * The component used to create artifacts.
+     * 
+     * @component
+     */
+    private ArtifactFactory artifactFactory;
+
+    /**
+     * The component used to create artifacts.
+     * 
+     * @component
+     */
+    private ArtifactRepositoryFactory repositoryFactory;
+
+    /**
+     * @parameter expression="${localRepository}"
+     * @required
+     * @readonly
+     */
+    protected ArtifactRepository localRepository;
+
+    /**
+     * The path to the local repository into which the project artifacts should be installed for the integration tests.
+     * If not set, the regular local repository will be used.
+     * 
+     * @parameter expression="${invoker.localRepositoryPath}"
+     */
+    private File localRepositoryPath;
+
+    /**
+     * The current Maven project.
+     * 
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+
+    /**
+     * Performs this mojo's tasks.
+     */
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        ArtifactRepository testRepository = createTestRepository();
+        installProjectArtifacts( testRepository );
+    }
+
+    /**
+     * Installs the main project artifact and any attached artifacts to the local repository.
+     * 
+     * @param testRepository The local repository to install the artifacts into, must not be <code>null</code>.
+     * @throws MojoExecutionException If any artifact could not be installed.
+     */
+    private void installProjectArtifacts( ArtifactRepository testRepository )
+        throws MojoExecutionException
+    {
+        try
+        {
+            // Install the pom
+            Artifact pomArtifact =
+                artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(),
+                                                null, "pom" );
+            installer.install( project.getFile(), pomArtifact, testRepository );
+
+            // Install the main project artifact
+            installer.install( project.getArtifact().getFile(), project.getArtifact(), testRepository );
+
+            // Install any attached project artifacts
+            Collection attachedArtifacts = project.getAttachedArtifacts();
+            for ( Iterator artifactIter = attachedArtifacts.iterator(); artifactIter.hasNext(); )
+            {
+                Artifact theArtifact = (Artifact) artifactIter.next();
+                installer.install( theArtifact.getFile(), theArtifact, testRepository );
+            }
+        }
+        catch ( ArtifactInstallationException e )
+        {
+            throw new MojoExecutionException( "Failed to install project artifacts", e );
+        }
+    }
+
+    /**
+     * Creates the local repository for the integration tests.
+     * 
+     * @return The local repository for the integration tests, never <code>null</code>.
+     * @throws MojoExecutionException If the repository could not be created.
+     */
+    private ArtifactRepository createTestRepository()
+        throws MojoExecutionException
+    {
+        ArtifactRepository testRepository = localRepository;
+
+        if ( localRepositoryPath != null )
+        {
+            try
+            {
+                if ( !localRepositoryPath.exists() )
+                {
+                    localRepositoryPath.mkdirs();
+                }
+
+                testRepository =
+                    repositoryFactory.createArtifactRepository( "it-repo", localRepositoryPath.toURL().toString(),
+                                                                localRepository.getLayout(),
+                                                                localRepository.getSnapshots(),
+                                                                localRepository.getReleases() );
+            }
+            catch ( Exception e )
+            {
+                throw new MojoExecutionException( "Failed to create local repository", e );
+            }
+        }
+
+        return testRepository;
+    }
+
+}

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java?rev=655034&r1=655033&r2=655034&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java Sat May 10 02:30:28 2008
@@ -28,7 +28,6 @@
 import java.io.PrintStream;
 import java.io.Reader;
 import java.io.Writer;
-import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -39,12 +38,6 @@
 import java.util.StringTokenizer;
 import java.util.TreeSet;
 
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.installer.ArtifactInstallationException;
-import org.apache.maven.artifact.installer.ArtifactInstaller;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -85,41 +78,13 @@
  *
  * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
  * @author <a href="mailto:jdcasey@apache.org">John Casey</a>
+ * @version $Id$
  */
 public class InvokerMojo
     extends AbstractMojo
 {
-    /**
-     * Maven artifact install component to copy artifacts to the local repository.
-     * 
-     * @component
-     */
-    protected ArtifactInstaller installer;
-
-    /**
-     * Used to create artifacts
-     *
-     * @component
-     */
-    private ArtifactFactory artifactFactory;
-
-    /**
-     * Used to create artifacts
-     *
-     * @component
-     */
-    private ArtifactRepositoryFactory artifactRepositoryFactory;
 
     /**
-     * Flag to determine if the project artifact(s) should be installed to the
-     * local repository.
-     * 
-     * @parameter default-value="false"
-     * @since 1.2
-     */
-    private boolean installProjectArtifacts;
-    
-    /**
      * Flag used to suppress certain invocations. This is useful in tailoring the
      * build using profiles.
      *
@@ -146,13 +111,6 @@
     private boolean streamLogs;
 
     /**
-     * @parameter expression="${localRepository}"
-     * @required
-     * @readonly
-     */
-    protected ArtifactRepository localRepository;
-
-    /**
      * The local repository for caching artifacts.
      *
      * @parameter expression="${invoker.localRepositoryPath}"
@@ -425,11 +383,6 @@
             return;
         }
 
-        if ( installProjectArtifacts )
-        {
-            installProjectArtifacts();
-        }
-        
         String[] includedPoms;
         if ( pom != null )
         {
@@ -555,60 +508,6 @@
         }
     }
 
-    /**
-     * Install the main project artifact and any attached artifacts to the local repository.
-     * 
-     * @throws MojoExecutionException
-     */
-    private void installProjectArtifacts()
-        throws MojoExecutionException
-    {
-        ArtifactRepository integrationTestRepository = localRepository;
-        
-        try
-        {
-            if ( localRepositoryPath != null )
-            {
-                if ( ! localRepositoryPath.exists() )
-                {
-                    localRepositoryPath.mkdirs();
-                }
-                integrationTestRepository =
-                    artifactRepositoryFactory.createArtifactRepository( "it-repo",
-                                                                        localRepositoryPath.toURL().toString(),
-                                                                        localRepository.getLayout(),
-                                                                        localRepository.getSnapshots(),
-                                                                        localRepository.getReleases() );
-            }
-                        
-            // Install the pom
-            Artifact pomArtifact = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), 
-                                                          project.getVersion(), null, "pom" );
-            installer.install( project.getFile(), pomArtifact, integrationTestRepository );
-            
-            // Install the main project artifact
-            installer.install( project.getArtifact().getFile(), project.getArtifact(), integrationTestRepository );
-            
-            // Install any attached project artifacts
-            List attachedArtifacts = project.getAttachedArtifacts();
-            Iterator artifactIter = attachedArtifacts.iterator();
-            while ( artifactIter.hasNext() )
-            {
-                Artifact theArtifact = (Artifact)artifactIter.next();
-                installer.install( theArtifact.getFile(), theArtifact, integrationTestRepository );
-            }
-        }
-        catch ( MalformedURLException e )
-        {
-            throw new MojoExecutionException( "MalformedURLException: " + e.getMessage(), e );
-        }
-        catch ( ArtifactInstallationException e )
-        {
-            throw new MojoExecutionException( "ArtifactInstallationException: " + e.getMessage(), e );
-        }
-        
-    }
-
     private void cloneProjects( String[] includedPoms )
         throws IOException
     {

Modified: maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/install-artifacts.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/install-artifacts.apt?rev=655034&r1=655033&r2=655034&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/install-artifacts.apt (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/install-artifacts.apt Sat May 10 02:30:28 2008
@@ -8,8 +8,8 @@
 
 Installing Artifacts Example
 
-  The following example shows a plugin configuration with the <<<\<installProjectArtifacts\>>>> 
-  parameter set to <<<true>>>.  This will cause the project artifact(s) to be installed to the local 
+  The following example shows a plugin configuration using the <<<{{{../install-mojo.html}invoker:install}}>>> 
+  goal.  This will cause the project artifact(s) to be installed to the local 
   repository before executing the projects.  This can be helpful if you 
   want to build you project and test the new artifacts artifact in a single step instead of 
   installing first and then running tests.
@@ -25,13 +25,12 @@
         <executions>
           <execution>
             <id>integration-test</id>
-            <phase>integration-test</phase>
             <goals>
+              <goal>install</goal>
               <goal>run</goal>
             </goals>
             <configuration>
               <localRepositoryPath>target/local-repo</localRepositoryPath>
-              <installProjectArtifacts>true</installProjectArtifacts>
               <projectsDirectory>src/it</projectsDirectory>
             </configuration>
           </execution>

Modified: maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt?rev=655034&r1=655033&r2=655034&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt Sat May 10 02:30:28 2008
@@ -14,6 +14,11 @@
   
 * Goals Overview
 
+  The Invoker Plugin has two goals:
+
+  * {{{install-mojo.html}invoker:install}} copies the project artifacts into the local repository to prepare the
+    execution of the integration tests.
+
   * {{{run-mojo.html}invoker:run}} runs a set of Maven projects in a directory and verifies the result.
 
   []