maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dant...@apache.org
Subject svn commit: r733437 - in /maven/scm/trunk: ./ maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ maven-scm-plugin/src/test/resources/mojos/export/ maven-scm-providers/maven-scm-provid...
Date Sun, 11 Jan 2009 09:25:52 GMT
Author: dantran
Date: Sun Jan 11 01:25:52 2009
New Revision: 733437

URL: http://svn.apache.org/viewvc?rev=733437&view=rev
Log:
SCM-375
  - Export Mojo should not pre-create initial export directory, the provider should be the
one.  This make checkout and export behave the same
  - Use File for exportDirector configuration rather than using String.
  - Convert bad file URL which derived from windows directory to unix path.
  - Add --force param into svn export command to support export to existing directory
  - No need to set workingDirectory for SvnExportCommand, actually workingDirectory has no
meaning to all providers when dealing with export command.
  - Add various export tests
  

Added:
    maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ExportMojoTest.java
    maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/export/
    maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/export/export.xml
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/export/
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExportCommandTest.java
Modified:
    maven/scm/trunk/   (props changed)
    maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ExportMojo.java
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnCommandUtils.java
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/SvnCommandLineUtils.java
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExeExportCommand.java

Propchange: maven/scm/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Jan 11 01:25:52 2009
@@ -6,3 +6,4 @@
 *.ipr
 *.iws
 *.iml
+.metadata

Modified: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ExportMojo.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ExportMojo.java?rev=733437&r1=733436&r2=733437&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ExportMojo.java
(original)
+++ maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ExportMojo.java
Sun Jan 11 01:25:52 2009
@@ -1,38 +1,33 @@
 package org.apache.maven.scm.plugin;
 
 /*
- * 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
- *
+ * 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.
+ * 
+ * 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.io.IOException;
+
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.command.export.ExportScmResult;
 import org.apache.maven.scm.repository.ScmRepository;
 import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.io.File;
-import java.io.IOException;
 
 /**
  * Get a fresh exported copy of the latest source from the configured scm url.
- *
+ * 
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  * @version $Id$
  * @goal export
@@ -43,25 +38,25 @@
 {
     /**
      * The version type (branch/tag/revision) of scmVersion.
-     *
+     * 
      * @parameter expression="${scmVersionType}"
      */
     private String scmVersionType;
 
     /**
      * The version (revision number/branch name/tag name).
-     *
+     * 
      * @parameter expression="${scmVersion}"
      */
     private String scmVersion;
 
     /**
      * The directory to export the sources to.
-     *
-     * @parameter expression="${exportDirectory}"
+     * 
+     * @parameter expression="${exportDirectory}" default-value="${project.build.directory}/export
      * @required
      */
-    private String exportDirectory;
+    private File exportDirectory;
 
     /** {@inheritDoc} */
     public void execute()
@@ -70,12 +65,12 @@
         export();
     }
 
-    protected String getExportDirectory()
+    protected File getExportDirectory()
     {
         return this.exportDirectory;
     }
 
-    public void setExportDirectory( String exportDirectory )
+    public void setExportDirectory( File exportDirectory )
     {
         this.exportDirectory = exportDirectory;
     }
@@ -91,17 +86,11 @@
 
             try
             {
-                if ( StringUtils.isNotEmpty( getExportDirectory() ) )
+                if ( this.exportDirectory.exists() )
                 {
-                    File f = new File( getExportDirectory() );
-                    if ( f.exists() )
-                    {
-                        this.getLog().info( "Removing " + getExportDirectory() );
-
-                        FileUtils.deleteDirectory( getExportDirectory() );
-                    }
+                    this.getLog().info( "Removing " + this.exportDirectory );
 
-                    f.mkdirs();
+                    FileUtils.deleteDirectory( this.exportDirectory );
                 }
             }
             catch ( IOException e )
@@ -109,9 +98,10 @@
                 throw new MojoExecutionException( "Cannot remove " + getExportDirectory()
);
             }
 
-            ExportScmResult result = getScmManager().export( repository, new ScmFileSet(
-                new File( getExportDirectory() ).getAbsoluteFile() ), getScmVersion( scmVersionType,
scmVersion ),
-                                                                      getExportDirectory()
);
+            ExportScmResult result = getScmManager().export( repository,
+                                                             new ScmFileSet( this.exportDirectory.getAbsoluteFile()
),
+                                                             getScmVersion( scmVersionType,
scmVersion ),
+                                                             this.exportDirectory.getAbsolutePath()
);
 
             checkResult( result );
         }

Added: maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ExportMojoTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ExportMojoTest.java?rev=733437&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ExportMojoTest.java
(added)
+++ maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ExportMojoTest.java
Sun Jan 11 01:25:52 2009
@@ -0,0 +1,62 @@
+package org.apache.maven.scm.plugin;
+
+/*
+ * 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.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * @version $Id: ExportMojoTest.java 687713 2008-08-21 11:12:33Z vsiveton $
+ */
+public class ExportMojoTest
+    extends AbstractMojoTestCase
+{
+    File exportDir;
+
+    File repository;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        exportDir = getTestFile( "target/export" );
+
+        repository = getTestFile( "target/repository" );
+
+        FileUtils.forceDelete( exportDir );
+    }
+
+    public void testExport()
+
+        throws Exception
+    {
+        SvnScmTestUtils.initializeRepository( repository );
+
+        ExportMojo mojo = (ExportMojo) lookupMojo( "export", getTestFile( "src/test/resources/mojos/export/export.xml"
) );
+
+        mojo.setExportDirectory( exportDir.getAbsoluteFile() );
+
+        mojo.execute();
+
+        assertTrue( exportDir.listFiles().length > 0  );
+        assertFalse( new File( exportDir, ".svn" ).exists() );
+    }
+
+}

