Hi

So, this is the commit that made Jenkins unhappy building plugins with
Maven 2.

I've found the problem now. In the code below I do something like this
to get the plugins for a project:

        Map<String,Plugin> map = project.getBuild().getPluginsAsMap();

This is nice, because in Maven 3 I get the complete effective set of
plugins, from both build/plugins and build/pluginManagement.

This doesn't work in Maven 2 :-(

What I have found is that I can get all plugins from build/plugins *or*
all plugins from build/pluginManagement, but not both at the same time.
I could combine the result of the two, but what happens if a plugin
exits in both? How would I merge the configuration of the two?

Is there a cleaner way to do this?

All I want is the (complete) configuration for maven-site-plugin in a
given MavenProject. Any pointer on how to do this would be most appreciated.




On 2011-08-07 01:21, [email protected] wrote:
> Author: dennisl
> Date: Sat Aug  6 23:21:05 2011
> New Revision: 1154621
> 
> URL: http://svn.apache.org/viewvc?rev=1154621&view=rev
> Log:
> [MSITE-602] The staged site is deployed to the wrong place
> 
> o Attempt at fixing this. All current ITs pass and manual testing shows that 
> it works for the use case described in the issue. Could use review from 
> others.
> 
> Modified:
>     
> maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractDeployMojo.java
>     
> 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/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=1154621&r1=1154620&r2=1154621&view=diff
> ==============================================================================
> --- 
> maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractDeployMojo.java
>  (original)
> +++ 
> maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractDeployMojo.java
>  Sat Aug  6 23:21:05 2011
> @@ -217,7 +217,7 @@ public abstract class AbstractDeployMojo
>       *
>       * @throws MojoExecutionException
>       */
> -    private String getDeployModuleDirectory()
> +    protected String getDeployModuleDirectory()
>          throws MojoExecutionException
>      {
>          String relative = siteTool.getRelativePath( getSite( project 
> ).getUrl(),
> @@ -785,7 +785,7 @@ public abstract class AbstractDeployMojo
>      }
>  
>      /**
> -     * Extract the distributionManagment site of the top level parent of the 
> given MavenProject.
> +     * Extract the distributionManagement site of the top level parent of 
> the given MavenProject.
>       * This climbs up the project hierarchy and returns the site of the last 
> project
>       * for which {@link #getSite(org.apache.maven.project.MavenProject)} 
> returns a site.
>       *
> 
> 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=1154621&r1=1154620&r2=1154621&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
>  Sat Aug  6 23:21:05 2011
> @@ -20,7 +20,13 @@ package org.apache.maven.plugins.site;
>   */
>  
>  
> +import org.apache.commons.lang.StringUtils;
> +import org.apache.maven.model.Build;
> +import org.apache.maven.model.Plugin;
> +import org.apache.maven.model.Site;
>  import org.apache.maven.plugin.MojoExecutionException;
> +import org.apache.maven.project.MavenProject;
> +import org.codehaus.plexus.util.xml.Xpp3Dom;
>  
>  /**
>   * Deploys the generated site to a staging or mock directory to the site URL
> @@ -71,6 +77,40 @@ public class SiteStageDeployMojo
>      private String stagingRepositoryId;
>  
>      @Override
> +    /**
> +     * Find the relative path between the distribution URLs of the parent 
> that
> +     * supplied the staging deploy URL and the current project.
> +     *
> +     * @return the relative path or "./" if the two URLs are the same.
> +     *
> +     * @throws MojoExecutionException
> +     */
> +    protected String getDeployModuleDirectory()
> +        throws MojoExecutionException
> +    {
> +        // MSITE-602: If the user specified an explicit stagingSiteURL, use 
> a special relative path
> +        if( StringUtils.isNotEmpty( stagingSiteURL ) )
> +        {
> +            // We need to calculate the relative path between this project 
> and
> +            // the first one that supplied a stagingSiteURL
> +            String relative = siteTool.getRelativePath( getSite( project 
> ).getUrl(),
> +                getSiteForFirstParentWithStagingSiteURL( project ).getUrl() 
> );
> +
> +            // SiteTool.getRelativePath() uses File.separatorChar,
> +            // so we need to convert '\' to '/' in order for the URL to be 
> valid for Windows users
> +            relative = relative.replace( '\\', '/' );
> +
> +            getLog().debug( "The stagingSiteURL is configured, using special 
> way to calculate relative path." );
> +            return ( "".equals( relative ) ) ? "./" : relative;
> +        }
> +        else
> +        {
> +            getLog().debug( "No stagingSiteURL is configured, using standard 
> way to calculate relative path." );
> +            return super.getDeployModuleDirectory();
> +        }
> +    }
> +
> +    @Override
>      protected String getDeployRepositoryID()
>          throws MojoExecutionException
>      {
> @@ -93,6 +133,83 @@ public class SiteStageDeployMojo
>      }
>  
>      /**
> +     * Extract the distributionManagement.site of the first project up the
> +     * hierarchy that specifies a stagingSiteURL, starting at the given
> +     * MavenProject.
> +     * <p/>
> +     * This climbs up the project hierarchy and returns the site of the first
> +     * project for which
> +     * {@link #getStagingSiteURL(org.apache.maven.project.MavenProject)} 
> returns
> +     * a URL.
> +     *
> +     * @param project the MavenProject. Not null.
> +     * @return the site for the first project that has a stagingSiteURL. Not 
> null.
> +     */
> +    protected Site getSiteForFirstParentWithStagingSiteURL( MavenProject 
> project )
> +    {
> +        Site site = project.getDistributionManagement().getSite();
> +
> +        MavenProject parent = project;
> +
> +        // @todo Should we check that the stagingSiteURL equals the one in 
> this project instead of being non-empty?
> +        while ( parent != null
> +                && StringUtils.isNotEmpty( getStagingSiteURL( parent ) ) )
> +        {
> +            site = parent.getDistributionManagement().getSite();
> +
> +            // MSITE-585, MNG-1943
> +            parent = siteTool.getParentProject( parent, reactorProjects, 
> localRepository );
> +        }
> +
> +        return site;
> +    }
> +
> +    /**
> +     * Extract the value of the stagingSiteURL configuration parameter of
> +     * maven-site-plugin for the given project.
> +     *
> +     * @param project The MavenProject, not null
> +     * @return The stagingSiteURL for the project, or null if it doesn't 
> have one
> +     */
> +    private String getStagingSiteURL( MavenProject project )
> +    {
> +        final String sitePluginKey = 
> "org.apache.maven.plugins:maven-site-plugin";
> +
> +        if ( project == null )
> +        {
> +            return null;
> +        }
> +
> +        final Build build = project.getBuild();
> +        if ( build == null )
> +        {
> +            return null;
> +        }
> +
> +        final Plugin sitePlugin = build.getPluginsAsMap().get( sitePluginKey 
> );
> +        if( sitePlugin == null )
> +        {
> +            return null;
> +        }
> +
> +        final Xpp3Dom sitePluginConfiguration = (Xpp3Dom) 
> sitePlugin.getConfiguration();
> +        if ( sitePluginConfiguration == null )
> +        {
> +            return null;
> +        }
> +
> +        final Xpp3Dom child = sitePluginConfiguration.getChild( 
> "stagingSiteURL" );
> +        if ( child == null )
> +        {
> +            return null;
> +        }
> +        else
> +        {
> +            return child.getValue();
> +        }
> +    }
> +
> +    /**
>       * Find the URL where staging will take place.
>       *
>       * @param usersStagingSiteURL The staging site URL as suggested by the 
> user's configuration
> 
> 
> 


-- 
Dennis Lundberg

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to