You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/04/27 13:04:03 UTC

[maven-assembly-plugin] branch master updated: [MASSEMBLY-765] add property groupIdPath

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e67eeb  [MASSEMBLY-765] add property groupIdPath
6e67eeb is described below

commit 6e67eeb41c3b647374fc4d2d969673f03ef1bbd3
Author: rfscholte <rf...@apache.org>
AuthorDate: Mon Apr 27 15:03:50 2020 +0200

    [MASSEMBLY-765] add property groupIdPath
---
 .../assembly/utils/AssemblyFormatUtils.java        | 28 +++++++++++-----------
 .../archive/phase/ModuleSetAssemblyPhaseTest.java  | 11 ++++++++-
 .../assembly/archive/task/AddArtifactTaskTest.java | 14 +++++------
 .../archive/task/AddDependencySetsTaskTest.java    |  2 ++
 .../assembly/utils/AssemblyFormatUtilsTest.java    | 18 +++++++++++++-
 5 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtils.java b/src/main/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtils.java
index b5ac4e0..363e286 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtils.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtils.java
@@ -116,15 +116,13 @@ public final class AssemblyFormatUtils
     {
         if ( moduleArtifact != null )
         {
-            // CHECKSTYLE_OFF: LineLength
-            return FixedStringSearchInterpolator.create( new PrefixedObjectValueSource( "module.", moduleArtifact ),
-                                                         new PrefixedObjectValueSource( "module.",
-                                                                                        moduleArtifact
-                                                                                            .getArtifactHandler() ),
-                                                         new PrefixedObjectValueSource( "module.handler.",
-                                                                                        moduleArtifact
-                                                                                            .getArtifactHandler() ) );
-            // CHECKSTYLE_ON: LineLength
+            final String groupIdPath = moduleArtifact.getGroupId().replace( '.', '/' );
+
+            return FixedStringSearchInterpolator.create(
+                     new MapBasedValueSource( Collections.singletonMap( "module.groupIdPath", groupIdPath ) ),
+                     new PrefixedObjectValueSource( "module.", moduleArtifact ),
+                     new PrefixedObjectValueSource( "module.", moduleArtifact.getArtifactHandler() ),
+                     new PrefixedObjectValueSource( "module.handler.", moduleArtifact.getArtifactHandler() ) );
         }
         else
         {
@@ -160,11 +158,13 @@ public final class AssemblyFormatUtils
     @Nonnull
     public static FixedStringSearchInterpolator artifactInterpolator( @Nonnull final Artifact artifact )
     {
-        return FixedStringSearchInterpolator.create( new PrefixedObjectValueSource( "artifact.", artifact ),
-                                                     new PrefixedObjectValueSource( "artifact.",
-                                                                                    artifact.getArtifactHandler() ),
-                                                     new PrefixedObjectValueSource( "artifact.handler.",
-                                                                                    artifact.getArtifactHandler() ) );
+        final String groupIdPath = artifact.getGroupId().replace( '.', '/' );
+
+        return FixedStringSearchInterpolator.create( 
+                         new MapBasedValueSource( Collections.singletonMap( "artifact.groupIdPath", groupIdPath ) ),
+                         new PrefixedObjectValueSource( "artifact.", artifact ),
+                         new PrefixedObjectValueSource( "artifact.", artifact.getArtifactHandler() ),
+                         new PrefixedObjectValueSource( "artifact.handler.", artifact.getArtifactHandler() ) );
     }
 
 
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java
index d3b65ad..1484e7b 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java
@@ -160,6 +160,7 @@ public class ModuleSetAssemblyPhaseTest
         artifactProject.setFile( new File( basedir, "pom.xml" ) );
 
         Artifact artifact = mock( Artifact.class );
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
         when( artifact.getArtifactId() ).thenReturn( "artifact" );
 
         artifactProject.setArtifact( artifact );
@@ -202,6 +203,7 @@ public class ModuleSetAssemblyPhaseTest
         artifactProject.setFile( new File( basedir, "pom.xml" ) );
 
         Artifact artifact = mock( Artifact.class );
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
         when( artifact.getArtifactId() ).thenReturn( "artifact" );
 
         artifactProject.setArtifact( artifact );
@@ -240,6 +242,7 @@ public class ModuleSetAssemblyPhaseTest
         project.setFile( new File( basedir, "pom.xml" ) );
 
         Artifact artifact = mock( Artifact.class );
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
 
         project.setArtifact( artifact );
         DefaultAssemblyArchiverTest.setupInterpolators( configSource, project );
@@ -275,6 +278,7 @@ public class ModuleSetAssemblyPhaseTest
 
         Artifact artifact = mock( Artifact.class );
         final File moduleArtifactFile = temporaryFolder.newFile();
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
         when( artifact.getFile() ).thenReturn( moduleArtifactFile );
         module.setArtifact( artifact );
 
@@ -368,6 +372,7 @@ public class ModuleSetAssemblyPhaseTest
         when( configSource.getFinalName() ).thenReturn( "final-name" );
 
         Artifact artifact = mock( Artifact.class );
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
         when( artifact.getClassifier() ).thenReturn( "test" );
         final File artifactFile = temporaryFolder.newFile();
         when( artifact.getFile() ).thenReturn( artifactFile );
@@ -457,6 +462,7 @@ public class ModuleSetAssemblyPhaseTest
     {
         Artifact artifact = mock( Artifact.class );
         final File artifactFile = temporaryFolder.newFile();
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
         when( artifact.getFile() ).thenReturn( artifactFile );
 
         final AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
@@ -528,6 +534,7 @@ public class ModuleSetAssemblyPhaseTest
         throws Exception
     {
         Artifact artifact = mock( Artifact.class );
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
         final File artifactFile = temporaryFolder.newFile();
         when( artifact.getFile() ).thenReturn( artifactFile );
 
@@ -580,7 +587,9 @@ public class ModuleSetAssemblyPhaseTest
         final AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
         when( configSource.getFinalName() ).thenReturn( "final-name" );
         when( configSource.getProject() ).thenReturn( project );
-        project.setArtifact( mock( Artifact.class ) );
+        Artifact artifact = mock( Artifact.class );
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
+        project.setArtifact( artifact );
 
         final Set<MavenProject> projects = singleton( project );
 
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java
index 75db5af..db4133e 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java
@@ -35,9 +35,7 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.model.Model;
 import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
-import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
 import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
-import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
 import org.apache.maven.plugins.assembly.model.DependencySet;
 import org.apache.maven.plugins.assembly.utils.TypeConversionUtils;
 import org.apache.maven.project.MavenProject;
@@ -88,11 +86,12 @@ public class AddArtifactTaskTest
 
     @Test
     public void testShouldAddArchiveFileWithoutUnpacking()
-        throws ArchiveCreationException, AssemblyFormattingException, IOException
+        throws Exception
     {
         String outputLocation = "artifact";
 
         Artifact artifact = mock( Artifact.class );
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
         File artifactFile = temporaryFolder.newFile();
         when( artifact.getFile() ).thenReturn( artifactFile );
 
@@ -119,7 +118,7 @@ public class AddArtifactTaskTest
 
     @Test
     public void testShouldAddArchiveFileWithDefaultOutputLocation()
-        throws ArchiveCreationException, AssemblyFormattingException, IOException
+        throws Exception
     {
         String artifactId = "myArtifact";
         String version = "1";
@@ -128,6 +127,7 @@ public class AddArtifactTaskTest
 
         Artifact artifact = mock( Artifact.class );
         ArtifactHandler artifactHandler = mock( ArtifactHandler.class );
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
         when( artifactHandler.getExtension() ).thenReturn( ext );
         when( artifact.getArtifactHandler() ).thenReturn( artifactHandler );
         File artifactFile = temporaryFolder.newFile();
@@ -176,7 +176,7 @@ public class AddArtifactTaskTest
 
     @Test
     public void testShouldAddArchiveFileWithUnpack()
-        throws ArchiveCreationException, AssemblyFormattingException, IOException
+        throws Exception
     {
         final int originalDirMode = -1;
         final int originalFileMode = -1;
@@ -205,7 +205,7 @@ public class AddArtifactTaskTest
 
     @Test
     public void testShouldAddArchiveFileWithUnpackAndModes()
-        throws ArchiveCreationException, AssemblyFormattingException, IOException
+        throws Exception
     {
         final int directoryMode = TypeConversionUtils.modeToInt( "777", new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
         final int fileMode = TypeConversionUtils.modeToInt( "777", new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
@@ -242,7 +242,7 @@ public class AddArtifactTaskTest
 
     @Test
     public void testShouldAddArchiveFileWithUnpackIncludesAndExcludes()
-        throws ArchiveCreationException, AssemblyFormattingException, IOException
+        throws Exception
     {
         final int originalDirMode = -1;
         final int originalFileMode = -1;
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 0c60279..04513f8 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
@@ -119,6 +119,7 @@ public class AddDependencySetsTaskTest
         when( depArtifact.getArtifactHandler() ).thenReturn( artifactHandler );
         final File newFile = temporaryFolder.newFile();
         when( depArtifact.getFile() ).thenReturn( newFile );
+        when( depArtifact.getGroupId() ).thenReturn( "GROUPID" );
 
         depProject.setArtifact( depArtifact );
 
@@ -301,6 +302,7 @@ public class AddDependencySetsTaskTest
         Artifact artifact = mock( Artifact.class );
         final File artifactFile = temporaryFolder.newFile();
         when( artifact.getFile() ).thenReturn( artifactFile );
+        when( artifact.getGroupId() ).thenReturn( "GROUPID" );
 
         final Archiver archiver = mock( Archiver.class );
         when( archiver.getDestFile() ).thenReturn( new File( "junk" ) );
diff --git a/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java b/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java
index 8c97ea9..ae7cf2b 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java
@@ -339,6 +339,7 @@ public class AssemblyFormatUtilsTest
         final MavenProject artifactProject = createProject( "group", "artifact", artifactVersion, null );
 
         Artifact artifact = mock( Artifact.class );
+        when( artifact.getGroupId() ).thenReturn( "group" );
         when( artifact.getBaseVersion() ).thenReturn( artifactBaseVersion );
 
         artifactProject.setArtifact( artifact );
@@ -668,12 +669,14 @@ public class AssemblyFormatUtilsTest
     {
 
         Artifact artifactMock = mock( Artifact.class );
+        when( artifactMock.getGroupId() ).thenReturn( artifactProject.getGroupId() );
         when( artifactMock.getClassifier() ).thenReturn( classifier );
         ArtifactHandler artifactHandler = mock( ArtifactHandler.class );
         when( artifactHandler.getExtension() ).thenReturn( extension );
         when( artifactMock.getArtifactHandler() ).thenReturn( artifactHandler );
 
         Artifact moduleArtifactMock = mock( Artifact.class );
+        when( moduleArtifactMock.getGroupId() ).thenReturn( moduleProject.getGroupId() );
 
         final MavenSession session = mock( MavenSession.class );
         when( session.getExecutionProperties() ).thenReturn( System.getProperties() );
@@ -824,7 +827,7 @@ public class AssemblyFormatUtilsTest
     }
 
     @Test
-    public void groupIdPath()
+    public void groupIdPath_artifactProjectInterpolator()
     {
         Artifact artifact = mock( Artifact.class );
         when( artifact.getFile() ).thenReturn( new File( "dir", "artifactId.jar" ) );
@@ -837,4 +840,17 @@ public class AssemblyFormatUtilsTest
         assertEquals( "a/b/c", interpolator.interpolate( "${artifact.groupIdPath}" ) );
         assertEquals( "a/b/c/artifactId.jar", interpolator.interpolate( "${artifact.groupIdPath}/${artifact.file.name}" ) );
     }
+
+    @Test
+    public void groupIdPath_artifactInterpolator()
+    {
+        Artifact artifact = mock( Artifact.class );
+        when( artifact.getGroupId() ).thenReturn( "a.b.c" );
+        when( artifact.getFile() ).thenReturn( new File( "dir", "artifactId.jar" ) );
+                        
+        FixedStringSearchInterpolator interpolator = AssemblyFormatUtils.artifactInterpolator( artifact );
+        assertEquals( "a/b/c", interpolator.interpolate( "${artifact.groupIdPath}" ) );
+        assertEquals( "a/b/c/artifactId.jar", interpolator.interpolate( "${artifact.groupIdPath}/${artifact.file.name}" ) );
+    }
+
 }