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 fb81cdd70f..74a2375347 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 @@ -167,6 +167,7 @@ public class IntegrationTestSuite suite.addTestSuite( MavenITmng4331DependencyCollectionTest.class ); suite.addTestSuite( MavenITmng4328PrimitiveMojoParameterConfigurationTest.class ); suite.addTestSuite( MavenITmng4327ExcludeForkingMojoFromForkedLifecycleTest.class ); + suite.addTestSuite( MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest.class ); suite.addTestSuite( MavenITmng4321CliUsesPluginMgmtConfigTest.class ); suite.addTestSuite( MavenITmng4320AggregatorAndDependenciesTest.class ); suite.addTestSuite( MavenITmng4319PluginExecutionGoalInterpolationTest.class ); diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest.java new file mode 100644 index 0000000000..675965abea --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest.java @@ -0,0 +1,182 @@ +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.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Properties; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.mortbay.jetty.Handler; +import org.mortbay.jetty.Request; +import org.mortbay.jetty.Server; +import org.mortbay.jetty.handler.AbstractHandler; + +/** + * This is a test set for MNG-4326. + * + * @author Benjamin Bentmann + */ +public class MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest + extends AbstractMavenIntegrationTestCase +{ + + public MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest() + { + super( "[3.0-alpha-8,)" ); + } + + /** + * Verify that locally built/installed snapshot artifacts suppress remote update checks (as long as the local copy + * still satifies the update policy configured for the remote repository). + */ + public void testit() + throws Exception + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4326" ); + + // setup: install a local snapshot + Verifier verifier = new Verifier( new File( testDir, "dependency" ).getAbsolutePath() ); + verifier.setAutoclean( false ); + verifier.deleteArtifacts( "org.apache.maven.its.mng4326" ); + verifier.deleteDirectory( "target" ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + verifier.resetStreams(); + + final List uris = new ArrayList(); + + Handler repoHandler = new AbstractHandler() + { + public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch ) + throws IOException, ServletException + { + PrintWriter writer = response.getWriter(); + + String uri = request.getRequestURI(); + + if ( uri.startsWith( "/repo/org/apache/maven/its/mng4326" ) + && !uri.endsWith( ".md5" ) && !uri.endsWith( ".sha1" ) ) + { + uris.add( uri.substring( 34 ) ); + } + + if ( uri.endsWith( "dep/0.1-SNAPSHOT/maven-metadata.xml" ) ) + { + java.text.DateFormat fmt = new java.text.SimpleDateFormat( "yyyyMMddHHmmss" ); + fmt.setTimeZone( java.util.TimeZone.getTimeZone( "UTC" ) ); + String now = fmt.format( new Date( System.currentTimeMillis() + 3000 ) ); + + response.setStatus( HttpServletResponse.SC_OK ); + writer.println( "" ); + writer.println( " org.apache.maven.its.mng4326" ); + writer.println( " dep" ); + writer.println( " 0.1-SNAPSHOT" ); + writer.println( " " ); + writer.println( " " ); + writer.println( " 20100329.235556" ); + writer.println( " 1" ); + writer.println( " " ); + writer.println( " " + now + "" ); + writer.println( " " ); + writer.println( "" ); + } + else if ( uri.endsWith( ".pom" ) ) + { + response.setStatus( HttpServletResponse.SC_OK ); + writer.println( "" ); + writer.println( " 4.0.0" ); + writer.println( " org.apache.maven.its.mng4326" ); + writer.println( " dep" ); + writer.println( " 0.1-SNAPSHOT" ); + writer.println( "" ); + } + else if ( uri.endsWith( ".jar" ) ) + { + response.setStatus( HttpServletResponse.SC_OK ); + writer.println( "empty" ); + } + else + { + response.setStatus( HttpServletResponse.SC_NOT_FOUND ); + } + + ( (Request) request ).setHandled( true ); + } + }; + + Server server = new Server( 0 ); + server.setHandler( repoHandler ); + server.start(); + + try + { + // test 1: resolve snapshot, just built local copy should suppress daily remote update check + verifier = new Verifier( new File( testDir, "test" ).getAbsolutePath() ); + verifier.setAutoclean( false ); + Properties filterProps = verifier.newDefaultFilterProperties(); + filterProps.setProperty( "@port@", Integer.toString( server.getConnectors()[0].getLocalPort() ) ); + verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps ); + verifier.getCliOptions().add( "--settings" ); + verifier.getCliOptions().add( "settings.xml" ); + verifier.setLogFileName( "log-daily.txt" ); + verifier.deleteDirectory( "target" ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + + List cp = verifier.loadLines( "target/classpath.txt", "UTF-8" ); + assertTrue( cp.toString(), cp.contains( "dep-0.1-SNAPSHOT.jar" ) ); + + assertFalse( uris.toString(), uris.contains( "/dep/0.1-SNAPSHOT/maven-metadata.xml" ) ); + assertFalse( uris.toString(), uris.contains( "/dep/0.1-SNAPSHOT/dep-0.1-20100329.235556-1.jar" ) ); + + uris.clear(); + + // test 2: force snapshot updates, remote metadata and artifacts should be fetched + verifier.getCliOptions().add( "-U" ); + verifier.setLogFileName( "log-force.txt" ); + verifier.deleteDirectory( "target" ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + + cp = verifier.loadLines( "target/classpath.txt", "UTF-8" ); + assertTrue( cp.toString(), cp.contains( "dep-0.1-SNAPSHOT.jar" ) ); + + assertTrue( uris.toString(), uris.contains( "/dep/0.1-SNAPSHOT/maven-metadata.xml" ) ); + assertTrue( uris.toString(), uris.contains( "/dep/0.1-SNAPSHOT/dep-0.1-20100329.235556-1.jar" ) ); + } + finally + { + verifier.resetStreams(); + server.stop(); + } + } + +} diff --git a/its/core-it-suite/src/test/resources/mng-4326/dependency/pom.xml b/its/core-it-suite/src/test/resources/mng-4326/dependency/pom.xml new file mode 100644 index 0000000000..bbc1313161 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-4326/dependency/pom.xml @@ -0,0 +1,59 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4326 + dep + 0.1-SNAPSHOT + jar + + Maven Integration Test :: MNG-4326 + + Verify that locally built/installed snapshot artifacts suppress remote update checks (as long as the local copy + still satifies the update policy configured for the remote repository). + + + + + + org.apache.maven.its.plugins + maven-it-plugin-artifact + 2.1-SNAPSHOT + + pom.xml + + + + test + validate + + set + attach-pom + install + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-4326/test/pom.xml b/its/core-it-suite/src/test/resources/mng-4326/test/pom.xml new file mode 100644 index 0000000000..dbc6690864 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-4326/test/pom.xml @@ -0,0 +1,67 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4326 + test + 0.1-SNAPSHOT + jar + + Maven Integration Test :: MNG-4326 + + Verify that locally built/installed snapshot artifacts suppress remote update checks (as long as the local copy + still satifies the update policy configured for the remote repository). + + + + + + org.apache.maven.its.mng4326 + dep + 0.1-SNAPSHOT + + + + + + + org.apache.maven.its.plugins + maven-it-plugin-dependency-resolution + 2.1-SNAPSHOT + + target/classpath.txt + 1 + + + + test + validate + + compile + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-4326/test/settings-template.xml b/its/core-it-suite/src/test/resources/mng-4326/test/settings-template.xml new file mode 100644 index 0000000000..820160c561 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-4326/test/settings-template.xml @@ -0,0 +1,44 @@ + + + + + + + + maven-core-it-repo + + + maven-core-it + http://localhost:@port@/repo + + false + + + ignore + daily + + + + + + + maven-core-it-repo + +