You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2019/06/26 20:36:51 UTC

[maven-site-plugin] branch MSITE-842 created (now 474320a)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch MSITE-842
in repository https://gitbox.apache.org/repos/asf/maven-site-plugin.git.


      at 474320a  MSITE-842

This branch includes the following new commits:

     new 474320a  MSITE-842

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-site-plugin] 01/01: MSITE-842

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MSITE-842
in repository https://gitbox.apache.org/repos/asf/maven-site-plugin.git

commit 474320a5deee56fd2c55a6f17a6f2ac0a0c6a9f7
Author: Bertrand Martin <be...@sentrysoftware.com>
AuthorDate: Wed Jun 26 20:28:26 2019 +0200

    MSITE-842
    
    * Ensured that the actual filename of the Sink being rendered is exposed in RenderingContext for multi-page reports
    * Sub-pages (or sub-sinks) in subdirectories are now supported
---
 src/it/projects/MSITE-842/invoker.properties       | 21 +++++
 src/it/projects/MSITE-842/pom.xml                  | 84 ++++++++++++++++++++
 src/it/projects/MSITE-842/src/it/MSITE-842.html    |  9 +++
 src/it/projects/MSITE-842/src/it/another-page.html |  9 +++
 src/it/projects/MSITE-842/src/it/sub/sub.html      |  9 +++
 .../java/org/apache/maven/plugins/it/MyReport.java | 91 ++++++++++++++++++++++
 .../projects/MSITE-842/src/site/show-properties.vm | 26 +++++++
 src/it/projects/MSITE-842/verify.groovy            | 44 +++++++++++
 .../site/render/ReportDocumentRenderer.java        | 71 ++++++++++++++---
 9 files changed, 352 insertions(+), 12 deletions(-)

