Index: src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java =================================================================== --- src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java (revision 643471) +++ src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java (working copy) @@ -26,6 +26,7 @@ import org.apache.maven.model.Site; import org.apache.maven.plugin.AbstractMojo; 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; @@ -104,9 +105,6 @@ private PlexusContainer container; - /** Map( String, XmlPlexusConfiguration ) with the repository id and the wagon configuration */ - private Map serverConfigurationMap = new HashMap(); - public void execute() throws MojoExecutionException { @@ -149,7 +147,7 @@ { // @todo Use WagonManager#getWagon(Repository) when available. It's available in Maven 2.0.5. wagon = wagonManager.getWagon( repository.getProtocol() ); - configureWagon( wagon, repository.getId() ); + configureWagon( wagon, repository.getId(), settings, container, getLog() ); } catch ( UnsupportedProtocolException e ) { @@ -300,52 +298,55 @@ * @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 void configureWagon( Wagon wagon, String repositoryId ) + 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 ); - if ( server.getConfiguration() != null ) + String id = server.getId(); + if ( id != null && id.equals( repositoryId ) ) { - final XmlPlexusConfiguration xmlConf = - new XmlPlexusConfiguration( (Xpp3Dom) server.getConfiguration() ); - serverConfigurationMap.put( server.getId(), xmlConf ); - } - } + if ( server.getConfiguration() != null ) + { + final PlexusConfiguration plexusConf = + new XmlPlexusConfiguration( (Xpp3Dom) server.getConfiguration() ); - if ( serverConfigurationMap.containsKey( repositoryId ) ) - { - ComponentConfigurator componentConfigurator = null; - try - { - componentConfigurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE ); - componentConfigurator.configureComponent( wagon, (PlexusConfiguration) serverConfigurationMap - .get( repositoryId ), 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 ) - { + ComponentConfigurator componentConfigurator = null; try { - container.release( componentConfigurator ); + componentConfigurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE ); + componentConfigurator.configureComponent( wagon, plexusConf, container.getContainerRealm() ); } - catch ( ComponentLifecycleException e ) + catch ( final ComponentLookupException e ) { - getLog().error( "Problem releasing configurator - ignoring: " + e.getMessage() ); + 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() ); + } + } + } + } } Index: src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java =================================================================== --- src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java (revision 643471) +++ src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java (working copy) @@ -19,6 +19,7 @@ * under the License. */ +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.MojoFailureException; @@ -33,6 +34,11 @@ 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.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import java.io.File; @@ -46,7 +52,7 @@ * @requiresDependencyResolution test */ public class SiteStageDeployMojo - extends SiteStageMojo + extends SiteStageMojo implements Contextualizable { /** * Staging site URL to deploy the staging directory. @@ -70,6 +76,10 @@ */ private Settings settings; + private PlexusContainer container; + + private final String STAGING_SERVER_ID = "stagingSite"; + /** * @see org.apache.maven.plugin.Mojo#execute() */ @@ -92,18 +102,22 @@ private void deployStagingSite() throws MojoExecutionException, MojoFailureException { - String id = "stagingSite"; - Repository repository = new Repository( id, stagingSiteURL ); + Repository repository = new Repository( STAGING_SERVER_ID, stagingSiteURL ); Wagon wagon; try { wagon = wagonManager.getWagon( repository.getProtocol() ); + SiteDeployMojo.configureWagon( wagon, STAGING_SERVER_ID, 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() ) { @@ -122,11 +136,11 @@ ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager ); if ( proxyInfo != null ) { - wagon.connect( repository, wagonManager.getAuthenticationInfo( id ), proxyInfo ); + wagon.connect( repository, wagonManager.getAuthenticationInfo( STAGING_SERVER_ID ), proxyInfo ); } else { - wagon.connect( repository, wagonManager.getAuthenticationInfo( id ) ); + wagon.connect( repository, wagonManager.getAuthenticationInfo( STAGING_SERVER_ID ) ); } wagon.putDirectory( new File( stagingDirectory, getStructure( project, false ) ), "." ); @@ -163,4 +177,11 @@ } } } + + public void contextualize( Context context ) + throws ContextException + { + container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } + }