[MNG-5280] Inconsistent order of repositories and pluginRepositories from profiles in settings (regression Maven 3)

Submitted by: Anders Hammar

* Applied without change

* This is the integration test that verifies the bug identified in MNG-5280.

* I have tested that the integration test passes for Maven 2.x and fails with 3.0.3 and 3.0.4

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@1373759 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Connolly 2012-08-16 08:50:24 +00:00
parent b07231ab33
commit 477138ef40
6 changed files with 425 additions and 0 deletions

View File

@ -106,6 +106,7 @@ public class IntegrationTestSuite
// -------------------------------------------------------------------------------------------------------------
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
suite.addTestSuite( MavenITmng5280SettingsProfilesRepositoriesOrderTest.class );
suite.addTestSuite( MavenITmng5224InjectedSettings.class );
suite.addTestSuite( MavenITmng5214DontMapWsdlToJar.class );
suite.addTestSuite( MavenITmng5137ReactorResolutionInForkedBuildTest.class );

View File

@ -0,0 +1,262 @@
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 java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.maven.it.util.ResourceExtractor;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
/**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-5280">MNG-5280</a>.
*
* @author Anders Hammar
*/
public class MavenITmng5280SettingsProfilesRepositoriesOrderTest
extends AbstractMavenIntegrationTestCase
{
private File testDir;
private Server server;
int httpPort;
public MavenITmng5280SettingsProfilesRepositoriesOrderTest()
{
super( ALL_MAVEN_VERSIONS );
}
public void setUp()
throws Exception
{
super.setUp();
testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5280" );
server = new Server( 0 );
server.start();
httpPort = server.getConnectors()[0].getLocalPort();
}
protected void tearDown()
throws Exception
{
if ( server != null )
{
server.stop();
server = null;
}
super.tearDown();
}
/**
* Verify that the repositories are used in the reversed order of definition in settings.xml.
*/
public void testRepositoriesOrder()
throws Exception
{
RepoHandler repoHandler = new RepoHandler();
server.setHandler( repoHandler );
Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng5280" );
Properties filterProps = verifier.newDefaultFilterProperties();
filterProps.setProperty( "@httpserver.port@", Integer.toString( httpPort ) );
verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
verifier.getCliOptions().add( "--settings" );
verifier.getCliOptions().add( "settings.xml" );
verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:compile" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
assertTrue( repoHandler.artifactRequestedFromRepo2 );
assertTrue( repoHandler.artifactRequestedFromRepo1Last );
}
/**
* Verify that the plugin repositories are used in the reversed order of definition in settings.xml.
*/
public void testPluginRepositoriesOrder()
throws Exception
{
PluginRepoHandler pluginRepoHandler = new PluginRepoHandler();
server.setHandler( pluginRepoHandler );
Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng5280" );
Properties filterProps = verifier.newDefaultFilterProperties();
filterProps.setProperty( "@httpserver.port@", Integer.toString( httpPort ) );
verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
verifier.getCliOptions().add( "--settings" );
verifier.getCliOptions().add( "settings.xml" );
verifier.executeGoal( "org.apache.maven.its.mng5280:fake-maven-plugin:1.0:fake" );
verifier.resetStreams();
assertTrue( pluginRepoHandler.pluginRequestedFromRepo2 );
assertTrue( pluginRepoHandler.pluginRequestedFromRepo1Last );
}
private class RepoHandler
extends AbstractHandler
{
boolean artifactRequestedFromRepo1Last = false;
boolean artifactRequestedFromRepo2 = false;
public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
throws IOException
{
String uri = request.getRequestURI();
if ( uri.startsWith( "/repo1/org/apache/maven/its/mng5280/fake-artifact/1.0/" ) )
{
PrintWriter writer = response.getWriter();
if ( uri.endsWith( ".pom" ) )
{
writer.println( "<project>" );
writer.println( " <modelVersion>4.0.0</modelVersion>" );
writer.println( " <groupId>org.apache.maven.its.mng5280</groupId>" );
writer.println( " <artifactId>fake-artifact</artifactId>" );
writer.println( " <version>1.0</version>" );
writer.println( "</project>" );
response.setStatus( HttpServletResponse.SC_OK );
}
else if ( uri.endsWith( ".jar" ) )
{
writer.println( "empty" );
response.setStatus( HttpServletResponse.SC_OK );
artifactRequestedFromRepo1Last = true;
}
else
{
response.setStatus( HttpServletResponse.SC_NOT_FOUND );
}
}
else if ( uri.startsWith( "/repo2/org/apache/maven/its/mng5280/fake-artifact/1.0/" ) )
{
if ( uri.endsWith( ".jar" ) )
{
artifactRequestedFromRepo1Last = false;
artifactRequestedFromRepo2 = true;
}
response.setStatus( HttpServletResponse.SC_NOT_FOUND );
}
else
{
response.setStatus( HttpServletResponse.SC_NOT_FOUND );
}
( (Request) request ).setHandled( true );
}
}
private class PluginRepoHandler
extends AbstractHandler
{
boolean pluginRequestedFromRepo1Last = false;
boolean pluginRequestedFromRepo2 = false;
public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
throws IOException
{
String uri = request.getRequestURI();
if ( uri.startsWith( "/pluginRepo1/org/apache/maven/its/mng5280/fake-maven-plugin/1.0/" ) )
{
OutputStream outStream = response.getOutputStream();
if ( uri.endsWith( ".pom" ) )
{
File pluginPom = new File( testDir, "fake-maven-plugin/fake-maven-plugin-1.0.pom" );
InputStream inStream = new FileInputStream( pluginPom );
copy( inStream, outStream );
response.setStatus( HttpServletResponse.SC_OK );
}
else if ( uri.endsWith( ".jar" ) )
{
File pluginJar = new File( testDir, "fake-maven-plugin/fake-maven-plugin-1.0.jar" );
InputStream inStream = new FileInputStream( pluginJar );
copy( inStream, outStream );
response.setStatus( HttpServletResponse.SC_OK );
pluginRequestedFromRepo1Last = true;
}
else
{
response.setStatus( HttpServletResponse.SC_NOT_FOUND );
}
}
else if ( uri.startsWith( "/pluginRepo2/org/apache/maven/its/mng5280/fake-maven-plugin/1.0/" ) )
{
if ( uri.endsWith( ".jar" ) )
{
pluginRequestedFromRepo1Last = false;
pluginRequestedFromRepo2 = true;
}
response.setStatus( HttpServletResponse.SC_NOT_FOUND );
}
else
{
response.setStatus( HttpServletResponse.SC_NOT_FOUND );
}
( (Request) request ).setHandled( true );
}
private long copy( InputStream input, OutputStream output )
throws IOException
{
byte[] buffer = new byte[4 * 1024];
long count = 0;
int n = 0;
while ( -1 != ( n = input.read( buffer ) ) )
{
output.write( buffer, 0, n );
count += n;
}
return count;
}
}
}

View File

@ -0,0 +1,37 @@
<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng5280</groupId>
<artifactId>fake-maven-plugin</artifactId>
<version>1.0</version>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,42 @@
<?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.mng5280</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
<name>Maven Integration Test :: MNG-5280</name>
<description>
Verify that repositories and pluginRepositories from profiles are ordered correctly. The order should be
the reversed order they are defined in settings.xml.
</description>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng5280</groupId>
<artifactId>fake-artifact</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,83 @@
<?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.
-->
<settings>
<profiles>
<profile>
<id>maven-core-it-repo-profile-1</id>
<repositories>
<repository>
<id>repo1</id>
<url>http://localhost:@httpserver.port@/repo1/</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>pluginRepo1</id>
<url>http://localhost:@httpserver.port@/pluginRepo1/</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>maven-core-it-repo-profile-2</id>
<repositories>
<repository>
<id>repo2</id>
<url>http://localhost:@httpserver.port@/repo2/</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>pluginRepo2</id>
<url>http://localhost:@httpserver.port@/pluginRepo2/</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>maven-core-it-repo-profile-1</activeProfile>
<activeProfile>maven-core-it-repo-profile-2</activeProfile>
</activeProfiles>
</settings>