Vincent Siveton wrote:
Hi Dennis,

2008/6/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
Author: dennisl
 Date: Sat Jun  7 12:13:57 2008
 New Revision: 664376

 URL: http://svn.apache.org/viewvc?rev=664376&view=rev
 Log:
 [MSITE-316] Broken links to submodules when staging site.

 Modified:
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageMojo.java

 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=664376&r1=664375&r2=664376&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
 Sat Jun  7 12:13:57 2008
 @@ -29,6 +29,7 @@

  import java.io.File;
  import java.util.Iterator;
 +import java.util.List;

  /**
  * Staging a site in specific directory.
 @@ -42,11 +43,14 @@
  public class SiteStageMojo
     extends SiteMojo
  {
 +    private static final String DEFAULT_STAGING_DIRECTORY = "staging";
 +
     /**
 -     * Staging directory location.
 +     * Staging directory location. This needs to be an absolute path, like
 +     * <code>C:\stagingArea\myProject\</code> on Windows or
 +     * <code>/stagingArea/myProject/</code> on Unix.
      *
 -     * @parameter expression="${stagingDirectory}" 
default-value="${project.build.directory}/staging"
 -     * @required
 +     * @parameter expression="${stagingDirectory}"
      */
     protected File stagingDirectory;

 @@ -63,7 +67,10 @@
             throw new MojoExecutionException( "Missing site information." );
         }

 -        outputDirectory = new File( stagingDirectory, structureProject );
 +        File calculatedStagingDirectory = getStagingDirectory( project, 
reactorProjects, stagingDirectory );
 +        getLog().info( "Using this directory for staging: " + 
calculatedStagingDirectory );
 +
 +        outputDirectory = new File( calculatedStagingDirectory, 
structureProject );

         // Safety
         if ( !outputDirectory.exists() )
 @@ -71,7 +78,7 @@
             outputDirectory.mkdirs();
         }

 -        String outputRelativePath = PathTool.getRelativePath( 
stagingDirectory.getAbsolutePath(), new File(
 +        String outputRelativePath = PathTool.getRelativePath( 
calculatedStagingDirectory.getAbsolutePath(), new File(
             outputDirectory, "dummy.html" ).getAbsolutePath() );
         project.setUrl( outputRelativePath + "/" + structureProject );

 @@ -106,6 +113,69 @@
     }

     /**
 +     * Find the directory where staging will take place.
 +     *
 +     * @param currentProject        The currently executing project
 +     * @param reactorProjects       The projects in the reactor
 +     * @param usersStagingDirectory The staging directory as suggested by the 
user's configuration
 +     * @return the directory for staging
 +     * @throws MojoFailureException if any
 +     */

reactorProjects is hiding a field so no need to be a parameter of this method.

That was intentional on my part. I find it easier to understand what the method does when you declaring all parameters, even though they are available as variables of the class or one of its ancestors.

If you don't like I could change it...

MojoFailureException is unused

Thanks, I'll fix that.


 +    protected File getStagingDirectory( MavenProject currentProject, List 
reactorProjects, File usersStagingDirectory )
 +        throws MojoFailureException
 +    {
 +        // Check if the user has specified a stagingDirectory
 +        if ( usersStagingDirectory != null )
 +        {
 +            getLog().debug( "stagingDirectory specified by the user." );
 +            return usersStagingDirectory;
 +        }
 +        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 );
 +    }
 +
 +    /**
 +     * Find the top level parent in the reactor, i.e. the execution root.
 +     *
 +     * @param reactorProjects The projects in the reactor
 +     * @return The top level project in the reactor, or <code>null</code> if 
none can be found
 +     */

Same about reactorProjects.

Cheers,

Vincent

 +    private MavenProject getTopLevelProject( List reactorProjects )
 +    {
 +        MavenProject topLevelProject = null;
 +        if ( reactorProjects != null )
 +        {
 +            Iterator iterator = reactorProjects.iterator();
 +            while ( iterator.hasNext() )
 +            {
 +                MavenProject reactorProject = (MavenProject) iterator.next();
 +                if ( reactorProject.isExecutionRoot() )
 +                {
 +                    topLevelProject = reactorProject;
 +                }
 +            }
 +        }
 +        return topLevelProject;
 +    }
 +
 +    /**
      * Generates the site structure using the project hiearchy (project and 
its modules) or using the
      * distributionManagement elements from the pom.xml.
      *




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
Dennis Lundberg

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to