You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2012/10/10 18:19:29 UTC

svn commit: r1396669 - /maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java

Author: hboutemy
Date: Wed Oct 10 16:19:29 2012
New Revision: 1396669

URL: http://svn.apache.org/viewvc?rev=1396669&view=rev
Log:
extracted and reworked checkCreateRemoteSvnPath()

Modified:
    maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java

Modified: maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java?rev=1396669&r1=1396668&r2=1396669&view=diff
==============================================================================
--- maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java (original)
+++ maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java Wed Oct 10 16:19:29 2012
@@ -212,11 +212,6 @@ public abstract class AbstractScmPublish
 
     protected ScmRepository scmRepository;
 
-    protected AbstractScmPublishMojo()
-    {
-        super();
-    }
-
     protected void logInfo( String format, Object... params )
     {
         getLog().info( String.format( format, params ) );
@@ -304,72 +299,7 @@ public abstract class AbstractScmPublish
 
         if ( scmProvider instanceof AbstractSvnScmProvider )
         {
-            File baseDir = null;
-            try
-            {
-                getLog().debug( "AbstractSvnScmProvider used, so we can check if remote url exists and eventually create it." );
-                AbstractSvnScmProvider svnScmProvider = (AbstractSvnScmProvider) scmProvider;
-                String remoteUrl = ( (SvnScmProviderRepository) scmRepository.getProviderRepository() ).getUrl();
-                boolean remoteExists = svnScmProvider.remoteUrlExist( scmRepository.getProviderRepository(), null );
-
-                if ( !remoteExists )
-                {
-                    if ( automaticRemotePathCreation )
-                    {
-                        logInfo( "Remote svn url %s does not exist: creating.", remoteUrl );
-
-                        // create a temporary directory for svnexec
-                        baseDir = File.createTempFile( "scm", "tmp" );
-                        baseDir.delete();
-                        baseDir.mkdirs();
-                        // to prevent fileSet cannot be empty
-                        ScmFileSet scmFileSet = new ScmFileSet( baseDir, new File( "" ) );
-
-                        CommandParameters commandParameters = new CommandParameters();
-                        commandParameters.setString( CommandParameter.SCM_MKDIR_CREATE_IN_LOCAL,
-                                                     Boolean.FALSE.toString() );
-                        commandParameters.setString( CommandParameter.MESSAGE,
-                                                     "Automatic svn path creation: " + remoteUrl );
-                        svnScmProvider.mkdir( scmRepository.getProviderRepository(), scmFileSet, commandParameters );
-
-                        // new remote url so force checkout!
-                        if ( checkoutDirectory.exists() )
-                        {
-                            FileUtils.deleteDirectory( checkoutDirectory );
-                        }
-                    }
-                    else
-                    {
-                        // olamy: return ?? that will fail during checkout IMHO :-)
-                        logWarn( "Remote svn url %s does not exist and automatic remote path creation disabled.",
-                                 remoteUrl );
-                    }
-                }
-            }
-            catch ( IOException e )
-            {
-                throw new MojoExecutionException( e.getMessage(), e );
-            }
-            catch ( ScmException e )
-            {
-                throw new MojoExecutionException( e.getMessage(), e );
-            }
-
-            finally
-
-            {
-                if ( baseDir != null )
-                {
-                    try
-                    {
-                        FileUtils.forceDeleteOnExit( baseDir );
-                    }
-                    catch ( IOException e )
-                    {
-                        throw new MojoExecutionException( e.getMessage(), e );
-                    }
-                }
-            }
+            checkCreateRemoteSvnPath();
         }
 
         logInfo( "%s the pub tree from  %s ...", ( tryUpdate ? "Updating" : "Checking out" ), pubScmUrl );
@@ -437,6 +367,84 @@ public abstract class AbstractScmPublish
         }
     }
 
+    private void checkCreateRemoteSvnPath()
+        throws MojoExecutionException
+    {
+        getLog().debug( "AbstractSvnScmProvider used, so we can check if remote url exists and eventually create it." );
+        AbstractSvnScmProvider svnScmProvider = (AbstractSvnScmProvider) scmProvider;
+
+        try
+        {
+            boolean remoteExists = svnScmProvider.remoteUrlExist( scmRepository.getProviderRepository(), null );
+
+            if ( remoteExists )
+            {
+                return;
+            }
+        }
+        catch ( ScmException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+
+        String remoteUrl = ( (SvnScmProviderRepository) scmRepository.getProviderRepository() ).getUrl();
+
+        if ( !automaticRemotePathCreation )
+        {
+            // olamy: return ?? that will fail during checkout IMHO :-)
+            logWarn( "Remote svn url %s does not exist and automatic remote path creation disabled.",
+                     remoteUrl );
+            return;
+        }
+
+        logInfo( "Remote svn url %s does not exist: creating.", remoteUrl );
+
+        File baseDir = null;
+        try
+        {
+
+            // create a temporary directory for svnexec
+            baseDir = File.createTempFile( "scm", "tmp" );
+            baseDir.delete();
+            baseDir.mkdirs();
+            // to prevent fileSet cannot be empty
+            ScmFileSet scmFileSet = new ScmFileSet( baseDir, new File( "" ) );
+
+            CommandParameters commandParameters = new CommandParameters();
+            commandParameters.setString( CommandParameter.SCM_MKDIR_CREATE_IN_LOCAL, Boolean.FALSE.toString() );
+            commandParameters.setString( CommandParameter.MESSAGE, "Automatic svn path creation: " + remoteUrl );
+            svnScmProvider.mkdir( scmRepository.getProviderRepository(), scmFileSet, commandParameters );
+
+            // new remote url so force checkout!
+            if ( checkoutDirectory.exists() )
+            {
+                FileUtils.deleteDirectory( checkoutDirectory );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+        catch ( ScmException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+        finally
+        {
+            if ( baseDir != null )
+            {
+                try
+                {
+                    FileUtils.forceDeleteOnExit( baseDir );
+                }
+                catch ( IOException e )
+                {
+                    throw new MojoExecutionException( e.getMessage(), e );
+                }
+            }
+        }
+    }
+
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {