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 6cde49c56b..c663e4c98e 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
@@ -87,6 +87,7 @@ public class IntegrationTestSuite
suite.addTestSuite( MavenITmng4789ScopeInheritanceMeetsConflictTest.class );
suite.addTestSuite( MavenITmng4788InstallationToCustomLocalRepoTest.class );
suite.addTestSuite( MavenITmng4786AntBased21xMojoSupportTest.class );
+ suite.addTestSuite( MavenITmng4785TransitiveResolutionInForkedThreadTest.class );
suite.addTestSuite( MavenITmng4781DeploymentToNexusStagingRepoTest.class );
suite.addTestSuite( MavenITmng4779MultipleDepsWithVersionRangeFromLocalRepoTest.class );
suite.addTestSuite( MavenITmng4776ForkedReactorPluginVersionResolutionTest.class );
diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4785TransitiveResolutionInForkedThreadTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4785TransitiveResolutionInForkedThreadTest.java
new file mode 100644
index 0000000000..adc7f322cc
--- /dev/null
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4785TransitiveResolutionInForkedThreadTest.java
@@ -0,0 +1,67 @@
+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-4785.
+ *
+ * @author Benjamin Bentmann
+ */
+public class MavenITmng4785TransitiveResolutionInForkedThreadTest
+ extends AbstractMavenIntegrationTestCase
+{
+
+ public MavenITmng4785TransitiveResolutionInForkedThreadTest()
+ {
+ super( "[2.0.3,3.0-alpha-1),[3.0-beta-4,)" );
+ }
+
+ /**
+ * Verify that dependency resolution using the 2.x API in forked threads works (e.g. has access to any required
+ * session state).
+ */
+ public void testit()
+ throws Exception
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4785" );
+
+ Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+ verifier.setAutoclean( false );
+ verifier.deleteDirectory( "target" );
+ verifier.deleteArtifacts( "org.apache.maven.its.mng4785" );
+ 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/artifacts.properties" );
+ String path = props.getProperty( "org.apache.maven.its.mng4785:dep:jar:0.1-SNAPSHOT", "" );
+ assertTrue( path, path.endsWith( "dep-0.1-SNAPSHOT.jar" ) );
+ }
+
+}
diff --git a/its/core-it-suite/src/test/resources/mng-4785/pom.xml b/its/core-it-suite/src/test/resources/mng-4785/pom.xml
new file mode 100644
index 0000000000..eeebef90ba
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-4785/pom.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.mng4785
+ test
+ 0.1
+ jar
+
+ Maven Integration Test :: MNG-4785
+
+ Verify that dependency resolution using 2.x API in forked threads works (e.g. has access to any required
+ session state).
+
+
+
+
+
+ org.apache.maven.its.plugins
+ maven-it-plugin-artifact
+ 2.1-SNAPSHOT
+
+
+ test
+ validate
+
+ resolve-transitive
+
+
+ target/artifacts.properties
+
+
+ org.apache.maven.its.mng4785
+ dep
+ 0.1-SNAPSHOT
+
+
+
+
+
+
+
+
+
diff --git a/its/core-it-suite/src/test/resources/mng-4785/repo/org/apache/maven/its/mng4785/dep/0.1-SNAPSHOT/dep-0.1-20100909.144341-1.jar b/its/core-it-suite/src/test/resources/mng-4785/repo/org/apache/maven/its/mng4785/dep/0.1-SNAPSHOT/dep-0.1-20100909.144341-1.jar
new file mode 100644
index 0000000000..921b12a085
Binary files /dev/null and b/its/core-it-suite/src/test/resources/mng-4785/repo/org/apache/maven/its/mng4785/dep/0.1-SNAPSHOT/dep-0.1-20100909.144341-1.jar differ
diff --git a/its/core-it-suite/src/test/resources/mng-4785/repo/org/apache/maven/its/mng4785/dep/0.1-SNAPSHOT/dep-0.1-20100909.144341-1.pom b/its/core-it-suite/src/test/resources/mng-4785/repo/org/apache/maven/its/mng4785/dep/0.1-SNAPSHOT/dep-0.1-20100909.144341-1.pom
new file mode 100644
index 0000000000..2c8dcecd8d
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-4785/repo/org/apache/maven/its/mng4785/dep/0.1-SNAPSHOT/dep-0.1-20100909.144341-1.pom
@@ -0,0 +1,36 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.mng4785
+ dep
+ 0.1-SNAPSHOT
+ jar
+
+
+
+ maven-core-it
+ file:///${basedir}/repo
+
+
+
diff --git a/its/core-it-suite/src/test/resources/mng-4785/repo/org/apache/maven/its/mng4785/dep/0.1-SNAPSHOT/maven-metadata.xml b/its/core-it-suite/src/test/resources/mng-4785/repo/org/apache/maven/its/mng4785/dep/0.1-SNAPSHOT/maven-metadata.xml
new file mode 100644
index 0000000000..b586236f26
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-4785/repo/org/apache/maven/its/mng4785/dep/0.1-SNAPSHOT/maven-metadata.xml
@@ -0,0 +1,13 @@
+
+
+ org.apache.maven.its.mng4785
+ dep
+ 0.1-SNAPSHOT
+
+
+ 20100909.144341
+ 1
+
+ 20100909144341
+
+
diff --git a/its/core-it-suite/src/test/resources/mng-4785/settings-template.xml b/its/core-it-suite/src/test/resources/mng-4785/settings-template.xml
new file mode 100644
index 0000000000..9f272b6611
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-4785/settings-template.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+ maven-core-it-repo
+
+
+ maven-core-it
+ @baseurl@/repo
+
+ false
+
+
+ ignore
+
+
+
+
+
+
+ maven-core-it-repo
+
+
diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/ResolveMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/ResolveMojo.java
index bdedc43b2f..a3faf5afd9 100644
--- a/its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/ResolveMojo.java
+++ b/its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/ResolveMojo.java
@@ -26,10 +26,8 @@ import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
@@ -96,10 +94,10 @@ public class ResolveMojo
/**
* Runs this mojo.
*
- * @throws MojoFailureException If the artifact file has not been set.
+ * @throws MojoFailureException If the artifact could not be resolved
*/
public void execute()
- throws MojoExecutionException, MojoFailureException
+ throws MojoExecutionException
{
getLog().info( "[MAVEN-CORE-IT-LOG] Resolving artifacts" );
@@ -163,6 +161,7 @@ public class ResolveMojo
private String getId( Artifact artifact )
{
+ artifact.isSnapshot(); // decouple from MNG-2961
return artifact.getId();
}
diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/ResolveTransitiveMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/ResolveTransitiveMojo.java
new file mode 100644
index 0000000000..33cc012f41
--- /dev/null
+++ b/its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/ResolveTransitiveMojo.java
@@ -0,0 +1,221 @@
+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 org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * Resolves user-specified artifacts transitively. As an additional exercise, the resolution happens in a forked thread
+ * to test access to any shared session state.
+ *
+ * @goal resolve-transitive
+ *
+ * @author Benjamin Bentmann
+ */
+public class ResolveTransitiveMojo
+ extends AbstractMojo
+{
+
+ /**
+ * The local repository.
+ *
+ * @parameter default-value="${localRepository}"
+ * @readonly
+ * @required
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ * The remote repositories of the current Maven project.
+ *
+ * @parameter default-value="${project.remoteArtifactRepositories}"
+ * @readonly
+ * @required
+ */
+ private List remoteRepositories;
+
+ /**
+ * The artifact resolver.
+ *
+ * @component
+ */
+ private ArtifactResolver resolver;
+
+ /**
+ * The artifact factory.
+ *
+ * @component
+ */
+ private ArtifactFactory factory;
+
+ /**
+ * The metadata source.
+ *
+ * @component
+ */
+ private ArtifactMetadataSource metadataSource;
+
+ /**
+ * The dependencies to resolve.
+ *
+ * @parameter
+ */
+ private Dependency[] dependencies;
+
+ /**
+ * The path to a properties file to store the resolved artifact paths in.
+ *
+ * @parameter
+ */
+ private File propertiesFile;
+
+ /**
+ * Runs this mojo.
+ *
+ * @throws MojoExecutionException If the artifacts couldn't be resolved.
+ */
+ public void execute()
+ throws MojoExecutionException
+ {
+ getLog().info( "[MAVEN-CORE-IT-LOG] Resolving artifacts" );
+
+ ResolverThread thread = new ResolverThread();
+ thread.start();
+ while ( thread.isAlive() )
+ {
+ try
+ {
+ thread.join();
+ }
+ catch ( InterruptedException e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ if ( thread.error != null )
+ {
+ throw new MojoExecutionException( "Failed to resolve artifacts: " + thread.error.getMessage(), thread.error );
+ }
+
+ if ( propertiesFile != null )
+ {
+ getLog().info( "[MAVEN-CORE-IT-LOG] Creating properties file " + propertiesFile );
+
+ try
+ {
+ propertiesFile.getParentFile().mkdirs();
+
+ FileOutputStream fos = new FileOutputStream( propertiesFile );
+ try
+ {
+ thread.props.store( fos, "MAVEN-CORE-IT" );
+ }
+ finally
+ {
+ fos.close();
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Failed to create properties file: " + e.getMessage(), e );
+ }
+ }
+ }
+
+ private String getId( Artifact artifact )
+ {
+ artifact.isSnapshot(); // decouple from MNG-2961
+ return artifact.getId();
+ }
+
+ class ResolverThread
+ extends Thread
+ {
+
+ Properties props = new Properties();
+
+ Exception error;
+
+ public void run()
+ {
+ if ( dependencies != null )
+ {
+ try
+ {
+ Set artifacts = new LinkedHashSet();
+
+ for ( int i = 0; i < dependencies.length; i++ )
+ {
+ Dependency dependency = dependencies[i];
+
+ Artifact artifact =
+ factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
+ dependency.getVersion(), dependency.getType(),
+ dependency.getClassifier() );
+
+ getLog().info( "[MAVEN-CORE-IT-LOG] Resolving " + getId( artifact ) );
+
+ artifacts.add( artifact );
+ }
+
+ Artifact origin = factory.createArtifact( "it", "it", "0.1", null, "pom" );
+
+ artifacts =
+ resolver.resolveTransitively( artifacts, origin, remoteRepositories, localRepository,
+ metadataSource ).getArtifacts();
+
+ for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+ {
+ Artifact artifact = (Artifact) it.next();
+
+ if ( artifact.getFile() != null )
+ {
+ props.setProperty( getId( artifact ), artifact.getFile().getPath() );
+ }
+
+ getLog().info( "[MAVEN-CORE-IT-LOG] " + artifact.getFile() );
+ }
+ }
+ catch ( Exception e )
+ {
+ error = e;
+ }
+ }
+ }
+ }
+
+}