You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2019/07/24 21:13:47 UTC

[maven-scm-publish-plugin] branch master updated: [MSCMPUB-41] Add the ability to deploy into SCM sub-directory (#5)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new af43cb4  [MSCMPUB-41] Add the ability to deploy into SCM sub-directory (#5)
af43cb4 is described below

commit af43cb4bb9493fccb17a77d3da1a89240d202f3f
Author: Laurent Verdoïa <ve...@gmail.com>
AuthorDate: Wed Jul 24 23:13:42 2019 +0200

    [MSCMPUB-41] Add the ability to deploy into SCM sub-directory (#5)
---
 .../plugins/scmpublish/AbstractScmPublishMojo.java |  7 ++++++
 .../scmpublish/ScmPublishPublishScmMojo.java       | 26 +++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java b/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
index 9d953cf..90ca989 100644
--- a/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
+++ b/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
@@ -103,6 +103,13 @@ public abstract class AbstractScmPublishMojo
     protected File checkoutDirectory;
 
     /**
+     * Location where the content is published inside the <code>${checkoutDirectory}</code>.
+     * By default, content is copyed at the root of <code>${checkoutDirectory}</code>.
+     */
+    @Parameter ( property = "scmpublish.subDirectory" )
+    protected String subDirectory;
+
+    /**
      * Display list of added, deleted, and changed files, but do not do any actual SCM operations.
      */
     @Parameter ( property = "scmpublish.dryRun" )
diff --git a/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.java b/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.java
index 0bd447f..c79ef0d 100644
--- a/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.java
+++ b/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.java
@@ -276,10 +276,34 @@ public class ScmPublishPublishScmMojo
 
         checkoutExisting();
 
+        final File updateDirectory;
+        if ( subDirectory == null )
+        {
+            updateDirectory = checkoutDirectory;
+        }
+        else
+        {
+            updateDirectory = new File( checkoutDirectory, subDirectory );
+
+            // Security check for subDirectory with .. inside
+            if ( !updateDirectory.toPath().normalize().startsWith( checkoutDirectory.toPath().normalize() ) )
+            {
+                logError( "Try to acces outside of the checkout directory with sub-directory: %s", subDirectory );
+                return;
+            }
+
+            if ( !updateDirectory.exists() )
+            {
+                updateDirectory.mkdirs();
+            }
+
+            logInfo( "Will copy content in sub-directory: %s", subDirectory );
+        }
+
         try
         {
             logInfo( "Updating checkout directory with actual content in %s", content );
-            update( checkoutDirectory, content, ( project == null ) ? null : project.getModel().getModules() );
+            update( updateDirectory, content, ( project == null ) ? null : project.getModel().getModules() );
             String displaySize = org.apache.commons.io.FileUtils.byteCountToDisplaySize( size );
             logInfo( "Content consists of " + MessageUtils.buffer().strong( "%d directories and %d files = %s" ),
                      directories, files, displaySize );