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/30 22:31:18 UTC

svn commit: r885587 - in /maven/core-integration-testing/trunk: core-it-suite/src/test/java/org/apache/maven/it/ core-it-suite/src/test/resources/mng-4474/ core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin...

Author: bentmann
Date: Mon Nov 30 21:31:17 2009
New Revision: 885587

URL: http://svn.apache.org/viewvc?rev=885587&view=rev
Log:
[MNG-4471] [regression] Wagon manager does not respect instantiation strategy of wagons

o Added IT

Added:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java   (with props)
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4474/
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4474/pom.xml   (with props)
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java   (with props)
Modified:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
    maven/core-integration-testing/trunk/core-it-support/core-it-wagon/src/main/java/org/apache/maven/wagon/providers/coreit/CoreItWagon.java

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java?rev=885587&r1=885586&r2=885587&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java (original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java Mon Nov 30 21:31:17 2009
@@ -85,6 +85,7 @@
         // suite.addTestSuite( MavenIT0109ReleaseUpdateTest.class );
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
 
+        suite.addTestSuite( MavenITmng4474PerLookupWagonInstantiationTest.class );
         suite.addTestSuite( MavenITmng4470AuthenticatedDeploymentToProxyTest.class );
         suite.addTestSuite( MavenITmng4469AuthenticatedDeploymentToCustomRepoTest.class );
         suite.addTestSuite( MavenITmng4465PluginPrefixFromLocalCacheOfDownRepoTest.class );

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java?rev=885587&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java (added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java Mon Nov 30 21:31:17 2009
@@ -0,0 +1,65 @@
+package org.apache.maven.it;
+
+/*
+ * 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.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4474">MNG-4474</a>.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class MavenITmng4474PerLookupWagonInstantiationTest
+    extends AbstractMavenIntegrationTestCase
+{
+
+    public MavenITmng4474PerLookupWagonInstantiationTest()
+    {
+        super( "[2.0.5,3.0-alpha-1),[3.0-alpha-6,)" );
+    }
+
+    /**
+     * Verify that the wagon manager does not erroneously cache/reuse wagon instances that use per-lookup instantiation.
+     */
+    public void testit()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4474" );
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        Properties props = verifier.loadProperties( "target/wagon.properties" );
+        String hash1 = props.getProperty( "coreit://one.hash" );
+        assertNotNull( hash1 );
+        String hash2 = props.getProperty( "coreit://two.hash" );
+        assertNotNull( hash2 );
+        assertFalse( hash1.equals( hash2 ) );
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4474/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4474/pom.xml?rev=885587&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4474/pom.xml (added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4474/pom.xml Mon Nov 30 21:31:17 2009
@@ -0,0 +1,67 @@
+<?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
+
+  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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng4474</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: MNG-4474</name> 
+  <description>
+    Verify that the wagon manager does not erroneously cache/reuse wagon instances that use per-lookup instantiation.
+  </description>
+
+  <build>
+    <extensions>
+      <extension>
+        <groupId>org.apache.maven.its</groupId>
+        <artifactId>core-it-wagon</artifactId>
+        <version>2.1-SNAPSHOT</version>
+      </extension>
+    </extensions>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.its.plugins</groupId>
+        <artifactId>maven-it-plugin-uses-wagon</artifactId>
+        <version>2.1-SNAPSHOT</version>
+        <configuration>
+          <outputFile>target/wagon.properties</outputFile>
+          <urls>
+            <url>coreit://one</url>
+            <url>coreit://two</url>
+          </urls>
+        </configuration>
+        <executions>
+          <execution>
+            <id>test</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>lookup-wagon</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4474/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4474/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java?rev=885587&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java (added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java Mon Nov 30 21:31:17 2009
@@ -0,0 +1,134 @@
+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.manager.WagonManager;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.repository.Repository;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Properties;
+
+/**
+ * Loads resources from a class loader used to load a wagon provider. The wagon is merely used to access the extension
+ * class loader it came from which is otherwise not accessible to a plugin.
+ * 
+ * @goal lookup-wagon
+ * @phase validate
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class LookupWagonMojo
+    extends AbstractMojo
+{
+
+    /**
+     * The Wagon manager used to retrieve wagon providers.
+     * 
+     * @component
+     */
+    private WagonManager wagonManager;
+
+    /**
+     * The path to the properties file used to track the results of the wagon lookups.
+     * 
+     * @parameter expression="${wagon.outputFile}"
+     */
+    private File outputFile;
+
+    /**
+     * The URLs for which to look up wagons.
+     * 
+     * @parameter
+     */
+    private String[] urls;
+
+    /**
+     * Runs this mojo.
+     * 
+     * @throws MojoFailureException If the attached file has not been set.
+     */
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        Properties loaderProperties = new Properties();
+
+        if ( urls != null )
+        {
+            for ( int i = 0; i < urls.length; i++ )
+            {
+                String url = urls[i];
+                getLog().info( "[MAVEN-CORE-IT-LOG] Looking up wagon for URL " + url );
+
+                try
+                {
+                    Repository repo = new Repository( "repo-" + i, url );
+                    Wagon wagon = wagonManager.getWagon( repo );
+                    getLog().info( "[MAVEN-CORE-IT-LOG]   " + wagon );
+
+                    loaderProperties.setProperty( url + ".hash", Integer.toString( System.identityHashCode( wagon ) ) );
+                    loaderProperties.setProperty( url + ".class", wagon.getClass().getName() );
+                }
+                catch ( Exception e )
+                {
+                    getLog().warn( "[MAVEN-CORE-IT-LOG] Failed to lookp up wagon for URL " + url, e );
+                }
+            }
+        }
+
+        getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + outputFile );
+
+        OutputStream out = null;
+        try
+        {
+            outputFile.getParentFile().mkdirs();
+            out = new FileOutputStream( outputFile );
+            loaderProperties.store( out, "MAVEN-CORE-IT-LOG" );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Output file could not be created: " + outputFile, e );
+        }
+        finally
+        {
+            if ( out != null )
+            {
+                try
+                {
+                    out.close();
+                }
+                catch ( IOException e )
+                {
+                    // just ignore
+                }
+            }
+        }
+
+        getLog().info( "[MAVEN-CORE-IT-LOG] Created output file " + outputFile );
+    }
+
+}

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

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

Modified: maven/core-integration-testing/trunk/core-it-support/core-it-wagon/src/main/java/org/apache/maven/wagon/providers/coreit/CoreItWagon.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-wagon/src/main/java/org/apache/maven/wagon/providers/coreit/CoreItWagon.java?rev=885587&r1=885586&r2=885587&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-wagon/src/main/java/org/apache/maven/wagon/providers/coreit/CoreItWagon.java (original)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-wagon/src/main/java/org/apache/maven/wagon/providers/coreit/CoreItWagon.java Mon Nov 30 21:31:17 2009
@@ -41,7 +41,7 @@
 /**
  * Shamelessly copied from ScpExternalWagon in this same project...
  *
- * @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="coreit"
+ * @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="coreit" instantiation-strategy="per-lookup"
  */
 public class CoreItWagon
     extends AbstractWagon