You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2005/12/22 06:14:52 UTC

svn commit: r358497 - /maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java

Author: brett
Date: Wed Dec 21 21:14:48 2005
New Revision: 358497

URL: http://svn.apache.org/viewcvs?rev=358497&view=rev
Log:
resolve the site descriptor from the remote repository if necessary

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

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java?rev=358497&r1=358496&r2=358497&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java (original)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java Wed Dec 21 21:14:48 2005
@@ -16,6 +16,12 @@
  * limitations under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.doxia.module.xdoc.XdocSiteModule;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 import org.apache.maven.doxia.site.decoration.inheritance.DecorationModelInheritanceAssembler;
@@ -186,6 +192,35 @@
     private DecorationModelInheritanceAssembler assembler;
 
     /**
+     * The component that is used to resolve additional artifacts required.
+     *
+     * @component
+     */
+    private ArtifactResolver artifactResolver;
+
+    /**
+     * The local repository.
+     *
+     * @parameter expression="${localRepository}
+     */
+    private ArtifactRepository localRepository;
+
+    /**
+     * Remote repositories used for the project.
+     *
+     * @todo this is used for site descriptor resolution - it should relate to the actual project but for some reason they are not always filled in
+     * @parameter expression="${project.remoteArtifactRepositories}"
+     */
+    private List repositories;
+
+    /**
+     * The component used for creating artifact instances.
+     *
+     * @component
+     */
+    private ArtifactFactory artifactFactory;
+
+    /**
      * Generate the project site
      * <p/>
      * throws MojoExecutionException if any
@@ -448,15 +483,20 @@
     {
         Map props = new HashMap( origProps );
 
-        // TODO: this isn't taking into account the pom in the repository. It should be resolving it in some way that
-        //  is compatible with the parent resolution and USD
+        // TODO: we should use a workspace API that would know if it was in the repository already or not
         File siteDescriptor = getSiteDescriptorFile( project.getBasedir(), locale );
 
         String siteDescriptorContent;
 
         try
         {
-            if ( siteDescriptor.exists() )
+            if ( !siteDescriptor.exists() )
+            {
+                // try the repository
+                siteDescriptor = getSiteDescriptorFromRepository( project, locale );
+            }
+
+            if ( siteDescriptor != null && siteDescriptor.exists() )
             {
                 siteDescriptorContent = FileUtils.fileRead( siteDescriptor );
             }
@@ -469,6 +509,11 @@
         {
             throw new MojoExecutionException( "The site descriptor cannot be read!", e );
         }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new MojoExecutionException(
+                "The site descriptor cannot be resolved from the repository: " + e.getMessage(), e );
+        }
 
         props.put( "outputEncoding", outputEncoding );
 
@@ -518,6 +563,53 @@
         }
 
         return decoration;
+    }
+
+    private File getSiteDescriptorFromRepository( MavenProject project, Locale locale )
+        throws ArtifactResolutionException
+    {
+        File result = null;
+
+        try
+        {
+            result = resolveSiteDescriptor( project, locale );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            getLog().debug( "Unable to locate site descriptor: " + e );
+        }
+
+        return result;
+    }
+
+    private File resolveSiteDescriptor( MavenProject project, Locale locale )
+        throws ArtifactResolutionException, ArtifactNotFoundException
+    {
+        File result;
+
+        try
+        {
+            // TODO: this is a bit crude - proper type, or proper handling as metadata rather than an artifact in 2.1?
+            Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(),
+                                                                              project.getArtifactId(),
+                                                                              project.getVersion(), "xml",
+                                                                              "site_" + locale.getLanguage() );
+            artifactResolver.resolve( artifact, repositories, localRepository );
+
+            result = artifact.getFile();
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            getLog().debug( "Unable to locate site descriptor: " + e );
+
+            Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(),
+                                                                              project.getArtifactId(),
+                                                                              project.getVersion(), "xml", "site" );
+            artifactResolver.resolve( artifact, repositories, localRepository );
+
+            result = artifact.getFile();
+        }
+        return result;
     }
 
     private List filterReports( List reports )