mirror of
https://github.com/apache/maven.git
synced 2025-02-06 10:09:04 +00:00
[MNG-4785] NPE in dependency resolution code for TC plugin
o Added IT git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@995456 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
59eaca8a41
commit
bd5218cbae
@ -87,6 +87,7 @@ public static Test suite()
|
||||
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 );
|
||||
|
@ -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 <a href="http://jira.codehaus.org/browse/MNG-4785">MNG-4785</a>.
|
||||
*
|
||||
* @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" ) );
|
||||
}
|
||||
|
||||
}
|
64
its/core-it-suite/src/test/resources/mng-4785/pom.xml
Normal file
64
its/core-it-suite/src/test/resources/mng-4785/pom.xml
Normal file
@ -0,0 +1,64 @@
|
||||
<?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.mng4785</groupId>
|
||||
<artifactId>test</artifactId>
|
||||
<version>0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Maven Integration Test :: MNG-4785</name>
|
||||
<description>
|
||||
Verify that dependency resolution using 2.x API in forked threads works (e.g. has access to any required
|
||||
session state).
|
||||
</description>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-artifact</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>test</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>resolve-transitive</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<propertiesFile>target/artifacts.properties</propertiesFile>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.its.mng4785</groupId>
|
||||
<artifactId>dep</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
Binary file not shown.
@ -0,0 +1,36 @@
|
||||
<?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.mng4785</groupId>
|
||||
<artifactId>dep</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>maven-core-it</id>
|
||||
<url>file:///${basedir}/repo</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</project>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata>
|
||||
<groupId>org.apache.maven.its.mng4785</groupId>
|
||||
<artifactId>dep</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<versioning>
|
||||
<snapshot>
|
||||
<timestamp>20100909.144341</timestamp>
|
||||
<buildNumber>1</buildNumber>
|
||||
</snapshot>
|
||||
<lastUpdated>20100909144341</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
@ -0,0 +1,43 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<settings>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>maven-core-it-repo</id>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven-core-it</id>
|
||||
<url>@baseurl@/repo</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
<activeProfiles>
|
||||
<activeProfile>maven-core-it-repo</activeProfile>
|
||||
</activeProfiles>
|
||||
</settings>
|
@ -26,10 +26,8 @@
|
||||
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 void execute()
|
||||
|
||||
private String getId( Artifact artifact )
|
||||
{
|
||||
artifact.isSnapshot(); // decouple from MNG-2961
|
||||
return artifact.getId();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user