You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by lt...@apache.org on 2011/03/02 13:37:04 UTC

svn commit: r1076195 - in /maven/plugins/trunk/maven-site-plugin/src: it/MSITE-159/ it/MSITE-159/src/ it/MSITE-159/src/site/ it/MSITE-159/src/site/apt/ main/java/org/apache/maven/plugins/site/

Author: ltheussl
Date: Wed Mar  2 12:37:04 2011
New Revision: 1076195

URL: http://svn.apache.org/viewvc?rev=1076195&view=rev
Log:
[MSITE-159] make relativization of links customizable

Added:
    maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/
    maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/invoker.properties
    maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/pom.xml
    maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/
    maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/
    maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/apt/
    maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/apt/index.apt
    maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/site.xml
    maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/verify.bsh
Modified:
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java

Added: maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/invoker.properties?rev=1076195&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/invoker.properties (added)
+++ maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/invoker.properties Wed Mar  2 12:37:04 2011
@@ -0,0 +1,2 @@
+invoker.maven.version = 3.0-
+invoker.goals.1 = clean site:site

Added: maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/pom.xml?rev=1076195&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/pom.xml (added)
+++ maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/pom.xml Wed Mar  2 12:37:04 2011
@@ -0,0 +1,50 @@
+<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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>msite159</groupId>
+  <artifactId>check</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <name>MSITE-159</name>
+
+  <url>http://webhost.company.com/</url>
+
+  <distributionManagement>
+    <site>
+      <id>website</id>
+      <url>scp://webhost.company.com/www/website</url>
+    </site>
+  </distributionManagement>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-site-plugin</artifactId>
+          <version>@project.version@</version>
+          <configuration>
+            <relativizeDecorationLinks>false</relativizeDecorationLinks>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+  <reporting>
+    <plugins>
+      <plugin>
+        <artifactId>maven-project-info-reports-plugin</artifactId>
+        <version>2.3.1</version>
+        <reportSets>
+          <reportSet>
+            <reports>
+              <report>index</report>
+            </reports>
+          </reportSet>
+        </reportSets>
+      </plugin>
+    </plugins>
+  </reporting>
+
+</project>

Added: maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/apt/index.apt?rev=1076195&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/apt/index.apt (added)
+++ maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/apt/index.apt Wed Mar  2 12:37:04 2011
@@ -0,0 +1,18 @@
+ -----
+ Title Here
+ -----
+ Author Here
+ -----
+ Date Here
+ -----
+
+Maven Site for your project
+
+ Congratulations! If you are looking at this page then you have successfully generated a
+ template site employing the site archetype and you have run:
+  
++-----+
+
+mvn site
+
++-----+

Added: maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/site.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/site.xml?rev=1076195&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/site.xml (added)
+++ maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/src/site/site.xml Wed Mar  2 12:37:04 2011
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<project name="Maven" xmlns="http://maven.apache.org/DECORATION/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd">
+
+  <body>
+    <links>
+      <item name="Link" href="http://webhost.company.com/"/>
+    </links>
+    <breadcrumbs>
+      <item name="Breadcrumb" href="http://webhost.company.com/index.html"/>
+    </breadcrumbs>
+
+    <menu name="Documentation">
+      <item name="Home" href="index.html"/>
+      <item name="Menu" href="http://webhost.company.com/"/>
+    </menu>
+  </body>
+</project>

Added: maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/verify.bsh?rev=1076195&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/verify.bsh (added)
+++ maven/plugins/trunk/maven-site-plugin/src/it/MSITE-159/verify.bsh Wed Mar  2 12:37:04 2011
@@ -0,0 +1,59 @@
+
+/*
+ * 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.*;
+
+import org.codehaus.plexus.util.*;
+
+boolean result = true;
+
+try
+{
+    final File siteDirectory = new File ( basedir, "target/site" );
+    if ( !siteDirectory.exists() || !siteDirectory.isDirectory() )
+    {
+        System.err.println( "site is missing or not a directory." );
+        result = false;
+    }
+
+    File index = new File ( siteDirectory, "index.html" );
+    if ( !index.exists() || index.isDirectory() )
+    {
+        System.err.println( "no index file or is a directory." );
+        result = false;
+    }
+
+    String content = IOUtil.toString ( new FileInputStream ( index ), "UTF-8" );
+    int index1 = content.indexOf( "<a href=\"http://webhost.company.com/index.html\" class=\"externalLink\" title=\"Breadcrumb\">Breadcrumb</a>" );
+    int index2 = content.indexOf( "<a href=\"http://webhost.company.com/\" class=\"externalLink\" title=\"Link\">Link</a>" );
+    int index3 = content.indexOf( "<a href=\"http://webhost.company.com/\" class=\"externalLink\" title=\"Menu\">Menu</a>" );
+    if ( index1 < 0 || index2 < 0 || index3 < 0 )
+    {
+        System.err.println( "index.html has incorrect links!" );
+        result = false;
+    }
+}
+catch( IOException e )
+{
+    e.printStackTrace();
+    result = false;
+}
+
+return result;

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java?rev=1076195&r1=1076194&r2=1076195&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java (original)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java Wed Mar  2 12:37:04 2011
@@ -170,6 +170,19 @@ public abstract class AbstractSiteRender
      */
     protected File generatedSiteDirectory;
 
+    /**
+     * Make links in the site descriptor relative to the project URL.
+     * By default, any absolute links that appear in the site descriptor,
+     * e.g. banner hrefs, breadcrumbs, menu links, etc., will be made relative to project.url.
+     *
+     * Links will not be changed if this is set to false, or if the project has no URL defined.
+     *
+     * @parameter expression="${relativizeDecorationLinks}" default-value="true"
+     *
+     * @since 2.3
+     */
+    private boolean relativizeDecorationLinks;
+
     protected List<MavenReport> filterReports( List<MavenReport> reports )
     {
         List<MavenReport> filteredReports = new ArrayList<MavenReport>( reports.size() );
@@ -221,6 +234,22 @@ public abstract class AbstractSiteRender
         {
             throw new MojoExecutionException( "SiteToolException: " + e.getMessage(), e );
         }
+
+        if ( relativizeDecorationLinks )
+        {
+            final String url = project.getUrl();
+
+            if ( url == null )
+            {
+                getLog().warn( "No project URL defined - decoration links will not be relativized!" );
+            }
+            else
+            {
+                getLog().info( "Relativizing decoration links with respect to project URL: " + url );
+                assembler.resolvePaths( decorationModel, url );
+            }
+        }
+
         if ( template != null )
         {
             if ( templateFile != null )