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;
|
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 ) )
|
if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_TEST.equals( inheritedScope ) )
|
||||||
{
|
{
|
||||||
desiredScope = Artifact.SCOPE_TEST;
|
desiredScope = Artifact.SCOPE_TEST;
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class DefaultPluginManager
|
||||||
protected PathTranslator pathTranslator;
|
protected PathTranslator pathTranslator;
|
||||||
|
|
||||||
protected ArtifactRepositoryFactory artifactRepositoryFactory;
|
protected ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||||
|
|
||||||
protected MavenSettingsBuilder mavenSettingsBuilder;
|
protected MavenSettingsBuilder mavenSettingsBuilder;
|
||||||
|
|
||||||
public DefaultPluginManager()
|
public DefaultPluginManager()
|
||||||
|
@ -605,7 +605,7 @@ public class DefaultPluginManager
|
||||||
Repository pluginRepo = new Repository();
|
Repository pluginRepo = new Repository();
|
||||||
pluginRepo.setId( "plugin-repository" );
|
pluginRepo.setId( "plugin-repository" );
|
||||||
pluginRepo.setUrl( "http://repo1.maven.org" );
|
pluginRepo.setUrl( "http://repo1.maven.org" );
|
||||||
|
|
||||||
ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository( pluginRepo, settings );
|
ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository( pluginRepo, settings );
|
||||||
|
|
||||||
remotePluginRepositories.add( pluginRepository );
|
remotePluginRepositories.add( pluginRepository );
|
||||||
|
@ -628,7 +628,7 @@ public class DefaultPluginManager
|
||||||
context.getLocalRepository(),
|
context.getLocalRepository(),
|
||||||
sourceReader );
|
sourceReader );
|
||||||
|
|
||||||
project.getArtifacts().addAll( result.getArtifacts().values() );
|
project.addArtifacts( result.getArtifacts().values() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class DefaultMavenProjectBuilder
|
||||||
private ModelDefaultsInjector modelDefaultsInjector;
|
private ModelDefaultsInjector modelDefaultsInjector;
|
||||||
|
|
||||||
private ModelInterpolator modelInterpolator;
|
private ModelInterpolator modelInterpolator;
|
||||||
|
|
||||||
private MavenSettingsBuilder mavenSettingsBuilder;
|
private MavenSettingsBuilder mavenSettingsBuilder;
|
||||||
|
|
||||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||||
|
@ -198,7 +198,7 @@ public class DefaultMavenProjectBuilder
|
||||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), repos,
|
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), repos,
|
||||||
localRepository, sourceReader );
|
localRepository, sourceReader );
|
||||||
|
|
||||||
project.getArtifacts().addAll( result.getArtifacts().values() );
|
project.addArtifacts( result.getArtifacts().values() );
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelValidationResult validationResult = validator.validate( model );
|
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.Artifact;
|
||||||
|
import org.apache.maven.artifact.DefaultArtifact;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
import org.apache.maven.model.CiManagement;
|
import org.apache.maven.model.CiManagement;
|
||||||
import org.apache.maven.model.Contributor;
|
import org.apache.maven.model.Contributor;
|
||||||
|
@ -40,8 +41,10 @@ import org.codehaus.plexus.util.dag.TopologicalSorter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -644,5 +647,53 @@ public class MavenProject
|
||||||
|
|
||||||
return sortedProjects;
|
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, "runtime", "runtime" );
|
||||||
checkArtifactIdScope( project, "default", "compile" );
|
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
|
// check all transitive deps of a test dependency are test, except test which is skipped
|
||||||
artifact = getArtifact( project, "maven-test-test", "scope-test" );
|
artifact = getArtifact( project, "maven-test-test", "scope-test" );
|
||||||
assertNull( "Check no test dependencies are transitive", artifact );
|
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
|
// check all transitive deps of a runtime dependency are runtime scope, except for test
|
||||||
checkGroupIdScope( project, "runtime", "runtime" );
|
checkGroupIdScope( project, "runtime", "runtime" );
|
||||||
|
|
||||||
// check all transitive deps of a compile dependency are runtime scope, except for test
|
// check all transitive deps of a compile dependency are compile scope, except for runtime and test
|
||||||
checkGroupIdScope( project, "compile", "runtime" );
|
checkGroupIdScope( project, "compile", "compile" );
|
||||||
|
|
||||||
// check all transitive deps of a default dependency are runtime scope, except for test
|
// check all transitive deps of a default dependency are compile scope, except for runtime and test
|
||||||
checkGroupIdScope( project, "default", "runtime" );
|
checkGroupIdScope( project, "default", "compile" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkGroupIdScope( MavenProject project, String scope, String scopeValue )
|
private void checkGroupIdScope( MavenProject project, String scope, String scopeValue )
|
||||||
|
@ -89,7 +93,7 @@ public class ProjectClasspathTest
|
||||||
artifact = getArtifact( project, groupId, "scope-default" );
|
artifact = getArtifact( project, groupId, "scope-default" );
|
||||||
assertEquals( "Check scope", scopeValue, artifact.getScope() );
|
assertEquals( "Check scope", scopeValue, artifact.getScope() );
|
||||||
artifact = getArtifact( project, groupId, "scope-runtime" );
|
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 )
|
private void checkArtifactIdScope( MavenProject project, String scope, String scopeValue )
|
||||||
|
@ -99,6 +103,13 @@ public class ProjectClasspathTest
|
||||||
assertEquals( "Check scope", scopeValue, artifact.getScope() );
|
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 )
|
private Artifact getArtifact( MavenProject project, String groupId, String artifactId )
|
||||||
{
|
{
|
||||||
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
|
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
|
||||||
|
|
|
@ -34,6 +34,25 @@
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
</model>
|
</model>
|
||||||
|
|
|
@ -33,6 +33,26 @@
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
</model>
|
</model>
|
||||||
|
|
Loading…
Reference in New Issue