From a2cba60e95cfdc7211cb253e78e1ddf3eccfa67d Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 2 Sep 2010 19:46:09 +0000 Subject: [PATCH] [MNG-4791] [regression] POM artifacts passed into MavenProjectBuilder.buildFromRepository() are no longer resolved o Added IT git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@992078 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/it/IntegrationTestSuite.java | 1 + ...tBuilderResolvesRemotePomArtifactTest.java | 70 +++++++++++++++++++ .../src/test/resources/mng-4791/pom.xml | 65 +++++++++++++++++ .../0.1-SNAPSHOT/a-0.1-20100902.190819-1.pom | 39 +++++++++++ .../mng4791/a/0.1-SNAPSHOT/maven-metadata.xml | 13 ++++ .../resources/mng-4791/settings-template.xml | 55 +++++++++++++++ .../maven/plugin/coreit/AbstractPomMojo.java | 22 +++--- .../plugin/coreit/BuildRemotePomMojo.java | 9 ++- 8 files changed, 262 insertions(+), 12 deletions(-) create mode 100644 its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4791ProjectBuilderResolvesRemotePomArtifactTest.java create mode 100644 its/core-it-suite/src/test/resources/mng-4791/pom.xml create mode 100644 its/core-it-suite/src/test/resources/mng-4791/repo/org/apache/maven/its/mng4791/a/0.1-SNAPSHOT/a-0.1-20100902.190819-1.pom create mode 100644 its/core-it-suite/src/test/resources/mng-4791/repo/org/apache/maven/its/mng4791/a/0.1-SNAPSHOT/maven-metadata.xml create mode 100644 its/core-it-suite/src/test/resources/mng-4791/settings-template.xml 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 5c2caf11d4..e3e5a929f3 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 @@ -81,6 +81,7 @@ public class IntegrationTestSuite // ------------------------------------------------------------------------------------------------------------- // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137 + suite.addTestSuite( MavenITmng4791ProjectBuilderResolvesRemotePomArtifactTest.class ); suite.addTestSuite( MavenITmng4786AntBased21xMojoSupportTest.class ); suite.addTestSuite( MavenITmng4781DeploymentToNexusStagingRepoTest.class ); suite.addTestSuite( MavenITmng4779MultipleDepsWithVersionRangeFromLocalRepoTest.class ); diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4791ProjectBuilderResolvesRemotePomArtifactTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4791ProjectBuilderResolvesRemotePomArtifactTest.java new file mode 100644 index 0000000000..48cfb476f5 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4791ProjectBuilderResolvesRemotePomArtifactTest.java @@ -0,0 +1,70 @@ +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-4791. + * + * @author Benjamin Bentmann + */ +public class MavenITmng4791ProjectBuilderResolvesRemotePomArtifactTest + extends AbstractMavenIntegrationTestCase +{ + + public MavenITmng4791ProjectBuilderResolvesRemotePomArtifactTest() + { + super( "[2.0.3,3.0-alpha-1),[3.0-beta-1,)" ); + } + + /** + * Test that the project builder resolves the input artifact when building remote POMs if the input artifact + * happens to be of type "pom". + */ + public void testit() + throws Exception + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4791" ); + + Verifier verifier = newVerifier( testDir.getAbsolutePath() ); + verifier.setAutoclean( false ); + verifier.deleteDirectory( "target" ); + verifier.deleteArtifacts( "org.apache.maven.its.mng4791" ); + verifier.getCliOptions().add( "-s" ); + verifier.getCliOptions().add( "settings.xml" ); + verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + verifier.resetStreams(); + + Properties props = verifier.loadProperties( "target/pom.properties" ); + + assertEquals( "0.1-20100902.190819-1", + props.getProperty( "org.apache.maven.its.mng4791:a:pom:0.1-SNAPSHOT.version" ) ); + String path = props.getProperty( "org.apache.maven.its.mng4791:a:pom:0.1-SNAPSHOT.file" ); + assertTrue( path, path.endsWith( ".pom" ) ); + } + +} diff --git a/its/core-it-suite/src/test/resources/mng-4791/pom.xml b/its/core-it-suite/src/test/resources/mng-4791/pom.xml new file mode 100644 index 0000000000..3fa8390d8d --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-4791/pom.xml @@ -0,0 +1,65 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4791 + test + 0.1 + jar + + Maven Integration Test :: MNG-4791 + + Test that the project builder resolves the input artifact when building remote POMs if the input artifact + happens to be of type "pom". + + + + + + org.apache.maven.its.plugins + maven-it-plugin-project + 2.1-SNAPSHOT + + + test + validate + + remote-pom + + + + + org.apache.maven.its.mng4791 + a + 0.1-SNAPSHOT + + pom + + + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-4791/repo/org/apache/maven/its/mng4791/a/0.1-SNAPSHOT/a-0.1-20100902.190819-1.pom b/its/core-it-suite/src/test/resources/mng-4791/repo/org/apache/maven/its/mng4791/a/0.1-SNAPSHOT/a-0.1-20100902.190819-1.pom new file mode 100644 index 0000000000..0c7e1920e7 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-4791/repo/org/apache/maven/its/mng4791/a/0.1-SNAPSHOT/a-0.1-20100902.190819-1.pom @@ -0,0 +1,39 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4791 + a + 0.1-SNAPSHOT + pom + + MNG-4791 + PASSED + + + + maven-core-it + file:///${basedir}/repo + + + diff --git a/its/core-it-suite/src/test/resources/mng-4791/repo/org/apache/maven/its/mng4791/a/0.1-SNAPSHOT/maven-metadata.xml b/its/core-it-suite/src/test/resources/mng-4791/repo/org/apache/maven/its/mng4791/a/0.1-SNAPSHOT/maven-metadata.xml new file mode 100644 index 0000000000..02d1d4e133 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-4791/repo/org/apache/maven/its/mng4791/a/0.1-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,13 @@ + + + org.apache.maven.its.mng4791 + a + 0.1-SNAPSHOT + + + 20100902.190819 + 1 + + 20100902190819 + + diff --git a/its/core-it-suite/src/test/resources/mng-4791/settings-template.xml b/its/core-it-suite/src/test/resources/mng-4791/settings-template.xml new file mode 100644 index 0000000000..5a7111a2e6 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-4791/settings-template.xml @@ -0,0 +1,55 @@ + + + + + + + + maven-core-it-repo + + + maven-core-it-repo + @baseurl@/repo + + false + + + ignore + + + + + + maven-core-it-repo + @baseurl@/repo + + false + + + ignore + + + + + + + maven-core-it-repo + + diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/AbstractPomMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/AbstractPomMojo.java index 558b89d7ac..918cc4dd48 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/AbstractPomMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/AbstractPomMojo.java @@ -45,18 +45,20 @@ public abstract class AbstractPomMojo protected void dump( Properties props, String key, MavenProject project ) { - props.setProperty( key + "project.id", project.getId() ); - if ( project.getName() != null ) - { - props.setProperty( key + "project.name", project.getName() ); - } - if ( project.getDescription() != null ) - { - props.setProperty( key + "project.description", project.getDescription() ); - } + put( props, key + "project.id", project.getId() ); + put( props, key + "project.name", project.getName() ); + put( props, key + "project.description", project.getDescription() ); if ( project.getArtifact() != null ) { - props.setProperty( key + "artifact.id", project.getArtifact().getId() ); + put( props, key + "artifact.id", project.getArtifact().getId() ); + } + } + + protected void put( Properties props, String key, Object value ) + { + if ( value != null ) + { + props.setProperty( key, value.toString() ); } } diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/BuildRemotePomMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/BuildRemotePomMojo.java index 926d865d3e..5ac3d5d56a 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/BuildRemotePomMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/BuildRemotePomMojo.java @@ -104,18 +104,23 @@ public class BuildRemotePomMojo dependency.getVersion(), dependency.getType(), dependency.getClassifier() ); - getLog().info( "[MAVEN-CORE-IT-LOG] Building " + artifact.getId() ); + String id = artifact.getId(); + + getLog().info( "[MAVEN-CORE-IT-LOG] Building " + id ); try { MavenProject project = builder.buildFromRepository( artifact, remoteRepositories, localRepository ); - dump( props, artifact.getId() + ".", project ); + dump( props, id + ".", project ); } catch ( Exception e ) { getLog().warn( "Failed to build remote POM for " + artifact.getId(), e ); } + + put( props, id + ".file", artifact.getFile() ); + put( props, id + ".version", artifact.getVersion() ); } }