maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] michael-o closed pull request #57: [SCM-853] Bootstrap-changes-for-checkout-and-update
Date Fri, 28 Dec 2018 13:10:25 GMT
michael-o closed pull request #57: [SCM-853] Bootstrap-changes-for-checkout-and-update
URL: https://github.com/apache/maven-scm/pull/57
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.gitignore b/.gitignore
index d93c7cd54..91a53c0dd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,4 @@ build
 .java-version
 maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvsexe/src/test/repository/CVSROOT/history
 maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvsjava/src/test/repository/CVSROOT/history
+.DS_Store
diff --git a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/AbstractScmMojo.java
b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/AbstractScmMojo.java
index a18e319a8..a492731a6 100644
--- a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/AbstractScmMojo.java
+++ b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/AbstractScmMojo.java
@@ -281,6 +281,20 @@ public ScmFileSet getFileSet()
         }
     }
 
+    //bootstrap update
+    public ScmFileSet getFileSetBU( File checkout_path, String includes, String excludes
)
+        throws IOException
+    {
+        if ( includes != null || excludes != null )
+        {
+            return new ScmFileSet( checkout_path, includes, excludes );
+        }
+        else
+        {
+            return new ScmFileSet( checkout_path );
+        }
+    }
+
     public ScmRepository getScmRepository()
         throws ScmException
     {
diff --git a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BootstrapMojo.java
b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BootstrapMojo.java
index 4f5a4d695..67ad416a1 100644
--- a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BootstrapMojo.java
+++ b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BootstrapMojo.java
@@ -1,7 +1,5 @@
 package org.apache.maven.scm.plugin;
 
-import java.io.File;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,6 +19,8 @@
  * under the License.
  */
 
+import java.io.File;
+
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
@@ -33,6 +33,13 @@
 import org.codehaus.plexus.util.cli.Commandline;
 import org.codehaus.plexus.util.cli.DefaultConsumer;
 import org.codehaus.plexus.util.cli.StreamConsumer;
+//update
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.command.update.UpdateScmResult;
+import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.project.MavenProject;
+import java.io.IOException;
 
 /**
  * Pull the project source from the configured scm and execute the configured goals.
@@ -69,15 +76,27 @@
     /**
      * The path where your maven is installed
      */
-    @Parameter( property = "mavenHome", defaultValue="${maven.home}")
+    @Parameter( property = "mavenHome", defaultValue = "${maven.home}" )
     private File mavenHome;
 
+    //update
+    @Parameter( property = "revisionKey", defaultValue = "scm.revision" )
+    private String revisionKey;
+
+    @Parameter( defaultValue = "${project}", required = true, readonly = true )
+    private MavenProject project;
+
+    @Parameter( property = "skipUpdateIfExists", defaultValue = "false", readonly = false
)
+    private boolean skipUpdateIfExists;
+
     /** {@inheritDoc} */
     public void execute()
         throws MojoExecutionException
     {
         super.execute();
+        boolean skipCheckout = true;
 
+        String relativePathProjectDirectory = "";
         if ( this.getCheckoutResult() != null )
         {
 
@@ -86,13 +105,22 @@ public void execute()
             //At the time of useExport feature is requested only SVN and and CVS have export
command implemented
             // we will deal with this as more user using this feature specially clearcase
where we need to
             // add relativePathProjectDirectory support to ExportScmResult
-            String relativePathProjectDirectory = "";
             if ( checkoutResult instanceof CheckOutScmResult )
             {
                 relativePathProjectDirectory = ( (CheckOutScmResult) checkoutResult ).getRelativePathProjectDirectory();
             }
 
             runGoals( relativePathProjectDirectory );
+            skipCheckout = false;
+        }
+
+        if ( skipCheckout )
+        {
+            if ( !skipUpdateIfExists )
+            {
+                executeUpdate();
+            }
+            runGoals( relativePathProjectDirectory );
         }
     }
 
@@ -117,7 +145,7 @@ private void runGoals( String relativePathProjectDirectory )
 
         if ( this.mavenHome == null )
         {
-            cl.setExecutable( "mvn" );//none windows only
+            cl.setExecutable( "mvn" ); //none windows only
         }
         else
         {
@@ -199,4 +227,43 @@ protected String determineWorkingDirectoryPath( File checkoutDirectory,
String r
 
         return new File( projectDirectory, goalsDirectory ).getPath();
     }
+
+    public void executeUpdate()
+        throws MojoExecutionException
+    {
+
+        try
+        {
+            ScmRepository repository = getScmRepository();
+
+            UpdateScmResult result = getScmManager().update( repository, 
+                getFileSetBU( this.getCheckoutDirectory(), this.getIncludes(), this.getExcludes()
), 
+                getScmVersion( this.getScmVersionType(), this.getScmVersion() ), 
+                false );
+
+            checkResult( result );
+
+            if ( result instanceof UpdateScmResultWithRevision )
+            {
+                String revision = ( (UpdateScmResultWithRevision) result ).getRevision();
+
+                getLog().info( "Storing revision in '" + revisionKey + "' project property."
);
+
+                if ( project.getProperties() != null ) // Remove the test when we'll use
plugin-test-harness 1.0-alpha-2
+                {
+                    project.getProperties().put( revisionKey, revision );
+                }
+
+                getLog().info( "Project at revision " + revision );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Cannot run update command : ", e );
+        }
+        catch ( ScmException e )
+        {
+            throw new MojoExecutionException( "Cannot run update command : ", e );
+        }
+    }
 }
diff --git a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/CheckoutMojo.java
b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/CheckoutMojo.java
index 4fd5cd69f..3896e2066 100644
--- a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/CheckoutMojo.java
+++ b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/CheckoutMojo.java
@@ -104,6 +104,16 @@ public void setCheckoutDirectory( File checkoutDirectory )
         this.checkoutDirectory = checkoutDirectory;
     }
 
+    public String getScmVersionType()
+    {
+        return this.scmVersionType;
+    }
+
+    public String getScmVersion()
+    {
+        return this.scmVersion;
+    }
+
     protected ScmResult checkout()
         throws MojoExecutionException
     {
diff --git a/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
b/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
index 68f21a41d..3648e5c10 100644
--- a/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
+++ b/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
@@ -315,7 +315,7 @@ public void consumeLine( String line )
      * @return true if a different outgoing branch was found
      * @throws ScmException on outgoing command error
      */
-    public static boolean differentOutgoingBranchFound( ScmLogger logger, File workingDir,String
workingbranchName )
+    public static boolean differentOutgoingBranchFound( ScmLogger logger, File workingDir,
String workingbranchName )
         throws ScmException
     {
         String[] outCmd = new String[]{ HgCommandConstants.OUTGOING_CMD };
@@ -326,10 +326,11 @@ public static boolean differentOutgoingBranchFound( ScmLogger logger,
File worki
         {
             for ( HgChangeSet set : changes )
             {
-                if (!getBranchName(workingbranchName).equals(getBranchName(set.getBranch())))
{
-                    logger.warn( "A different branch than " + getBranchName(workingbranchName)
-                        + " was found in outgoing changes, branch name was " + getBranchName(set.getBranch())
-                        + ". Only local branch named " + getBranchName(workingbranchName)
+ " will be pushed." );
+                if ( !getBranchName( workingbranchName ).equals( getBranchName( set.getBranch()
) ) )
+                {
+                    logger.warn( "A different branch than " + getBranchName( workingbranchName
)
+                        + " was found in outgoing changes, branch name was " + getBranchName(
set.getBranch() )
+                        + ". Only local branch named " + getBranchName( workingbranchName
) + " will be pushed." );
                     return true;
                 }
             }
@@ -337,7 +338,8 @@ public static boolean differentOutgoingBranchFound( ScmLogger logger,
File worki
         return false;
     }
 
-    private static String getBranchName(String branch) {
+    private static String getBranchName( String branch )
+    {
         return branch == null ? DEFAULT : branch;
     }
 
diff --git a/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
b/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
index f5eebfbc5..be1081441 100644
--- a/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
+++ b/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
@@ -22,8 +22,6 @@
 import org.apache.maven.scm.log.ScmLogger;
 import org.apache.maven.scm.provider.hg.command.HgConsumer;
 
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
index 7d850da80..f5d680889 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
@@ -264,7 +264,8 @@ public static URI resolveURI( String fileEntry, URI path )
     private static String stripQuotes( String str )
     {
         int strLen = str.length();
-        return ( strLen > 0 && str.startsWith( "\"" ) && str.endsWith(
"\"" ) ) ? unescape( str.substring( 1, strLen - 1 ) ) : str;
+        return ( strLen > 0 && str.startsWith( "\"" ) && str.endsWith(
"\"" ) ) 
+        ? unescape( str.substring( 1, strLen - 1 ) ) : str;
     }
     
     /**
@@ -348,7 +349,7 @@ private static String unescape( String fileEntry )
                     inSub--;
                     break;
             }
-            pos = fileEntry.indexOf( '\\', inSub);
+            pos = fileEntry.indexOf( '\\', inSub );
             if ( pos == -1 )        // No more backslashes; we're done
             {
                 System.arraycopy( inba, inSub, outba, outSub, inba.length - inSub );
@@ -359,7 +360,7 @@ private static String unescape( String fileEntry )
         try
         {
             // explicit say UTF-8, otherwise it'll fail at least on Windows cmdline
-            return new String(outba, 0, outSub, "UTF-8");
+            return new String( outba, 0, outSub, "UTF-8" );
         }
         catch ( UnsupportedEncodingException e )
         {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message