diff --git a/src/it/projects/MSITE-842/invoker.properties b/src/it/projects/MSITE-842/invoker.properties
new file mode 100644
index 0000000..2381059
--- /dev/null
+++ b/src/it/projects/MSITE-842/invoker.properties
@@ -0,0 +1,21 @@
+# 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.
+
+invoker.goals.1 = clean install
+invoker.debug.1 = false
+invoker.goals.2 = site
+invoker.maven.version = 3.0+
\ No newline at end of file
diff --git a/src/it/projects/MSITE-842/pom.xml b/src/it/projects/MSITE-842/pom.xml
new file mode 100644
index 0000000..f502dc2
--- /dev/null
+++ b/src/it/projects/MSITE-842/pom.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- 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. -->
+
+<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>org.apache.maven.plugins.site.its</groupId>
+	<artifactId>MSITE-842</artifactId>
+	<version>1.0-SNAPSHOT</version>
+	<packaging>maven-plugin</packaging>
+
+	<name>it-plugin-test Maven Mojo</name>
+	<url>http://maven.apache.org</url>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.maven.reporting</groupId>
+			<artifactId>maven-reporting-impl</artifactId>
+			<version>3.0.0</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+
+		<pluginManagement>
+			<plugins>
+				<plugin>
+					<groupId>org.apache.maven.plugins</groupId>
+					<artifactId>maven-site-plugin</artifactId>
+					<version>@project.version@</version>
+				</plugin>
+			</plugins>
+		</pluginManagement>
+
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-site-plugin</artifactId>
+				<configuration>
+					<templateFile>${basedir}/src/site/show-properties.vm</templateFile>
+				</configuration>
+			</plugin>
+		</plugins>
+
+	</build>
+
+	<reporting>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins.site.its</groupId>
+				<artifactId>MSITE-842</artifactId>
+				<version>${project.version}</version>
+			</plugin>
+	        <plugin>
+	            <groupId>org.apache.maven.plugins</groupId>
+	            <artifactId>maven-project-info-reports-plugin</artifactId>
+	            <version>2.9</version>
+	            <reportSets>
+	                <reportSet>
+	                    <configuration>
+	                        <skip>true</skip>
+	                    </configuration>
+	                </reportSet>
+	            </reportSets>
+	        </plugin>
+		</plugins>
+	</reporting>
+</project>
diff --git a/src/it/projects/MSITE-842/src/it/MSITE-842.html b/src/it/projects/MSITE-842/src/it/MSITE-842.html
new file mode 100644
index 0000000..feb6006
--- /dev/null
+++ b/src/it/projects/MSITE-842/src/it/MSITE-842.html
@@ -0,0 +1,9 @@
+
+
+alignedFileName = MSITE-842.html
+
+currentFileName = MSITE-842.html
+
+getRelativePath() = .
+
+content = Main Sink
diff --git a/src/it/projects/MSITE-842/src/it/another-page.html b/src/it/projects/MSITE-842/src/it/another-page.html
new file mode 100644
index 0000000..49481da
--- /dev/null
+++ b/src/it/projects/MSITE-842/src/it/another-page.html
@@ -0,0 +1,9 @@
+
+
+alignedFileName = another-page.html
+
+currentFileName = another-page.html
+
+getRelativePath() = .
+
+content = Another Sink
diff --git a/src/it/projects/MSITE-842/src/it/sub/sub.html b/src/it/projects/MSITE-842/src/it/sub/sub.html
new file mode 100644
index 0000000..a09f44e
--- /dev/null
+++ b/src/it/projects/MSITE-842/src/it/sub/sub.html
@@ -0,0 +1,9 @@
+
+
+alignedFileName = ../sub/sub.html
+
+currentFileName = sub/sub.html
+
+getRelativePath() = ..
+
+content = Subdirectory Sink
diff --git a/src/it/projects/MSITE-842/src/main/java/org/apache/maven/plugins/it/MyReport.java b/src/it/projects/MSITE-842/src/main/java/org/apache/maven/plugins/it/MyReport.java
new file mode 100644
index 0000000..0ea4196
--- /dev/null
+++ b/src/it/projects/MSITE-842/src/main/java/org/apache/maven/plugins/it/MyReport.java
@@ -0,0 +1,91 @@
+package org.apache.maven.plugins.it;
+
+/*
+ * 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 org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Locale;
+
+/**
+ * Goal which creates several pages in a report.
+ *
+ * @goal test
+ * @phase site
+ */
+public class MyReport
+    extends AbstractMavenReport
+{
+
+    public String getOutputName()
+    {
+        return "MSITE-842";
+    }
+
+    public String getName( Locale locale )
+    {
+        return "MSITE-842";
+    }
+
+    public String getDescription( Locale locale )
+    {
+        return "Test Report for MSITE-842";
+    }
+
+    @Override
+    protected void executeReport( Locale locale ) throws MavenReportException
+    {
+    	// Main Sink
+    	Sink mainSink = getSink();
+    	if (mainSink == null) {
+    		throw new MavenReportException("Could not get the main Sink");
+    	}
+
+    	// Write to the main Sink
+    	mainSink.text("Main Sink");
+
+		// Create a new sink!
+		Sink anotherSink;
+		try {
+			anotherSink = getSinkFactory().createSink(outputDirectory, "another-page.html");
+		} catch (IOException e) {
+			throw new MavenReportException("Could not create sink for another-page.html in " + outputDirectory.getAbsolutePath(), e);
+		}
+
+		// Write to the other Sink
+		anotherSink.text("Another Sink");
+
+		// Create a new sink, in a subdirectory
+		File subDirectory = new File(outputDirectory, "sub");
+		Sink subDirectorySink;
+		try {
+			subDirectorySink = getSinkFactory().createSink(subDirectory, "sub.html");
+		} catch (IOException e) {
+			throw new MavenReportException("Could not create sink for sub.html in " + subDirectory.getAbsolutePath(), e);
+		}
+
+		// Write to the sink in the subdirectory
+		subDirectorySink.text("Subdirectory Sink");
+
+    }
+}
diff --git a/src/it/projects/MSITE-842/src/site/show-properties.vm b/src/it/projects/MSITE-842/src/site/show-properties.vm
new file mode 100644
index 0000000..1b58ba7
--- /dev/null
+++ b/src/it/projects/MSITE-842/src/site/show-properties.vm
@@ -0,0 +1,26 @@
+#*
+ * 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.
+ *#
+
+alignedFileName = $alignedFileName
+
+currentFileName = $currentFileName
+
+getRelativePath() = $docRenderingContext.getRelativePath()
+
+content = $bodyContent
diff --git a/src/it/projects/MSITE-842/verify.groovy b/src/it/projects/MSITE-842/verify.groovy
new file mode 100644
index 0000000..956ddf4
--- /dev/null
+++ b/src/it/projects/MSITE-842/verify.groovy
@@ -0,0 +1,44 @@
+
+/*
+ * 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.
+ */
+
+File resultFile;
+File expectedFile;
+
+// Check MSITE-842.html (must exist and be exactly like the model
+resultFile = new File(basedir, "target/site/MSITE-842.html");
+expectedFile = new File(basedir, "src/it/MSITE-842.html");
+
+assert resultFile.exists() && resultFile.isFile()
+assert resultFile.text.equals(expectedFile.text)
+
+// Check another-page.html (must exist and be exactly like the model
+resultFile = new File(basedir, "target/site/another-page.html");
+expectedFile = new File(basedir, "src/it/another-page.html");
+
+assert resultFile.exists() && resultFile.isFile()
+assert resultFile.text.equals(expectedFile.text)
+
+// Check sub/sub.html (must exist and be exactly like the model
+resultFile = new File(basedir, "target/site/sub/sub.html");
+expectedFile = new File(basedir, "src/it/sub/sub.html");
+
+assert resultFile.exists() && resultFile.isFile()
+assert resultFile.text.equals(expectedFile.text)
+
diff --git a/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java b/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java
index a5e8201..0dc7769 100644
--- a/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java
+++ b/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java
@@ -46,6 +46,7 @@ import org.apache.maven.reporting.MavenMultiPageReport;
 import org.apache.maven.reporting.MavenReport;
 import org.apache.maven.reporting.MavenReportException;
 import org.apache.maven.reporting.exec.MavenReportExecution;
