You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by lt...@apache.org on 2011/02/04 10:28:53 UTC

svn commit: r1067120 - in /maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site: AbstractDeployMojo.java SiteDeployMojo.java SiteStageDeployMojo.java SiteStageMojo.java wagon/repository/Repository.java

Author: ltheussl
Date: Fri Feb  4 09:28:52 2011
New Revision: 1067120

URL: http://svn.apache.org/viewvc?rev=1067120&view=rev
Log:
refactor: pull out an abstract base class for deploy mojos

Added:
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractDeployMojo.java
Modified:
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageMojo.java
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/wagon/repository/Repository.java

Added: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractDeployMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractDeployMojo.java?rev=1067120&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractDeployMojo.java (added)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractDeployMojo.java Fri Feb  4 09:28:52 2011
@@ -0,0 +1,500 @@
+package org.apache.maven.plugins.site;
+
+/*
+ * 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.List;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.apache.maven.artifact.manager.WagonConfigurationException;
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.wagon.CommandExecutionException;
+import org.apache.maven.wagon.CommandExecutor;
+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.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+/**
+ * Abstract base class for deploy mojos.
+ * Since 2.3 this includes {@link SiteStageMojo} and {@link SiteStageDeployMojo}.
+ *
+ * @author ltheussl
+ *
+ * @since 2.3
+ */
+public abstract class AbstractDeployMojo
+    extends AbstractSiteMojo implements Contextualizable
+{
+    /**
+     * Directory containing the generated project sites and report distributions.
+     *
+     * @parameter alias="outputDirectory" expression="${project.reporting.outputDirectory}"
+     * @required
+     */
+    private File inputDirectory;
+
+    /**
+     * Whether to run the "chmod" command on the remote site after the deploy.
+     * Defaults to "true".
+     *
+     * @parameter expression="${maven.site.chmod}" default-value="true"
+     * @since 2.1
+     */
+    private boolean chmod;
+
+    /**
+     * The mode used by the "chmod" command. Only used if chmod = true.
+     * Defaults to "g+w,a+rX".
+     *
+     * @parameter expression="${maven.site.chmod.mode}" default-value="g+w,a+rX"
+     * @since 2.1
+     */
+    private String chmodMode;
+
+    /**
+     * The options used by the "chmod" command. Only used if chmod = true.
+     * Defaults to "-Rf".
+     *
+     * @parameter expression="${maven.site.chmod.options}" default-value="-Rf"
+     * @since 2.1
+     */
+    private String chmodOptions;
+
+    /**
+     * @component
+     */
+    private WagonManager wagonManager;
+
+    /**
+     * The current user system settings for use in Maven.
+     *
+     * @parameter expression="${settings}"
+     * @required
+     * @readonly
+     */
+    private Settings settings;
+
+    private PlexusContainer container;
+
+    /** {@inheritDoc} */
+    public void execute()
+        throws MojoExecutionException
+    {
+        deployTo( new org.apache.maven.plugins.site.wagon.repository.Repository(
+            getDeployRepositoryID(), getDeployRepositoryURL() ) );
+    }
+
+    /**
+     * Specifies the id to look up credential settings.
+     *
+     * @return the id to look up credentials for the deploy. Not null.
+     *
+     * @throws MojoExecutionException
+     */
+    protected abstract String getDeployRepositoryID()
+        throws MojoExecutionException;
+
+    /**
+     * Specifies the target URL for the deploy.
+     *
+     * @return the url to deploy to. Not null.
+     *
+     * @throws MojoExecutionException
+     */
+    protected abstract String getDeployRepositoryURL()
+        throws MojoExecutionException;
+
+    /**
+     * Use wagon to deploy the generated site to a given repository.
+     *
+     * @param repository the repository to deply to.
+     *      This needs to contain a valid, non-null {@link Repository#getId() id}
+     *      to look up credentials for the deploy, and a valid, non-null
+     *      {@link Repository#getUrl() scm url} to deploy to.
+     *
+     * @throws MojoExecutionException if the deploy fails.
+     */
+    private void deployTo( final Repository repository )
+        throws MojoExecutionException
+    {
+        if ( !inputDirectory.exists() )
+        {
+            throw new MojoExecutionException( "The site does not exist, please run site:site first" );
+        }
+
+        if ( getLog().isDebugEnabled() )
+        {
+            getLog().debug( "Deploying to '" + repository.getUrl()
+                + "',\n    Using credentials from server id '" + repository.getId() + "'" );
+        }
+
+        // TODO: deploy to top level site? is it safe to assume that modules deploy to the same site?
+        //Site topLevelSite = getSite( getTopLevelProject( reactorProjects ) );
+
+        deploy( inputDirectory, repository );
+    }
+
+    private void deploy( final File inputDirectory, final Repository repository )
+        throws MojoExecutionException
+    {
+        // TODO: work on moving this into the deployer like the other deploy methods
+        final Wagon wagon = getWagon( repository, wagonManager );
+
+        try
+        {
+            configureWagon( wagon, repository.getId(), settings, container, getLog() );
+        }
+        catch ( WagonConfigurationException e )
+        {
+            throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e );
+        }
+
+        try
+        {
+            push( inputDirectory, repository, wagonManager, wagon );
+
+            if ( chmod )
+            {
+                chmod( wagon, repository, chmodOptions, chmodMode );
+            }
+        }
+        finally
+        {
+            try
+            {
+                wagon.disconnect();
+            }
+            catch ( ConnectionException e )
+            {
+                getLog().error( "Error disconnecting wagon - ignored", e );
+            }
+        }
+    }
+
+    /**
+     * Find the build directory of the top level project in the reactor.
+     * If no top level project is found, the build directory of the current project is returned.
+     *
+     * @return the build directory of the top level project.
+     */
+    protected File getTopLevelBuildDirectory()
+    {
+        // Find the top level project in the reactor
+        final MavenProject topLevelProject = getTopLevelProject( reactorProjects );
+
+        // Use the top level project's build directory if there is one, otherwise use this project's build directory
+        final File buildDirectory;
+
+        if ( topLevelProject == null )
+        {
+            getLog().debug( "No top level project found in the reactor, using the current project." );
+
+            buildDirectory = new File( project.getBuild().getDirectory() );
+        }
+        else
+        {
+            getLog().debug( "Using the top level project found in the reactor." );
+
+            buildDirectory = new File( topLevelProject.getBuild().getDirectory() );
+        }
+
+        return buildDirectory;
+    }
+
+    private static Wagon getWagon( final Repository repository, final WagonManager manager )
+        throws MojoExecutionException
+    {
+        final Wagon wagon;
+
+        try
+        {
+            wagon = manager.getWagon( repository );
+        }
+        catch ( UnsupportedProtocolException e )
+        {
+            throw new MojoExecutionException( "Unsupported protocol: '" + repository.getProtocol() + "'", e );
+        }
+        catch ( WagonConfigurationException e )
+        {
+            throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e );
+        }
+
+        if ( !wagon.supportsDirectoryCopy() )
+        {
+            throw new MojoExecutionException(
+                "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying" );
+        }
+
+        return wagon;
+    }
+
+    private static void push( final File inputDirectory, final Repository repository,
+        final WagonManager manager, final Wagon wagon )
+        throws MojoExecutionException
+    {
+        try
+        {
+            Debug debug = new Debug();
+
+            wagon.addSessionListener( debug );
+
+            wagon.addTransferListener( debug );
+
+            ProxyInfo proxyInfo = getProxyInfo( repository, manager );
+
+            if ( proxyInfo == null )
+            {
+                wagon.connect( repository, manager.getAuthenticationInfo( repository.getId() ) );
+            }
+            else
+            {
+                wagon.connect( repository, manager.getAuthenticationInfo( repository.getId() ), proxyInfo );
+            }
+
+            wagon.putDirectory( inputDirectory, "." );
+        }
+        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 );
+        }
+    }
+
+    private static void chmod( final Wagon wagon, final Repository repository,
+        final String chmodOptions, final String chmodMode )
+        throws MojoExecutionException
+    {
+        try
+        {
+            if ( wagon instanceof CommandExecutor )
+            {
+                CommandExecutor exec = (CommandExecutor) wagon;
+                exec.executeCommand( "chmod " + chmodOptions + " " + chmodMode + " " + repository.getBasedir() );
+            }
+            // else ? silently ignore, FileWagon is not a CommandExecutor!
+        }
+        catch ( CommandExecutionException e )
+        {
+            throw new MojoExecutionException( "Error uploading site", e );
+        }
+    }
+
+    /**
+     * <p>
+     * Get the <code>ProxyInfo</code> of the proxy associated with the <code>host</code>
+     * and the <code>protocol</code> of the given <code>repository</code>.
+     * </p>
+     * <p>
+     * Extract from <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html">
+     * J2SE Doc : Networking Properties - nonProxyHosts</a> : "The value can be a list of hosts,
+     * each separated by a |, and in addition a wildcard character (*) can be used for matching"
+     * </p>
+     * <p>
+     * Defensively support for comma (",") and semi colon (";") in addition to pipe ("|") as separator.
+     * </p>
+     *
+     * @param repository the Repository to extract the ProxyInfo from.
+     * @param wagonManager the WagonManager used to connect to the Repository.
+     * @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found
+     */
+    public static ProxyInfo getProxyInfo( Repository repository, WagonManager wagonManager )
+    {
+        ProxyInfo proxyInfo = wagonManager.getProxy( repository.getProtocol() );
+
+        if ( proxyInfo == null )
+        {
+            return null;
+        }
+
+        String host = repository.getHost();
+        String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
+        String[] nonProxyHosts = StringUtils.split( nonProxyHostsAsString, ",;|" );
+        for ( int i = 0; i < nonProxyHosts.length; i++ )
+        {
+            String nonProxyHost = nonProxyHosts[i];
+            if ( StringUtils.contains( nonProxyHost, "*" ) )
+            {
+                // Handle wildcard at the end, beginning or middle of the nonProxyHost
+                String nonProxyHostPrefix = StringUtils.substringBefore( nonProxyHost, "*" );
+                String nonProxyHostSuffix = StringUtils.substringAfter( nonProxyHost, "*" );
+                // prefix*
+                if ( StringUtils.isNotEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix )
+                    && StringUtils.isEmpty( nonProxyHostSuffix ) )
+                {
+                    return null;
+                }
+                // *suffix
+                if ( StringUtils.isEmpty( nonProxyHostPrefix )
+                    && StringUtils.isNotEmpty( nonProxyHostSuffix ) && host.endsWith( nonProxyHostSuffix ) )
+                {
+                    return null;
+                }
+                // prefix*suffix
+                if ( StringUtils.isNotEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix )
+                    && StringUtils.isNotEmpty( nonProxyHostSuffix ) && host.endsWith( nonProxyHostSuffix ) )
+                {
+                    return null;
+                }
+            }
+            else if ( host.equals( nonProxyHost ) )
+            {
+                return null;
+            }
+        }
+        return proxyInfo;
+    }
+
+    /**
+     * Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml )
+     *
+     * @todo Remove when {@link WagonManager#getWagon(Repository) is available}. It's available in Maven 2.0.5.
+     * @param wagon
+     * @param repositoryId
+     * @param settings
+     * @param container
+     * @param log
+     * @throws WagonConfigurationException
+     */
+    private static void configureWagon( Wagon wagon, String repositoryId, Settings settings, PlexusContainer container,
+        Log log )
+        throws WagonConfigurationException
+    {
+        // MSITE-25: Make sure that the server settings are inserted
+        for ( int i = 0; i < settings.getServers().size(); i++ )
+        {
+            Server server = (Server) settings.getServers().get( i );
+            String id = server.getId();
+            if ( id != null && id.equals( repositoryId ) )
+            {
+                if ( server.getConfiguration() != null )
+                {
+                    final PlexusConfiguration plexusConf =
+                        new XmlPlexusConfiguration( (Xpp3Dom) server.getConfiguration() );
+
+                    ComponentConfigurator componentConfigurator = null;
+                    try
+                    {
+                        componentConfigurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE );
+                        componentConfigurator.configureComponent( wagon, plexusConf, container.getContainerRealm() );
+                    }
+                    catch ( final ComponentLookupException e )
+                    {
+                        throw new WagonConfigurationException( repositoryId, "Unable to lookup wagon configurator."
+                            + " Wagon configuration cannot be applied.", e );
+                    }
+                    catch ( ComponentConfigurationException e )
+                    {
+                        throw new WagonConfigurationException( repositoryId, "Unable to apply wagon configuration.",
+                            e );
+                    }
+                    finally
+                    {
+                        if ( componentConfigurator != null )
+                        {
+                            try
+                            {
+                                container.release( componentConfigurator );
+                            }
+                            catch ( ComponentLifecycleException e )
+                            {
+                                log.error( "Problem releasing configurator - ignoring: " + e.getMessage() );
+                            }
+                        }
+                    }
+
+                }
+
+            }
+        }
+    }
+
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+
+    /**
+     * Find the top level parent in the reactor, i.e. the execution root.
+     *
+     * @param reactorProjects The projects in the reactor. May be null in which case null is returnned.
+     *
+     * @return The top level project in the reactor, or <code>null</code> if none can be found
+     */
+    protected static MavenProject getTopLevelProject( List<MavenProject> reactorProjects )
+    {
+        if ( reactorProjects == null )
+        {
+            return null;
+        }
+
+        for ( MavenProject reactorProject : reactorProjects )
+        {
+            if ( reactorProject.isExecutionRoot() )
+            {
+                return reactorProject;
+            }
+        }
+
+        return null;
+    }
+}

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java?rev=1067120&r1=1067119&r2=1067120&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java (original)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java Fri Feb  4 09:28:52 2011
@@ -19,46 +19,10 @@ package org.apache.maven.plugins.site;
  * under the License.
  */
 
