diff --git a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java index 5f6534d856..68acd290bc 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java @@ -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; } diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index ffa3ac6fae..bde81f380c 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -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 ) { diff --git a/maven-project/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java b/maven-project/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java index 587ec0fb22..3c40aaadd3 100644 --- a/maven-project/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java @@ -3,18 +3,71 @@ 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