This is an automated email from the ASF dual-hosted git repository. cstamas pushed a commit to branch do-not-download-whole-universe in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git
commit f3885e79d940e6cba310b7b9e745036236b0220c Author: Tamas Cservenak <[email protected]> AuthorDate: Tue Apr 26 13:58:31 2022 +0200 Do not download whole universe Problem: try to build maven master with empty repository, you will notice that we get things from repository.sonatype.org repository, that is wrong. Moreover, if you look carefully, you will notice that we download/resolve totally unrelated things to our build, like felix plugin etc. For fun, it downloads Maven 2.2.0, Maven 2.0.7 etc as well. Without PR: https://gist.github.com/cstamas/badb32a25dbe444679774611f61d94b1 Reason: m-assembly-p "rebuilds" all the project of depSet to get MavenProject instance of them and transitive deps, but alas, it was doing it too eagerly: it was getting even plugins that built our dependendencies, while we are really not want them. So, instead to re-use the "project building request" of currently built project, just create a simple PBR that is tuned "just enough" to get results we want, nothing more. We do not want the plugins that built our dependencies. With PR: https://gist.github.com/cstamas/1e9dfd0384dceda7a8195edfc1bfb61b --- .../archive/task/AddDependencySetsTask.java | 9 ++++++- .../archive/task/AddDependencySetsTaskTest.java | 28 ++++++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTask.java b/src/main/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTask.java index 70aec22f..8644c44f 100644 --- a/src/main/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTask.java +++ b/src/main/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTask.java @@ -30,6 +30,7 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.plugins.assembly.AssemblerConfigurationSource; @@ -43,6 +44,7 @@ import org.apache.maven.plugins.assembly.model.UnpackOptions; import org.apache.maven.plugins.assembly.utils.AssemblyFormatUtils; import org.apache.maven.plugins.assembly.utils.FilterUtils; import org.apache.maven.plugins.assembly.utils.TypeConversionUtils; +import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; import org.apache.maven.project.ProjectBuildingException; @@ -181,7 +183,12 @@ public class AddDependencySetsTask extends ComponentSupport private ProjectBuildingRequest getProjectBuildingRequest( AssemblerConfigurationSource configSource ) { - return configSource.getMavenSession().getProjectBuildingRequest(); + MavenSession mavenSession = configSource.getMavenSession(); + return new DefaultProjectBuildingRequest() + .setRepositorySession( mavenSession.getRepositorySession() ) + .setSystemProperties( mavenSession.getSystemProperties() ) + .setUserProperties( mavenSession.getUserProperties() ) + .setProcessPlugins( false ); } private boolean isUnpackWithOptions( DependencySet dependencySet ) diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java index 1d316b1a..d327ac10 100644 --- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java +++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java @@ -62,6 +62,7 @@ import org.codehaus.plexus.archiver.ArchivedFileSet; import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.FileSet; +import org.eclipse.aether.RepositorySystemSession; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -128,7 +129,6 @@ public class AddDependencySetsTaskTest when( projectBuilder.build( any( Artifact.class ), any( ProjectBuildingRequest.class ) ) ).thenReturn( pbr ); final MavenSession session = mock( MavenSession.class ); - when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) ); when( session.getExecutionProperties() ).thenReturn( new Properties() ); final AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class ); @@ -163,7 +163,7 @@ public class AddDependencySetsTaskTest verify( archiver ).setFileMode( 10 ); verify( archiver ).setFileMode( 146 ); - verify( session ).getProjectBuildingRequest(); + verify( session ).getRepositorySession(); verify( session, times( 2 ) ).getExecutionProperties(); verify( projectBuilder ).build( any( Artifact.class ), any( ProjectBuildingRequest.class ) ); @@ -219,7 +219,6 @@ public class AddDependencySetsTaskTest when( projectBuilder.build( any(Artifact.class), any(ProjectBuildingRequest.class) ) ).thenThrow( pbe ); final MavenSession session = mock( MavenSession.class ); - when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) ); when( session.getExecutionProperties() ).thenReturn( new Properties() ); final AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class ); @@ -248,7 +247,7 @@ public class AddDependencySetsTaskTest verify( archiver ).getOverrideDirectoryMode(); verify( archiver ).getOverrideFileMode(); - verify( session ).getProjectBuildingRequest(); + verify( session ).getRepositorySession(); verify( session, times( 2 ) ).getExecutionProperties(); verify( projectBuilder ).build( any(Artifact.class), any(ProjectBuildingRequest.class) ); @@ -283,9 +282,12 @@ public class AddDependencySetsTaskTest ds.setDirectoryMode( Integer.toString( 10, 8 ) ); ds.setFileMode( Integer.toString( 10, 8 ) ); + final RepositorySystemSession repoSession = mock( RepositorySystemSession.class ); final MavenSession session = mock( MavenSession.class ); - when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) ); + when( session.getRepositorySession() ).thenReturn( repoSession ); when( session.getExecutionProperties() ).thenReturn( new Properties() ); + when( session.getSystemProperties() ).thenReturn( new Properties() ); + when( session.getUserProperties() ).thenReturn( new Properties() ); final AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class ); when( configSource.getMavenSession() ).thenReturn( session ); @@ -336,7 +338,7 @@ public class AddDependencySetsTaskTest verify( archiver ).setDirectoryMode( 10 ); verify( archiver ).setDirectoryMode( 146 ); - verify( session ).getProjectBuildingRequest(); + verify( session ).getRepositorySession(); verify( session, atLeastOnce() ).getExecutionProperties(); verify( projectBuilder ).build( any( Artifact.class ), any( ProjectBuildingRequest.class ) ); @@ -386,14 +388,13 @@ public class AddDependencySetsTaskTest Artifact am1 = mock( Artifact.class ); when( am1.getGroupId() ).thenReturn( "group" ); when( am1.getArtifactId() ).thenReturn( "artifact" ); - when( am1.getId() ).thenReturn( "group:artifact:1.0:jar" ); + when( am1.getBaseVersion() ).thenReturn( "version" ); artifacts.add( am1 ); Artifact am2 = mock( Artifact.class ); when( am2.getGroupId() ).thenReturn( "group2" ); when( am2.getArtifactId() ).thenReturn( "artifact2" ); - when( am2.getId() ).thenReturn( "group2:artifact2:1.0:jar" ); - when( am2.getDependencyConflictId() ).thenReturn( "group2:artifact2:jar" ); + when( am2.getBaseVersion() ).thenReturn( "version" ); artifacts.add( am2 ); final DependencySet dependencySet = new DependencySet(); @@ -422,14 +423,13 @@ public class AddDependencySetsTaskTest Artifact am1 = mock( Artifact.class ); when( am1.getGroupId() ).thenReturn( "group" ); when( am1.getArtifactId() ).thenReturn( "artifact" ); - when( am1.getId() ).thenReturn( "group:artifact:1.0:jar" ); + when( am1.getBaseVersion() ).thenReturn( "version" ); artifacts.add( am1 ); Artifact am2 = mock( Artifact.class ); when( am2.getGroupId() ).thenReturn( "group2" ); when( am2.getArtifactId() ).thenReturn( "artifact2" ); - when( am2.getId() ).thenReturn( "group2:artifact2:1.0:jar" ); - when( am2.getDependencyConflictId() ).thenReturn( "group2:artifact2:jar" ); + when( am2.getBaseVersion() ).thenReturn( "version" ); artifacts.add( am2 ); final DependencySet dependencySet = new DependencySet(); @@ -477,18 +477,16 @@ public class AddDependencySetsTaskTest final MavenProject project = new MavenProject( new Model() ); project.setGroupId( "GROUPID" ); - ProjectBuildingRequest pbReq = mock( ProjectBuildingRequest.class ); ProjectBuildingResult pbRes = mock( ProjectBuildingResult.class ); when( pbRes.getProject() ).thenReturn( project ); final ProjectBuilder projectBuilder = mock( ProjectBuilder.class ); - when( projectBuilder.build( any( Artifact.class ), eq( pbReq ) ) ).thenReturn( pbRes ); + when( projectBuilder.build( any( Artifact.class ), any( ProjectBuildingRequest.class ) ) ).thenReturn( pbRes ); final AddDependencySetsTask task = new AddDependencySetsTask( Collections.singletonList( dependencySet ), artifacts, project, projectBuilder ); final MavenSession session = mock( MavenSession.class ); - when( session.getProjectBuildingRequest() ).thenReturn( pbReq ); final AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class ); when( configSource.getMavenSession() ).thenReturn( session );