-import java.io.File;
-import java.util.List;
-
-import org.apache.commons.lang.StringUtils;
-
-import org.apache.maven.artifact.manager.WagonConfigurationException;
-import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.model.DistributionManagement;
 import org.apache.maven.model.Site;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.settings.Server;
-import org.apache.maven.settings.Settings;
-import org.apache.maven.wagon.CommandExecutionException;
-import org.apache.maven.wagon.CommandExecutor;
-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.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
-import org.codehaus.plexus.component.configurator.ComponentConfigurator;
-import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.configuration.PlexusConfiguration;
-import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
-
 
 /**
  * Deploys the generated site using <code>scp</code> or <code>file</code>
@@ -77,343 +41,36 @@ import org.codehaus.plexus.util.xml.Xpp3
  * @goal deploy
  */
 public class SiteDeployMojo
-    extends AbstractSiteMojo implements Contextualizable
+    extends AbstractDeployMojo
 {
-    /**
-     * Directory containing the generated project sites and report distributions.
-     *
-     * @parameter alias="outputDirectory" expression="${project.reporting.outputDirectory}"
-     * @required
-     */
-    private File inputDirectory;
-
-    /**
-     * Whether to run the "chmod" command on the remote site after the deploy.
-     * Defaults to "true".
-     *
-     * @parameter expression="${maven.site.chmod}" default-value="true"
-     * @since 2.1
-     */
-    private boolean chmod;
-
-    /**
-     * The mode used by the "chmod" command. Only used if chmod = true.
-     * Defaults to "g+w,a+rX".
-     *
-     * @parameter expression="${maven.site.chmod.mode}" default-value="g+w,a+rX"
-     * @since 2.1
-     */
-    private String chmodMode;
-
-    /**
-     * The options used by the "chmod" command. Only used if chmod = true.
-     * Defaults to "-Rf".
-     *
-     * @parameter expression="${maven.site.chmod.options}" default-value="-Rf"
-     * @since 2.1
-     */
-    private String chmodOptions;
-
-    /**
-     * @component
-     */
-    private WagonManager wagonManager;
-
-    /**
-     * The current user system settings for use in Maven.
-     *
-     * @parameter expression="${settings}"
-     * @required
-     * @readonly
-     */
-    private Settings settings;
+    private Site site;
 
-    private PlexusContainer container;
-
-    /** {@inheritDoc} */
-    public void execute()
+    @Override
+    public String getDeployRepositoryID()
         throws MojoExecutionException
     {
-        final Site site = getSite( project );
-
-        if ( getLog().isDebugEnabled() )
-        {
-            getLog().debug( "The site will be deployed to '" + site.getUrl() + "'");
-            getLog().debug( "Using credentials from repository '" + site.getId() + "'" );
-        }
-
-        deployTo( site.getId(), site.getUrl() );
-    }
-
-    /**
-     * Use wagon to deploy the generated site to a given repository.
-     *
-     * @param id the id that is used to look up credentials for the deploy. Not null.
-     * @param url a valid scm url to deploy to. Not null.
-     *
-     * @throws MojoExecutionException if the deploy fails.
-     *
-     * @since 2.3
-     */
-    protected void deployTo( final String id, final String url )
-            throws MojoExecutionException
-    {
-        if ( !inputDirectory.exists() )
-        {
-            throw new MojoExecutionException( "The site does not exist, please run site:site first" );
-        }
-
-        Repository repository = new Repository( id, url );
-        // TODO: work on moving this into the deployer like the other deploy methods
-
-        Wagon wagon;
-
-        try
-        {
-            wagon = wagonManager.getWagon( repository );
-            configureWagon( wagon, repository.getId(), settings, container, getLog() );
-        }
-        catch ( UnsupportedProtocolException e )
-        {
-            throw new MojoExecutionException( "Unsupported protocol: '" + repository.getProtocol() + "'", e );
-        }
-        catch ( WagonConfigurationException e )
-        {
-            throw new MojoExecutionException( "Unable to configure Wagon: '" + 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 = getProxyInfo( repository, wagonManager );
-            if ( proxyInfo != null )
-            {
-                wagon.connect( repository, wagonManager.getAuthenticationInfo( id ), proxyInfo );
-            }
-            else
-            {
-                wagon.connect( repository, wagonManager.getAuthenticationInfo( id ) );
-            }
-
-            wagon.putDirectory( inputDirectory, "." );
-
-            if ( chmod && wagon instanceof CommandExecutor )
-            {
-                CommandExecutor exec = (CommandExecutor) wagon;
-                exec.executeCommand( "chmod " + chmodOptions + " " + chmodMode + " " + repository.getBasedir() );
-            }
-        }
-        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 );
-        }
-        catch ( CommandExecutionException e )
-        {
-            throw new MojoExecutionException( "Error uploading site", e );
-        }
-        finally
-        {
-            try
-            {
-                wagon.disconnect();
-            }
-            catch ( ConnectionException e )
-            {
-                getLog().error( "Error disconnecting wagon - ignored", e );
-            }
-        }
-    }
-
-    /**
-     * <p>
-     * Get the <code>ProxyInfo</code> of the proxy associated with the <code>host</code>
-     * and the <code>protocol</code> of the given <code>repository</code>.
-     * </p>
-     * <p>
-     * Extract from <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html">
-     * J2SE Doc : Networking Properties - nonProxyHosts</a> : "The value can be a list of hosts,
-     * each separated by a |, and in addition a wildcard character (*) can be used for matching"
-     * </p>
-     * <p>
-     * Defensively support for comma (",") and semi colon (";") in addition to pipe ("|") as separator.
-     * </p>
-     *
-     * @param repository the Repository to extract the ProxyInfo from.
-     * @param wagonManager the WagonManager used to connect to the Repository.
-     * @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found
-     */
-    public static ProxyInfo getProxyInfo( Repository repository, WagonManager wagonManager )
-    {
-        ProxyInfo proxyInfo = wagonManager.getProxy( repository.getProtocol() );
-
-        if ( proxyInfo == null )
-        {
-            return null;
-        }
-
-        String host = repository.getHost();
-        String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
-        String[] nonProxyHosts = StringUtils.split( nonProxyHostsAsString, ",;|" );
-        for ( int i = 0; i < nonProxyHosts.length; i++ )
+        if ( site == null )
         {
-            String nonProxyHost = nonProxyHosts[i];
-            if ( StringUtils.contains( nonProxyHost, "*" ) )
-            {
-                // Handle wildcard at the end, beginning or middle of the nonProxyHost
-                String nonProxyHostPrefix = StringUtils.substringBefore( nonProxyHost, "*" );
-                String nonProxyHostSuffix = StringUtils.substringAfter( nonProxyHost, "*" );
-                // prefix*
-                if ( StringUtils.isNotEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix )
-                    && StringUtils.isEmpty( nonProxyHostSuffix ) )
-                {
-                    return null;
-                }
-                // *suffix
-                if ( StringUtils.isEmpty( nonProxyHostPrefix )
-                    && StringUtils.isNotEmpty( nonProxyHostSuffix ) && host.endsWith( nonProxyHostSuffix ) )
-                {
-                    return null;
-                }
-                // prefix*suffix
-                if ( StringUtils.isNotEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix )
-                    && StringUtils.isNotEmpty( nonProxyHostSuffix ) && host.endsWith( nonProxyHostSuffix ) )
-                {
-                    return null;
-                }
-            }
-            else if ( host.equals( nonProxyHost ) )
-            {
-                return null;
-            }
+            site = getSite( project );
         }
