mirror of https://github.com/apache/maven.git
[MNG-1797][MNG-2420] Fixing exclusions that bleed over into other dependencies, and modifying DefaultProfileManager to (a) deprecate constructor that takes Settings but no properties, and (b) add a constructor that takes Settings and properties.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@438189 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
136739b708
commit
5d99b35cfe
|
@ -66,13 +66,14 @@ public class DefaultProfileManager
|
|||
*/
|
||||
public DefaultProfileManager( PlexusContainer container, Properties props )
|
||||
{
|
||||
this( container, (Settings)null );
|
||||
if (props != null) {
|
||||
systemProperties = props;
|
||||
}
|
||||
this( container, (Settings)null, props );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated without passing in the system properties, the SystemPropertiesProfileActivator will not work correctly
|
||||
* in embedded envirnments.
|
||||
*/
|
||||
public DefaultProfileManager( PlexusContainer container, Settings settings )
|
||||
{
|
||||
this.container = container;
|
||||
|
@ -80,6 +81,23 @@ public class DefaultProfileManager
|
|||
loadSettingsProfiles( settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* the properties passed to the profile manager are the props that
|
||||
* are passed to maven, possibly containing profile activator properties
|
||||
*
|
||||
*/
|
||||
public DefaultProfileManager( PlexusContainer container, Settings settings, Properties props )
|
||||
{
|
||||
this.container = container;
|
||||
|
||||
loadSettingsProfiles( settings );
|
||||
|
||||
if ( props != null )
|
||||
{
|
||||
systemProperties = props;
|
||||
}
|
||||
}
|
||||
|
||||
public Properties getSystemProperties() {
|
||||
return systemProperties;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ import org.codehaus.plexus.util.StringUtils;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
@ -337,7 +336,9 @@ public class MavenMetadataSource
|
|||
artifact.setFile( new File( d.getSystemPath() ) );
|
||||
}
|
||||
|
||||
if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) )
|
||||
ArtifactFilter artifactFilter = dependencyFilter;
|
||||
|
||||
if ( artifact != null && ( artifactFilter == null || artifactFilter.include( artifact ) ) )
|
||||
{
|
||||
if ( d.getExclusions() != null && !d.getExclusions().isEmpty() )
|
||||
{
|
||||
|
@ -350,20 +351,20 @@ public class MavenMetadataSource
|
|||
|
||||
ArtifactFilter newFilter = new ExcludesArtifactFilter( exclusions );
|
||||
|
||||
if ( dependencyFilter != null )
|
||||
if ( artifactFilter != null )
|
||||
{
|
||||
AndArtifactFilter filter = new AndArtifactFilter();
|
||||
filter.add( dependencyFilter );
|
||||
filter.add( artifactFilter );
|
||||
filter.add( newFilter );
|
||||
dependencyFilter = filter;
|
||||
artifactFilter = filter;
|
||||
}
|
||||
else
|
||||
{
|
||||
dependencyFilter = newFilter;
|
||||
artifactFilter = newFilter;
|
||||
}
|
||||
}
|
||||
|
||||
artifact.setDependencyFilter( dependencyFilter );
|
||||
artifact.setDependencyFilter( artifactFilter );
|
||||
|
||||
if ( project != null )
|
||||
{
|
||||
|
|
|
@ -3,19 +3,72 @@ 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.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
import org.apache.maven.model.Exclusion;
|
||||
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.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class MavenMetadataSourceTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
|
||||
public void testShouldNotCarryExclusionsOverFromDependencyToDependency()
|
||||
throws Exception
|
||||
{
|
||||
Dependency dep1 = new Dependency();
|
||||
dep1.setGroupId( "test" );
|
||||
dep1.setArtifactId( "test-artifact" );
|
||||
dep1.setVersion( "1" );
|
||||
dep1.setType( "jar" );
|
||||
|
||||
Exclusion exc = new Exclusion();
|
||||
exc.setGroupId( "test" );
|
||||
exc.setArtifactId( "test-artifact3" );
|
||||
|
||||
dep1.addExclusion( exc );
|
||||
|
||||
Dependency dep2 = new Dependency();
|
||||
dep2.setGroupId( "test" );
|
||||
dep2.setArtifactId( "test-artifact2" );
|
||||
dep2.setVersion( "1" );
|
||||
dep2.setType( "jar" );
|
||||
|
||||
List deps = new ArrayList();
|
||||
deps.add( dep1 );
|
||||
deps.add( dep2 );
|
||||
|
||||
ArtifactFactory factory = ( ArtifactFactory ) lookup( ArtifactFactory.ROLE );
|
||||
|
||||
ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
|
||||
|
||||
MavenProject project = new MavenProject( new Model() );
|
||||
|
||||
Set result = MavenMetadataSource.createArtifacts( factory, deps, null, dependencyFilter, project );
|
||||
|
||||
for ( Iterator it = result.iterator(); it.hasNext(); )
|
||||
{
|
||||
Artifact artifact = ( Artifact ) it.next();
|
||||
|
||||
if ( "test-artifact2".equals( artifact.getArtifactId() ) )
|
||||
{
|
||||
ArtifactFilter filter = artifact.getDependencyFilter();
|
||||
|
||||
assertSame( dependencyFilter, filter );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testShouldUseCompileScopeIfDependencyScopeEmpty()
|
||||
throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue