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 2006/05/10 15:02:36 UTC

svn commit: r405746 - in /maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site: SiteStageDeployMojo.java SiteStageMojo.java

Author: brett
Date: Wed May 10 06:02:26 2006
New Revision: 405746

URL: http://svn.apache.org/viewcvs?rev=405746&view=rev
Log:
[MSITE-115] split into stage and stage-deploy to make deployment optional

Added:
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java   (with props)
Modified:
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageMojo.java

Added: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java?rev=405746&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java (added)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java Wed May 10 06:02:26 2006
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+package org.apache.maven.plugins.site;
+
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.settings.Settings;
+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.authentication.AuthenticationException;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+import org.apache.maven.wagon.observers.Debug;
+import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.repository.Repository;
+
+import java.io.File;
+
+/**
+ * Deploy a staging site in specific directory.
+ * <p>Useful to test the generated site.</p>
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @goal stage-deploy
+ * @requiresDependencyResolution test
+ */
+public class SiteStageDeployMojo
+    extends SiteStageMojo
+{
+    /**
+     * Staging site URL to deploy the staging directory.
+     *
+     * @parameter expression="${stagingSiteURL}" default-value="${project.distributionManagement.site.url}/staging"
+     * @see <a href="http://maven.apache.org/maven-model/maven.html#class_site">MavenModel#class_site</a>
+     */
+    private String stagingSiteURL;
+
+    /**
+     * @component
+     */
+    private WagonManager wagonManager;
+
+    /**
+     * The current user system settings for use in Maven.
+     *
+     * @parameter expression="${settings}"
+     * @required
+     * @readonly
+     */
+    private Settings settings;
+
+    /**
+     * @see org.apache.maven.plugin.Mojo#execute()
+     */
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        super.execute();
+
+        deployStagingSite();
+    }
+
+    /**
+     * Deploy the staging directory using the stagingSiteURL.
+     *
+     * @throws org.apache.maven.plugin.MojoExecutionException
+     *          if any
+     * @throws org.apache.maven.plugin.MojoFailureException
+     *          if any
+     */
+    private void deployStagingSite()
+        throws MojoExecutionException, MojoFailureException
+    {
+        String id = "stagingSite";
+        Repository repository = new Repository( id, stagingSiteURL );
+
+        Wagon wagon;
+        try
+        {
+            wagon = wagonManager.getWagon( repository.getProtocol() );
+        }
+        catch ( UnsupportedProtocolException e )
+        {
+            throw new MojoExecutionException( "Unsupported protocol: '" + repository.getProtocol() + "'", e );
+        }
+
+        if ( !wagon.supportsDirectoryCopy() )
+        {
+            throw new MojoExecutionException(
+                "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying" );
+        }
+
+        try
+        {
+            Debug debug = new Debug();
+
+            wagon.addSessionListener( debug );
+
+            wagon.addTransferListener( debug );
+
+            ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( settings );
+            if ( proxyInfo != null )
+            {
+                wagon.connect( repository, wagonManager.getAuthenticationInfo( id ), proxyInfo );
+            }
+            else
+            {
+                wagon.connect( repository, wagonManager.getAuthenticationInfo( id ) );
+            }
+
+            wagon.putDirectory( new File( stagingDirectory, getStructure( project, false ) ), "." );
+        }
+        catch ( ResourceDoesNotExistException e )
+        {
+            throw new MojoExecutionException( "Error uploading site", e );
+        }
+        catch ( TransferFailedException e )
+        {
+            throw new MojoExecutionException( "Error uploading site", e );
+        }
+        catch ( AuthorizationException e )
+        {
+            throw new MojoExecutionException( "Error uploading site", e );
+        }
+        catch ( ConnectionException e )
+        {
+            throw new MojoExecutionException( "Error uploading site", e );
+        }
+        catch ( AuthenticationException e )
+        {
+            throw new MojoExecutionException( "Error uploading site", e );
+        }
+        finally
+        {
+            try
+            {
+                wagon.disconnect();
+            }
+            catch ( ConnectionException e )
+            {
+                getLog().error( "Error disconnecting wagon - ignored", e );
+            }
+        }
+    }
+}

Propchange: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageMojo.java?rev=405746&r1=405745&r2=405746&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageMojo.java (original)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageMojo.java Wed May 10 06:02:26 2006
@@ -16,21 +16,10 @@
  * limitations under the License.
  */
 