-        return proxyInfo;
-    }
 
-    /**
-     * Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml )
-     *
-     * @todo Remove when {@link WagonManager#getWagon(Repository) is available}. It's available in Maven 2.0.5.
-     * @param wagon
-     * @param repositoryId
-     * @param settings
-     * @param container
-     * @param log
-     * @throws WagonConfigurationException
-     */
-    static void configureWagon( Wagon wagon, String repositoryId, Settings settings, PlexusContainer container,
-                                Log log )
-        throws WagonConfigurationException
-    {
-        // MSITE-25: Make sure that the server settings are inserted
-        for ( int i = 0; i < settings.getServers().size(); i++ )
-        {
-            Server server = (Server) settings.getServers().get( i );
-            String id = server.getId();
-            if ( id != null && id.equals( repositoryId ) )
-            {
-                if ( server.getConfiguration() != null )
-                {
-                    final PlexusConfiguration plexusConf =
-                        new XmlPlexusConfiguration( (Xpp3Dom) server.getConfiguration() );
-
-                    ComponentConfigurator componentConfigurator = null;
-                    try
-                    {
-                        componentConfigurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE );
-                        componentConfigurator.configureComponent( wagon, plexusConf, container.getContainerRealm() );
-                    }
-                    catch ( final ComponentLookupException e )
-                    {
-                        throw new WagonConfigurationException( repositoryId, "Unable to lookup wagon configurator."
-                            + " Wagon configuration cannot be applied.", e );
-                    }
-                    catch ( ComponentConfigurationException e )
-                    {
-                        throw new WagonConfigurationException( repositoryId, "Unable to apply wagon configuration.",
-                                                               e );
-                    }
-                    finally
-                    {
-                        if ( componentConfigurator != null )
-                        {
-                            try
-                            {
-                                container.release( componentConfigurator );
-                            }
-                            catch ( ComponentLifecycleException e )
-                            {
-                                log.error( "Problem releasing configurator - ignoring: " + e.getMessage() );
-                            }
-                        }
-                    }
-
-                }
-
-            }
-        }
+        return site.getId();
     }
 
-    public void contextualize( Context context )
-        throws ContextException
-    {
-        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
-    }
-
-    /**
-     * Find the top level parent in the reactor, i.e. the execution root.
-     *
-     * @param reactorProjects The projects in the reactor. May be null in which case null is returnned.
-     * @return The top level project in the reactor, or <code>null</code> if none can be found
-     *
-     * @since 2.3
-     */
-    protected static MavenProject getTopLevelProject( List<MavenProject> reactorProjects )
+    @Override
+    public String getDeployRepositoryURL()
+        throws MojoExecutionException
     {
-        if ( reactorProjects == null )
-        {
-            return null;
-        }
-
-        for ( MavenProject reactorProject : reactorProjects )
+        if ( site == null )
         {
-            if ( reactorProject.isExecutionRoot() )
-            {
-                return reactorProject;
-            }
+            site = getSite( project );
         }
 
-        return null;
+        return site.getUrl();
     }
 
     private static Site getSite( final MavenProject project )
-            throws MojoExecutionException
+        throws MojoExecutionException
     {
         final DistributionManagement distributionManagement = project.getDistributionManagement();
 

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java?rev=1067120&r1=1067119&r2=1067120&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java (original)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java Fri Feb  4 09:28:52 2011
@@ -22,7 +22,6 @@ package org.apache.maven.plugins.site;
 import java.util.List;
 
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 
 /**
@@ -37,7 +36,7 @@ import org.apache.maven.project.MavenPro
  * @requiresDependencyResolution test
  */
 public class SiteStageDeployMojo
-    extends SiteStageMojo
+    extends AbstractDeployMojo
 {
     /**
      * The staged site will be deployed to this URL.
@@ -67,31 +66,25 @@ public class SiteStageDeployMojo
      */
     private String stagingRepositoryId;
 
-    /**
-     * {@inheritDoc}
-     */
+    private static final String DEFAULT_STAGING_DIRECTORY = "staging";
+
+
     @Override
-    public void execute()
+    protected String getDeployRepositoryID()
         throws MojoExecutionException
     {
-        deployStagingSite();
+        return stagingRepositoryId;
     }
 
-    /**
-     * 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()
+    @Override
+    protected String getDeployRepositoryURL()
         throws MojoExecutionException
     {
         stagingSiteURL = getStagingSiteURL( project, reactorProjects, stagingSiteURL );
+
         getLog().info( "Using this URL for stage deploy: " + stagingSiteURL );
 
-        deployTo( stagingRepositoryId, stagingSiteURL );
+        return stagingSiteURL;
     }
 
     /**
@@ -102,7 +95,7 @@ public class SiteStageDeployMojo
      * @param usersStagingSiteURL The staging site URL as suggested by the user's configuration
      * @return the site URL for staging
      */
-    protected String getStagingSiteURL( MavenProject currentProject, List<MavenProject> reactorProjects,
+    private String getStagingSiteURL( MavenProject currentProject, List<MavenProject> reactorProjects,
                                         String usersStagingSiteURL )
     {
         String topLevelURL = null;

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageMojo.java?rev=1067120&r1=1067119&r2=1067120&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 Fri Feb  4 09:28:52 2011
@@ -46,7 +46,7 @@ import org.codehaus.plexus.util.StringUt
  * @requiresDependencyResolution test
  */
 public class SiteStageMojo
-    extends SiteDeployMojo
+    extends AbstractDeployMojo
 {
     protected static final String DEFAULT_STAGING_DIRECTORY = "staging";
 
@@ -57,13 +57,17 @@ public class SiteStageMojo
      *
      * @parameter expression="${stagingDirectory}"
      */
-    protected File stagingDirectory;
+    private File stagingDirectory;
+
+    @Override
+    protected String getDeployRepositoryID()
+        throws MojoExecutionException
+    {
+        return "stagingLocal";
+    }
 
-    /**
-     * @see org.apache.maven.plugin.Mojo#execute()
-     */
     @Override
-    public void execute()
+    protected String getDeployRepositoryURL()
         throws MojoExecutionException
     {
         String structureProject;
@@ -93,10 +97,7 @@ public class SiteStageMojo
             outputDirectory.mkdirs();
         }
 
-        final String url = "file://" + outputDirectory.getAbsolutePath();
-        final String id = "stagingLocal";
-
-        deployTo( id, url );
+        return "file://" + outputDirectory.getAbsolutePath();
     }
 
     /**
@@ -107,7 +108,7 @@ public class SiteStageMojo
      * @param usersStagingDirectory The staging directory as suggested by the user's configuration
      * @return the directory for staging
      */
-    protected File getStagingDirectory( MavenProject currentProject, List<MavenProject> reactorProjects,
+    private File getStagingDirectory( MavenProject currentProject, List<MavenProject> reactorProjects,
                                         File usersStagingDirectory )
     {
         // Check if the user has specified a stagingDirectory
@@ -118,23 +119,7 @@ public class SiteStageMojo
         }
         getLog().debug( "stagingDirectory NOT specified by the user." );
 
-        // Find the top level project in the reactor
-        MavenProject topLevelProject = getTopLevelProject( reactorProjects );
-
-        // Use the top level project's build directory if there is one, otherwise use this project's build directory
-        File buildDirectory;
-        if ( topLevelProject == null )
-        {
-            getLog().debug( "No top level project found in the reactor, using the current project." );
-            buildDirectory = new File( currentProject.getBuild().getDirectory() );
-        }
-        else
-        {
-            getLog().debug( "Using the top level project found in the reactor." );
-            buildDirectory = new File( topLevelProject.getBuild().getDirectory() );
-        }
-
-        return new File( buildDirectory, DEFAULT_STAGING_DIRECTORY );
+        return new File( getTopLevelBuildDirectory(), DEFAULT_STAGING_DIRECTORY );
     }
 
     /**
@@ -146,7 +131,7 @@ public class SiteStageMojo
      * @return the structure relative path
      * @throws MojoFailureException if any
      */
-    protected static String getStructure( MavenProject project, boolean ignoreMissingSiteUrl )
+    private static String getStructure( MavenProject project, boolean ignoreMissingSiteUrl )
         throws MojoFailureException
     {
         if ( project.getDistributionManagement() == null )

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/wagon/repository/Repository.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/wagon/repository/Repository.java?rev=1067120&r1=1067119&r2=1067120&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/wagon/repository/Repository.java (original)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/wagon/repository/Repository.java Fri Feb  4 09:28:52 2011
@@ -24,7 +24,6 @@ import org.apache.maven.wagon.WagonConst
 import org.apache.maven.wagon.repository.RepositoryPermissions;
 import org.codehaus.plexus.util.StringUtils;
 
-import java.io.Serializable;
 import java.util.Properties;
 
 /**
@@ -39,7 +38,7 @@ import java.util.Properties;
  * @todo [BP] some things are specific to certain wagons (eg key stuff in authInfo, permissions)
  */
 public class Repository
-    implements Serializable
+    extends org.apache.maven.wagon.repository.Repository
 {
     private static final long serialVersionUID = 1312227676322136247L;