You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/06/01 20:34:25 UTC

[maven-dependency-plugin] 01/02: [MDEP-651] - allow unpack dependency to configure archive entries overwrite

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

slachiewicz pushed a commit to branch MDEP-651
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit 278b25f9f5ad9bf3c4f4c333e017f89b31d61500
Author: viqueen <hr...@atlassian.com>
AuthorDate: Sat Apr 27 03:19:50 2019 +1000

    [MDEP-651] - allow unpack dependency to configure archive entries overwrite
---
 .../plugins/dependency/AbstractDependencyMojo.java | 22 ++++++++++++++++++
 .../fromDependencies/UnpackDependenciesMojo.java   | 27 ++++++++++++++++++++--
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
index 07df9f6..2e80f98 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
@@ -243,6 +243,26 @@ public abstract class AbstractDependencyMojo
      */
     protected void unpack( Artifact artifact, String type, File location, String includes, String excludes,
                            String encoding, FileMapper[] fileMappers )
+            throws MojoExecutionException
+    {
+        unpack( artifact, type, location, includes, excludes, encoding, fileMappers, true );
+    }
+
+    /**
+     * @param artifact {@link Artifact}
+     * @param type The type.
+     * @param location The location.
+     * @param includes includes list.
+     * @param excludes excludes list.
+     * @param encoding the encoding.
+     * @param fileMappers {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no rewriting
+     *                    shall happen.
+     * @param overwrite overwrite duplicate entries when unpacking artifacts
+     *
+     * @throws MojoExecutionException in case of an error.
+     */
+    protected void unpack( Artifact artifact, String type, File location, String includes, String excludes,
+                           String encoding, FileMapper[] fileMappers, boolean overwrite )
         throws MojoExecutionException
     {
         File file = artifact.getFile();
@@ -289,6 +309,8 @@ public abstract class AbstractDependencyMojo
 
             unArchiver.setDestDirectory( location );
 
+            unArchiver.setOverwrite( overwrite );
+
             if ( StringUtils.isNotEmpty( excludes ) || StringUtils.isNotEmpty( includes ) )
             {
                 // Create the selectors that will filter
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 abd3d90..b131347 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
@@ -83,12 +83,18 @@ public class UnpackDependenciesMojo
     private FileMapper[] fileMappers;
 
     /**
+     * @since 3.1.2
+     */
+    @Parameter( property = "mdep.unpack.overwrite", defaultValue = "true" )
+    private boolean overwrite;
+
+    /**
      * Main entry into mojo. This method gets the dependencies and iterates through each one passing it to
      * DependencyUtil.unpackFile().
      *
      * @throws MojoExecutionException with a message if an error occurs.
      * @see #getDependencySets(boolean)
-     * @see #unpack(Artifact, File, String, FileMapper[])
+     * @see #unpack(Artifact, String, File, String, String, String, FileMapper[], boolean)
      */
     @Override
     protected void doExecute()
@@ -101,7 +107,8 @@ public class UnpackDependenciesMojo
             File destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType,
                                                                   useSubDirectoryPerArtifact, useRepositoryLayout,
                                                                   stripVersion, outputDirectory, artifact );
-            unpack( artifact, destDir, getIncludes(), getExcludes(), getEncoding(), getFileMappers() );
+            unpack( artifact, artifact.getType(), destDir, getIncludes(), getExcludes(),
+                    getEncoding(), getFileMappers(), isOverwrite() );
             DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory );
             handler.setMarker();
         }
@@ -190,4 +197,20 @@ public class UnpackDependenciesMojo
     {
         this.fileMappers = fileMappers;
     }
+
+    /**
+     * @since 3.1.2
+     */
+    public boolean isOverwrite()
+    {
+        return overwrite;
+    }
+
+    /**
+     * @since 3.1.2
+     */
+    public void setOverwrite( boolean overwrite )
+    {
+        this.overwrite = overwrite;
+    }
 }