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 2009/11/11 16:45:06 UTC

svn commit: r834918 - in /maven/core-integration-testing/trunk: core-it-suite/src/test/java/org/apache/maven/it/ core-it-suite/src/test/resources/mng-4412/ core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/c...

Author: bentmann
Date: Wed Nov 11 15:45:06 2009
New Revision: 834918

URL: http://svn.apache.org/viewvc?rev=834918&view=rev
Log:
[MNG-4412] Make legacy entry points to repository system pick offline mode from session

o Extended IT

Added:
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/CollectMojo.java   (with props)
Modified:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4412OfflineModeInPluginTest.java
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4412/pom.xml

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4412OfflineModeInPluginTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4412OfflineModeInPluginTest.java?rev=834918&r1=834917&r2=834918&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4412OfflineModeInPluginTest.java (original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4412OfflineModeInPluginTest.java Wed Nov 11 15:45:06 2009
@@ -42,7 +42,7 @@
      * Verify that plugins using the 2.x style artifact resolver directly are subject to the offline mode of the
      * current Maven session.
      */
-    public void testit()
+    public void testitResolver()
         throws Exception
     {
         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4412" );
@@ -52,9 +52,11 @@
         verifier.deleteDirectory( "target" );
         verifier.deleteArtifacts( "org.apache.maven.its.mng4412" );
         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
+        verifier.getCliOptions().add( "-Presolver" );
         verifier.getCliOptions().add( "--offline" );
         verifier.getCliOptions().add( "-s" );
         verifier.getCliOptions().add( "settings.xml" );
+        verifier.setLogFileName( "log-resolver.txt" );
         try
         {
             verifier.executeGoal( "validate" );
@@ -71,4 +73,30 @@
         }
     }
 
+    /**
+     * Verify that plugins using the 2.x style artifact collector directly are subject to the offline mode of the
+     * current Maven session.
+     */
+    public void testitCollector()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4412" );
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        verifier.deleteArtifacts( "org.apache.maven.its.mng4412" );
+        verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
+        verifier.getCliOptions().add( "-Pcollector" );
+        verifier.getCliOptions().add( "--offline" );
+        verifier.getCliOptions().add( "-s" );
+        verifier.getCliOptions().add( "settings.xml" );
+        verifier.setLogFileName( "log-collector.txt" );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        verifier.assertArtifactNotPresent( "org.apache.maven.its.mng4412", "dep", "0.1", "pom" );
+    }
+
 }

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4412/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4412/pom.xml?rev=834918&r1=834917&r2=834918&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4412/pom.xml (original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4412/pom.xml Wed Nov 11 15:45:06 2009
@@ -29,35 +29,70 @@
 
   <name>Maven Integration Test :: MNG-4412</name>
   <description>
-    Verify that plugins using the 2.x style artifact resolver directly are subject to the offline mode of the
-    current Maven session.
+    Verify that plugins using the 2.x style artifact resolver/collector directly are subject to the offline mode of
+    the current Maven session.
   </description>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.its.plugins</groupId>
-        <artifactId>maven-it-plugin-artifact</artifactId>
-        <version>2.1-SNAPSHOT</version>
-        <executions>
-          <execution>
-            <id>test</id>
-            <phase>validate</phase>
-            <goals>
-              <goal>resolve</goal>
-            </goals>
-            <configuration>
-              <dependencies>
-                <dependency>
-                  <groupId>org.apache.maven.its.mng4412</groupId>
-                  <artifactId>dep</artifactId>
-                  <version>0.1</version>
-                </dependency>
-              </dependencies>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
+  <profiles>
+    <profile>
+      <id>resolver</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.its.plugins</groupId>
+            <artifactId>maven-it-plugin-artifact</artifactId>
+            <version>2.1-SNAPSHOT</version>
+            <executions>
+              <execution>
+                <id>test</id>
+                <phase>validate</phase>
+                <goals>
+                  <goal>resolve</goal>
+                </goals>
+                <configuration>
+                  <dependencies>
+                    <dependency>
+                      <groupId>org.apache.maven.its.mng4412</groupId>
+                      <artifactId>dep</artifactId>
+                      <version>0.1</version>
+                    </dependency>
+                  </dependencies>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
+      <id>collector</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.its.plugins</groupId>
+            <artifactId>maven-it-plugin-artifact</artifactId>
+            <version>2.1-SNAPSHOT</version>
+            <executions>
+              <execution>
+                <id>test</id>
+                <phase>validate</phase>
+                <goals>
+                  <goal>collect</goal>
+                </goals>
+                <configuration>
+                  <dependencies>
+                    <dependency>
+                      <groupId>org.apache.maven.its.mng4412</groupId>
+                      <artifactId>dep</artifactId>
+                      <version>0.1</version>
+                    </dependency>
+                  </dependencies>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
 </project>

Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/CollectMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/CollectMojo.java?rev=834918&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/CollectMojo.java (added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/CollectMojo.java Wed Nov 11 15:45:06 2009
@@ -0,0 +1,137 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * 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.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Collects user-specified artifacts. This mimics in part the Maven Assembly Plugin.
+ * 
+ * @goal collect
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class CollectMojo
+    extends AbstractMojo
+{
+
+    /**
+     * The local repository.
+     * 
+     * @parameter default-value="${localRepository}"
+     * @readonly
+     * @required
+     */
+    private ArtifactRepository localRepository;
+
+    /**
+     * The remote repositories of the current Maven project.
+     * 
+     * @parameter default-value="${project.remoteArtifactRepositories}"
+     * @readonly
+     * @required
+     */
+    private List remoteRepositories;
+
+    /**
+     * The artifact collector.
+     * 
+     * @component
+     */
+    private ArtifactCollector collector;
+
+    /**
+     * The artifact factory.
+     * 
+     * @component
+     */
+    private ArtifactFactory factory;
+
+    /**
+     * The metadata source.
+     * 
+     * @component
+     */
+    private ArtifactMetadataSource metadataSource;
+
+    /**
+     * The dependencies to resolve.
+     * 
+     * @parameter
+     */
+    private Dependency[] dependencies;
+
+    /**
+     * Runs this mojo.
+     * 
+     * @throws MojoFailureException If the artifact file has not been set.
+     */
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        getLog().info( "[MAVEN-CORE-IT-LOG] Collecting artifacts" );
+
+        try
+        {
+            Artifact origin = factory.createArtifact( "it", "it", "0.1", null, "pom" );
+
+            Set artifacts = new LinkedHashSet();
+
+            if ( dependencies != null )
+            {
+                for ( int i = 0; i < dependencies.length; i++ )
+                {
+                    Dependency dependency = dependencies[i];
+
+                    Artifact artifact =
+                        factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
+                                                              dependency.getVersion(), dependency.getType(),
+                                                              dependency.getClassifier() );
+
+                    artifacts.add( artifact );
+
+                    getLog().info( "[MAVEN-CORE-IT-LOG] Collecting " + artifact.getId() );
+                }
+            }
+
+            collector.collect( artifacts, origin, localRepository, remoteRepositories, metadataSource, null,
+                               Collections.EMPTY_LIST );
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Failed to collect artifacts: " + e.getMessage(), e );
+        }
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/CollectMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/CollectMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision