From 75a424452ca6a297ff993519fd140f1723cb2877 Mon Sep 17 00:00:00 2001 From: Benson Margulies Date: Sat, 10 Dec 2011 21:00:40 +0000 Subject: [PATCH] MNG-5214: Dependency resolution substitutes g:a:v:jar for j:a:v:something-else when something-else isn't in the reactor o Add an integration test for the new behavior, conditioned for 3.0.5 and after. o Add another mojo to maven-it-plugin-dependency-resolution to support the test. Note that I had to tweak dependencies on the plugin to add this mojo; if anyone really wants to run against 2.0 with the trunk of the tests this will need something, I'm not sure what. git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@1212870 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/it/IntegrationTestSuite.java | 1 + .../it/MavenITmng5214DontMapWsdlToJar.java | 76 +++++++ .../test/resources/mng-5214/consumer/pom.xml | 73 +++++++ .../mng-5214/dependency/notmuch.wsdl | 23 ++ .../resources/mng-5214/dependency/pom.xml | 83 ++++++++ .../src/test/resources/mng-5214/pom.xml | 69 ++++++ .../pom.xml | 8 +- .../coreit/ResolveOneDependencyMojo.java | 199 ++++++++++++++++++ 8 files changed, 531 insertions(+), 1 deletion(-) create mode 100644 its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5214DontMapWsdlToJar.java create mode 100644 its/core-it-suite/src/test/resources/mng-5214/consumer/pom.xml create mode 100644 its/core-it-suite/src/test/resources/mng-5214/dependency/notmuch.wsdl create mode 100644 its/core-it-suite/src/test/resources/mng-5214/dependency/pom.xml create mode 100644 its/core-it-suite/src/test/resources/mng-5214/pom.xml create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/ResolveOneDependencyMojo.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 804df5135d..d85528dbf1 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 @@ -83,6 +83,7 @@ public class IntegrationTestSuite // ------------------------------------------------------------------------------------------------------------- // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137 + suite.addTestSuite( MavenITmng5214DontMapWsdlToJar.class ); suite.addTestSuite( MavenITmng5137ReactorResolutionInForkedBuildTest.class ); suite.addTestSuite( MavenITmng5135AggregatorDepResolutionModuleExtensionTest.class ); suite.addTestSuite( MavenITmng5096ExclusionAtDependencyWithImpliedClassifierTest.class ); diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5214DontMapWsdlToJar.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5214DontMapWsdlToJar.java new file mode 100644 index 0000000000..72c33f3f24 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5214DontMapWsdlToJar.java @@ -0,0 +1,76 @@ +package org.apache.maven.it; + +import java.io.File; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.it.util.ResourceExtractor; + +/* + * 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. + */ + + +public class MavenITmng5214DontMapWsdlToJar extends AbstractMavenIntegrationTestCase +{ + public MavenITmng5214DontMapWsdlToJar() + { + super( "[3.0-5,)" ); + } + + /** + * Test that the code that allows test-jar and ejb-client dependencies to resolve to the + * target/classes or target/test-class is *not* applies to other types, e.g. wsdl. + */ + public void testitTestPhase() + throws Exception + { + File setupDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5214/dependency" ); + + Verifier setupVerifier = newVerifier( setupDir.getAbsolutePath() ); + setupVerifier.setAutoclean( false ); + setupVerifier.setMavenDebug( true ); + setupVerifier.deleteDirectory( "target" ); + setupVerifier.deleteArtifacts( "org.apache.maven.its.mng5214" ); + setupVerifier.setLogFileName( "log-setup.txt" ); + setupVerifier.addCliOption( "-PcreateWsdl" ); + setupVerifier.executeGoal( "generate-resources" ); + + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5214" ); + + Verifier verifier = newVerifier( testDir.getAbsolutePath() ); + verifier.setAutoclean( false ); + verifier.deleteDirectory( "consumer/target" ); + verifier.deleteDirectory( "dependency/target" ); + verifier.setLogFileName( "log-test.txt" ); + verifier.executeGoal( "test" ); + verifier.verifyErrorFreeLog(); + List lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false ); + Iterator lineIt = lines.iterator(); + // RESOLVE-ONE-DEPENDENCY org.apache.maven.its.mng5214:dependency:wsdl:1.0-SNAPSHOT $ /tmp/it.repo/org/apache/maven/its/mng5214/dependency/1.0-SNAPSHOT/dependency-1.0-SNAPSHOT.wsdl + while ( lineIt.hasNext() ) + { + String line = (String) lineIt.next(); + if ( line.contains( "RESOLVE-ONE-DEPENDENCY org.apache.maven.its.mng5214:dependency:wsdl:1.0-SNAPSHOT" ) ) + { + assertFalse( line.contains( "classes-main" ) ); + assertTrue( line.endsWith( ".wsdl" ) ); + } + } + } +} diff --git a/its/core-it-suite/src/test/resources/mng-5214/consumer/pom.xml b/its/core-it-suite/src/test/resources/mng-5214/consumer/pom.xml new file mode 100644 index 0000000000..770f634876 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-5214/consumer/pom.xml @@ -0,0 +1,73 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.mng5214 + parent + 1.0-SNAPSHOT + + + consumer + + Maven Integration Test :: MNG-5214 :: Consumer + + Test that a dependency on a type other than jar/test-jar/ejb is not mapped to target/classes. + + + + + + ${project.groupId} + dependency + ${project.version} + wsdl + + + + + + + org.apache.maven.its.plugins + maven-it-plugin-dependency-resolution + 2.1-SNAPSHOT + + + compile-classpath + validate + + resolve-one-dependency + + + compile + ${project.groupId} + dependency + ${project.version} + wsdl + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-5214/dependency/notmuch.wsdl b/its/core-it-suite/src/test/resources/mng-5214/dependency/notmuch.wsdl new file mode 100644 index 0000000000..1b5d4a7e40 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-5214/dependency/notmuch.wsdl @@ -0,0 +1,23 @@ + + + + \ No newline at end of file diff --git a/its/core-it-suite/src/test/resources/mng-5214/dependency/pom.xml b/its/core-it-suite/src/test/resources/mng-5214/dependency/pom.xml new file mode 100644 index 0000000000..6b947df03f --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-5214/dependency/pom.xml @@ -0,0 +1,83 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.mng5214 + parent + 1.0-SNAPSHOT + + + dependency + + Maven Integration Test :: MNG-5214 :: Dependency + A very dull project, which exists only so that its g:a:v is in the reactor. + + + + classes-main + classes-test + + + + + createWsdl + + + + org.apache.maven.its.plugins + maven-it-plugin-artifact + 2.1-SNAPSHOT + + + attach-artifacts + generate-resources + + attach + + + notmuch.wsdl + wsdl + + + + install + generate-resources + + pom.xml + + pom.xml + + + set + attach-pom + install + + + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-5214/pom.xml b/its/core-it-suite/src/test/resources/mng-5214/pom.xml new file mode 100644 index 0000000000..975c891ed4 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-5214/pom.xml @@ -0,0 +1,69 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng5214 + parent + 1.0-SNAPSHOT + pom + + Maven Integration Test :: MNG-5214 + + Test that a dependency with a type other than jar, test-jar, or ejb-client + *not* get assigned a reactor path (target/classes, e.g.) just + because the corresponding 'jar' + artifact is in the reactor. + + + + dependency + consumer + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 0.1-stub-SNAPSHOT + + + org.apache.maven.plugins + maven-jar-plugin + 0.1-stub-SNAPSHOT + + + org.apache.maven.plugins + maven-resources-plugin + 0.1-stub-SNAPSHOT + + + org.apache.maven.plugins + maven-surefire-plugin + 0.1-stub-SNAPSHOT + + + + + diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/pom.xml b/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/pom.xml index 0b373cdd2d..a4d88f1411 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/pom.xml +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/pom.xml @@ -51,7 +51,13 @@ under the License. org.apache.maven maven-project - 2.0 + 2.1.0 + + + org.apache.maven + maven-core + 2.1.0 + provided org.apache.maven diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/ResolveOneDependencyMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/ResolveOneDependencyMojo.java new file mode 100644 index 0000000000..694f4a576a --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/ResolveOneDependencyMojo.java @@ -0,0 +1,199 @@ +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 java.io.File; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; + +/** + * Attempts to resolve a single artifact from dependencies, and logs the results for the Verifier to look at. + * + * @goal resolve-one-dependency + * @requiresDependencyResolution runtime + * @author bimargulies + * @version $Id$ + */ +public class ResolveOneDependencyMojo + extends AbstractDependencyMojo +{ + + /** + * Group ID of the artifact to resolve. + * + * @parameter + * @required + */ + private String groupId; + /** + * Artifact ID of the artifact to resolve. + * + * @parameter + * @required + */ + private String artifactId; + /** + * Version of the artifact to resolve. + * + * @parameter + * @required + */ + private String version; + /** + * Type of the artifact to resolve. + * + * @parameter + * @required + */ + private String type; + /** + * Classifier of the artifact to resolve. + * + * @parameter + */ + private String classifier; + + /** + * The scope to resolve for. + * + * @parameter + * @required + */ + private String scope; + + /** + * @parameter expression="${project}" + * @required + */ + MavenProject project; + + /** + * @component + */ + private ArtifactResolver resolver; + + /** + * @component + * @readonly + * @required + */ + private ArtifactFactory artifactFactory; + + /** + * The Maven session. + * + * @parameter expression="${session}" + * @readonly + * @required + */ + private MavenSession session; + + /** + * Metadata source object. + * + * @component + */ + private ArtifactMetadataSource metadataSource; + + /** + * Runs this mojo. + * + * @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved. + */ + public void execute() + throws MojoExecutionException + { + + Artifact projectArtifact = project.getArtifact(); + if ( projectArtifact == null ) + { + projectArtifact = + artifactFactory.createProjectArtifact( project.getGroupId(), project.getArtifactId(), + project.getVersion() ); + } + + Set depArtifacts = new HashSet(); + Artifact artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); + depArtifacts.add( artifact ); + + ScopeArtifactFilter scopeFilter = new ScopeArtifactFilter( scope ); + + ArtifactResolutionResult result; + try + { + result = + resolver.resolveTransitively( depArtifacts, projectArtifact, project.getManagedVersionMap(), + session.getLocalRepository(), project.getRemoteArtifactRepositories(), + metadataSource, scopeFilter ); + } + catch ( ArtifactResolutionException e ) + { + throw new MojoExecutionException( "RESOLVE-ONE-DEPENDENCY ArtifactResolutionException exception ", e ); + } + catch ( ArtifactNotFoundException e ) + { + throw new MojoExecutionException( "RESOLVE-ONE-DEPENDENCY ArtifactNotFoundException exception ", e ); + } + + if ( result == null ) + { + getLog().info( "RESOLVE-ONE-DEPENDENCY null result" ); + } + else + { + Set resolvedArtifacts = result.getArtifacts(); + Iterator it = resolvedArtifacts.iterator(); + /* + * Assume that the user of this is not interested in transitive deps and such, just report the one. + */ + while ( it.hasNext() ) + { + Artifact a = (Artifact) it.next(); + if ( a.equals( artifact ) ) + { + File file = a.getFile(); + if ( file == null ) + { + getLog().info( " RESOLVE-ONE-DEPENDENCY " + a.toString() + " $ NO-FILE" ); + } + else + { + getLog().info( " RESOLVE-ONE-DEPENDENCY " + a.toString() + " $ " + file.getAbsolutePath() ); + } + return; + } + } + getLog().info(" RESOLVE-ONE-DEPENDENCY " + artifact.toString() + " $ NOT-RESOLVED" ); + } + } +}