Author: dennisl Date: Tue Jun 10 15:37:44 2008 New Revision: 666352 URL: http://svn.apache.org/viewvc?rev=666352&view=rev Log: [MSITE-304] site:stage-deploy creates different directory structure than site:site
Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java 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=666352&r1=666351&r2=666352&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 Jun 10 15:37:44 2008 @@ -23,6 +23,7 @@ import org.apache.maven.artifact.manager.WagonManager; 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; @@ -41,9 +42,10 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import java.io.File; +import java.util.List; /** - * Deploy a staging site in specific directory. + * Deploy a staging site in a specific directory. * <p>Useful to test the generated site.</p> * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> @@ -55,9 +57,14 @@ extends SiteStageMojo implements Contextualizable { /** - * Staging site URL to deploy the staging directory. + * The staged site will be deployed to this URL. * - * @parameter expression="${stagingSiteURL}" default-value="${project.distributionManagement.site.url}/staging" + * If you don't specify this, the default-value will be + * "${project.distributionManagement.site.url}/staging", where "project" is + * either the current project or, in a reactor build, the top level project + * in the reactor. + * + * @parameter expression="${stagingSiteURL}" * @see <a href="http://maven.apache.org/maven-model/maven.html#class_site">MavenModel#class_site</a> */ private String stagingSiteURL; @@ -102,6 +109,9 @@ private void deployStagingSite() throws MojoExecutionException, MojoFailureException { + stagingSiteURL = getStagingSiteURL( project, reactorProjects, stagingSiteURL ); + getLog().info( "Using this URL for staging: " + stagingSiteURL ); + Repository repository = new Repository( STAGING_SERVER_ID, stagingSiteURL ); Wagon wagon; @@ -184,4 +194,63 @@ container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); } + /** + * Find the URL where staging will take place. + * + * @param currentProject The currently executing project + * @param reactorProjects The projects in the reactor + * @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 reactorProjects, String usersStagingSiteURL ) + { + String topLevelURL = null; + String relative = ""; + + // If the user has specified a stagingSiteURL - use it + if ( usersStagingSiteURL != null ) + { + getLog().debug( "stagingSiteURL specified by the user." ); + topLevelURL = usersStagingSiteURL; + } + getLog().debug( "stagingSiteURL NOT specified by the user." ); + + // Find the top level project in the reactor + MavenProject topLevelProject = getTopLevelProject( reactorProjects ); + + // Take the distributionManagement site url from the top level project, + // if there is one, otherwise take it from the current project + if ( topLevelProject == null ) + { + if ( topLevelURL == null ) + { + // The user didn't specify a URL and there is no top level project in the reactor + // Use current project + getLog().debug( "No top level project found in the reactor, using the current project." ); + topLevelURL = + currentProject.getDistributionManagement().getSite().getUrl() + "/" + DEFAULT_STAGING_DIRECTORY; + } + } + else + { + // Find the relative path between the parent and child distribution URLs, if any + relative = "/" + siteTool.getRelativePath( currentProject.getDistributionManagement().getSite().getUrl(), + topLevelProject.getDistributionManagement().getSite().getUrl() ); + + if ( topLevelURL == null ) + { + // The user didn't specify a URL and there is a top level project in the reactor + // Use the top level project + getLog().debug( "Using the top level project found in the reactor." ); + topLevelURL = + topLevelProject.getDistributionManagement().getSite().getUrl() + "/" + DEFAULT_STAGING_DIRECTORY; + } + } + + // Return either + // usersURL + relative(from parent, to child) + // or + // topLevelProjectURL + staging + relative(from parent, to child) + return topLevelURL + relative; + } }