maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r543898 - in /maven/jxr/trunk/maven-jxr-plugin: pom.xml src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java
Date Sun, 03 Jun 2007 14:05:23 GMT
Author: vsiveton
Date: Sun Jun  3 07:05:22 2007
New Revision: 543898

URL: http://svn.apache.org/viewvc?view=rev&rev=543898
Log:
JXR-51: Javadoc link broken for site:stage

o handle the stagingDirectory for the site:stage in getJavadocLocation()
o added xalan:2.7.0 to get javadoc configuration

Added:
    maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java
  (with props)
Modified:
    maven/jxr/trunk/maven-jxr-plugin/pom.xml
    maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java

Modified: maven/jxr/trunk/maven-jxr-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/pom.xml?view=diff&rev=543898&r1=543897&r2=543898
==============================================================================
--- maven/jxr/trunk/maven-jxr-plugin/pom.xml (original)
+++ maven/jxr/trunk/maven-jxr-plugin/pom.xml Sun Jun  3 07:05:22 2007
@@ -61,6 +61,12 @@
       <version>2.0.2</version>
     </dependency>
     <dependency>
+      <groupId>xalan</groupId>
+      <artifactId>xalan</artifactId>
+      <version>2.7.0</version>
+    </dependency>
+
+    <dependency>
       <groupId>org.apache.maven.shared</groupId>
       <artifactId>maven-plugin-testing-harness</artifactId>
       <version>1.0</version>

Modified: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java
URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java?view=diff&rev=543898&r1=543897&r2=543898
==============================================================================
--- maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java
(original)
+++ maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java
Sun Jun  3 07:05:22 2007
@@ -19,17 +19,6 @@
  * under the License.
  */
 
-import org.apache.maven.doxia.siterenderer.Renderer;
-import org.apache.maven.jxr.JXR;
-import org.apache.maven.jxr.JxrException;
-import org.apache.maven.model.Organization;
-import org.apache.maven.model.ReportPlugin;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.reporting.AbstractMavenReport;
-import org.apache.maven.reporting.MavenReportException;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.StringUtils;
-
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
@@ -41,6 +30,17 @@
 import java.util.Locale;
 import java.util.ResourceBundle;
 
+import org.apache.maven.doxia.siterenderer.Renderer;
+import org.apache.maven.jxr.JXR;
+import org.apache.maven.jxr.JxrException;
+import org.apache.maven.model.Organization;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
+
 /**
  * Base class for the JXR reports.
  *
@@ -166,7 +166,7 @@
     /**
      * Compiles the list of directories which contain source files that will be included
in the JXR report generation.
      *
-     * @param sourceDirs    the List of the source directories
+     * @param sourceDirs the List of the source directories
      * @return a List of the directories that will be included in the JXR report generation
      */
     protected List pruneSourceDirs( List sourceDirs )
@@ -268,8 +268,8 @@
             jxr.setIncludes( (String[]) includes.toArray( new String[0] ) );
         }
 
-        jxr.xref( sourceDirs, templateDir, windowTitle, docTitle,
-                  getBottomText( project.getInceptionYear(), project.getOrganization() )
);
+        jxr.xref( sourceDirs, templateDir, windowTitle, docTitle, getBottomText( project.getInceptionYear(),
project
+            .getOrganization() ) );
 
         // and finally copy the stylesheet
         copyRequiredResources( destinationDirectory );
@@ -374,7 +374,7 @@
     /**
      * Returns the correct resource bundle according to the locale
      *
-     * @param locale: the locale of the user
+     * @param locale the locale of the user
      * @return the bundle correponding to the locale
      */
     protected ResourceBundle getBundle( Locale locale )
@@ -469,9 +469,9 @@
      * @return a String that contains the loaction of the javadocs
      */
     private String getJavadocLocation()