Added: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/export/export.xml
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/export/export.xml?rev=733437&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/export/export.xml (added)
+++ maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/export/export.xml Sun Jan 11
01:25:52 2009
@@ -0,0 +1,34 @@
+<!--
+  ~ 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.
+  -->
+
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-scm-plugin</artifactId>
+        <configuration>
+          <settings implementation="org.apache.maven.settings.Settings"/>
+          <exportDirectory>target/export</exportDirectory>
+          <connectionType>connection</connectionType>
+          <connectionUrl>scm:svn:file:///${basedir}/target/repository/trunk</connectionUrl>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnCommandUtils.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnCommandUtils.java?rev=733437&r1=733436&r2=733437&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnCommandUtils.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnCommandUtils.java
Sun Jan 11 01:25:52 2009
@@ -35,7 +35,9 @@
      * <p/>
      * Svn 1.3.1 doesn't use the username information specified by --username when the url
      * uses the svn+ssh scheme. This allows to fix it. See MRELEASE-35.
-     *
+     * </p>
+     * Convert file url which derived from windows file path to unix path.
+     * </p>
      * @param url      the url, not <code>null</code>
      * @param username the username, may be <code>null</code>
      * @return the fixed url
@@ -50,6 +52,12 @@
             int cutIdx = idx < 0 ? "svn+ssh://".length() : idx + 1;
             url = "svn+ssh://" + username + "@" + url.substring( cutIdx );
         }
+        else if ( url.startsWith( "file://" ) )
+        {
+            //some svn commands does not understand windows path separator in file URL derived
from windows file path
+            url = url.replace( '\\', '/' );
+        }        
+        
         return url;
     }
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/SvnCommandLineUtils.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/SvnCommandLineUtils.java?rev=733437&r1=733436&r2=733437&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/SvnCommandLineUtils.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/SvnCommandLineUtils.java
Sun Jan 11 01:25:52 2009
@@ -88,7 +88,10 @@
             //Do nothing
         }
 
-        cl.setWorkingDirectory( workingDirectory.getAbsolutePath() );
+        if ( workingDirectory != null )
+        {
+            cl.setWorkingDirectory( workingDirectory.getAbsolutePath() );
+        }
 
         if ( !StringUtils.isEmpty( System.getProperty( "maven.scm.svn.config_directory" )
) )
         {

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExeExportCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExeExportCommand.java?rev=733437&r1=733436&r2=733437&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExeExportCommand.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExeExportCommand.java
Sun Jan 11 01:25:52 2009
@@ -40,8 +40,6 @@
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
 
-import java.io.File;
-
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  * @version $Id$
@@ -74,7 +72,7 @@
         url = SvnCommandUtils.fixUrl( url, repository.getUser() );
 
         Commandline cl =
-            createCommandLine( (SvnScmProviderRepository) repo, fileSet.getBasedir(), version,
url, outputDirectory );
+            createCommandLine( (SvnScmProviderRepository) repo, version, url, outputDirectory
);
 
         SvnUpdateConsumer consumer = new SvnUpdateConsumer( getLogger(), fileSet.getBasedir()
);
 
@@ -83,7 +81,10 @@
         if ( getLogger().isInfoEnabled() )
         {
             getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) );
-            getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath()
);
+            if ( cl.getWorkingDirectory() != null )
+            {
+                getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath()
);
+            }
         }
 
         int exitCode;
@@ -110,15 +111,14 @@
     //
     // ----------------------------------------------------------------------
 
-    public static Commandline createCommandLine( SvnScmProviderRepository repository, File
workingDirectory,
-                                                 ScmVersion version, String url, String outputSirectory
)
+    public static Commandline createCommandLine( SvnScmProviderRepository repository, ScmVersion
version, String url, String outputSirectory )
     {
         if ( version != null && StringUtils.isEmpty( version.getName() ) )
         {
             version = null;
         }
 
-        Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( workingDirectory, repository
);
+        Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( null, repository );
 
         cl.createArg().setValue( "export" );
 
@@ -131,6 +131,9 @@
                 cl.createArg().setValue( version.getName() );
             }
         }
+        
+        //support exporting to an existing directory
+        cl.createArg().setValue( "--force" );
 
         cl.createArg().setValue( url );
 

Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExportCommandTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExportCommandTest.java?rev=733437&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExportCommandTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/export/SvnExportCommandTest.java
Sun Jan 11 01:25:52 2009
@@ -0,0 +1,33 @@
+package org.apache.maven.scm.provider.svn.svnexe.command.export;
+
+import java.io.File;
+
+import org.apache.maven.scm.ScmTestCase;
+import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.codehaus.plexus.util.cli.Commandline;
+
+public class SvnExportCommandTest
+    extends ScmTestCase
+{
+
+    public void testGetExportCommandLine()
+        throws Exception
+    {
+        File exportDirectory = new File( getBasedir() );
+        
+        testCommandLine( "scm:svn:http://foo.com/svn/trunk", exportDirectory, "svn --non-interactive
export --force scm:svn:http://foo.com/svn/trunk " + exportDirectory );
+    }
+    
+    private void testCommandLine( String scmUrl, File exportDirectory, String commandLine
)
+        throws Exception
+    {
+        ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
+
+        SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository();
+
+        Commandline cl = SvnExeExportCommand.createCommandLine( svnRepository, null, scmUrl,
exportDirectory.getAbsolutePath() );
+        
+        assertCommandLine( commandLine, exportDirectory, cl );
+    }
+}



Mime
View raw message