You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2005/10/11 03:11:24 UTC

svn commit: r312774 - in /maven/components/trunk/maven-plugins/maven-site-plugin: pom.xml src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java

Author: brett
Date: Mon Oct 10 18:11:17 2005
New Revision: 312774

URL: http://svn.apache.org/viewcvs?rev=312774&view=rev
Log:
PR: MNG-484
allow using any directory copy enabled wagon for site

Modified:
    maven/components/trunk/maven-plugins/maven-site-plugin/pom.xml
    maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java

Modified: maven/components/trunk/maven-plugins/maven-site-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-site-plugin/pom.xml?rev=312774&r1=312773&r2=312774&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-site-plugin/pom.xml (original)
+++ maven/components/trunk/maven-plugins/maven-site-plugin/pom.xml Mon Oct 10 18:11:17 2005
@@ -57,24 +57,12 @@
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-ssh</artifactId>
-      <version>1.0-alpha-4</version>
-      <exclusions>
-        <exclusion>
-          <groupId>plexus</groupId>
-          <artifactId>plexus-utils</artifactId>
-        </exclusion>
-      </exclusions>
+      <version>1.0-alpha-5-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-provider-api</artifactId>
-      <version>1.0-alpha-4</version>
-      <exclusions>
-        <exclusion>
-          <groupId>plexus</groupId>
-          <artifactId>plexus-utils</artifactId>
-        </exclusion>
-      </exclusions>
+      <version>1.0-alpha-5-SNAPSHOT</version>
     </dependency>
   </dependencies>
 </project>

Modified: maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java?rev=312774&r1=312773&r2=312774&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java Mon Oct 10 18:11:17 2005
@@ -23,18 +23,16 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.wagon.ConnectionException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.UnsupportedProtocolException;
+import org.apache.maven.wagon.Wagon;
 import org.apache.maven.wagon.observers.Debug;
-import org.apache.maven.wagon.providers.ssh.SshCommandExecutor;
+import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.repository.Repository;
-import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
 
 /**
  * Deploys website using scp/file protocol.
@@ -58,11 +56,6 @@
     private File inputDirectory;
 
     /**
-     * @parameter
-     */
-    private String unzipCommand = "unzip -o";
-
-    /**
      * @parameter expression="${project}"
      * @required
      * @readonly
@@ -70,9 +63,7 @@
     private MavenProject project;
 
     /**
-     * @parameter expression="${component.org.apache.maven.artifact.manager.WagonManager}"
-     * @required
-     * @readonly
+     * @component
      */
     private WagonManager wagonManager;
 
@@ -84,17 +75,6 @@
             throw new MojoExecutionException( "The site does not exist, please run site:site first" );
         }
 
-        File zipFile;
-
-        try
-        {
-            zipFile = File.createTempFile( "site", ".zip" );
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( "Cannot create site archive!", e );
-        }
-
         DistributionManagement distributionManagement = project.getDistributionManagement();
 
         if ( distributionManagement == null )
@@ -121,159 +101,66 @@
 
         Repository repository = new Repository( id, url );
 
-        String siteProtocol = repository.getProtocol();
+        // TODO: work on moving this into the deployer like the other deploy methods
 
-        if ( "scp".equals( siteProtocol ) )
+        Wagon wagon = null;
+        try
         {
-            scpDeploy( zipFile, id, repository );
+            wagon = wagonManager.getWagon( repository.getProtocol() );
         }
-        else if ( "file".equals( siteProtocol ) )
+        catch ( UnsupportedProtocolException e )
         {
-            File toDir = new File( repository.getBasedir() );
-            fileDeploy( toDir );
+            throw new MojoExecutionException( "Unsupported protocol: '" + repository.getProtocol() + "'", e );
         }
-        else
-        {
-            throw new MojoExecutionException(
-                "The deploy mojo currently only supports site deployment using the 'scp' and 'file' protocols." );
-        }
-    }
-
 
