This is an automated email from the ASF dual-hosted git repository. sjaranowski pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit 790dac4e34b7d6dc743255c550493eff03578b6b Author: Jasper Kamerling <[email protected]> AuthorDate: Thu Aug 4 17:27:33 2022 +0200 [MDEP-782] Add ability to strip type --- .../AbstractFromDependenciesMojo.java | 24 ++++++ .../fromDependencies/CopyDependenciesMojo.java | 16 ++-- .../fromDependencies/UnpackDependenciesMojo.java | 2 +- .../plugins/dependency/utils/DependencyUtil.java | 10 ++- .../dependency/utils/filters/DestFileFilter.java | 21 ++++- .../fromDependencies/TestCopyDependenciesMojo.java | 2 +- .../TestCopyDependenciesMojo2.java | 53 +++++++++++-- .../TestUnpackDependenciesMojo.java | 4 +- .../TestUnpackDependenciesMojo2.java | 2 +- .../dependency/utils/TestDependencyUtil.java | 89 +++++++++++++++++----- .../utils/filters/TestDestFileFilter.java | 2 +- 11 files changed, 184 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractFromDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractFromDependenciesMojo.java index 8de1c07d..b5fcfe59 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractFromDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractFromDependenciesMojo.java @@ -45,6 +45,12 @@ public abstract class AbstractFromDependenciesMojo @Parameter( property = "mdep.stripVersion", defaultValue = "false" ) protected boolean stripVersion = false; + /** + * Strip artifact type during copy + */ + @Parameter( property = "mdep.stripType", defaultValue = "false" ) + protected boolean stripType = false; + /** * Strip artifact classifier during copy */ @@ -197,6 +203,24 @@ public abstract class AbstractFromDependenciesMojo this.stripVersion = stripVersion; } + + /** + * @return {@link #stripType} + */ + public boolean isStripType() + { + return stripType; + } + + /** + * @param stripType {@link #stripType} + */ + public void setStripType( boolean stripType ) + { + this.stripType = stripType; + } + + /** * @return true, if dependencies must be planted in a repository layout */ diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java index 04c28187..85a90daa 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java @@ -108,7 +108,7 @@ public class CopyDependenciesMojo * * @throws MojoExecutionException with a message if an error occurs. * @see #getDependencySets(boolean, boolean) - * @see #copyArtifact(Artifact, boolean, boolean, boolean, boolean) + * @see #copyArtifact(Artifact, boolean, boolean, boolean, boolean, boolean) */ @Override protected void doExecute() @@ -121,7 +121,7 @@ public class CopyDependenciesMojo { for ( Artifact artifact : artifacts ) { - copyArtifact( artifact, isStripVersion(), this.prependGroupId, this.useBaseVersion, + copyArtifact( artifact, isStripVersion(), isStripType(), this.prependGroupId, this.useBaseVersion, this.stripClassifier ); } } @@ -204,16 +204,17 @@ public class CopyDependenciesMojo * * @param artifact representing the object to be copied. * @param removeVersion specifies if the version should be removed from the file name when copying. + * @param removeType specifies if the type should be removed from the file name when copying. * @param prependGroupId specifies if the groupId should be prepend to the file while copying. * @param theUseBaseVersion specifies if the baseVersion of the artifact should be used instead of the version. * @throws MojoExecutionException with a message if an error occurs. * @see #copyArtifact(Artifact, boolean, boolean, boolean, boolean) */ - protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean prependGroupId, + protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean removeType, boolean prependGroupId, boolean theUseBaseVersion ) throws MojoExecutionException { - copyArtifact( artifact, removeVersion, prependGroupId, theUseBaseVersion, false ); + copyArtifact( artifact, removeVersion, removeType, prependGroupId, theUseBaseVersion, false ); } /** @@ -222,14 +223,15 @@ public class CopyDependenciesMojo * * @param artifact representing the object to be copied. * @param removeVersion specifies if the version should be removed from the file name when copying. + * @param removeType specifies if the type should be removed from the file name when copying. * @param prependGroupId specifies if the groupId should be prepend to the file while copying. * @param theUseBaseVersion specifies if the baseVersion of the artifact should be used instead of the version. * @param removeClassifier specifies if the classifier should be removed from the file name when copying. * @throws MojoExecutionException with a message if an error occurs. * @see #copyFile(File, File) - * @see DependencyUtil#getFormattedOutputDirectory(boolean, boolean, boolean, boolean, boolean, File, Artifact) + * @see DependencyUtil#getFormattedOutputDirectory(boolean, boolean, boolean, boolean, boolean, boolean, File, Artifact) */ - protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean prependGroupId, + protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean stripType, boolean prependGroupId, boolean theUseBaseVersion, boolean removeClassifier ) throws MojoExecutionException { @@ -239,7 +241,7 @@ public class CopyDependenciesMojo File destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, useSubDirectoryPerArtifact, useRepositoryLayout, - stripVersion, outputDirectory, artifact ); + stripVersion, stripType, outputDirectory, artifact ); File destFile = new File( destDir, destFileName ); copyFile( artifact.getFile(), destFile ); diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java index abd3d903..12a574f9 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java @@ -100,7 +100,7 @@ public class UnpackDependenciesMojo { File destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, useSubDirectoryPerArtifact, useRepositoryLayout, - stripVersion, outputDirectory, artifact ); + stripVersion, stripType, outputDirectory, artifact ); unpack( artifact, destDir, getIncludes(), getExcludes(), getEncoding(), getFileMappers() ); DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory ); handler.setMarker(); diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java index 80cbcb33..6639c04a 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java +++ b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java @@ -148,13 +148,15 @@ public final class DependencyUtil * @param useRepositoryLayout if dependencies must be moved into a Maven repository layout, if set, other settings * will be ignored. * @param removeVersion if the version must not be mentioned in the filename + * @param removeType if the type must not be mentioned in the filename * @param outputDirectory base outputDirectory. * @param artifact information about the artifact. * @return a formatted File object to use for output. */ public static File getFormattedOutputDirectory( boolean useSubdirsPerScope, boolean useSubdirsPerType, boolean useSubdirPerArtifact, boolean useRepositoryLayout, - boolean removeVersion, File outputDirectory, Artifact artifact ) + boolean removeVersion, boolean removeType, File outputDirectory, + Artifact artifact ) { StringBuilder sb = new StringBuilder( 128 ); if ( useRepositoryLayout ) @@ -178,14 +180,14 @@ public final class DependencyUtil } if ( useSubdirPerArtifact ) { - String artifactString = getDependencyId( artifact, removeVersion ); + String artifactString = getDependencyId( artifact, removeVersion, removeType ); sb.append( artifactString ).append( File.separatorChar ); } } return new File( outputDirectory, sb.toString() ); } - private static String getDependencyId( Artifact artifact, boolean removeVersion ) + private static String getDependencyId( Artifact artifact, boolean removeVersion, boolean removeType ) { StringBuilder sb = new StringBuilder(); @@ -206,7 +208,7 @@ public final class DependencyUtil // if the classifier and type are the same (sources), then don't // repeat. // avoids names like foo-sources-sources - if ( !Objects.equals( artifact.getClassifier(), artifact.getType() ) ) + if ( !removeType && !Objects.equals( artifact.getClassifier(), artifact.getType() ) ) { sb.append( "-" ); sb.append( artifact.getType() ); diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/filters/DestFileFilter.java b/src/main/java/org/apache/maven/plugins/dependency/utils/filters/DestFileFilter.java index 2fe0ab41..f2a28482 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/utils/filters/DestFileFilter.java +++ b/src/main/java/org/apache/maven/plugins/dependency/utils/filters/DestFileFilter.java @@ -55,6 +55,8 @@ public class DestFileFilter private boolean removeVersion; + private boolean removeType; + private boolean removeClassifier; private final boolean prependGroupId; @@ -195,6 +197,22 @@ public class DestFileFilter return this.removeVersion; } + /** + * @param removeType The removeType to set. + */ + public void setRemoveType( boolean removeType ) + { + this.removeType = removeType; + } + + /** + * @return Returns the removeType. + */ + public boolean isRemoveType() + { + return this.removeType; + } + /** * @param removeVersion The removeVersion to set. */ @@ -281,7 +299,8 @@ public class DestFileFilter destFolder = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, useSubDirectoryPerArtifact, useRepositoryLayout, - removeVersion, this.outputFileDirectory, artifact ); + removeVersion, removeType, this.outputFileDirectory, + artifact ); } File destFile; diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java index 2f65c859..842e6614 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java @@ -407,7 +407,7 @@ public class TestCopyDependenciesMojo for ( Artifact artifact : artifacts ) { String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, true, false, false, false, + File folder = DependencyUtil.getFormattedOutputDirectory( false, true, false, false, false, false, mojo.outputDirectory, artifact ); File file = new File( folder, fileName ); assertTrue( file.exists() ); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java index 96afe1c9..d88415ce 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java @@ -197,7 +197,7 @@ public class TestCopyDependenciesMojo2 for ( Artifact artifact : artifacts ) { String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, + File folder = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, false, mojo.outputDirectory, artifact ); File file = new File( folder, fileName ); assertTrue( file.exists() ); @@ -218,7 +218,7 @@ public class TestCopyDependenciesMojo2 for ( Artifact artifact : artifacts ) { String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, + File folder = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, false, mojo.outputDirectory, artifact ); File file = new File( folder, fileName ); assertTrue( file.exists() ); @@ -239,7 +239,7 @@ public class TestCopyDependenciesMojo2 for ( Artifact artifact : artifacts ) { String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File folder = DependencyUtil.getFormattedOutputDirectory( true, false, true, false, false, + File folder = DependencyUtil.getFormattedOutputDirectory( true, false, true, false, false, false, mojo.outputDirectory, artifact ); File file = new File( folder, fileName ); assertTrue( file.exists() ); @@ -351,7 +351,7 @@ public class TestCopyDependenciesMojo2 for ( Artifact artifact : artifacts ) { String fileName = DependencyUtil.getFormattedFileName( artifact, true ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, + File folder = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, false, mojo.outputDirectory, artifact ); File file = new File( folder, fileName ); assertTrue( file.exists() ); @@ -373,7 +373,50 @@ public class TestCopyDependenciesMojo2 for ( Artifact artifact : artifacts ) { String fileName = DependencyUtil.getFormattedFileName( artifact, true ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, + File folder = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, false, + mojo.outputDirectory, artifact ); + File file = new File( folder, fileName ); + assertTrue( file.exists() ); + } + } + + public void testSubPerArtifactRemoveType() + throws Exception + { + mojo.useSubDirectoryPerArtifact = true; + mojo.stripType = true; + + mojo.execute(); + + Set<Artifact> artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + // TODO fix test + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File folder = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, true, + mojo.outputDirectory, artifact ); + File file = new File( folder, fileName ); + assertTrue( file.exists() ); + } + } + + public void testSubPerArtifactAndTypeRemoveType() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet<Artifact>() ); + mojo.useSubDirectoryPerArtifact = true; + mojo.useSubDirectoryPerType = true; + mojo.stripType = true; + + mojo.execute(); + + Set<Artifact> artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + // TODO fix test + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File folder = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, true, mojo.outputDirectory, artifact ); File file = new File( folder, fileName ); assertTrue( file.exists() ); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java index 2406071a..5fa692e1 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java @@ -109,7 +109,7 @@ public class TestUnpackDependenciesMojo File folder = DependencyUtil.getFormattedOutputDirectory( mojo.useSubDirectoryPerScope, mojo.useSubDirectoryPerType, mojo.useSubDirectoryPerArtifact, mojo.useRepositoryLayout, - mojo.stripVersion, mojo.outputDirectory, artifact ); + mojo.stripVersion, mojo.stripType, mojo.outputDirectory, artifact ); File destFile = new File( folder, DependencyArtifactStubFactory.getUnpackableFileName( artifact ) ); @@ -606,7 +606,7 @@ public class TestUnpackDependenciesMojo DependencyUtil.getFormattedOutputDirectory( mojo.isUseSubDirectoryPerScope(), mojo.isUseSubDirectoryPerType(), mojo.isUseSubDirectoryPerArtifact(), mojo.useRepositoryLayout, - mojo.stripVersion, mojo.getOutputDirectory(), artifact ); + mojo.stripVersion, mojo.stripType, mojo.getOutputDirectory(), artifact ); File unpacked = new File( destDir, DependencyArtifactStubFactory.getUnpackableFileName( artifact ) ); assertTrue( unpacked.exists() ); return unpacked; diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java index 2a975bf1..f4f4a359 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java @@ -89,7 +89,7 @@ public class TestUnpackDependenciesMojo2 DependencyUtil.getFormattedOutputDirectory( mojo.isUseSubDirectoryPerScope(), mojo.isUseSubDirectoryPerType(), mojo.isUseSubDirectoryPerArtifact(), mojo.useRepositoryLayout, - mojo.stripVersion, mojo.getOutputDirectory(), artifact ); + mojo.stripVersion, mojo.stripType, mojo.getOutputDirectory(), artifact ); File unpacked = new File( destDir, DependencyArtifactStubFactory.getUnpackableFileName( artifact ) ); assertTrue( unpacked.exists() ); return unpacked; diff --git a/src/test/java/org/apache/maven/plugins/dependency/utils/TestDependencyUtil.java b/src/test/java/org/apache/maven/plugins/dependency/utils/TestDependencyUtil.java index 2d420a9e..86f71790 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/utils/TestDependencyUtil.java +++ b/src/test/java/org/apache/maven/plugins/dependency/utils/TestDependencyUtil.java @@ -93,91 +93,144 @@ public class TestDependencyUtil { File folder = new File( "target/a" ); final Artifact artifact = artifacts.get( 0 ); - File name = DependencyUtil.getFormattedOutputDirectory( false, false, false, false, false, folder, artifact ); + File name = DependencyUtil.getFormattedOutputDirectory( false, false, false, false, false, false, folder, artifact ); // object is the same. assertEquals( folder, name ); - name = DependencyUtil.getFormattedOutputDirectory( false, false, false, true, false, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, false, false, true, false, false, folder, artifact ); String expectedResult = folder.getAbsolutePath() + File.separatorChar + "test" + File.separatorChar + "one" + File.separatorChar + "1.1"; assertTrue( expectedResult.equalsIgnoreCase( name.getAbsolutePath() ) ); - name = DependencyUtil.getFormattedOutputDirectory( false, true, false, false, false, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, true, false, false, false, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "jars"; assertTrue( expectedResult.equalsIgnoreCase( name.getAbsolutePath() ) ); - name = DependencyUtil.getFormattedOutputDirectory( true, false, false, false, false, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( true, false, false, false, false, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "compile"; assertEquals( expectedResult, name.getAbsolutePath() ); assertTrue( expectedResult.equalsIgnoreCase( name.getAbsolutePath() ) ); - name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "one-1.1-sources-jar"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "one-sources-jar"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, true, folder, artifact ); + expectedResult = folder.getAbsolutePath() + File.separatorChar + "one-1.1-sources"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, true, folder, artifact ); + expectedResult = folder.getAbsolutePath() + File.separatorChar + "one-sources"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "jars" + File.separatorChar + "one-1.1-sources-jar"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "jars" + File.separatorChar + "one-sources-jar"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( true, false, true, false, true, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, true, folder, artifact ); + expectedResult = + folder.getAbsolutePath() + File.separatorChar + "jars" + File.separatorChar + "one-1.1-sources"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, true, folder, artifact ); + expectedResult = + folder.getAbsolutePath() + File.separatorChar + "jars" + File.separatorChar + "one-sources"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( true, false, true, false, true, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "compile" + File.separatorChar + "one-sources-jar"; assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( true, false, true, false, false, true, folder, artifact ); + expectedResult = + folder.getAbsolutePath() + File.separatorChar + "compile" + File.separatorChar + "one-1.1-sources"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( true, false, true, false, true, true, folder, artifact ); + expectedResult = + folder.getAbsolutePath() + File.separatorChar + "compile" + File.separatorChar + "one-sources"; + assertEquals( expectedResult, name.getAbsolutePath() ); } + // TODO fix test public void testDirectoryName2() { File folder = new File( "target/a" ); final Artifact artifact = artifacts.get( 1 ); - File name = DependencyUtil.getFormattedOutputDirectory( false, false, false, false, false, folder, artifact ); + File name = DependencyUtil.getFormattedOutputDirectory( false, false, false, false, false, false, folder, artifact ); // object is the same. assertEquals( folder, name ); - name = DependencyUtil.getFormattedOutputDirectory( false, true, false, false, false, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, true, false, false, false, false, folder, artifact ); String expectedResult = folder.getAbsolutePath() + File.separatorChar + "wars"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( false, false, false, true, false, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, false, false, true, false, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "test" + File.separatorChar + "two" + File.separatorChar + "1.1-SNAPSHOT"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "two-1.1-SNAPSHOT-war"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "wars" + File.separatorChar + "two-1.1-SNAPSHOT-war"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "two-war"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, folder, artifact ); + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, true, folder, artifact ); + expectedResult = folder.getAbsolutePath() + File.separatorChar + "two-1.1-SNAPSHOT"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, true, folder, artifact ); + expectedResult = folder.getAbsolutePath() + File.separatorChar + "two"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "wars" + File.separatorChar + "two-war"; assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, true, folder, artifact ); + expectedResult = folder.getAbsolutePath() + File.separatorChar + "wars" + File.separatorChar + "two-1.1-SNAPSHOT"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, true, folder, artifact ); + expectedResult = folder.getAbsolutePath() + File.separatorChar + "wars" + File.separatorChar + "two"; + assertEquals( expectedResult, name.getAbsolutePath() ); } public void testDirectoryNameSources() { File folder = new File( "target/a" ); - File name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, folder, sources ); + File name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, false, folder, sources ); String expectedResult = folder.getAbsolutePath() + File.separatorChar + "two-sources"; assertEquals( expectedResult, name.getAbsolutePath() ); - name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, folder, sources ); + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, true, folder, sources ); + expectedResult = folder.getAbsolutePath() + File.separatorChar + "two-sources"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, false, folder, sources ); + expectedResult = folder.getAbsolutePath() + File.separatorChar + "two-1.1-SNAPSHOT-sources"; + assertEquals( expectedResult, name.getAbsolutePath() ); + + name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, true, folder, sources ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "two-1.1-SNAPSHOT-sources"; assertEquals( expectedResult, name.getAbsolutePath() ); } diff --git a/src/test/java/org/apache/maven/plugins/dependency/utils/filters/TestDestFileFilter.java b/src/test/java/org/apache/maven/plugins/dependency/utils/filters/TestDestFileFilter.java index 86dca0c4..aacaae2e 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/utils/filters/TestDestFileFilter.java +++ b/src/test/java/org/apache/maven/plugins/dependency/utils/filters/TestDestFileFilter.java @@ -87,7 +87,7 @@ public class TestDestFileFilter { File destFolder = DependencyUtil.getFormattedOutputDirectory( false, useSubDirectoryPerType, useSubDirectoryPerArtifact, - false, false, outputFolder, artifact ); + false, false, false, outputFolder, artifact ); File destFile = new File( destFolder, DependencyUtil.getFormattedFileName( artifact, removeVersion, false, false, removeClassifier ) );