+import org.codehaus.plexus.util.PathTool;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.WriterFactory;
 
@@ -155,37 +156,73 @@ public class ReportDocumentRenderer
     private static class MultiPageSinkFactory
         implements SinkFactory
     {
+        /**
+         * The report that is (may be) generating multiple pages
+         */
+        private MavenReport report;
+
+        /**
+         * The main RenderingContext, which is the base for the RenderingContext of sub-pages
+         */
         private RenderingContext context;
 
+        /**
+         * List of sinks (sub-pages) associated to this report
+         */
         private List<MultiPageSubSink> sinks = new ArrayList<MultiPageSubSink>();
 
-        MultiPageSinkFactory( RenderingContext ctx )
+        MultiPageSinkFactory( MavenReport report, RenderingContext ctx )
         {
+        	this.report = report;
             this.context = ctx;
         }
 
-        public Sink createSink( File outputDir, String outputName )
+        @Override
+		public Sink createSink( File outputDir, String outputName )
         {
-            MultiPageSubSink sink = new MultiPageSubSink( outputDir, outputName, context );
+        	// Create a new context, similar to the main one, but with a different output name
+        	String outputRelativeToTargetSite = PathTool.getRelativeFilePath(
+					report.getReportOutputDirectory().getPath(),
+					new File( outputDir, outputName ).getPath()
+				);
+
+        	RenderingContext newContext = new RenderingContext(
+        			context.getBasedir(),
+        			context.getBasedirRelativePath(),
+        			outputRelativeToTargetSite,
+        			context.getParserId(),
+        			context.getExtension(),
+        			context.isEditable(),
+        			context.getGenerator()
+        		);
+
+        	// Create a sink for this sub-page, based on this new context
+            MultiPageSubSink sink = new MultiPageSubSink( outputDir, outputName, newContext );
+
+            // Add it to the list of sinks associated to this report
             sinks.add( sink );
+
             return sink;
         }
 
-        public Sink createSink( File arg0, String arg1, String arg2 )
+        @Override
+		public Sink createSink( File arg0, String arg1, String arg2 )
             throws IOException
         {
             // Not used
             return null;
         }
 
-        public Sink createSink( OutputStream arg0 )
+        @Override
+		public Sink createSink( OutputStream arg0 )
             throws IOException
         {
             // Not used
             return null;
         }
 
-        public Sink createSink( OutputStream arg0, String arg1 )
+        @Override
+		public Sink createSink( OutputStream arg0, String arg1 )
             throws IOException
         {
             // Not used
@@ -198,7 +235,8 @@ public class ReportDocumentRenderer
         }
     }
 
-    public void renderDocument( Writer writer, Renderer renderer, SiteRenderingContext siteRenderingContext )
+    @Override
+	public void renderDocument( Writer writer, Renderer renderer, SiteRenderingContext siteRenderingContext )
         throws RendererException, FileNotFoundException
     {
         Locale locale = siteRenderingContext.getLocale();
@@ -213,7 +251,7 @@ public class ReportDocumentRenderer
         // main sink
         SiteRendererSink mainSink = new SiteRendererSink( renderingContext );
         // sink factory, for multi-page reports that need sub-sinks
-        MultiPageSinkFactory multiPageSinkFactory = new MultiPageSinkFactory( renderingContext );
+        MultiPageSinkFactory multiPageSinkFactory = new MultiPageSinkFactory( report, renderingContext );
 
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try
@@ -288,6 +326,11 @@ public class ReportDocumentRenderer
                 outputName = mySink.getOutputName();
                 log.debug( "  Rendering " + outputName );
 
+                // Create directories if necessary
+                if (!mySink.getOutputDir().exists()) {
+                	mySink.getOutputDir().mkdirs();
+                }
+
                 File outputFile = new File( mySink.getOutputDir(), outputName );
 
                 try ( Writer out = WriterFactory.newWriter( outputFile, siteRenderingContext.getOutputEncoding() ) )
@@ -344,17 +387,20 @@ public class ReportDocumentRenderer
         }
     }
 
-    public String getOutputName()
+    @Override
+	public String getOutputName()
     {
         return renderingContext.getOutputName();
     }
 
-    public RenderingContext getRenderingContext()
+    @Override
+	public RenderingContext getRenderingContext()
     {
         return renderingContext;
     }
 
-    public boolean isOverwrite()
+    @Override
+	public boolean isOverwrite()
     {
         // TODO: would be nice to query the report to see if it is modified
         return true;
@@ -363,7 +409,8 @@ public class ReportDocumentRenderer
     /**
      * @return true if the current report is external, false otherwise
      */
-    public boolean isExternalReport()
+    @Override
+	public boolean isExternalReport()
     {
         return report.isExternalReport();
     }