maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1245806 - in /maven/release/trunk: maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java
Date Fri, 17 Feb 2012 23:20:49 GMT
Author: struberg
Date: Fri Feb 17 23:20:48 2012
New Revision: 1245806

URL: http://svn.apache.org/viewvc?rev=1245806&view=rev
Log:
MRELEASE-740 fix sparse release:perform with localCheckout

Modified:
    maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java
    maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java

Modified: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java?rev=1245806&r1=1245805&r2=1245806&view=diff
==============================================================================
--- maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java
(original)
+++ maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java
Fri Feb 17 23:20:48 2012
@@ -61,15 +61,9 @@ public class CheckoutProjectFromScm
 
     public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment
releaseEnvironment,
                                   List<MavenProject> reactorProjects )
-        throws ReleaseExecutionException, ReleaseFailureException
+            throws ReleaseExecutionException, ReleaseFailureException
     {
-        ReleaseResult result = new ReleaseResult();
-
-        logInfo( result, "Checking out the project to perform the release ..." );
-
-        ScmRepository repository;
-        ScmProvider provider;
-
+        ReleaseResult releaseResult = null;
 
         if ( releaseDescriptor.isLocalCheckout() )
         {
@@ -78,15 +72,83 @@ public class CheckoutProjectFromScm
 
             // the first step is a bit tricky, we need to know which provider! like e.g.
"scm:jgit:http://"
             // the offset of 4 is because 'scm:' has 4 characters...
-            String providerPart =
-                releaseDescriptor.getScmSourceUrl().substring( 0, releaseDescriptor.getScmSourceUrl().indexOf(
':', 4 ) );
+            String providerPart = releaseDescriptor.getScmSourceUrl()
+                    .substring(0, releaseDescriptor.getScmSourceUrl().indexOf(':', 4));
+
+            String scmPath = releaseDescriptor.getWorkingDirectory();
+
+            // now we iteratively try to checkout.
+            // if the local checkout fails, then we might be in a subdirectory
+            // and need to walk a few directories up.
+            do
+            {
+                try
+                {
+                    String scmUrl = providerPart + ":file://" + scmPath;
+                    releaseDescriptor.setScmSourceUrl( scmUrl );
+                    getLogger().info( "Performing a LOCAL checkout from " + releaseDescriptor.getScmSourceUrl()
);
 
-            //X TODO: also check the information from releaseDescriptor.getScmRelativePathProjectDirectory()
-            //X TODO: in case our toplevel git directory has no pom.
+                    releaseResult = performCheckout( releaseDescriptor, releaseEnvironment,
reactorProjects );
+                }
+                catch ( ScmException scmEx)
+                {
+                    // the checkout from _this_ directory failed
+                    releaseResult = null;
+                }
 
-            releaseDescriptor.setScmSourceUrl( providerPart + ":file://" + releaseDescriptor.getWorkingDirectory()
);
-            getLogger().info( "Performing a LOCAL checkout from " + releaseDescriptor.getScmSourceUrl()
);
+                if ( releaseResult == null || releaseResult.getResultCode() == ReleaseResult.ERROR
)
+                {
+                    // this means that there is no SCM repo in this directory
+                    // thus we try to step one directory up
+                    releaseResult = null;
+
+                    // remove last sub-directory path
+                    int lastSlashPos = scmPath.lastIndexOf( "/" );
+                    if ( lastSlashPos > 0 )
+                    {
+                        scmPath = scmPath.substring( 0, lastSlashPos );
+                    }
+                    else
+                    {
+                        throw new ReleaseExecutionException( "could not perform a local checkout"
);
+                    }
+                }
+            }
+            while ( releaseResult == null );
         }
+        else
+        {
+            // when there is no localCheckout, then we just do a standard SCM checkout.
+            try
+            {
+                releaseResult =  performCheckout( releaseDescriptor, releaseEnvironment,
reactorProjects );
+            }
+            catch ( ScmException e )
+            {
+                releaseResult = new ReleaseResult();
+                releaseResult.setResultCode( ReleaseResult.ERROR );
+                logError( releaseResult, e.getMessage() );
+
+                throw new ReleaseExecutionException( "An error is occurred in the checkout
process: "
+                                                     + e.getMessage(), e );
+            }
+
+        }
+
+        return releaseResult;
+    }
+
+
+    public ReleaseResult performCheckout( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment
releaseEnvironment,
+                                  List<MavenProject> reactorProjects )
+        throws ReleaseExecutionException, ReleaseFailureException, ScmException
+    {
+        ReleaseResult result = new ReleaseResult();
+
+        logInfo( result, "Checking out the project to perform the release ..." );
+
+        ScmRepository repository;
+        ScmProvider provider;
 
         try
         {
@@ -142,17 +204,14 @@ public class CheckoutProjectFromScm
 
         CheckOutScmResult scmResult;
 
-        try
-        {
-            scmResult = provider.checkOut( repository, new ScmFileSet( checkoutDirectory
),
-                                           new ScmTag( releaseDescriptor.getScmReleaseLabel()
) );
-        }
-        catch ( ScmException e )
-        {
-            result.setResultCode( ReleaseResult.ERROR );
-            logError( result, e.getMessage() );
+        scmResult = provider.checkOut( repository, new ScmFileSet( checkoutDirectory ),
+                                       new ScmTag( releaseDescriptor.getScmReleaseLabel()
) );
 
-            throw new ReleaseExecutionException( "An error is occurred in the checkout process:
" + e.getMessage(), e );
+        if ( releaseDescriptor.isLocalCheckout() && !scmResult.isSuccess() )
+        {
+            // this is not beautiful but needed to indicate that the execute() method
+            // should continue in the parent directory
+            return null;
         }
 
         String scmRelativePathProjectDirectory = scmResult.getRelativePathProjectDirectory();

Modified: maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java?rev=1245806&r1=1245805&r2=1245806&view=diff
==============================================================================
--- maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java
(original)
+++ maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java
Fri Feb 17 23:20:48 2012
@@ -281,7 +281,7 @@ public abstract class AbstractReleaseMoj
         descriptor.setPushChanges( pushChanges );
 
         @SuppressWarnings("unchecked")
-		List<Profile> profiles = project.getActiveProfiles();
+        List<Profile> profiles = project.getActiveProfiles();
 
         String arguments = this.arguments;
         if ( profiles != null && !profiles.isEmpty() )



Mime
View raw message