[MASSEMBLY-675] Maven Assembly packaging wildcard-excluded dependencies
Since Maven 3 requirement, there is no need to resolve any dependencies
manually, and we can rely on requiresDependencyResolution. Initial patch
failed when module sets were involved: instead of getting the list of
transitive/direct dependencies on the current project, they need to be
fetched for each project so that it encompasses the possible modules in
module sets.
All the dead code as a result of this change is removed.
This closes #2.
diff --git a/src/it/projects/dependency-sets/massembly-675/pom.xml b/src/it/projects/dependency-sets/massembly-675/pom.xml
new file mode 100644
index 0000000..369030c
--- /dev/null
+++ b/src/it/projects/dependency-sets/massembly-675/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.plugin.assembly.test</groupId>
+ <artifactId>it-project-parent</artifactId>
+ <version>1</version>
+ </parent>
+
+ <groupId>test</groupId>
+ <artifactId>massembly-675</artifactId>
+ <version>1</version>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>com.google.javascript</groupId>
+ <artifactId>closure-compiler</artifactId>
+ <version>v20131014</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>*</artifactId>
+ <groupId>*</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>${testVersion}</version>
+ <executions>
+ <execution>
+ <id>assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/bin.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/projects/dependency-sets/massembly-675/src/main/assembly/bin.xml b/src/it/projects/dependency-sets/massembly-675/src/main/assembly/bin.xml
new file mode 100644
index 0000000..6cf159c
--- /dev/null
+++ b/src/it/projects/dependency-sets/massembly-675/src/main/assembly/bin.xml
@@ -0,0 +1,28 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<assembly>
+ <id>bin</id>
+ <formats>
+ <format>dir</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <dependencySets>
+ <dependencySet/>
+ </dependencySets>
+</assembly>
\ No newline at end of file
diff --git a/src/it/projects/dependency-sets/massembly-675/verify.bsh b/src/it/projects/dependency-sets/massembly-675/verify.bsh
new file mode 100644
index 0000000..f8a95ab
--- /dev/null
+++ b/src/it/projects/dependency-sets/massembly-675/verify.bsh
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+
+boolean result = true;
+
+result = result && new File( basedir, "target/massembly-675-1-bin/massembly-675-1.jar" ).exists();
+result = result && new File( basedir, "target/massembly-675-1-bin/closure-compiler-v20131014.jar" ).exists();
+
+// assert that all the transitive dependencies of closure-compiler were excluded
+result = result && !new File( basedir, "target/massembly-675-1-bin/args4j-2.0.16.jar" ).exists();
+result = result && !new File( basedir, "target/massembly-675-1-bin/json-20090211.jar" ).exists();
+result = result && !new File( basedir, "target/massembly-675-1-bin/protobuf-java-2.4.1.jar" ).exists();
+result = result && !new File( basedir, "target/massembly-675-1-bin/jsr305-1.3.9.jar" ).exists();
+result = result && !new File( basedir, "target/massembly-675-1-bin/guava-15.0.jar" ).exists();
+
+
+return result;
diff --git a/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java b/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java
index 936e250..81a98cb 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java
@@ -19,15 +19,12 @@
* under the License.
*/
-import java.util.ArrayList;
-import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
import org.apache.maven.plugins.assembly.archive.phase.ModuleSetAssemblyPhase;
@@ -35,16 +32,8 @@
import org.apache.maven.plugins.assembly.model.DependencySet;
import org.apache.maven.plugins.assembly.model.ModuleBinaries;
import org.apache.maven.plugins.assembly.model.ModuleSet;
-import org.apache.maven.plugins.assembly.model.Repository;
-import org.apache.maven.plugins.assembly.resolved.AssemblyId;
-import org.apache.maven.plugins.assembly.utils.FilterUtils;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.RepositorySystem;
-import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
-import org.apache.maven.shared.artifact.resolve.ArtifactResult;
-import org.apache.maven.shared.dependencies.resolve.DependencyResolverException;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@@ -62,9 +51,6 @@
@Requirement
private RepositorySystem resolver;
- @Requirement
- private org.apache.maven.shared.dependencies.resolve.DependencyResolver dependencyResolver;
-
@Override
public Map<DependencySet, Set<Artifact>> resolveDependencySets( final Assembly assembly, ModuleSet moduleSet,
final AssemblerConfigurationSource configSource,
@@ -78,38 +64,16 @@
final MavenProject currentProject = configSource.getProject();
- final ResolutionManagementInfo info = new ResolutionManagementInfo( currentProject );
- updateRepositoryResolutionRequirements( assembly, info );
- final AssemblyId assemblyId = AssemblyId.createAssemblyId( assembly );
- updateDependencySetResolutionRequirements( dependencySet, info, assemblyId,
- configSource.getMavenSession().getProjectBuildingRequest(),
- currentProject );
- updateModuleSetResolutionRequirements( assemblyId, moduleSet, dependencySet, info, configSource );
+ final ResolutionManagementInfo info = new ResolutionManagementInfo();
+ updateDependencySetResolutionRequirements( dependencySet, info, currentProject );
+ updateModuleSetResolutionRequirements( moduleSet, dependencySet, info, configSource );
- result.put( dependencySet, resolve( info, currentProject ) );
+ result.put( dependencySet, info.getArtifacts() );
}
return result;
}
- private Set<Artifact> resolve( ResolutionManagementInfo info, MavenProject project )
- {
- Set<Artifact> artifacts = new HashSet<>();
- if ( info.isResolvedTransitively() )
- {
- getLogger().debug( "Resolving project dependencies transitively." );
- artifacts = project.getArtifacts();
- }
- else
- {
- getLogger().debug( "Resolving project dependencies ONLY. "
- + "Transitive dependencies WILL NOT be included in the results." );
- artifacts = project.getDependencyArtifacts();
- }
-
- return artifacts;
- }
-
@Override
public Map<DependencySet, Set<Artifact>> resolveDependencySets( final Assembly assembly,
final AssemblerConfigurationSource configSource,
@@ -123,41 +87,16 @@
final MavenProject currentProject = configSource.getProject();
- final ResolutionManagementInfo info = new ResolutionManagementInfo( currentProject );
- updateRepositoryResolutionRequirements( assembly, info );
- final AssemblyId assemblyId = AssemblyId.createAssemblyId( assembly );
- updateDependencySetResolutionRequirements( dependencySet, info, assemblyId,
- configSource.getMavenSession().getProjectBuildingRequest(),
- currentProject );
+ final ResolutionManagementInfo info = new ResolutionManagementInfo();
+ updateDependencySetResolutionRequirements( dependencySet, info, currentProject );
- result.put( dependencySet, resolve( info, currentProject ) );
+ result.put( dependencySet, info.getArtifacts() );
}
return result;
}
-
- void updateRepositoryResolutionRequirements( final Assembly assembly, final ResolutionManagementInfo requirements )
- {
- final List<Repository> repositories = assembly.getRepositories();
-
- Set<String> rootScopes = new HashSet<String>();
-
- if ( repositories != null && !repositories.isEmpty() )
- {
-
- requirements.setResolutionRequired( true );
- for ( final Repository repo : repositories )
- {
- rootScopes.add( repo.getScope() );
- }
- }
-
- requirements.setScopeFilter( FilterUtils.newScopeFilter( rootScopes ) );
- }
-
-
- void updateModuleSetResolutionRequirements( AssemblyId assemblyId, ModuleSet set, DependencySet dependencySet,
+ void updateModuleSetResolutionRequirements( ModuleSet set, DependencySet dependencySet,
final ResolutionManagementInfo requirements,
final AssemblerConfigurationSource configSource )
throws DependencyResolutionException
@@ -176,47 +115,30 @@
e );
}
- if ( !projects.isEmpty() )
+ for ( final MavenProject p : projects )
{
- for ( final MavenProject p : projects )
+ if ( p.getArtifact() == null )
{
- requirements.enableProjectResolution( p );
-
- if ( p.getArtifact() == null )
- {
- // TODO: such a call in MavenMetadataSource too - packaging not really the intention of
- // type
- final Artifact artifact =
- resolver.createArtifact( p.getGroupId(), p.getArtifactId(), p.getVersion(),
- p.getPackaging() );
- p.setArtifact( artifact );
- }
+ // TODO: such a call in MavenMetadataSource too - packaging not really the intention of type
+ final Artifact artifact =
+ resolver.createArtifact( p.getGroupId(), p.getArtifactId(), p.getVersion(), p.getPackaging() );
+ p.setArtifact( artifact );
}
}
if ( binaries.isIncludeDependencies() )
{
- updateDependencySetResolutionRequirements( dependencySet, requirements, assemblyId,
- configSource.getMavenSession().getProjectBuildingRequest(),
+ updateDependencySetResolutionRequirements( dependencySet, requirements,
projects.toArray( new MavenProject[projects.size()] ) );
}
}
}
void updateDependencySetResolutionRequirements( final DependencySet set,
- final ResolutionManagementInfo requirements, AssemblyId assemblyId,
- ProjectBuildingRequest buildingRequest,
+ final ResolutionManagementInfo requirements,
final MavenProject... projects )
throws DependencyResolutionException
{
- requirements.setResolutionRequired( true );
-
- requirements.setResolvedTransitively( set.isUseTransitiveDependencies() );
-
- ScopeFilter scopeFilter = FilterUtils.newScopeFilter( set.getScope() );
-
- requirements.setScopeFilter( scopeFilter );
-
for ( final MavenProject project : projects )
{
if ( project == null )
@@ -224,30 +146,14 @@
continue;
}
- Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
- if ( dependencyArtifacts == null )
+ Set<Artifact> dependencyArtifacts = null;
+ if ( set.isUseTransitiveDependencies() )
{
- try
- {
- ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( buildingRequest );
- pbr.setRemoteRepositories( project.getRemoteArtifactRepositories() );
- Iterable<ArtifactResult> artifactResults =
- dependencyResolver.resolveDependencies( pbr, project.getModel(), scopeFilter );
-
- dependencyArtifacts = new HashSet<Artifact>();
-
- for ( ArtifactResult artifactResult : artifactResults )
- {
- dependencyArtifacts.add( artifactResult.getArtifact() );
- }
-
- project.setDependencyArtifacts( dependencyArtifacts );
- }
- catch ( final DependencyResolverException e )
- {
- throw new DependencyResolutionException(
- "Failed to create dependency artifacts for resolution. Assembly: " + assemblyId, e );
- }
+ dependencyArtifacts = project.getArtifacts();
+ }
+ else
+ {
+ dependencyArtifacts = project.getDependencyArtifacts();
}
requirements.addArtifacts( dependencyArtifacts );
@@ -256,36 +162,4 @@
}
}
- List<ArtifactRepository> aggregateRemoteArtifactRepositories( final List<ArtifactRepository> remoteRepositories,
- final Set<MavenProject> projects )
- {
- final List<List<ArtifactRepository>> repoLists = new ArrayList<List<ArtifactRepository>>();
-
- repoLists.add( remoteRepositories );
- for ( final MavenProject project : projects )
- {
- repoLists.add( project.getRemoteArtifactRepositories() );
- }
-
- final List<ArtifactRepository> remoteRepos = new ArrayList<ArtifactRepository>();
- final Set<String> encounteredUrls = new HashSet<String>();
-
- for ( final List<ArtifactRepository> repositoryList : repoLists )
- {
- if ( ( repositoryList != null ) && !repositoryList.isEmpty() )
- {
- for ( final ArtifactRepository repo : repositoryList )
- {
- if ( !encounteredUrls.contains( repo.getUrl() ) )
- {
- remoteRepos.add( repo );
- encounteredUrls.add( repo.getUrl() );
- }
- }
- }
- }
-
- return remoteRepos;
- }
-
}
diff --git a/src/main/java/org/apache/maven/plugins/assembly/artifact/ResolutionManagementInfo.java b/src/main/java/org/apache/maven/plugins/assembly/artifact/ResolutionManagementInfo.java
index 87d1e3d..59904a4 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/artifact/ResolutionManagementInfo.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/artifact/ResolutionManagementInfo.java
@@ -20,8 +20,6 @@
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -34,66 +32,8 @@
*/
class ResolutionManagementInfo
{
- private ScopeFilter scopeFilter;
-
- private final Set<MavenProject> enabledProjects = new LinkedHashSet<MavenProject>();
-
private final LinkedHashSet<Artifact> artifacts = new LinkedHashSet<Artifact>();
- private boolean resolutionRequired;
-
- private boolean resolvedTransitively;
-
- ResolutionManagementInfo( final MavenProject currentProject )
- {
- enabledProjects.add( currentProject );
- }
-
- boolean isResolutionRequired()
- {
- return resolutionRequired;
- }
-
- void setResolutionRequired( final boolean resolutionRequired )
- {
- this.resolutionRequired = resolutionRequired;
- }
-
- boolean isResolvedTransitively()
- {
- return resolvedTransitively;
- }
-
- void setResolvedTransitively( final boolean resolvedTransitively )
- {
- this.resolvedTransitively = this.resolvedTransitively || resolvedTransitively;
- }
-
- ScopeFilter getScopeFilter()
- {
- return scopeFilter;
- }
-
- void setScopeFilter( ScopeFilter scopeFilter )
- {
- this.scopeFilter = scopeFilter;
- }
-
-
-
- void enableProjectResolution( final MavenProject project )
- {
- if ( !enabledProjects.contains( project ) )
- {
- enabledProjects.add( project );
- }
- }
-
- Set<MavenProject> getEnabledProjects()
- {
- return enabledProjects;
- }
-
Set<Artifact> getArtifacts()
{
return artifacts;
diff --git a/src/test/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolverTest.java b/src/test/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolverTest.java
index 4d418b4..7b238c2 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolverTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolverTest.java
@@ -22,18 +22,16 @@
import static org.easymock.EasyMock.expect;
import java.io.File;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.List;
+import java.util.HashSet;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.repository.LegacyLocalRepositoryManager;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
@@ -42,33 +40,18 @@
import org.apache.maven.model.Model;
import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
-import org.apache.maven.plugins.assembly.model.Assembly;
import org.apache.maven.plugins.assembly.model.DependencySet;
import org.apache.maven.plugins.assembly.model.ModuleBinaries;
import org.apache.maven.plugins.assembly.model.ModuleSet;
-import org.apache.maven.plugins.assembly.model.Repository;
-import org.apache.maven.plugins.assembly.resolved.AssemblyId;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.easymock.classextension.EasyMockSupport;
-import org.sonatype.aether.RepositorySystemSession;
-import org.sonatype.aether.repository.LocalRepositoryManager;
public class DefaultDependencyResolverTest
extends PlexusTestCase
{
- private ArtifactFactory factory;
-
- private ArtifactRepositoryFactory repoFactory;
-
- private ArtifactRepositoryLayout layout;
-
private DefaultDependencyResolver resolver;
@Override
@@ -78,10 +61,6 @@
super.setUp();
resolver = (DefaultDependencyResolver) lookup( DependencyResolver.class );
-
- factory = lookup( ArtifactFactory.class );
- repoFactory = lookup( ArtifactRepositoryFactory.class );
- layout = lookup( ArtifactRepositoryLayout.class, "default" );
}
protected MavenSession newMavenSession( MavenProject project )
@@ -100,41 +79,49 @@
}
- public void test_getDependencySetResolutionRequirements()
+ public void test_getDependencySetResolutionRequirements_transitive()
throws DependencyResolutionException
{
- final DependencySet ds1 = new DependencySet();
- ds1.setScope( Artifact.SCOPE_COMPILE );
- ds1.setUseTransitiveDependencies( false );
-
- final DependencySet ds2 = new DependencySet();
- ds2.setScope( Artifact.SCOPE_SYSTEM );
- ds2.setUseTransitiveDependencies( false );
+ final DependencySet ds = new DependencySet();
+ ds.setScope( Artifact.SCOPE_SYSTEM );
+ ds.setUseTransitiveDependencies( true );
final MavenProject project = createMavenProject( "main-group", "main-artifact", "1", null );
- final ResolutionManagementInfo info = new ResolutionManagementInfo( project );
+ Set<Artifact> dependencyArtifacts = new HashSet<>();
+ dependencyArtifacts.add( newArtifact( "g.id", "a-id", "1" ) );
+ Set<Artifact> artifacts = new HashSet<>( dependencyArtifacts );
+ artifacts.add( newArtifact( "g.id", "a-id-2", "2" ) );
+ project.setArtifacts( artifacts );
+ project.setDependencyArtifacts( dependencyArtifacts );
- final Assembly assembly = new Assembly();
-
- ProjectBuildingRequest buildingRequest = newMavenSession( project ).getProjectBuildingRequest();
-
- resolver.updateDependencySetResolutionRequirements( ds1, info, AssemblyId.createAssemblyId( assembly ),
- buildingRequest, project );
-
- assertTrue( info.isResolutionRequired() );
- assertFalse( info.isResolvedTransitively() );
-
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_COMPILE ) );
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_SYSTEM ) );
-
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_PROVIDED ) );
-
- assertFalse( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_RUNTIME ) );
- assertFalse( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_TEST ) );
+ final ResolutionManagementInfo info = new ResolutionManagementInfo();
+ resolver.updateDependencySetResolutionRequirements( ds, info, project );
+ assertEquals( artifacts, info.getArtifacts() );
}
- public void test_getModuleSetResolutionRequirements()
+ public void test_getDependencySetResolutionRequirements_nonTransitive()
+ throws DependencyResolutionException
+ {
+ final DependencySet ds = new DependencySet();
+ ds.setScope( Artifact.SCOPE_SYSTEM );
+ ds.setUseTransitiveDependencies( false );
+
+ final MavenProject project = createMavenProject( "main-group", "main-artifact", "1", null );
+
+ Set<Artifact> dependencyArtifacts = new HashSet<>();
+ dependencyArtifacts.add( newArtifact( "g.id", "a-id", "1" ) );
+ Set<Artifact> artifacts = new HashSet<>( dependencyArtifacts );
+ artifacts.add( newArtifact( "g.id", "a-id-2", "2" ) );
+ project.setArtifacts( artifacts );
+ project.setDependencyArtifacts( dependencyArtifacts );
+
+ final ResolutionManagementInfo info = new ResolutionManagementInfo();
+ resolver.updateDependencySetResolutionRequirements( ds, info, project );
+ assertEquals( dependencyArtifacts, info.getArtifacts() );
+ }
+
+ public void test_getModuleSetResolutionRequirements_withoutBinaries()
throws DependencyResolutionException
{
final EasyMockSupport mm = new EasyMockSupport();
@@ -143,484 +130,71 @@
final File rootDir = new File( "root" );
final MavenProject project = createMavenProject( "main-group", "main-artifact", "1", rootDir );
-
- final File module1Dir = new File( rootDir, "module-1" );
- final MavenProject module1 = createMavenProject( "main-group", "module-1", "1", module1Dir );
- final MavenProject module1a =
- createMavenProject( "group1", "module-1a", "1", new File( module1Dir, "module-1a" ) );
- final MavenProject module1b =
- createMavenProject( "group1.b", "module-1b", "1", new File( module1Dir, "module-1b" ) );
-
- module1.getModel().addModule( module1a.getArtifactId() );
- module1.getModel().addModule( module1b.getArtifactId() );
-
- final File module2Dir = new File( rootDir, "module-2" );
- final MavenProject module2 = createMavenProject( "main-group", "module-2", "1", module2Dir );
- final MavenProject module2a =
- createMavenProject( "main-group", "module-2a", "1", new File( module2Dir, "module-2a" ) );
-
- module2.getModel().addModule( module2a.getArtifactId() );
+ final MavenProject module1 =
+ createMavenProject( "main-group", "module-1", "1", new File( rootDir, "module-1" ) );
+ final MavenProject module2 =
+ createMavenProject( "main-group", "module-2", "1", new File( rootDir, "module-2" ) );
project.getModel().addModule( module1.getArtifactId() );
project.getModel().addModule( module2.getArtifactId() );
- final List<MavenProject> allProjects = new ArrayList<MavenProject>();
- allProjects.add( project );
- allProjects.add( module1 );
- allProjects.add( module1a );
- allProjects.add( module1b );
- allProjects.add( module2 );
- allProjects.add( module2a );
-
- expect( cs.getReactorProjects() ).andReturn( allProjects ).anyTimes();
-
+ expect( cs.getReactorProjects() ).andReturn( Arrays.asList( project, module1, module2 ) ).anyTimes();
expect( cs.getProject() ).andReturn( project ).anyTimes();
-
expect( cs.getMavenSession() ).andReturn( newMavenSession( project ) ).anyTimes();
- final ResolutionManagementInfo info = new ResolutionManagementInfo( project );
+ final ResolutionManagementInfo info = new ResolutionManagementInfo();
- final List<ModuleSet> moduleSets = new ArrayList<ModuleSet>();
-
- final ModuleSet ms1 = new ModuleSet();
- final DependencySet ds1 = new DependencySet();
- {
- ms1.addInclude( "*module1*" );
- ms1.setIncludeSubModules( false );
-
- final ModuleBinaries mb = new ModuleBinaries();
-
- ds1.setScope( Artifact.SCOPE_COMPILE );
-
- mb.addDependencySet( ds1 );
- ms1.setBinaries( mb );
- moduleSets.add( ms1 );
- }
-
- final ModuleSet ms2 = new ModuleSet();
- final DependencySet ds2 = new DependencySet();
- {
- ms2.addInclude( "main-group:*" );
- ms2.setIncludeSubModules( true );
-
- final ModuleBinaries mb = new ModuleBinaries();
-
- ds2.setScope( Artifact.SCOPE_TEST );
-
- mb.addDependencySet( ds2 );
- ms2.setBinaries( mb );
- moduleSets.add( ms2 );
- }
+ final ModuleSet ms = new ModuleSet();
+ ms.setBinaries( null );
mm.replayAll();
- resolver.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
-
- final Assembly assembly = new Assembly();
- assembly.setModuleSets( moduleSets );
-
- resolver.updateModuleSetResolutionRequirements( AssemblyId.createAssemblyId( assembly ), ms1, ds1, info, cs );
- resolver.updateModuleSetResolutionRequirements( AssemblyId.createAssemblyId( assembly ), ms2, ds2, info, cs );
-
- assertTrue( info.isResolutionRequired() );
-
- final Set<MavenProject> enabledProjects = info.getEnabledProjects();
- assertTrue( enabledProjects.contains( project ) );
-
- assertTrue( enabledProjects.contains( module1 ) );
-
- // these should be excluded since sub-modules are not traversable
- assertFalse( enabledProjects.contains( module1a ) );
- assertFalse( enabledProjects.contains( module1b ) );
-
- assertTrue( enabledProjects.contains( module2 ) );
- assertTrue( enabledProjects.contains( module2a ) );
-
- // these are the two we directly set above.
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_TEST ) );
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_COMPILE ) );
-
- // this combination should be implied by the two direct scopes set above.
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_RUNTIME ) );
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_PROVIDED ) );
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_SYSTEM ) );
+ resolver.updateModuleSetResolutionRequirements( ms, new DependencySet(), info, cs );
+ assertTrue( info.getArtifacts().isEmpty() );
mm.verifyAll();
}
- public void test_getRepositoryResolutionRequirements()
+ public void test_getModuleSetResolutionRequirements_includeDeps()
+ throws DependencyResolutionException
{
- final List<Repository> repositories = new ArrayList<Repository>();
+ final EasyMockSupport mm = new EasyMockSupport();
- {
- final Repository r = new Repository();
- r.setScope( Artifact.SCOPE_COMPILE );
- repositories.add( r );
- }
+ final AssemblerConfigurationSource cs = mm.createMock( AssemblerConfigurationSource.class );
- {
- final Repository r = new Repository();
- r.setScope( Artifact.SCOPE_SYSTEM );
- repositories.add( r );
- }
+ final File rootDir = new File( "root" );
+ final MavenProject project = createMavenProject( "main-group", "main-artifact", "1", rootDir );
+ final MavenProject module1 =
+ createMavenProject( "main-group", "module-1", "1", new File( rootDir, "module-1" ) );
+ final MavenProject module2 =
+ createMavenProject( "main-group", "module-2", "1", new File( rootDir, "module-2" ) );
- final MavenProject project = createMavenProject( "group", "artifact", "1.0", null );
- final Assembly assembly = new Assembly();
- assembly.setRepositories( repositories );
+ Set<Artifact> module1Artifacts = Collections.singleton( newArtifact( "group.id", "module-1-dep", "1" ) );
+ Set<Artifact> module2Artifacts = Collections.singleton( newArtifact( "group.id", "module-2-dep", "1" ) );
+ module1.setArtifacts( module1Artifacts );
+ module2.setArtifacts( module2Artifacts );
- final ResolutionManagementInfo info = new ResolutionManagementInfo( project );
- resolver.updateRepositoryResolutionRequirements( assembly,
- info );
+ project.getModel().addModule( module1.getArtifactId() );
+ project.getModel().addModule( module2.getArtifactId() );
- assertTrue( info.isResolutionRequired() );
+ expect( cs.getReactorProjects() ).andReturn( Arrays.asList( project, module1, module2 ) ).anyTimes();
+ expect( cs.getProject() ).andReturn( project ).anyTimes();
+ expect( cs.getMavenSession() ).andReturn( newMavenSession( project ) ).anyTimes();
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_COMPILE ) );
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_SYSTEM ) );
+ final ResolutionManagementInfo info = new ResolutionManagementInfo();
- assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_PROVIDED ) );
+ final ModuleSet ms = new ModuleSet();
+ final ModuleBinaries mb = new ModuleBinaries();
+ mb.setIncludeDependencies( true );
+ ms.setBinaries( mb );
+ ms.addInclude( "*:module-1" );
- assertFalse( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_RUNTIME ) );
- assertFalse( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_TEST ) );
- }
+ mm.replayAll();
- public void test_aggregateRemoteArtifactRepositories()
- {
- final List<ArtifactRepository> externalRepos = new ArrayList<ArtifactRepository>();
+ resolver.updateModuleSetResolutionRequirements( ms, new DependencySet(), info, cs );
+ assertEquals( module1Artifacts, info.getArtifacts() );
- final ArtifactRepository er1 =
- repoFactory.createArtifactRepository( "test.1", "http://test.com/path", layout, null, null );
- externalRepos.add( er1 );
-
- final ArtifactRepository er2 =
- repoFactory.createArtifactRepository( "test.2", "http://test2.com/path", layout, null, null );
- externalRepos.add( er2 );
-
- final List<ArtifactRepository> projectRepos = new ArrayList<ArtifactRepository>();
-
- final ArtifactRepository pr1 =
- repoFactory.createArtifactRepository( "project.1", "http://test.com/project", layout, null, null );
- projectRepos.add( pr1 );
-
- final ArtifactRepository pr2 =
- repoFactory.createArtifactRepository( "project.2", "http://test2.com/path", layout, null, null );
- projectRepos.add( pr2 );
-
- final MavenProject project = createMavenProject( "group", "artifact", "1", new File( "base" ) );
- project.setRemoteArtifactRepositories( projectRepos );
-
- final List<ArtifactRepository> aggregated =
- resolver.aggregateRemoteArtifactRepositories( externalRepos, Collections.singleton( project ) );
-
- assertRepositoryWithId( er1.getId(), aggregated, true );
- assertRepositoryWithId( er2.getId(), aggregated, true );
- assertRepositoryWithId( pr1.getId(), aggregated, true );
- assertRepositoryWithId( pr2.getId(), aggregated, false );
- }
-
- // public void test_manageArtifact()
- // {
- // Artifact managed = factory.createArtifact( "group", "artifact", "1", Artifact.SCOPE_PROVIDED, "jar" );
- //
- // Artifact target =
- // factory.createArtifact( managed.getGroupId(), managed.getArtifactId(), "2", Artifact.SCOPE_COMPILE,
- // managed.getType() );
- //
- // Artifact target2 =
- // factory.createArtifact( "other-group", managed.getArtifactId(), "2", Artifact.SCOPE_COMPILE,
- // managed.getType() );
- //
- // Map managedVersions = Collections.singletonMap( managed.getDependencyConflictId(), managed );
- //
- // DefaultDependencyResolver resolver =
- // new DefaultDependencyResolver().setLogger( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
- //
- // resolver.manageArtifact( target, managedVersions );
- // resolver.manageArtifact( target2, managedVersions );
- //
- // assertEquals( managed.getVersion(), target.getVersion() );
- // assertEquals( managed.getScope(), target.getScope() );
- //
- // assertEquals( "2", target2.getVersion() );
- // assertEquals( Artifact.SCOPE_COMPILE, target2.getScope() );
- // }
-
- // public void test_buildManagedVersionMap_NonTransitiveResolution()
- // throws ArtifactResolutionException, ArchiveCreationException, InvalidVersionSpecificationException,
- // InvalidDependencyVersionException
- // {
- // Assembly assembly = new Assembly();
- //
- // DependencySet ds = new DependencySet();
- // ds.setScope( Artifact.SCOPE_PROVIDED );
- // ds.setUseTransitiveDependencies( false );
- //
- // assembly.addDependencySet( ds );
- //
- // ModuleSet ms = new ModuleSet();
- // ModuleBinaries mb = new ModuleBinaries();
- // ms.setBinaries( mb );
- //
- // DependencySet mds = new DependencySet();
- // mds.setScope( Artifact.SCOPE_PROVIDED );
- // mds.setUseTransitiveDependencies( false );
- //
- // mb.addDependencySet( mds );
- //
- // assembly.addModuleSet( ms );
- //
- // MavenProject project = createMavenProject( "group", "artifact", "1", new File( "base" ) );
- //
- // Dependency d1 = new Dependency();
- // d1.setGroupId( "group.dep" );
- // d1.setArtifactId( "dep1" );
- // d1.setVersion( "1" );
- // d1.setScope( Artifact.SCOPE_COMPILE );
- //
- // project.getModel().addDependency( d1 );
- //
- // Dependency d2 = new Dependency();
- // d2.setGroupId( "group.dep" );
- // d2.setArtifactId( "dep2" );
- // d2.setVersion( "1" );
- // d2.setScope( Artifact.SCOPE_PROVIDED );
- //
- // project.getModel().addDependency( d2 );
- //
- // Dependency d3 = new Dependency();
- // d3.setGroupId( "group.dep" );
- // d3.setArtifactId( "dep3" );
- // d3.setVersion( "1" );
- // d3.setScope( Artifact.SCOPE_PROVIDED );
- //
- // project.getModel().addDependency( d3 );
- //
- // MavenProject module = createMavenProject( "group", "module", "1", new File( "base/module" ) );
- //
- // project.getModel().addModule( module.getArtifactId() );
- //
- // Dependency md = new Dependency();
- // md.setGroupId( "group.dep" );
- // md.setArtifactId( "dep3" );
- // md.setVersion( "2" );
- // md.setScope( Artifact.SCOPE_PROVIDED );
- //
- // module.getModel().addDependency( md );
- //
- // List allProjects = new ArrayList();
- // allProjects.add( project );
- // allProjects.add( module );
- //
- // MockManager mm = new MockManager();
- //
- // MockControl csControl = MockControl.createControl( AssemblerConfigurationSource.class );
- // mm.add( csControl );
- //
- // AssemblerConfigurationSource cs = (AssemblerConfigurationSource) csControl.getMock();
- //
- // cs.getProject();
- // csControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
- //
- // cs.getReactorProjects();
- // csControl.setReturnValue( allProjects, MockControl.ZERO_OR_MORE );
- //
- // cs.getRemoteRepositories();
- // csControl.setReturnValue( Collections.EMPTY_LIST, MockControl.ZERO_OR_MORE );
- //
- // mm.replayAll();
- //
- // DefaultDependencyResolver resolver = new DefaultDependencyResolver();
- // resolver.setArtifactFactory( factory );
- // resolver.setLogger( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
- //
- // Map managedVersionMap = resolver.buildManagedVersionMap( assembly, cs );
- //
- // {
- // Dependency d = d1;
- // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
- // assertNull( a );
- // }
- //
- // {
- // Dependency d = d2;
- // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
- // assertNotNull( a );
- // assertEquals( d.getVersion(), a.getVersion() );
- // assertEquals( d.getScope(), a.getScope() );
- // }
- //
- // {
- // Dependency d = d3;
- // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
- // assertNotNull( a );
- // assertEquals( d.getVersion(), a.getVersion() );
- // assertEquals( d.getScope(), a.getScope() );
- // }
- //
- // mm.verifyAll();
- // }
- //
- // public void test_buildManagedVersionMap_TransitiveResolution()
- // throws ArtifactResolutionException, ArchiveCreationException, InvalidVersionSpecificationException,
- // InvalidDependencyVersionException
- // {
- // Assembly assembly = new Assembly();
- //
- // DependencySet ds = new DependencySet();
- // ds.setScope( Artifact.SCOPE_COMPILE );
- // ds.setUseTransitiveDependencies( true );
- //
- // assembly.addDependencySet( ds );
- //
- // MavenProject project = createMavenProject( "group", "artifact", "1", new File( "base" ) );
- //
- // Dependency d1 = new Dependency();
- // d1.setGroupId( "group.dep" );
- // d1.setArtifactId( "dep1" );
- // d1.setVersion( "1" );
- // d1.setScope( Artifact.SCOPE_COMPILE );
- //
- // project.getModel().addDependency( d1 );
- //
- // Dependency d2 = new Dependency();
- // d2.setGroupId( "group.dep" );
- // d2.setArtifactId( "dep2" );
- // d2.setVersion( "1" );
- // d2.setScope( Artifact.SCOPE_COMPILE );
- // final Artifact a2 = factory.createArtifact( d2.getGroupId(), d2.getArtifactId(), d2.getVersion(), d2.getScope(),
- // "jar" );
- //
- // project.getModel().addDependency( d2 );
- //
- // Dependency d3 = new Dependency();
- // d3.setGroupId( "group.dep" );
- // d3.setArtifactId( "dep3" );
- // d3.setVersion( "1" );
- // d3.setScope( Artifact.SCOPE_COMPILE );
- //
- // project.getModel().addDependency( d3 );
- //
- // final Artifact a2a = factory.createArtifact( d3.getGroupId(), d3.getArtifactId(), "2", Artifact.SCOPE_RUNTIME,
- // "jar" );
- //
- // MockManager mm = new MockManager();
- //
- // MockControl msControl = MockControl.createControl( ArtifactMetadataSource.class );
- // mm.add( msControl );
- //
- // ArtifactMetadataSource ms = (ArtifactMetadataSource) msControl.getMock();
- //
- // try
- // {
- // ms.retrieve( null, null, null );
- // }
- // catch ( ArtifactMetadataRetrievalException e )
- // {
- // }
- //
- // msControl.setDefaultReturnValue( new ResolutionGroup( null, Collections.EMPTY_SET, Collections.EMPTY_LIST ) );
- // msControl.setMatcher( new ArgumentsMatcher()
- // {
- // public boolean matches( Object[] expected, Object[] actual )
- // {
- // Artifact a = (Artifact) actual[0];
- //
- // return a2.getArtifactId().equals( a.getArtifactId() );
- // }
- //
- // public String toString( Object[] args )
- // {
- // return "with artifact: " + args[0] ;
- // }
- //
- // } );
- // msControl.setReturnValue( new ResolutionGroup( a2, Collections.singleton( a2a ), Collections.EMPTY_LIST ) );
- //
- //
- // MockControl csControl = MockControl.createControl( AssemblerConfigurationSource.class );
- // mm.add( csControl );
- //
- // AssemblerConfigurationSource cs = (AssemblerConfigurationSource) csControl.getMock();
- //
- // cs.getProject();
- // csControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
- //
- // String tmpDir = System.getProperty( "java.io.tmpdir" );
- // ArtifactRepository lr = repoFactory.createArtifactRepository( "local", "file://" + tmpDir, layout, null, null );
- //
- // cs.getLocalRepository();
- // csControl.setReturnValue( lr, MockControl.ZERO_OR_MORE );
- //
- // cs.getRemoteRepositories();
- // csControl.setReturnValue( Collections.EMPTY_LIST, MockControl.ZERO_OR_MORE );
- //
- // mm.replayAll();
- //
- // DefaultDependencyResolver resolver = new DefaultDependencyResolver();
- // resolver.setArtifactMetadataSource( ms );
- // resolver.setArtifactCollector( collector );
- // resolver.setArtifactFactory( factory );
- // resolver.setLogger( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
- //
- // Map managedVersionMap = resolver.buildManagedVersionMap( assembly, cs );
- //
- // {
- // Dependency d = d1;
- // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
- // assertNotNull( a );
- // assertEquals( d.getVersion(), a.getVersion() );
- // assertEquals( d.getScope(), a.getScope() );
- // }
- //
- // {
- // Dependency d = d2;
- // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
- // assertNotNull( a );
- // assertEquals( d.getVersion(), a.getVersion() );
- // assertEquals( d.getScope(), a.getScope() );
- // }
- //
- // {
- // Dependency d = d3;
- // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
- // assertNotNull( a );
- // assertEquals( d.getVersion(), a.getVersion() );
- // assertEquals( d.getScope(), a.getScope() );
- // }
- //
- // mm.verifyAll();
- // }
-
- private void assertRepositoryWithId( final String repoId, final List<ArtifactRepository> repos,
- final boolean shouldExist )
- {
- if ( ( repos == null || repos.isEmpty() ) )
- {
- if ( shouldExist )
- {
- fail( "Repository with id: " + repoId + " should be present, but repository list is null or empty." );
- }
- }
- else
- {
- boolean found = false;
- for ( final ArtifactRepository repo : repos )
- {
- if ( repoId.equals( repo.getId() ) )
- {
- found = true;
- break;
- }
- }
-
- if ( shouldExist )
- {
- assertTrue( "Repository with id: " + repoId + " should be present in repository list.", found );
- }
- else
- {
- assertFalse( "Repository with id: " + repoId + " should NOT be present in repository list.", found );
- }
- }
+ mm.verifyAll();
}
private MavenProject createMavenProject( final String groupId, final String artifactId, final String version,
@@ -635,12 +209,20 @@
final MavenProject project = new MavenProject( model );
- final Artifact pomArtifact = factory.createProjectArtifact( groupId, artifactId, version );
+ final Artifact pomArtifact = newArtifact( groupId, artifactId, version );
project.setArtifact( pomArtifact );
+ project.setArtifacts( new HashSet<Artifact>() );
+ project.setDependencyArtifacts( new HashSet<Artifact>() );
project.setFile( new File( basedir, "pom.xml" ) );
return project;
}
+ private Artifact newArtifact( final String groupId, final String artifactId, final String version )
+ {
+ return new DefaultArtifact( groupId, artifactId, VersionRange.createFromVersion( version ), "compile", "jar",
+ null, new DefaultArtifactHandler() );
+ }
+
}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/artifact/ResolutionManagementInfoTest.java b/src/test/java/org/apache/maven/plugins/assembly/artifact/ResolutionManagementInfoTest.java
index ede62bc..86c2b71 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/artifact/ResolutionManagementInfoTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/artifact/ResolutionManagementInfoTest.java
@@ -24,7 +24,6 @@
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.project.MavenProject;
import java.util.Arrays;
import java.util.Collections;
@@ -43,7 +42,7 @@
public void testAddSingleArtifactWithReplacemen()
throws Exception
{
- ResolutionManagementInfo rmi = new ResolutionManagementInfo( new MavenProject() );
+ ResolutionManagementInfo rmi = new ResolutionManagementInfo();
Artifact a1 = new DefaultArtifact( "groupid", "1", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
new DefaultArtifactHandler() );
rmi.addArtifacts( Collections.singleton( a1 ) );
@@ -59,7 +58,7 @@
public void testAddMultiArtifactWithReplacemen()
throws Exception
{
- ResolutionManagementInfo rmi = new ResolutionManagementInfo( new MavenProject() );
+ ResolutionManagementInfo rmi = new ResolutionManagementInfo();
Artifact a1 =
new DefaultArtifact( "groupid", "a1", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
new DefaultArtifactHandler() );