-import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.model.Site;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.settings.Settings;
-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.authentication.AuthenticationException;
-import org.apache.maven.wagon.authorization.AuthorizationException;
-import org.apache.maven.wagon.observers.Debug;
-import org.apache.maven.wagon.proxy.ProxyInfo;
 import org.apache.maven.wagon.repository.Repository;
 import org.codehaus.plexus.util.PathTool;
 import org.codehaus.plexus.util.StringUtils;
@@ -56,29 +45,7 @@
      * @parameter expression="${stagingDirectory}" default-value="${project.build.directory}/staging"
      * @required
      */
-    private File stagingDirectory;
-
-    /**
-     * Staging site URL to deploy the staging directory.
-     *
-     * @parameter expression="${stagingSiteURL}" default-value="${project.distributionManagement.site.url}/staging"
-     * @see <a href="http://maven.apache.org/maven-model/maven.html#class_site">MavenModel#class_site</a>
-     */
-    private String stagingSiteURL;
-
-    /**
-     * @component
-     */
-    private WagonManager wagonManager;
-
-    /**
-     * The current user system settings for use in Maven.
-     *
-     * @parameter expression="${settings}"
-     * @required
-     * @readonly
-     */
-    private Settings settings;
+    protected File stagingDirectory;
 
     /**
      * @see org.apache.maven.plugin.Mojo#execute()
@@ -133,11 +100,6 @@
         }
 
         super.execute();
-
-        if ( !StringUtils.isEmpty( stagingSiteURL ) )
-        {
-            deployStagingSite();
-        }
     }
 
     /**
@@ -149,7 +111,7 @@
      * @return the structure relative path
      * @throws MojoFailureException if any
      */
-    private static String getStructure( MavenProject project, boolean ignoreMissingSiteUrl )
+    protected static String getStructure( MavenProject project, boolean ignoreMissingSiteUrl )
         throws MojoFailureException
     {
         if ( project.getDistributionManagement() == null )
@@ -201,86 +163,5 @@
         }
 
         return repository.getHost() + "/" + repository.getBasedir();
-    }
-
-    /**
-     * Deploy the staging directory using the stagingSiteURL.
-     *
-     * @throws MojoExecutionException if any
-     * @throws MojoFailureException   if any
-     */
-    private void deployStagingSite()
-        throws MojoExecutionException, MojoFailureException
-    {
-        String id = "stagingSite";
-        Repository repository = new Repository( id, stagingSiteURL );
-
-        Wagon wagon;
-        try
-        {
-            wagon = wagonManager.getWagon( repository.getProtocol() );
-        }
-        catch ( UnsupportedProtocolException e )
-        {
-            throw new MojoExecutionException( "Unsupported protocol: '" + repository.getProtocol() + "'", e );
-        }
-
-        if ( !wagon.supportsDirectoryCopy() )
-        {
-            throw new MojoExecutionException(
-                "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying" );
-        }
-
-        try
-        {
-            Debug debug = new Debug();
-
-            wagon.addSessionListener( debug );
-
-            wagon.addTransferListener( debug );
-
-            ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( settings );
-            if ( proxyInfo != null )
-            {
-                wagon.connect( repository, wagonManager.getAuthenticationInfo( id ), proxyInfo );
-            }
-            else
-            {
-                wagon.connect( repository, wagonManager.getAuthenticationInfo( id ) );
-            }
-
-            wagon.putDirectory( new File( stagingDirectory, getStructure( project, false ) ), "." );
-        }
-        catch ( ResourceDoesNotExistException e )
-        {
-            throw new MojoExecutionException( "Error uploading site", e );
-        }
-        catch ( TransferFailedException e )
-        {
-            throw new MojoExecutionException( "Error uploading site", e );
-        }
-        catch ( AuthorizationException e )
-        {
-            throw new MojoExecutionException( "Error uploading site", e );
-        }
-        catch ( ConnectionException e )
-        {
-            throw new MojoExecutionException( "Error uploading site", e );
-        }
-        catch ( AuthenticationException e )
-        {
-            throw new MojoExecutionException( "Error uploading site", e );
-        }
-        finally
-        {
-            try
-            {
-                wagon.disconnect();
-            }
-            catch ( ConnectionException e )
-            {
-                getLog().error( "Error disconnecting wagon - ignored", e );
-            }
-        }
     }
 }