continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jzurb...@apache.org
Subject svn commit: r928579 - in /continuum/trunk/continuum-release/src: main/java/org/apache/maven/continuum/release/phase/ test/java/org/apache/maven/continuum/release/phase/
Date Mon, 29 Mar 2010 03:15:32 GMT
Author: jzurbano
Date: Mon Mar 29 03:15:30 2010
New Revision: 928579

URL: http://svn.apache.org/viewvc?rev=928579&view=rev
Log:
[CONTINUUM-2458] Continuum Release should do a checkout if there is no working copy
* applied patch
* additional unit tests for working directory with project checkout and empty working directory

Submitted by: Gwen Harold Autencio
* checkout project if working directory does not exist
* unit test for non-existing working directory


Added:
    continuum/trunk/continuum-release/src/test/java/org/apache/maven/continuum/release/phase/
    continuum/trunk/continuum-release/src/test/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhaseTest.java
  (with props)
Modified:
    continuum/trunk/continuum-release/src/main/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhase.java

Modified: continuum/trunk/continuum-release/src/main/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhase.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-release/src/main/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhase.java?rev=928579&r1=928578&r2=928579&view=diff
==============================================================================
--- continuum/trunk/continuum-release/src/main/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhase.java
(original)
+++ continuum/trunk/continuum-release/src/main/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhase.java
Mon Mar 29 03:15:30 2010
@@ -22,6 +22,7 @@ package org.apache.maven.continuum.relea
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.ScmVersion;
+import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 import org.apache.maven.scm.command.update.UpdateScmResult;
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
 import org.apache.maven.scm.provider.ScmProvider;
@@ -82,11 +83,26 @@ public class UpdateWorkingCopyPhase
             throw new ReleaseExecutionException( "Unable to configure SCM repository: " +
e.getMessage(), e );
         }
 
-        UpdateScmResult result;
+        UpdateScmResult updateScmResult = null;
+        CheckOutScmResult checkOutScmResult = null;
+        
+        File workingDirectory = new File( releaseDescriptor.getWorkingDirectory() );
+        
         try
         {
-            result = provider.update( repository, new ScmFileSet( new File( releaseDescriptor.getWorkingDirectory()
) ),
-                                      (ScmVersion) null );
+            if ( !workingDirectory.exists() )
+            {
+                workingDirectory.mkdirs();
+            }
+            
+            if( workingDirectory.listFiles().length > 1 )
+            {
+                updateScmResult = provider.update( repository, new ScmFileSet( workingDirectory
), (ScmVersion) null );
+            }
+            else
+            {
+                checkOutScmResult = provider.checkOut( repository, new ScmFileSet( workingDirectory
) );
+            }
         }
         catch ( ScmException e )
         {
@@ -94,13 +110,25 @@ public class UpdateWorkingCopyPhase
                                                  e );
         }
 
-        if ( !result.isSuccess() )
+        if ( updateScmResult != null )
         {
-            throw new ReleaseScmCommandException( "Unable to update current working copy",
result );
+            if( !updateScmResult.isSuccess() )
+            {
+                throw new ReleaseScmCommandException( "Unable to update current working copy",
updateScmResult );
+            }
+            
+            copyUpdated = updateScmResult.getUpdatedFiles().size() > 0;
+        }
+        else
+        {
+            if( !checkOutScmResult.isSuccess() )
+            {
+                throw new ReleaseScmCommandException( "Unable to checkout project", checkOutScmResult
);
+            }
+            
+            copyUpdated = checkOutScmResult.getCheckedOutFiles().size() > 0;
         }
 
-        copyUpdated = ( result.getUpdatedFiles().size() > 0 );
-
         relResult.setResultCode( ReleaseResult.SUCCESS );
 
         return relResult;

Added: continuum/trunk/continuum-release/src/test/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhaseTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-release/src/test/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhaseTest.java?rev=928579&view=auto
==============================================================================
--- continuum/trunk/continuum-release/src/test/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhaseTest.java
(added)
+++ continuum/trunk/continuum-release/src/test/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhaseTest.java
Mon Mar 29 03:15:30 2010
@@ -0,0 +1,100 @@
+package org.apache.maven.continuum.release.phase;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.continuum.release.config.ContinuumReleaseDescriptor;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.shared.release.phase.ReleasePhase;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+public class UpdateWorkingCopyPhaseTest
+    extends PlexusInSpringTestCase
+{
+    private UpdateWorkingCopyPhase phase;
+    
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        
+        phase = (UpdateWorkingCopyPhase) lookup( ReleasePhase.ROLE, "update-working-copy"
);
+        
+        // set up project scm
+        File scmPathFile = new File( getBasedir(), "target/scm-src" ).getAbsoluteFile();
+        File scmTargetPathFile = new File( getBasedir(), "/target/scm-test" ).getAbsoluteFile();
+        FileUtils.copyDirectoryStructure( scmPathFile, scmTargetPathFile );
+    }
+    
+    public void testWorkingDirDoesNotExist()
+        throws Exception
+    {
+        assertNotNull( phase );
+        
+        ContinuumReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
+        
+        File workingDirectory = new File( releaseDescriptor.getWorkingDirectory() );
+        
+        // assert no working directory yet
+        assertFalse( workingDirectory.exists() );
+        
+        phase.execute( releaseDescriptor, new Settings(), null );
+        
+        assertTrue( workingDirectory.exists() );
+    }
+    
+    public void testWorkingDirAlreadyExistsWithProjectCheckout()
+        throws Exception
+    {
+        assertNotNull( phase );
+        
+        ContinuumReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
+        
+        File workingDirectory = new File( releaseDescriptor.getWorkingDirectory() );
+        
+        // assert working directory already exists with project checkout
+        assertTrue( workingDirectory.exists() );
+        assertTrue( workingDirectory.listFiles().length > 0 );
+        
+        phase.execute( releaseDescriptor, new Settings(), null );
+        
+        assertTrue( workingDirectory.exists() );
+    }
+    
+    public void testWorkingDirAlreadyExistsNoProjectCheckout()
+        throws Exception
+    {
+        assertNotNull( phase );
+        
+        ContinuumReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
+        
+        File workingDirectory = new File( releaseDescriptor.getWorkingDirectory() );
+        FileUtils.deleteDirectory( workingDirectory );
+        workingDirectory.mkdirs();
+        
+        // assert empty working directory
+        assertTrue( workingDirectory.exists() );
+        assertTrue( workingDirectory.listFiles().length == 0 );
+        
+        phase.execute( releaseDescriptor, new Settings(), null );
+        
+        assertTrue( workingDirectory.exists() );
+    }
+    
+    private ContinuumReleaseDescriptor createReleaseDescriptor()
+    {
+        // project source and working directory paths
+        String projectUrl = getBasedir() + "/target/scm-test/trunk";
+        String workingDirPath = getBasedir() + "/target/test-classes/updateWorkingCopy_working-directory";
+        
+        // create release descriptor
+        ContinuumReleaseDescriptor releaseDescriptor = new ContinuumReleaseDescriptor();
+        releaseDescriptor.setScmSourceUrl( "scm:svn:file://" + projectUrl );
+        releaseDescriptor.setWorkingDirectory( workingDirPath );
+        
+        return releaseDescriptor;
+    }
+}

Propchange: continuum/trunk/continuum-release/src/test/java/org/apache/maven/continuum/release/phase/UpdateWorkingCopyPhaseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message