Author: ltheussl Date: Tue Jan 4 14:12:55 2011 New Revision: 1055047 URL: http://svn.apache.org/viewvc?rev=1055047&view=rev Log: [MSITE-533] make site:stage a local file deploy
Modified: maven/plugins/trunk/maven-site-plugin/src/it/MSITE-304/goals.txt 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 Modified: maven/plugins/trunk/maven-site-plugin/src/it/MSITE-304/goals.txt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/it/MSITE-304/goals.txt?rev=1055047&r1=1055046&r2=1055047&view=diff ============================================================================== --- maven/plugins/trunk/maven-site-plugin/src/it/MSITE-304/goals.txt (original) +++ maven/plugins/trunk/maven-site-plugin/src/it/MSITE-304/goals.txt Tue Jan 4 14:12:55 2011 @@ -1 +1 @@ -site:stage-deploy \ No newline at end of file +clean site:site site:stage site:stage-deploy \ No newline at end of file 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=1055047&r1=1055046&r2=1055047&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 Tue Jan 4 14:12:55 2011 @@ -116,7 +116,7 @@ public class SiteDeployMojo * @required * @readonly */ - private MavenProject project; + protected MavenProject project; /** * @component 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=1055047&r1=1055046&r2=1055047&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 Tue Jan 4 14:12:55 2011 @@ -19,31 +19,11 @@ package org.apache.maven.plugins.site; * under the License. */ -import org.apache.maven.artifact.manager.WagonConfigurationException; -import org.apache.maven.artifact.manager.WagonManager; +import org.apache.maven.doxia.tools.SiteTool; 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.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.context.Context; -import org.codehaus.plexus.context.ContextException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; -import java.io.File; import java.util.List; /** @@ -58,7 +38,7 @@ import java.util.List; * @requiresDependencyResolution test */ public class SiteStageDeployMojo - extends SiteStageMojo implements Contextualizable + extends SiteStageMojo { /** * The staged site will be deployed to this URL. @@ -89,56 +69,19 @@ public class SiteStageDeployMojo private String stagingRepositoryId; /** - * Whether to run the "chmod" command on the remote site after the deploy. - * Defaults to "true". + * SiteTool. * - * @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 + * @since 2.3 */ - private WagonManager wagonManager; - - /** - * The current user system settings for use in Maven. - * - * @parameter expression="${settings}" - * @required - * @readonly - */ - private Settings settings; - - private PlexusContainer container; + private SiteTool siteTool; /** * {...@inheritdoc} */ public void execute() - throws MojoExecutionException, MojoFailureException + throws MojoExecutionException { - super.execute(); - deployStagingSite(); } @@ -151,101 +94,12 @@ public class SiteStageDeployMojo * if any */ private void deployStagingSite() - throws MojoExecutionException, MojoFailureException + throws MojoExecutionException { stagingSiteURL = getStagingSiteURL( project, reactorProjects, stagingSiteURL ); - getLog().info( "Using this URL for staging: " + stagingSiteURL ); - - Repository repository = new Repository( stagingRepositoryId, stagingSiteURL ); - - Wagon wagon; - try - { - wagon = wagonManager.getWagon( repository ); - SiteDeployMojo.configureWagon( wagon, stagingRepositoryId, 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 ); + getLog().info( "Using this URL for stage deploy: " + stagingSiteURL ); - wagon.addTransferListener( debug ); - - ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager ); - if ( proxyInfo != null ) - { - wagon.connect( repository, wagonManager.getAuthenticationInfo( stagingRepositoryId ), proxyInfo ); - } - else - { - wagon.connect( repository, wagonManager.getAuthenticationInfo( stagingRepositoryId ) ); - } - - wagon.putDirectory( new File( stagingDirectory, getStructure( project, false ) ), "." ); - - 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 ); - } - } - } - - public void contextualize( Context context ) - throws ContextException - { - container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + deployTo( stagingRepositoryId, stagingSiteURL ); } /** 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=1055047&r1=1055046&r2=1055047&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 Tue Jan 4 14:12:55 2011 @@ -27,7 +27,6 @@ import org.apache.maven.plugin.MojoExecu import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.plugins.site.wagon.repository.Repository; -import org.codehaus.plexus.util.PathTool; import org.codehaus.plexus.util.StringUtils; /** @@ -45,7 +44,7 @@ import org.codehaus.plexus.util.StringUt * @requiresDependencyResolution test */ public class SiteStageMojo - extends SiteMojo + extends SiteDeployMojo { protected static final String DEFAULT_STAGING_DIRECTORY = "staging"; @@ -59,12 +58,31 @@ public class SiteStageMojo protected File stagingDirectory; /** + * The reactor projects. + * + * @parameter default-value="${reactorProjects}" + * @required + * @readonly + * @since 2.3 + */ + protected List<MavenProject> reactorProjects; + + /** * @see org.apache.maven.plugin.Mojo#execute() */ public void execute() - throws MojoExecutionException, MojoFailureException + throws MojoExecutionException { - String structureProject = getStructure( project, false ); + String structureProject; + + try + { + structureProject = getStructure( project, false ); + } + catch ( MojoFailureException ex ) + { + throw new MojoExecutionException( "Missing site information.", ex ); + } if ( structureProject == null ) { @@ -74,7 +92,7 @@ public class SiteStageMojo stagingDirectory = getStagingDirectory( project, reactorProjects, stagingDirectory ); getLog().info( "Using this directory for staging: " + stagingDirectory ); - outputDirectory = new File( stagingDirectory, structureProject ); + final File outputDirectory = new File( stagingDirectory, structureProject ); // Safety if ( !outputDirectory.exists() ) @@ -82,34 +100,10 @@ public class SiteStageMojo outputDirectory.mkdirs(); } - String outputRelativePath = PathTool.getRelativePath( stagingDirectory.getAbsolutePath(), new File( - outputDirectory, "dummy.html" ).getAbsolutePath() ); - project.setUrl( outputRelativePath + "/" + structureProject ); - - MavenProject parent = siteTool.getParentProject( project, reactorProjects, localRepository ); - if ( parent != null ) - { - String structureParentProject = getStructure( parent, true ); - if ( structureParentProject != null ) - { - parent.setUrl( outputRelativePath + "/" + structureParentProject ); - } - } - - if ( reactorProjects != null && reactorProjects.size() > 1 ) - { - for ( MavenProject reactorProject : reactorProjects ) - { - if ( reactorProject != null && reactorProject.getParent() != null - && project.getArtifactId().equals( reactorProject.getParent().getArtifactId() ) ) - { - String structureReactorProject = getStructure( reactorProject, false ); - reactorProject.setUrl( outputRelativePath + "/" + structureReactorProject ); - } - } - } + final String url = "file://" + outputDirectory.getAbsolutePath(); + final String id = "stagingLocal"; - super.execute(); + deployTo( id, url ); } /**