maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r957146 - in /maven/scm/trunk: maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/ maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/mkdir/ mav...
Date Wed, 23 Jun 2010 10:07:46 GMT
Author: oching
Date: Wed Jun 23 10:07:45 2010
New Revision: 957146

URL: http://svn.apache.org/viewvc?rev=957146&view=rev
Log:
[SCM-558] Add support for 'mkdir' command
o implement mkdir command for local scm + tck tests
o add test case when directory to be created already exists in repo for SVN scm provider

Added:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/mkdir/
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommand.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/mkdir/
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommandTckTest.java
Modified:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/LocalScmProvider.java
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/mkdir/SvnMkdirCommandTckTest.java
    maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/LocalScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/LocalScmProvider.java?rev=957146&r1=957145&r2=957146&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/LocalScmProvider.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/LocalScmProvider.java
Wed Jun 23 10:07:45 2010
@@ -27,6 +27,7 @@ import org.apache.maven.scm.command.chan
 import org.apache.maven.scm.command.checkin.CheckInScmResult;
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 import org.apache.maven.scm.command.list.ListScmResult;
+import org.apache.maven.scm.command.mkdir.MkdirScmResult;
 import org.apache.maven.scm.command.update.UpdateScmResult;
 import org.apache.maven.scm.command.status.StatusScmResult;
 import org.apache.maven.scm.command.tag.TagScmResult;
@@ -37,6 +38,7 @@ import org.apache.maven.scm.provider.loc
 import org.apache.maven.scm.provider.local.command.checkin.LocalCheckInCommand;
 import org.apache.maven.scm.provider.local.command.checkout.LocalCheckOutCommand;
 import org.apache.maven.scm.provider.local.command.list.LocalListCommand;
+import org.apache.maven.scm.provider.local.command.mkdir.LocalMkdirCommand;
 import org.apache.maven.scm.provider.local.command.update.LocalUpdateCommand;
 import org.apache.maven.scm.provider.local.command.status.LocalStatusCommand;
 import org.apache.maven.scm.provider.local.command.tag.LocalTagCommand;
@@ -218,6 +220,17 @@ public class LocalScmProvider
 
         return (ListScmResult) command.execute( repository, fileSet, parameters );
     }
+    
+    /** {@inheritDoc} */
+    protected MkdirScmResult mkdir( ScmProviderRepository repository, ScmFileSet fileSet,
CommandParameters parameters )
+        throws ScmException
+    {
+        LocalMkdirCommand command = new LocalMkdirCommand();
+
+        command.setLogger( getLogger() );
+
+        return (MkdirScmResult) command.execute( repository, fileSet, parameters );
+    }
 
     /** {@inheritDoc} */
     public UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet,
