Skip to content

Commit

Permalink
[MASSEMBLY-765] add property groupIdPath
Browse files Browse the repository at this point in the history
  • Loading branch information
rfscholte committed Apr 27, 2020
1 parent 919d189 commit 6e67eeb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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() ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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<MavenProject> projects = singleton( project );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

Expand All @@ -119,7 +118,7 @@ public void testShouldAddArchiveFileWithoutUnpacking()

@Test
public void testShouldAddArchiveFileWithDefaultOutputLocation()
throws ArchiveCreationException, AssemblyFormattingException, IOException
throws Exception
{
String artifactId = "myArtifact";
String version = "1";
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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" ) );
Expand All @@ -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}" ) );
}

}

0 comments on commit 6e67eeb

Please sign in to comment.