You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2005/12/04 16:59:59 UTC

svn commit: r353867 - in /maven/plugins/trunk/maven-site-plugin/src: main/java/org/apache/maven/plugins/site/ site/apt/ test/projects/site-plugin-test10/

Author: vsiveton
Date: Sun Dec  4 07:59:54 2005
New Revision: 353867

URL: http://svn.apache.org/viewcvs?rev=353867&view=rev
Log:
PR: MNG-1555
Custom velocity template error: unable to find resource 'maven.vm' in any class loader

TemplateDirectory parameter is now a file. 
Updated the howto file.
Added a project test case

Added:
    maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/
    maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/maven-site.vm   (with props)
    maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/pom.xml   (with props)
Modified:
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java
    maven/plugins/trunk/maven-site-plugin/src/site/apt/howto.apt

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=353867&r1=353866&r2=353867&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 Sun Dec  4 07:59:54 2005
@@ -119,7 +119,7 @@
      *
      * @parameter expression="${templateDirectory}"
      */
-    private String templateDirectory;
+    private File templateDirectory;
 
     /**
      * Default template page.
@@ -203,7 +203,12 @@
         {
             try
             {
-                URL templateDirectoryUrl = new URL( templateDirectory );
+                if ( !templateDirectory.exists() )
+                {
+                    throw new MojoExecutionException( "This templateDirectory=[" + templateDirectory + "] doesn't exist." );
+                }
+
+                URL templateDirectoryUrl = templateDirectory.toURL();
 
                 URL[] urls = {templateDirectoryUrl};
 

Modified: maven/plugins/trunk/maven-site-plugin/src/site/apt/howto.apt
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-site-plugin/src/site/apt/howto.apt?rev=353867&r1=353866&r2=353867&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/site/apt/howto.apt (original)
+++ maven/plugins/trunk/maven-site-plugin/src/site/apt/howto.apt Sun Dec  4 07:59:54 2005
@@ -4,7 +4,7 @@
  Vincent Siveton
  <vi...@gmail.com>
  ------
- September 20, 2005
+ December 4, 2005
  ------
 
 Maven 2 Site Plugin
@@ -29,6 +29,30 @@
 -------------------
   mvn site:deploy
 -------------------
+
+*How to change the site template
+
+  It is possible to change the velocity template used for creating the site.
+  In your pom, just add something like this:
+
+-------------------
+  ...
+  <reporting>
+    <plugins>
+      <plugin>
+       <groupId>org.apache.maven.plugins</groupId>
+       <artifactId>maven-site-plugin</artifactId>
+       <configuration>
+         <templateDirectory>${basedir}</templateDirectory>
+         <template>maven-site.vm</template>
+       </configuration>
+      </plugin>
+    </plugins>
+  </reporting>
+  ...
+-------------------
+
+  And execute the site goal from your project.
 
 *Site Descriptor
 

Added: maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/maven-site.vm
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/maven-site.vm?rev=353867&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/maven-site.vm (added)
+++ maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/maven-site.vm Sun Dec  4 07:59:54 2005
@@ -0,0 +1,269 @@
+#macro ( banner $id )
+  #if ( $siteDescriptor.getChild( $id ) )
+    #set ( $e = $siteDescriptor.getChild( $id ) )
+    #if( $e.getChild( "href" ) )
+        #set ( $link = $e.getChild( "href" ).getValue() )
+        <a href="$link" id="$id">
+    #else
+        <span id="$id">
+    #end
+
+    #if( $e.getChild( "src" ) )
+        #set ( $src = $e.getChild( "src" ).getValue() )
+        #if ( ! ( $src.toLowerCase().startsWith("http") || $src.toLowerCase().startsWith("https") ) )
+            #set ( $src = $PathTool.calculateLink( $src, $relativePath ) )
+            #set ( $src = $src.replaceAll( "\\", "/" ) )
+        #end
+        #if ( $e.getChild( "alt" ) )
+            #set ( $alt = $e.getChild( "alt" ).getValue() )
+        #else
+            #set ( $alt = "" )
+        #end
+        <img src="$src" alt="$alt" />
+    #else
+        $e.getChild( "name" ).getValue()
+    #end
+
+    #if( $e.getChild( "href" ) )
+        </a>
+    #else
+        </span>
+    #end
+  #end
+#end
+
+#macro ( links )
+  #set ( $counter = 0 )
+  #set ( $links = $siteDescriptor.getChild( "body" ).getChild( "links" ) )
+  #foreach( $item in $links.getChildren() )
+    #set ( $counter = $counter + 1 )
+    <a href="$item.getAttribute( "href" )">$item.getAttribute( "name" )</a>
+    #if ( $links.getChildCount() > $counter )
+      |
+    #end
+  #end
+#end
+
+#macro ( displayTree $display $item )
+  #if ( $item && $item.getChildren() && $item.getChildCount() > 0 )
+    #foreach( $subitem in $item.getChildren() )
+      #set ( $subitemHref = $PathTool.calculateLink( $subitem.getAttribute( "href" ), $relativePath ) )
+      #set ( $subitemHref = $subitemHref.replaceAll( "\\", "/" ) )
+
+      #if ( $currentFileName == $subitemHref )
+        #set ( $display = true )
+      #end
+
+      #displayTree( $display $subitem )
+    #end
+  #end
+#end
+
+#macro ( menuItem $item )
+  #set ( $collapse = "none" )
+  #set ( $currentItemHref = $PathTool.calculateLink( $item.getAttribute( "href" ), $relativePath ) )
+  #set ( $currentFileName = $currentFileName.replaceAll( "\\", "/" ) )
+  #set ( $currentItemHref = $currentItemHref.replaceAll( "\\", "/" ) )
+
+  #if ( $item && $item.getChildCount() > 0 )
+    #if ( ( $item.getAttribute( "collapse" ) ) && ( $item.getAttribute( "collapse" ).equalsIgnoreCase( "false" ) ) )
+      #set ( $collapse = "expanded" )
+    #else
+      ## By default collapsed
+      #set ( $collapse = "collapsed" )
+    #end
+
+    #if ( $currentFileName == $currentItemHref )
+      #set ( $collapse = "expanded" )
+    #end
+  #end
+  <li class="$collapse">
+    #if ( $currentFileName == $currentItemHref )
+      <strong><a href="$currentItemHref">$item.getAttribute( "name" )</a></strong>
+    #else
+      <a href="$currentItemHref">$item.getAttribute( "name" )</a>
+    #end
+  #if ( $item && $item.getChildren() && $item.getChildCount() > 0 )
+    #set ( $display = false )
+    #set ( $itemTmp = $item )
+    #displayTree( $display $itemTmp )
+
+    #if ( $collapse == "expanded" || $display )
+      <ul>
+        #foreach( $subitem in $item.getChildren() )
+          #menuItem( $subitem )
+        #end
+      </ul>
+    #end
+  #end
+  </li>
+#end
+
+#macro ( mainMenu )
+  #set ( $menus = $siteDescriptor.getChild( "body" ).getChildren( "menu" ) )
+  #foreach( $menu in $menus )
+    <h5>$menu.getAttribute( "name" )</h5>
+    <ul>
+      #foreach( $item in $menu.getChildren() )
+        #menuItem( $item )
+      #end
+    </ul>
+  #end
+#end
+
+#macro ( copyright )
+  #if ( $project )
+    #set ( $currentYear = ${currentDate.year} + 1900 )
+
+    #if ( ${project.inceptionYear} && ( ${project.inceptionYear} != ${currentYear.toString()} ) )
+      ${project.inceptionYear}-${currentYear}
+    #else
+      ${currentYear}
+    #end
+
+    #if ( ${project.organization} && ${project.organization.name} )
+      ${project.organization.name}
+    #end
+  #end
+#end
+
+#macro ( publishDate $position)
+  #if ( $siteDescriptor.getChild( "publishDate" ) )
+      
+      #if ( $siteDescriptor.getChild( "publishDate" ).getAttribute( "format" ) ) 
+          #set ( $format = $siteDescriptor.getChild( "publishDate" ).getAttribute( "format" ) )
+      #end
+      
+      #if ( $format )
+          $dateFormat.applyPattern( $format )
+      #end
+          ##$dateFormat.applyPattern( "MM/dd/yyyy" )          
+      ##end    
+      
+      #set ( $dateToday = $dateFormat.format( $currentDate ) )
+      
+      #set ( $datePosition = $siteDescriptor.getChild( "publishDate" ).getAttribute( "position" ) ) 
+      #if ( $datePosition.equalsIgnoreCase( $position ) )
+        
+        #if ( $datePosition.equalsIgnoreCase( "right" ) || $datePosition.equalsIgnoreCase( "bottom" ) )
+          &nbsp;| $i18n.getString( "site-plugin", $locale, "template.lastpublished" ): $dateToday
+        
+        #elseif ( $datePosition.equalsIgnoreCase( "navigation-bottom" ) || $datePosition.equalsIgnoreCase( "navigation-top" ) )
+           <div id="lastPublished">$i18n.getString( "site-plugin", $locale, "template.lastpublished" ): $dateToday</div>
+        
+        #elseif ( $datePosition.equalsIgnoreCase("left") )
+            <div class="xleft">
+              $i18n.getString( "site-plugin", $locale, "template.lastpublished" ): $dateToday &nbsp; | &nbsp; Doc for 
+              #if ( $siteDescriptor.getChild( "version" ))
+                $siteDescriptor.getChild( "version" ).getValue()
+              #else
+                ${project.version}
+              #end
+            </div>
+        #end   
+      #end
+  #end                
+#end
+
+#macro ( poweredByLogo )
+                
+    #if( $siteDescriptor.getChild( "powered-by" ) )
+        #foreach ($item in $siteDescriptor.getChild( "powered-by" ).getChildren() )
+            #if( $item.getAttribute( "href" ) )
+                #set ( $href = $item.getAttribute( "href" ) )
+            #else
+                #set ( $href="http://maven.apache.org/" )
+            #end
+            
+            #if( $item.getAttribute( "name" ) )
+                #set ( $name = $item.getAttribute( "name" ) )
+            #else
+                #set ( $name = $i18n.getString( "site-plugin", $locale, "template.builtby" )  )
+                #set ( $name = "${name} Maven"  )
+            #end   
+            
+            #if( $item.getAttribute( "img" ) )
+                #set ( $img = $item.getAttribute( "img" ) )
+            #else
+                #set ( $img = "maven-feather.png" )
+            #end 
+            
+            <a href="$href" title="$name" id="poweredBy">
+              <img alt="$name" src="$relativePath/images/logos/$img"></img>
+            </a>
+        #end
+        #if( $siteDescriptor.getChild( "powered-by" ).getChildCount() == 0 )
+          <a href="http://maven.apache.org/" title="$i18n.getString( "site-plugin", $locale, "template.builtby" ) Maven" id="poweredBy">
+            <img alt="$i18n.getString( "site-plugin", $locale, "template.builtby" ) Maven" src="$relativePath/images/logos/maven-feather.png"></img>
+          </a>
+        #end
+    #else
+        <a href="http://maven.apache.org/" title="$i18n.getString( "site-plugin", $locale, "template.builtby" ) Maven" id="poweredBy">
+          <img alt="$i18n.getString( "site-plugin", $locale, "template.builtby" ) Maven" src="$relativePath/images/logos/maven-feather.png"></img>
+        </a>
+    #end
+#end
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+  <head>
+    <title>$title</title>
+    <style type="text/css" media="all">
+      @import url("$relativePath/css/maven-base.css");
+      @import url("$relativePath/css/maven-theme.css");
+      @import url("$relativePath/css/site.css");
+    </style>
+    <link rel="stylesheet" href="$relativePath/css/print.css" type="text/css" media="print" />
+    #foreach( $author in $authors )
+      <meta name="author" content="$author" />
+    #end
+    <meta http-equiv="Content-Type" content="text/html; charset=${outputEncoding}" />
+    #if ( $siteDescriptor.getChild( "body" ).getChild( "head" ) )
+      #foreach( $item in $siteDescriptor.getChild( "body" ).getChild( "head" ).getChildren() )
+        $item
+      #end
+    #end
+  </head>
+  <body class="composite">
+    <div id="banner">
+      #set ( $banner = "bannerLeft" )
+      #banner( $banner )
+      #set ( $banner = "bannerRight" )
+      #banner( $banner )
+      <div class="clear">
+        <hr/>
+      </div>
+    </div>
+    <div id="breadcrumbs">
+      #publishDate( "left" )
+      <div class="xright">#links()#publishDate( "right" )</div>
+      <div class="clear">
+        <hr/>
+      </div>
+    </div>
+    <div id="leftColumn">
+      <div id="navcolumn">
+       #publishDate( "navigation-top" )   
+       #mainMenu()
+       #poweredByLogo()
+       #publishDate( "navigation-bottom" )
+      </div>
+    </div>
+    <div id="bodyColumn">
+      <div id="contentBox">
+        $bodyContent
+      </div>
+    </div>
+    <div class="clear">
+      <hr/>
+    </div>
+    <div id="footer">
+      <div class="xright">&#169;#copyright()#publishDate( "bottom" )</div>
+      <div class="clear">
+        <hr/>
+      </div>
+      <div class="xright">TESTING MNG-1555</div>
+    </div>
+  </body>
+</html>

Propchange: maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/maven-site.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/maven-site.vm
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/pom.xml?rev=353867&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/pom.xml (added)
+++ maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/pom.xml Sun Dec  4 07:59:54 2005
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!--
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugin.site.test10</groupId>
+  <artifactId>site-plugin-test10</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <inceptionYear>2005</inceptionYear>
+  <name>Maven Site Plugin Test10</name>
+  <description>MNG-1555:Custom velocity template error: unable to find resource 'maven.vm' in any class loader</description>
+  <url>http://maven.apache.org</url>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <developers>
+    <developer>
+      <id>vsiveton</id>
+      <name>Vincent Siveton</name>
+      <email>vsiveton@apache.org</email>
+      <organization>Apache Software Foundation</organization>
+      <roles>
+        <role>Java Developer</role>
+      </roles>
+      <timezone>-5</timezone>
+    </developer>
+  </developers>
+  
+  <reporting>
+    <plugins> 
+      <plugin> 
+       <groupId>org.apache.maven.plugins</groupId> 
+       <artifactId>maven-site-plugin</artifactId> 
+       <configuration> 
+          
+        <templateDirectory>${basedir}</templateDirectory> 
+         <template>maven-site.vm</template> 
+       </configuration> 
+      </plugin> 
+    </plugins> 
+  </reporting>
+</project>

Propchange: maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-site-plugin/src/test/projects/site-plugin-test10/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"