+        throws IOException
     {
         String location = null;
-
         if ( linkJavadoc )
         {
             // We don't need to do the whole translation thing like normal, because JXR does
it internally.
@@ -484,15 +484,53 @@
             else
             {
                 // Not yet generated - check if the report is on its way
-                for ( Iterator reports = getProject().getReportPlugins().iterator(); reports.hasNext();
)
+
+                // Special case: using the site:stage goal
+                String stagingDirectory = System.getProperty( "stagingDirectory" );
+
+                if ( StringUtils.isNotEmpty( stagingDirectory ) )
                 {
-                    ReportPlugin report = (ReportPlugin) reports.next();
+                    String javadocDestDir = getJavadocDir().getName();
+                    boolean javadocAggregate = Boolean
+                        .valueOf( JxrReportUtil.getMavenJavadocPluginBasicOption( project,
"aggregate", "false" ) )
+                        .booleanValue();
+
+                    String structureProject = JxrReportUtil.getStructure( project, false
);
+
+                    if ( aggregate && javadocAggregate )
+                    {
+                        File outputDirectory = new File( stagingDirectory, structureProject
);
+                        location = outputDirectory + "/" + javadocDestDir;
+                    }
+                    if ( !aggregate && javadocAggregate )
+                    {
+                        location = stagingDirectory + "/" + javadocDestDir;
 
-                    String artifactId = report.getArtifactId();
-                    if ( "maven-javadoc-plugin".equals( artifactId ) )
+                        String hierarchy = project.getName();
+
+                        MavenProject parent = project.getParent();
+                        while ( parent != null )
+                        {
+                            hierarchy = parent.getName();
+                            parent = parent.getParent();
+                        }
+                        File outputDirectory = new File( stagingDirectory, hierarchy );
+                        location = outputDirectory + "/" + javadocDestDir;
+                    }
+                    if ( aggregate && !javadocAggregate )
                     {
-                        location = getJavadocDir().getAbsolutePath();
+                        getLog().warn(
+                                       "The JXR plugin is configured to build an aggregated
report at the root, "
+                                           + "not the Javadoc plugin." );
                     }
+                    if ( !aggregate && !javadocAggregate )
+                    {
+                        location = stagingDirectory + "/" + structureProject + "/" + javadocDestDir;
+                    }
+                }
+                else
+                {
+                    location = getJavadocDir().getAbsolutePath();
                 }
             }
 

Added: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java
URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java?view=auto&rev=543898
==============================================================================
--- maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java
(added)
+++ maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java
Sun Jun  3 07:05:22 2007
@@ -0,0 +1,213 @@
+package org.apache.maven.plugin.jxr;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.Site;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.wagon.repository.Repository;
+import org.apache.xpath.XPathAPI;
+import org.apache.xpath.objects.XObject;
+import org.codehaus.plexus.util.StringInputStream;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * Utility class for the jxr report.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id $
+ */
+public class JxrReportUtil
+{
+    /**
+     * Return the <code>optionName</code> value defined in a project for the
"maven-javadoc-plugin" plugin.
+     *
+     * @param project not null
+     * @param optionName the option name wanted
+     * @param defaultValue a default value
+     * @return the value for the option name or the default value. Could be null if not found.
+     * @throws IOException if any
+     */
+    protected static String getMavenJavadocPluginBasicOption( MavenProject project, String
optionName,
+                                                              String defaultValue )
+        throws IOException
+    {
+        List plugins = new ArrayList();
+        for ( Iterator it = project.getModel().getReporting().getPlugins().iterator(); it.hasNext();
)
+        {
+            plugins.add( it.next() );
+        }
+        for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext();
)
+        {
+            plugins.add( it.next() );
+        }
+
+        String pluginArtifactId = "maven-javadoc-plugin";
+        for ( Iterator it = plugins.iterator(); it.hasNext(); )
+        {
+            Object next = it.next();
+
+            Xpp3Dom pluginConf = null;
+
+            if ( next instanceof Plugin )
+            {
+                Plugin plugin = (Plugin) next;
+
+                // using out-of-box Maven plugins
+                if ( !( ( plugin.getGroupId().equals( "org.apache.maven.plugins" ) ) &&
( plugin.getArtifactId()
+                    .equals( pluginArtifactId ) ) ) )
+                {
+                    continue;
+                }
+
+                pluginConf = (Xpp3Dom) plugin.getConfiguration();
+            }
+
+            if ( next instanceof ReportPlugin )
+            {
+                ReportPlugin reportPlugin = (ReportPlugin) next;
+
+                // using out-of-box Maven plugins
+                if ( !( ( reportPlugin.getGroupId().equals( "org.apache.maven.plugins" )
) && ( reportPlugin
+                    .getArtifactId().equals( pluginArtifactId ) ) ) )
+                {
+                    continue;
+                }
+
+                pluginConf = (Xpp3Dom) reportPlugin.getConfiguration();
+            }
+
+            if ( pluginConf == null )
+            {
+                continue;
+            }
+
+            try
+            {
+                Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
+                    .parse( new StringInputStream( pluginConf.toString() ) );
+
+                XObject obj = XPathAPI.eval( doc, "//configuration/" + optionName );
+
+                if ( StringUtils.isNotEmpty( obj.toString() ) )
+                {
+                    return obj.toString();
+                }
+            }
+            catch ( SAXException e )
+            {
+                throw new IOException( "SAXException: " + e.getMessage() );
+            }
+            catch ( ParserConfigurationException e )
+            {
+                throw new IOException( "ParserConfigurationException: " + e.getMessage()
);
+            }
+            catch ( FactoryConfigurationError e )
+            {
+                throw new IOException( "FactoryConfigurationError: " + e.getMessage() );
+            }
+            catch ( TransformerException e )
+            {
+                throw new IOException( "TransformerException: " + e.getMessage() );
+            }
+        }
+
+        return defaultValue;
+    }
+
+    /**
+     * Generates the site structure using the project hiearchy (project and its modules)
or using the
+     * distributionManagement elements from the pom.xml.
+     *
+     * @todo come from javadoc plugin!
+     *
+     * @param project
+     * @param ignoreMissingSiteUrl
+     * @return the structure relative path
+     * @throws IOException if any
+     */
+    protected static String getStructure( MavenProject project, boolean ignoreMissingSiteUrl
)
+        throws IOException
+    {
+        if ( project.getDistributionManagement() == null )
+        {
+            String hierarchy = project.getName();
+
+            MavenProject parent = project.getParent();
+            while ( parent != null )
+            {
+                hierarchy = parent.getName() + "/" + hierarchy;
+                parent = parent.getParent();
+            }
+
+            return hierarchy;
+        }
+
+        Site site = project.getDistributionManagement().getSite();
+        if ( site == null )
+        {
+            if ( !ignoreMissingSiteUrl )
+            {
+                throw new IOException(
+                                       "Missing site information in the distribution management
element in the project: '"
+                                           + project.getName() + "'." );
+            }
+
+            return null;
+        }
+
+        if ( StringUtils.isEmpty( site.getUrl() ) )
+        {
+            if ( !ignoreMissingSiteUrl )
+            {
+                throw new IOException( "The URL in the site is missing in the project descriptor."
);
+            }
+
+            return null;
+        }
+
+        Repository repository = new Repository( site.getId(), site.getUrl() );
+        if ( StringUtils.isEmpty( repository.getBasedir() ) )
+        {
+            return repository.getHost();
+        }
+
+        if ( repository.getBasedir().startsWith( "/" ) )
+        {
+            return repository.getHost() + repository.getBasedir();
+        }
+
+        return repository.getHost() + "/" + repository.getBasedir();
+    }
+}

Propchange: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message