CommandParameters parameters )

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommand.java?rev=957146&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommand.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommand.java
Wed Jun 23 10:07:45 2010
@@ -0,0 +1,98 @@
+package org.apache.maven.scm.provider.local.command.mkdir;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.scm.CommandParameter;
+import org.apache.maven.scm.CommandParameters;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmFileStatus;
+import org.apache.maven.scm.command.add.AddScmResult;
+import org.apache.maven.scm.command.mkdir.AbstractMkdirCommand;
+import org.apache.maven.scm.command.mkdir.MkdirScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.local.command.add.LocalAddCommand;
+import org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @version $Id$
+ */
+public class LocalMkdirCommand
+    extends AbstractMkdirCommand
+{
+    protected MkdirScmResult executeMkdirCommand( ScmProviderRepository repository, ScmFileSet
fileSet, String message,
+                                                  boolean createInLocal )
+        throws ScmException
+    {
+        LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
+        List createdDirs = new ArrayList();
+
+        // create/commit the directory directly in the repository
+        if ( !createInLocal )
+        {
+            File file = (File) fileSet.getFileList().get( 0 );
+            File modulePath = new File( repo.getRoot(), repo.getModule() );
+            File dir = new File( modulePath, file.getName() );
+
+            if ( dir.exists() )
+            {
+                return new MkdirScmResult( null, "Directory already exists!", "Directory
already exists.", false );
+            }
+            else
+            {
+                if ( getLogger().isInfoEnabled() )
+                {
+                    getLogger().info( "Creating directory in '" + modulePath.getAbsolutePath()
+ "'" );
+                }
+
+                FileUtils.mkdir( dir.getAbsolutePath() );
+                createdDirs.add( new ScmFile( dir.getPath(), ScmFileStatus.CHECKED_IN ) );
+            }
+        }
+        else
+        {
+            // add the directory, but not commit
+            LocalAddCommand addCmd = new LocalAddCommand();
+            addCmd.setLogger( getLogger() );
+
+            CommandParameters parameters = new CommandParameters();
+            parameters.setString( CommandParameter.MESSAGE, message );
+            parameters.setString( CommandParameter.BINARY, "false" );
+
+            String path = ( (File) fileSet.getFileList().get( 0 ) ).getPath();
+            if ( repo.isFileAdded( path ) )
+            {
+                return new MkdirScmResult( null, "Directory already exists!", "Directory
already exists.", false );
+            }
+
+            AddScmResult result = (AddScmResult) addCmd.execute( repository, fileSet, parameters
);
+            createdDirs.addAll( result.getAddedFiles() );
+        }
+
+        return new MkdirScmResult( null, createdDirs );
+    }
+}

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommandTckTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommandTckTest.java?rev=957146&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommandTckTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/mkdir/LocalMkdirCommandTckTest.java
Wed Jun 23 10:07:45 2010
@@ -0,0 +1,98 @@
+package org.apache.maven.scm.provider.local.command.mkdir;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.command.list.ListScmResult;
+import org.apache.maven.scm.command.mkdir.MkdirScmResult;
+import org.apache.maven.scm.tck.command.mkdir.MkdirCommandTckTest;
+
+/**
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @version $Id$
+ */
+public class LocalMkdirCommandTckTest
+    extends MkdirCommandTckTest
+{
+    private static final String moduleName = "checkin-tck";
+
+    public String getScmUrl()
+        throws Exception
+    {
+        return "scm:local|" + getRepositoryRoot() + "|" + moduleName;
+    }
+
+    public void initRepo()
+        throws Exception
+    {
+        makeRepo( getRepositoryRoot() );
+    }
+
+    private void makeRepo( File workingDirectory )
+        throws Exception
+    {
+        makeFile( workingDirectory, moduleName + "/pom.xml", "/pom.xml" );
+
+        makeFile( workingDirectory, moduleName + "/readme.txt", "/readme.txt" );
+
+        makeFile( workingDirectory, moduleName + "/src/main/java/Application.java", "/src/main/java/Application.java"
);
+
+        makeFile( workingDirectory, moduleName + "/src/test/java/Test.java", "/src/test/java/Test.java"
);
+
+        makeDirectory( workingDirectory, moduleName + "/src/test/resources" );
+    }
+
+    public void testMkdirCommandMkdirUrl()
+        throws Exception
+    {
+        ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( getMissingDirectory()
) );
+
+        MkdirScmResult result = getScmManager().mkdir( getScmRepository(), fileSet, "Mkdir
message", false );
+
+        assertResultIsSuccess( result );
+
+        ListScmResult listResult = getScmManager().list( getScmRepository(), fileSet, true,
null );
+
+        assertTrue( "Directory should have been found.", listResult.isSuccess() );
+    }
+
+    public void testMkdirCommandDirAlreadyAdded()
+        throws Exception
+    {
+        ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( getMissingDirectory()
) );
+
+        MkdirScmResult result = getScmManager().mkdir( getScmRepository(), fileSet, "Mkdir
message", false );
+
+        assertResultIsSuccess( result );
+
+        ListScmResult listResult = getScmManager().list( getScmRepository(), fileSet, true,
null );
+
+        assertTrue( "Directory should have been found.", listResult.isSuccess() );
+
+        // add the directory again
+        result = getScmManager().mkdir( getScmRepository(), fileSet, "Mkdir message", false
);
+
+        assertFalse( result.isSuccess() );
+
+        printOutputError( result );
+    }
+}

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/mkdir/SvnMkdirCommandTckTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/mkdir/SvnMkdirCommandTckTest.java?rev=957146&r1=957145&r2=957146&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/mkdir/SvnMkdirCommandTckTest.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/mkdir/SvnMkdirCommandTckTest.java
Wed Jun 23 10:07:45 2010
@@ -63,4 +63,27 @@ public class SvnMkdirCommandTckTest
     
         assertTrue( "Directory should have been found.", listResult.isSuccess() );
     }
+    
+    public void testMkdirCommandDirAlreadyAdded()
+        throws Exception
+    {
+        ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( getMissingDirectory()
) );
+    
+        MkdirScmResult result = getScmManager().mkdir( getScmRepository(), fileSet, null,
false );
+    
+        assertResultIsSuccess( result );
+    
+        assertNotNull( result.getRevision() );
+    
+        ListScmResult listResult = getScmManager().list( getScmRepository(), fileSet, true,
null );
+        
+        assertTrue( "Directory should have been found.", listResult.isSuccess() );
+                
+        // add the directory again
+        result = getScmManager().mkdir( getScmRepository(), fileSet, null, false );
+    
+        printOutputError( result ); 
+        
+        assertFalse( result.isSuccess() );
+    }
 }

Modified: maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java?rev=957146&r1=957145&r2=957146&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java (original)
+++ maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java Wed
Jun 23 10:07:45 2010
@@ -181,6 +181,13 @@ public abstract class ScmTestCase
             return;
         }
 
+        printOutputError( result );
+
+        fail( "The check out result success flag was false." );
+    }
+
+    protected void printOutputError( ScmResult result )
+    {
         System.err.println( "----------------------------------------------------------------------"
);
         System.err.println( "Provider message" );
         System.err.println( "----------------------------------------------------------------------"
);
@@ -192,8 +199,6 @@ public abstract class ScmTestCase
         System.err.println( "----------------------------------------------------------------------"
);
         System.err.println( result.getCommandOutput() );
         System.err.println( "----------------------------------------------------------------------"
);
-
-        fail( "The check out result success flag was false." );
     }
 
     protected ScmFileSet getScmFileSet()



Mime
View raw message