[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
This commit is contained in:
Benjamin Bentmann 2009-11-30 21:31:17 +00:00
parent 84f6b19954
commit e45c1a3bed
5 changed files with 268 additions and 1 deletions

View File

@ -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 );

View File

@ -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 ) );
}
}

View File

@ -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>

View File

@ -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 );
}
}

View File

@ -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