-    /**
-     * @throws MojoExecutionException
-     */
-    private void fileDeploy( File toDir )
-        throws MojoExecutionException
-    {
-        try
-        {
-            FileUtils.copyDirectoryStructure( inputDirectory, toDir );
-        }
-        catch ( IOException e )
+        if ( !wagon.supportsDirectoryCopy() )
         {
-            throw new MojoExecutionException( "Error transfering site!", e );
+            throw new MojoExecutionException(
+                "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying" );
         }
-    }
-
-
-    /**
-     * @param zipFile
-     * @param id
-     * @param repository
-     * @throws MojoExecutionException
-     */
-    private void scpDeploy( File zipFile, String id, Repository repository )
-        throws MojoExecutionException
-    {
-        SshCommandExecutor commandExecutor = null;
 
         try
         {
-            commandExecutor = (SshCommandExecutor) wagonManager.getWagon( "scp" );
-
-            commandExecutor.connect( repository, wagonManager.getAuthenticationInfo( id ) );
-
-            String basedir = repository.getBasedir();
-
-            List files = FileUtils.getFileNames( inputDirectory, "**/**", "", false );
-
-            createZip( files, zipFile, inputDirectory );
-
             Debug debug = new Debug();
 
-            commandExecutor.addSessionListener( debug );
-
-            commandExecutor.addTransferListener( debug );
+            wagon.addSessionListener( debug );
 
-            String cmd = " mkdir -p " + basedir;
+            wagon.addTransferListener( debug );
 
-            commandExecutor.executeCommand( cmd );
+            wagon.connect( repository, wagonManager.getAuthenticationInfo( id ) );
 
-            commandExecutor.put( zipFile, zipFile.getName() );
-
-            // TODO: cat to file is temporary until the ssh executor is fixed to deal with output
-            cmd = " cd " + basedir + ";" + unzipCommand + " " + zipFile.getName() + " >scpdeploymojo.log";
-
-            commandExecutor.executeCommand( cmd );
-
-            if ( !basedir.endsWith( "/" ) )
-            {
-                basedir = basedir + "/";
-            }
-
-            commandExecutor.executeCommand( "rm -f " + basedir + zipFile.getName() + " scpdeploymojo.log" );
+            wagon.putDirectory( inputDirectory, "." );
         }
-        catch ( Exception e )
+        catch ( ResourceDoesNotExistException e )
         {
-            throw new MojoExecutionException( "Error transfering site archive!", e );
+            throw new MojoExecutionException( "Error uploading site", e );
         }
-        finally
+        catch ( TransferFailedException e )
         {
-            if ( commandExecutor != null )
-            {
-                try
-                {
-                    commandExecutor.disconnect();
-                }
-                catch ( ConnectionException e )
-                {
-                    //what to to here?
-                }
-            }
-
-            if ( !zipFile.delete() )
-            {
-                zipFile.deleteOnExit();
-            }
+            throw new MojoExecutionException( "Error uploading site", e );
         }
-    }
-
-
-    public void createZip( List files, File zipName, File basedir )
-        throws Exception
-    {
-        ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( zipName ) );
-
-        try
+        catch ( AuthorizationException e )
         {
-            for ( int i = 0; i < files.size(); i++ )
-            {
-                String file = (String) files.get( i );
-
-                writeZipEntry( zos, new File( basedir, file ), file );
-            }
+            throw new MojoExecutionException( "Error uploading site", e );
         }
-        finally
+        catch ( ConnectionException e )
         {
-            zos.close();
+            throw new MojoExecutionException( "Error uploading site", e );
         }
-    }
-
-    private void writeZipEntry( ZipOutputStream jar, File source, String entryName )
-        throws Exception
-    {
-        byte[] buffer = new byte[1024];
-
-        int bytesRead;
-
-        FileInputStream is = new FileInputStream( source );
-
-        try
+        catch ( AuthenticationException e )
         {
-            ZipEntry entry = new ZipEntry( entryName );
-
-            jar.putNextEntry( entry );
-
-            while ( ( bytesRead = is.read( buffer ) ) != -1 )
-            {
-                jar.write( buffer, 0, bytesRead );
-            }
+            throw new MojoExecutionException( "Error uploading site", e );
         }
-
         finally
         {
-            is.close();
+            try
+            {
+                wagon.disconnect();
+            }
+            catch ( ConnectionException e )
+            {
+                getLog().error( "Error disconnecting wagon - ignored", e );
+            }
         }
     }
 }