From e45c1a3bed068a531e4609200935a7adc9ec1c46 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 30 Nov 2009 21:31:17 +0000 Subject: [PATCH] [MNG-4471] [regression] Wagon manager does not respect instantiation strategy of wagons o Added IT git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@885587 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/it/IntegrationTestSuite.java | 1 + ...ng4474PerLookupWagonInstantiationTest.java | 65 +++++++++ .../src/test/resources/mng-4474/pom.xml | 67 +++++++++ .../maven/plugin/coreit/LookupWagonMojo.java | 134 ++++++++++++++++++ .../wagon/providers/coreit/CoreItWagon.java | 2 +- 5 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java create mode 100644 its/core-it-suite/src/test/resources/mng-4474/pom.xml create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java index 5fd2cfb972..36ee1bdc68 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java @@ -85,6 +85,7 @@ public class IntegrationTestSuite // 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 ); diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java new file mode 100644 index 0000000000..f102ba2a91 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4474PerLookupWagonInstantiationTest.java @@ -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 MNG-4474. + * + * @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 ) ); + } + +} diff --git a/its/core-it-suite/src/test/resources/mng-4474/pom.xml b/its/core-it-suite/src/test/resources/mng-4474/pom.xml new file mode 100644 index 0000000000..8af597cb04 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-4474/pom.xml @@ -0,0 +1,67 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4474 + test + 1.0 + jar + + Maven Integration Test :: MNG-4474 + + Verify that the wagon manager does not erroneously cache/reuse wagon instances that use per-lookup instantiation. + + + + + + org.apache.maven.its + core-it-wagon + 2.1-SNAPSHOT + + + + + org.apache.maven.its.plugins + maven-it-plugin-uses-wagon + 2.1-SNAPSHOT + + target/wagon.properties + + coreit://one + coreit://two + + + + + test + validate + + lookup-wagon + + + + + + + diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java new file mode 100644 index 0000000000..606cd8b97d --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/LookupWagonMojo.java @@ -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 ); + } + +} diff --git a/its/core-it-support/core-it-wagon/src/main/java/org/apache/maven/wagon/providers/coreit/CoreItWagon.java b/its/core-it-support/core-it-wagon/src/main/java/org/apache/maven/wagon/providers/coreit/CoreItWagon.java index 6ad8cce97a..291efffa77 100644 --- a/its/core-it-support/core-it-wagon/src/main/java/org/apache/maven/wagon/providers/coreit/CoreItWagon.java +++ b/its/core-it-support/core-it-wagon/src/main/java/org/apache/maven/wagon/providers/coreit/CoreItWagon.java @@ -41,7 +41,7 @@ import org.apache.maven.wagon.resource.Resource; /** * 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