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 b5ac4e073..363e2869b 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 static FixedStringSearchInterpolator moduleArtifactInterpolator( Artifact { 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 static FixedStringSearchInterpolator artifactProjectInterpolator( final M @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 d3b65ad3d..1484e7b02 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 void testCreateFileSet_ShouldUseModuleDirOnlyWhenOutDirIsNull() 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 void testCreateFileSet_ShouldPrependModuleDirWhenOutDirIsProvided() 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 void testCreateFileSet_ShouldAddExcludesForSubModulesWhenExcludeSubModDir 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 void testExecute_ShouldAddOneModuleSetWithOneModuleInIt() 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 void testAddModuleBinaries_ShouldAddOneModuleAttachmentArtifactAndNoDeps( 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 void testAddModuleBinaries_ShouldAddOneModuleArtifactAndNoDeps() { 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 void testAddModuleArtifact_ShouldAddOneArtifact() 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 void testAddModuleSourceFileSets_ShouldAddOneSourceDirectory() 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 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 75db5afc8..db4133e4a 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.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 void tearDown() @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 void testShouldAddArchiveFileWithoutUnpacking() @Test public void testShouldAddArchiveFileWithDefaultOutputLocation() - throws ArchiveCreationException, AssemblyFormattingException, IOException + throws Exception { String artifactId = "myArtifact"; String version = "1"; @@ -128,6 +127,7 @@ public void testShouldAddArchiveFileWithDefaultOutputLocation() 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 @@ private AddArtifactTask createTask( Artifact artifact ) @Test public void testShouldAddArchiveFileWithUnpack() - throws ArchiveCreationException, AssemblyFormattingException, IOException + throws Exception { final int originalDirMode = -1; final int originalFileMode = -1; @@ -205,7 +205,7 @@ public void testShouldAddArchiveFileWithUnpack() @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 void testShouldAddArchiveFileWithUnpackAndModes() @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 0c60279b4..04513f819 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 void testAddDependencySet_ShouldInterpolateDefaultOutputFileNameMapping() 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 @@ private void verifyOneDependencyAdded( final String outputLocation, final boolea 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 8c97ea921..ae7cf2b91 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 void testEvalFileNameMapping_ShouldResolveArtifactIdAndBaseVersionInOutDi 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 @@ private void verifyEvalFileNameMapping( final String expression, final String cl { 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 void testLinuxRootReferencePath() } @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 void groupIdPath() 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}" ) ); + } + }