MNG-5214: Dependency resolution substitutes g🅰️v:jar for j🅰️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
This commit is contained in:
Benson Margulies 2011-12-10 21:00:40 +00:00
parent 1de4f83c5a
commit 75a424452c
8 changed files with 531 additions and 1 deletions

View File

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

View File

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

View File

@ -0,0 +1,73 @@
<?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>
<parent>
<groupId>org.apache.maven.its.mng5214</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>consumer</artifactId>
<name>Maven Integration Test :: MNG-5214 :: Consumer</name>
<description>
Test that a dependency on a type other than jar/test-jar/ejb is not mapped to target/classes.
</description>
<dependencies>
<!-- This module depends *only* on the test JAR -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dependency</artifactId>
<version>${project.version}</version>
<type>wsdl</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-dependency-resolution</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>compile-classpath</id>
<phase>validate</phase>
<goals>
<goal>resolve-one-dependency</goal>
</goals>
<configuration>
<scope>compile</scope>
<groupId>${project.groupId}</groupId>
<artifactId>dependency</artifactId>
<version>${project.version}</version>
<type>wsdl</type>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,23 @@
<?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.
-->
<wsdl:definitions name="HelloWorld"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
</wsdl:definitions>

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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.mng5214</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>dependency</artifactId>
<name>Maven Integration Test :: MNG-5214 :: Dependency</name>
<description>A very dull project, which exists only so that its g:a:v is in the reactor.
</description>
<build>
<outputDirectory>classes-main</outputDirectory>
<testOutputDirectory>classes-test</testOutputDirectory>
</build>
<profiles>
<profile>
<id>createWsdl</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-artifact</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>generate-resources</phase>
<goals>
<goal>attach</goal>
</goals>
<configuration>
<attachedFile>notmuch.wsdl</attachedFile>
<artifactType>wsdl</artifactType>
</configuration>
</execution>
<execution>
<id>install</id>
<phase>generate-resources</phase>
<configuration>
<pomFile>pom.xml</pomFile>
<!-- borrow the POM as the main artifact -->
<mainFile>pom.xml</mainFile>
</configuration>
<goals>
<goal>set</goal>
<goal>attach-pom</goal>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,69 @@
<?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.mng5214</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-5214</name>
<description>
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.
</description>
<modules>
<module>dependency</module>
<module>consumer</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -51,7 +51,13 @@ under the License.
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0</version>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>

View File

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