mirror of https://github.com/apache/maven.git
Adding system scope...uses scope == 'system' and systemPath in dependency. SystemPath was chosen over mappings inside the setings.xml for scalability, heritability, and injectability (via managed deps).
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@264960 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
94ab6a4076
commit
8201bb9d18
|
@ -73,8 +73,24 @@ public class DefaultArtifactResolver
|
||||||
boolean force )
|
boolean force )
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
|
if ( artifact != null )
|
||||||
|
{
|
||||||
|
if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
|
||||||
|
{
|
||||||
|
File systemFile = artifact.getFile();
|
||||||
|
|
||||||
|
if ( !systemFile.exists() )
|
||||||
|
{
|
||||||
|
throw new ArtifactResolutionException( "System artifact: " + artifact.getId()
|
||||||
|
+ " not found in path: " + systemFile, artifact );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
artifact.setResolved( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
// skip artifacts with a file - they are already resolved
|
// skip artifacts with a file - they are already resolved
|
||||||
if ( artifact != null && artifact.getFile() == null )
|
else if ( artifact.getFile() == null )
|
||||||
{
|
{
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Check for the existence of the artifact in the specified local
|
// Check for the existence of the artifact in the specified local
|
||||||
|
@ -144,6 +160,7 @@ public class DefaultArtifactResolver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
||||||
ArtifactRepository localRepository, List remoteRepositories,
|
ArtifactRepository localRepository, List remoteRepositories,
|
||||||
|
|
|
@ -50,6 +50,8 @@ public interface Artifact
|
||||||
|
|
||||||
String SCOPE_PROVIDED = "provided";
|
String SCOPE_PROVIDED = "provided";
|
||||||
|
|
||||||
|
String SCOPE_SYSTEM = "system";
|
||||||
|
|
||||||
String getGroupId();
|
String getGroupId();
|
||||||
|
|
||||||
String getArtifactId();
|
String getArtifactId();
|
||||||
|
|
|
@ -36,10 +36,13 @@ public class ScopeArtifactFilter
|
||||||
|
|
||||||
private final boolean providedScope;
|
private final boolean providedScope;
|
||||||
|
|
||||||
|
private final boolean systemScope;
|
||||||
|
|
||||||
public ScopeArtifactFilter( String scope )
|
public ScopeArtifactFilter( String scope )
|
||||||
{
|
{
|
||||||
if ( DefaultArtifact.SCOPE_COMPILE.equals( scope ) )
|
if ( DefaultArtifact.SCOPE_COMPILE.equals( scope ) )
|
||||||
{
|
{
|
||||||
|
systemScope = true;
|
||||||
providedScope = true;
|
providedScope = true;
|
||||||
compileScope = true;
|
compileScope = true;
|
||||||
runtimeScope = false;
|
runtimeScope = false;
|
||||||
|
@ -47,6 +50,7 @@ public class ScopeArtifactFilter
|
||||||
}
|
}
|
||||||
else if ( DefaultArtifact.SCOPE_RUNTIME.equals( scope ) )
|
else if ( DefaultArtifact.SCOPE_RUNTIME.equals( scope ) )
|
||||||
{
|
{
|
||||||
|
systemScope = false;
|
||||||
providedScope = false;
|
providedScope = false;
|
||||||
compileScope = true;
|
compileScope = true;
|
||||||
runtimeScope = true;
|
runtimeScope = true;
|
||||||
|
@ -54,6 +58,7 @@ public class ScopeArtifactFilter
|
||||||
}
|
}
|
||||||
else if ( DefaultArtifact.SCOPE_TEST.equals( scope ) )
|
else if ( DefaultArtifact.SCOPE_TEST.equals( scope ) )
|
||||||
{
|
{
|
||||||
|
systemScope = true;
|
||||||
providedScope = true;
|
providedScope = true;
|
||||||
compileScope = true;
|
compileScope = true;
|
||||||
runtimeScope = true;
|
runtimeScope = true;
|
||||||
|
@ -61,6 +66,7 @@ public class ScopeArtifactFilter
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
systemScope = false;
|
||||||
providedScope = false;
|
providedScope = false;
|
||||||
compileScope = false;
|
compileScope = false;
|
||||||
runtimeScope = false;
|
runtimeScope = false;
|
||||||
|
@ -70,22 +76,26 @@ public class ScopeArtifactFilter
|
||||||
|
|
||||||
public boolean include( Artifact artifact )
|
public boolean include( Artifact artifact )
|
||||||
{
|
{
|
||||||
if ( DefaultArtifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
|
if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
|
||||||
{
|
{
|
||||||
return compileScope;
|
return compileScope;
|
||||||
}
|
}
|
||||||
else if ( DefaultArtifact.SCOPE_RUNTIME.equals( artifact.getScope() ) )
|
else if ( Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) )
|
||||||
{
|
{
|
||||||
return runtimeScope;
|
return runtimeScope;
|
||||||
}
|
}
|
||||||
else if ( DefaultArtifact.SCOPE_TEST.equals( artifact.getScope() ) )
|
else if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
|
||||||
{
|
{
|
||||||
return testScope;
|
return testScope;
|
||||||
}
|
}
|
||||||
else if ( DefaultArtifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
|
else if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
|
||||||
{
|
{
|
||||||
return providedScope;
|
return providedScope;
|
||||||
}
|
}
|
||||||
|
else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
|
||||||
|
{
|
||||||
|
return systemScope;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: should this be true? Does it even happen?
|
// TODO: should this be true? Does it even happen?
|
||||||
|
|
|
@ -178,6 +178,8 @@ it0061: Verify that deployment of artifacts to a legacy-layout repository
|
||||||
it0062: Test that a deployment of a snapshot falls back to a non-snapshot repository if no snapshot repository is
|
it0062: Test that a deployment of a snapshot falls back to a non-snapshot repository if no snapshot repository is
|
||||||
specified.
|
specified.
|
||||||
|
|
||||||
|
it0063: Test the use of a system scoped dependency to tools.jar.
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
- generated sources
|
- generated sources
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
it0063
|
||||||
it0062
|
it0062
|
||||||
it0061
|
it0061
|
||||||
it0060
|
it0060
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
compile
|
|
||||||
package
|
package
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
target/classes/org/apache/maven/it0001/Person.class
|
||||||
|
target/test-classes/org/apache/maven/it0001/PersonTest.class
|
||||||
|
target/maven-core-it0063-1.0.jar
|
||||||
|
target/maven-core-it0063-1.0.jar!/it0001.properties
|
|
@ -0,0 +1 @@
|
||||||
|
package
|
|
@ -0,0 +1,22 @@
|
||||||
|
<model>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.apache.maven.it</groupId>
|
||||||
|
<artifactId>maven-core-it0063</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1.0</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jdk-tools</groupId>
|
||||||
|
<artifactId>jdk-tools</artifactId>
|
||||||
|
<version>1.4.2</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${java.home}/../lib/tools.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</model>
|
|
@ -0,0 +1,18 @@
|
||||||
|
package org.apache.maven.it0001;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.Main;
|
||||||
|
|
||||||
|
public class Person
|
||||||
|
{
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public void setName( String name )
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
name = jason
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.apache.maven.it0001;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class PersonTest
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
public void testPerson()
|
||||||
|
{
|
||||||
|
Person person = new Person();
|
||||||
|
|
||||||
|
person.setName( "foo" );
|
||||||
|
|
||||||
|
assertEquals( "foo", person.getName() );
|
||||||
|
}
|
||||||
|
}
|
|
@ -1253,6 +1253,12 @@
|
||||||
|-->
|
|-->
|
||||||
<!-- defaultValue>compile</defaultValue -->
|
<!-- defaultValue>compile</defaultValue -->
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>systemPath</name>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<description>FOR SYSTEM SCOPE ONLY. This specifies the path on the filesystem for this dependency.</description>
|
||||||
|
<type>String</type>
|
||||||
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>exclusions</name>
|
<name>exclusions</name>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
|
|
|
@ -579,7 +579,9 @@ public class DefaultMavenProjectBuilder
|
||||||
// TODO: Clean this up...we're using this to 'jump' the interpolation step for model properties not expressed in XML.
|
// TODO: Clean this up...we're using this to 'jump' the interpolation step for model properties not expressed in XML.
|
||||||
// [BP] - Can this above comment be explained?
|
// [BP] - Can this above comment be explained?
|
||||||
// We don't need all the project methods that are added over those in the model, but we do need basedir
|
// We don't need all the project methods that are added over those in the model, but we do need basedir
|
||||||
Map context = Collections.singletonMap( "basedir", project.getBasedir() );
|
Map context = new HashMap( System.getProperties() );
|
||||||
|
context.put( "basedir", project.getBasedir() );
|
||||||
|
|
||||||
model = modelInterpolator.interpolate( model, context );
|
model = modelInterpolator.interpolate( model, context );
|
||||||
|
|
||||||
// interpolation is before injection, because interpolation is off-limits in the injected variables
|
// interpolation is before injection, because interpolation is off-limits in the injected variables
|
||||||
|
|
|
@ -347,7 +347,8 @@ public class MavenProject
|
||||||
if ( isAddedToClasspath( a ) )
|
if ( isAddedToClasspath( a ) )
|
||||||
{
|
{
|
||||||
// TODO: let the scope handler deal with this
|
// TODO: let the scope handler deal with this
|
||||||
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) )
|
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
|
||||||
|
|| Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
|
||||||
{
|
{
|
||||||
String refId = getProjectReferenceId( a.getGroupId(), a.getArtifactId() );
|
String refId = getProjectReferenceId( a.getGroupId(), a.getArtifactId() );
|
||||||
MavenProject project = (MavenProject) projectReferences.get( refId );
|
MavenProject project = (MavenProject) projectReferences.get( refId );
|
||||||
|
@ -382,7 +383,8 @@ public class MavenProject
|
||||||
if ( isAddedToClasspath( a ) )
|
if ( isAddedToClasspath( a ) )
|
||||||
{
|
{
|
||||||
// TODO: let the scope handler deal with this
|
// TODO: let the scope handler deal with this
|
||||||
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) )
|
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
|
||||||
|
|| Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
|
||||||
{
|
{
|
||||||
list.add( a );
|
list.add( a );
|
||||||
}
|
}
|
||||||
|
@ -407,7 +409,8 @@ public class MavenProject
|
||||||
Artifact a = (Artifact) i.next();
|
Artifact a = (Artifact) i.next();
|
||||||
|
|
||||||
// TODO: let the scope handler deal with this
|
// TODO: let the scope handler deal with this
|
||||||
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) )
|
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
|
||||||
|
|| Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
|
||||||
{
|
{
|
||||||
Dependency dependency = new Dependency();
|
Dependency dependency = new Dependency();
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.apache.maven.project.ProjectBuildingException;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -72,7 +73,7 @@ public class MavenMetadataSource
|
||||||
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
|
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
|
||||||
throws ArtifactMetadataRetrievalException
|
throws ArtifactMetadataRetrievalException
|
||||||
{
|
{
|
||||||
MavenProject project;
|
MavenProject project = null;
|
||||||
|
|
||||||
Artifact pomArtifact;
|
Artifact pomArtifact;
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
@ -82,13 +83,23 @@ public class MavenMetadataSource
|
||||||
pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
||||||
artifact.getVersion(), artifact.getScope() );
|
artifact.getVersion(), artifact.getScope() );
|
||||||
|
|
||||||
|
if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
|
||||||
|
{
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
|
project = mavenProjectBuilder
|
||||||
|
.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
|
||||||
}
|
}
|
||||||
catch ( InvalidModelException e )
|
catch ( InvalidModelException e )
|
||||||
{
|
{
|
||||||
getLogger().warn( "POM for: \'" + pomArtifact.getId() + "\' does not appear to be valid. Its will be ignored for artifact resolution." );
|
getLogger()
|
||||||
|
.warn(
|
||||||
|
"POM for: \'" + pomArtifact.getId()
|
||||||
|
+ "\' does not appear to be valid. Its will be ignored for artifact resolution." );
|
||||||
|
|
||||||
project = null;
|
project = null;
|
||||||
}
|
}
|
||||||
|
@ -142,6 +153,7 @@ public class MavenMetadataSource
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
while ( !done );
|
while ( !done );
|
||||||
|
|
||||||
// TODO: this could come straight from the project, negating the need to set it in the project itself?
|
// TODO: this could come straight from the project, negating the need to set it in the project itself?
|
||||||
|
@ -251,6 +263,11 @@ public class MavenMetadataSource
|
||||||
versionRange, d.getType(), d.getClassifier(),
|
versionRange, d.getType(), d.getClassifier(),
|
||||||
scope, inheritedScope );
|
scope, inheritedScope );
|
||||||
|
|
||||||
|
if ( Artifact.SCOPE_SYSTEM.equals( scope ) )
|
||||||
|
{
|
||||||
|
artifact.setFile( new File( d.getSystemPath() ) );
|
||||||
|
}
|
||||||
|
|
||||||
if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) )
|
if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) )
|
||||||
{
|
{
|
||||||
if ( d.getExclusions() != null && !d.getExclusions().isEmpty() )
|
if ( d.getExclusions() != null && !d.getExclusions().isEmpty() )
|
||||||
|
|
|
@ -83,6 +83,7 @@ public class DefaultModelDefaultsInjector
|
||||||
if ( dep.getScope() == null && def.getScope() != null )
|
if ( dep.getScope() == null && def.getScope() != null )
|
||||||
{
|
{
|
||||||
dep.setScope( def.getScope() );
|
dep.setScope( def.getScope() );
|
||||||
|
dep.setSystemPath( def.getSystemPath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( dep.getVersion() == null && def.getVersion() != null )
|
if ( dep.getVersion() == null && def.getVersion() != null )
|
||||||
|
|
|
@ -16,6 +16,7 @@ package org.apache.maven.project.validation;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
import org.apache.maven.model.DependencyManagement;
|
import org.apache.maven.model.DependencyManagement;
|
||||||
|
@ -23,6 +24,7 @@ import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.ReportPlugin;
|
import org.apache.maven.model.ReportPlugin;
|
||||||
import org.apache.maven.model.Reporting;
|
import org.apache.maven.model.Reporting;
|
||||||
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -62,6 +64,15 @@ public class DefaultModelValidator
|
||||||
validateSubElementStringNotEmpty( d, "dependencies.dependency.type", result, d.getType() );
|
validateSubElementStringNotEmpty( d, "dependencies.dependency.type", result, d.getType() );
|
||||||
|
|
||||||
validateSubElementStringNotEmpty( d, "dependencies.dependency.version", result, d.getVersion() );
|
validateSubElementStringNotEmpty( d, "dependencies.dependency.version", result, d.getVersion() );
|
||||||
|
|
||||||
|
if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isEmpty( d.getSystemPath() ) )
|
||||||
|
{
|
||||||
|
result.addMessage( "For dependency " + d + ": system-scoped dependency must specify systemPath." );
|
||||||
|
}
|
||||||
|
else if ( !Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isNotEmpty( d.getSystemPath() ) )
|
||||||
|
{
|
||||||
|
result.addMessage( "For dependency " + d + ": only dependency with system scope can specify systemPath." );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DependencyManagement mgmt = model.getDependencyManagement();
|
DependencyManagement mgmt = model.getDependencyManagement();
|
||||||
|
@ -76,6 +87,15 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
validateSubElementStringNotEmpty( d, "dependencyManagement.dependencies.dependency.groupId", result,
|
validateSubElementStringNotEmpty( d, "dependencyManagement.dependencies.dependency.groupId", result,
|
||||||
d.getGroupId() );
|
d.getGroupId() );
|
||||||
|
|
||||||
|
if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isEmpty( d.getSystemPath() ) )
|
||||||
|
{
|
||||||
|
result.addMessage( "For managed dependency " + d + ": system-scoped dependency must specify systemPath." );
|
||||||
|
}
|
||||||
|
else if ( !Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isNotEmpty( d.getSystemPath() ) )
|
||||||
|
{
|
||||||
|
result.addMessage( "For managed dependency " + d + ": only dependency with system scope can specify systemPath." );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
package org.apache.maven.project.artifact;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
|
import org.apache.maven.model.Dependency;
|
||||||
|
import org.apache.maven.model.DependencyManagement;
|
||||||
|
import org.apache.maven.model.Model;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.project.injection.ModelDefaultsInjector;
|
||||||
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MavenMetadataSourceTest
|
||||||
|
extends PlexusTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public void testShouldUseCompileScopeIfDependencyScopeEmpty() throws Exception
|
||||||
|
{
|
||||||
|
String groupId = "org.apache.maven";
|
||||||
|
String artifactId = "maven-model";
|
||||||
|
|
||||||
|
Dependency dep = new Dependency();
|
||||||
|
|
||||||
|
dep.setGroupId(groupId);
|
||||||
|
dep.setArtifactId(artifactId);
|
||||||
|
dep.setVersion("2.0-alpha-3");
|
||||||
|
|
||||||
|
Model model = new Model();
|
||||||
|
|
||||||
|
model.addDependency(dep);
|
||||||
|
|
||||||
|
MavenProject project = new MavenProject( model );
|
||||||
|
|
||||||
|
ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||||
|
|
||||||
|
project.setArtifacts( project.createArtifacts(factory, null, null) );
|
||||||
|
|
||||||
|
String key = ArtifactUtils.versionlessKey(groupId, artifactId );
|
||||||
|
|
||||||
|
Map artifactMap = project.getArtifactMap();
|
||||||
|
|
||||||
|
assertNotNull( "artifact-map should not be null.", artifactMap );
|
||||||
|
assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
|
||||||
|
|
||||||
|
Artifact artifact = (Artifact) artifactMap.get( key );
|
||||||
|
|
||||||
|
assertNotNull( "dependency artifact not found in map.", artifact );
|
||||||
|
assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_COMPILE, artifact.getScope() );
|
||||||
|
|
||||||
|
//check for back-propagation of default scope.
|
||||||
|
assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_COMPILE, dep.getScope() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testShouldUseInjectedTestScopeFromDependencyManagement() throws Exception
|
||||||
|
{
|
||||||
|
String groupId = "org.apache.maven";
|
||||||
|
String artifactId = "maven-model";
|
||||||
|
|
||||||
|
Dependency dep = new Dependency();
|
||||||
|
|
||||||
|
dep.setGroupId(groupId);
|
||||||
|
dep.setArtifactId(artifactId);
|
||||||
|
dep.setVersion("2.0-alpha-3");
|
||||||
|
|
||||||
|
Model model = new Model();
|
||||||
|
|
||||||
|
model.addDependency(dep);
|
||||||
|
|
||||||
|
Dependency mgd = new Dependency();
|
||||||
|
mgd.setGroupId( groupId);
|
||||||
|
mgd.setArtifactId( artifactId );
|
||||||
|
mgd.setScope( Artifact.SCOPE_TEST);
|
||||||
|
|
||||||
|
DependencyManagement depMgmt = new DependencyManagement();
|
||||||
|
|
||||||
|
depMgmt.addDependency(mgd);
|
||||||
|
|
||||||
|
model.setDependencyManagement(depMgmt);
|
||||||
|
|
||||||
|
MavenProject project = new MavenProject( model );
|
||||||
|
|
||||||
|
ModelDefaultsInjector injector = (ModelDefaultsInjector) lookup( ModelDefaultsInjector.ROLE );
|
||||||
|
|
||||||
|
injector.injectDefaults( model );
|
||||||
|
|
||||||
|
ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||||
|
|
||||||
|
project.setArtifacts( project.createArtifacts(factory, null, null) );
|
||||||
|
|
||||||
|
String key = ArtifactUtils.versionlessKey(groupId, artifactId );
|
||||||
|
|
||||||
|
Map artifactMap = project.getArtifactMap();
|
||||||
|
|
||||||
|
assertNotNull( "artifact-map should not be null.", artifactMap );
|
||||||
|
assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
|
||||||
|
|
||||||
|
Artifact artifact = (Artifact) artifactMap.get( key );
|
||||||
|
|
||||||
|
assertNotNull( "dependency artifact not found in map.", artifact );
|
||||||
|
assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_TEST, artifact.getScope() );
|
||||||
|
|
||||||
|
//check for back-propagation of default scope.
|
||||||
|
assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue