mirror of https://github.com/apache/maven.git
PR: MNG-207
scope must be considered globally - redefining it weaker must not win. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163589 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
764181f925
commit
829e2051f6
|
@ -73,6 +73,13 @@ public class DefaultArtifactFactory
|
|||
desiredScope = Artifact.SCOPE_COMPILE;
|
||||
}
|
||||
|
||||
// vvv added to retain compile scope. Remove if you want compile inherited as runtime
|
||||
else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals( inheritedScope ) )
|
||||
{
|
||||
desiredScope = Artifact.SCOPE_COMPILE;
|
||||
}
|
||||
// ^^^ added to retain compile scope. Remove if you want compile inherited as runtime
|
||||
|
||||
if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_TEST.equals( inheritedScope ) )
|
||||
{
|
||||
desiredScope = Artifact.SCOPE_TEST;
|
||||
|
|
|
@ -628,7 +628,7 @@ public class DefaultPluginManager
|
|||
context.getLocalRepository(),
|
||||
sourceReader );
|
||||
|
||||
project.getArtifacts().addAll( result.getArtifacts().values() );
|
||||
project.addArtifacts( result.getArtifacts().values() );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -198,7 +198,7 @@ public class DefaultMavenProjectBuilder
|
|||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), repos,
|
||||
localRepository, sourceReader );
|
||||
|
||||
project.getArtifacts().addAll( result.getArtifacts().values() );
|
||||
project.addArtifacts( result.getArtifacts().values() );
|
||||
}
|
||||
|
||||
ModelValidationResult validationResult = validator.validate( model );
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.project;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.DefaultArtifact;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.CiManagement;
|
||||
import org.apache.maven.model.Contributor;
|
||||
|
@ -40,8 +41,10 @@ import org.codehaus.plexus.util.dag.TopologicalSorter;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -644,5 +647,53 @@ public class MavenProject
|
|||
|
||||
return sortedProjects;
|
||||
}
|
||||
|
||||
public void addArtifacts( Collection newArtifacts )
|
||||
{
|
||||
// project.getArtifacts().addAll( result.getArtifacts().values() );
|
||||
// We need to override the scope if one declared it higher
|
||||
// TODO: could surely be more efficient, and use the scope handler, be part of maven-artifact...
|
||||
Map artifacts = new HashMap();
|
||||
for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact a = (Artifact) i.next();
|
||||
artifacts.put( a.getId(), a );
|
||||
}
|
||||
for ( Iterator i = newArtifacts.iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact a = (Artifact) i.next();
|
||||
String id = a.getId();
|
||||
if ( artifacts.containsKey( id ) )
|
||||
{
|
||||
Artifact existing = (Artifact) artifacts.get( id );
|
||||
boolean updateScope = false;
|
||||
if ( Artifact.SCOPE_RUNTIME.equals( a.getScope() ) &&
|
||||
Artifact.SCOPE_TEST.equals( existing.getScope() ) )
|
||||
{
|
||||
updateScope = true;
|
||||
}
|
||||
|
||||
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) &&
|
||||
!Artifact.SCOPE_COMPILE.equals( existing.getScope() ) )
|
||||
{
|
||||
updateScope = true;
|
||||
}
|
||||
|
||||
if ( updateScope )
|
||||
{
|
||||
// TODO: Artifact factory?
|
||||
Artifact artifact = new DefaultArtifact( existing.getGroupId(), existing.getArtifactId(),
|
||||
existing.getVersion(), a.getScope(), existing.getType(),
|
||||
existing.getExtension() );
|
||||
artifacts.put( id, artifact );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
artifacts.put( id, a );
|
||||
}
|
||||
}
|
||||
setArtifacts( new HashSet( artifacts.values() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,10 @@ public class ProjectClasspathTest
|
|||
checkArtifactIdScope( project, "runtime", "runtime" );
|
||||
checkArtifactIdScope( project, "default", "compile" );
|
||||
|
||||
checkInheritedArtifactIdScope( project, "compile", "compile" );
|
||||
checkInheritedArtifactIdScope( project, "runtime", "runtime" );
|
||||
checkInheritedArtifactIdScope( project, "default", "compile" );
|
||||
|
||||
// check all transitive deps of a test dependency are test, except test which is skipped
|
||||
artifact = getArtifact( project, "maven-test-test", "scope-test" );
|
||||
assertNull( "Check no test dependencies are transitive", artifact );
|
||||
|
@ -71,11 +75,11 @@ public class ProjectClasspathTest
|
|||
// check all transitive deps of a runtime dependency are runtime scope, except for test
|
||||
checkGroupIdScope( project, "runtime", "runtime" );
|
||||
|
||||
// check all transitive deps of a compile dependency are runtime scope, except for test
|
||||
checkGroupIdScope( project, "compile", "runtime" );
|
||||
// check all transitive deps of a compile dependency are compile scope, except for runtime and test
|
||||
checkGroupIdScope( project, "compile", "compile" );
|
||||
|
||||
// check all transitive deps of a default dependency are runtime scope, except for test
|
||||
checkGroupIdScope( project, "default", "runtime" );
|
||||
// check all transitive deps of a default dependency are compile scope, except for runtime and test
|
||||
checkGroupIdScope( project, "default", "compile" );
|
||||
}
|
||||
|
||||
private void checkGroupIdScope( MavenProject project, String scope, String scopeValue )
|
||||
|
@ -89,7 +93,7 @@ public class ProjectClasspathTest
|
|||
artifact = getArtifact( project, groupId, "scope-default" );
|
||||
assertEquals( "Check scope", scopeValue, artifact.getScope() );
|
||||
artifact = getArtifact( project, groupId, "scope-runtime" );
|
||||
assertEquals( "Check scope", scopeValue, artifact.getScope() );
|
||||
assertEquals( "Check scope", "runtime", artifact.getScope() );
|
||||
}
|
||||
|
||||
private void checkArtifactIdScope( MavenProject project, String scope, String scopeValue )
|
||||
|
@ -99,6 +103,13 @@ public class ProjectClasspathTest
|
|||
assertEquals( "Check scope", scopeValue, artifact.getScope() );
|
||||
}
|
||||
|
||||
private void checkInheritedArtifactIdScope( MavenProject project, String scope, String scopeValue )
|
||||
{
|
||||
String artifactId = "scope-" + scope;
|
||||
Artifact artifact = getArtifact( project, "maven-inherited", artifactId );
|
||||
assertEquals( "Check scope", scopeValue, artifact.getScope() );
|
||||
}
|
||||
|
||||
private Artifact getArtifact( MavenProject project, String groupId, String artifactId )
|
||||
{
|
||||
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
|
||||
|
|
|
@ -34,6 +34,25 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>maven-inherited</groupId>
|
||||
<artifactId>scope-default</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>maven-inherited</groupId>
|
||||
<artifactId>scope-compile</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>maven-inherited</groupId>
|
||||
<artifactId>scope-runtime</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</model>
|
||||
|
|
|
@ -33,6 +33,26 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>maven-inherited</groupId>
|
||||
<artifactId>scope-compile</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>maven-inherited</groupId>
|
||||
<artifactId>scope-default</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>maven-inherited</groupId>
|
||||
<artifactId>scope-runtime</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</model>
|
||||
|
|
Loading…
Reference in New Issue