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/07/01 10:22:30 UTC

[maven-site-plugin] branch MSITE-842 updated (d6b4a0f -> 7d3bb8c)

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.


 discard d6b4a0f  Drop license header for testing purposes
 discard 512abf5  [MSITE-842] $currentFileName and $alignedFileName are incorrect for Maven Report plugins that use several Sink instances
     new 7d3bb8c  [MSITE-842] $currentFileName and $alignedFileName are incorrect for Maven Report plugins that use several Sink instances

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (d6b4a0f)
            \
             N -- N -- N   refs/heads/MSITE-842 (7d3bb8c)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 src/it/projects/MSITE-842/src/it/MSITE-842.html       | 19 +++++++++++++++++++
 src/it/projects/MSITE-842/src/it/another-page.html    | 19 +++++++++++++++++++
 src/it/projects/MSITE-842/src/it/sub/sub.html         | 19 +++++++++++++++++++
 src/it/projects/MSITE-842/src/site/show-properties.vm | 19 +++++++++++++++++++
 4 files changed, 76 insertions(+)


[maven-site-plugin] 01/01: [MSITE-842] $currentFileName and $alignedFileName are incorrect for Maven Report plugins that use several Sink instances

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 7d3bb8cf04f951723feb28fb5fcf7286776bb74e
Author: Bertrand Martin <be...@sentrysoftware.com>
AuthorDate: Wed Jun 26 20:28:26 2019 +0200

    [MSITE-842] $currentFileName and $alignedFileName are incorrect for Maven Report plugins that use several Sink instances
    
    * Ensured that the actual filename of the Sink being rendered is exposed in RenderingContext for multi-page reports
    * Subpages (or subsinks) in subdirectories are now supported
    
    This closes #8
---
 src/it/projects/MSITE-842/invoker.properties       |  21 +++++
 src/it/projects/MSITE-842/pom.xml                  |  93 +++++++++++++++++++
 src/it/projects/MSITE-842/src/it/MSITE-842.html    |  26 ++++++
 src/it/projects/MSITE-842/src/it/another-page.html |  26 ++++++
 src/it/projects/MSITE-842/src/it/sub/sub.html      |  26 ++++++
 .../java/org/apache/maven/plugins/it/MyReport.java | 100 +++++++++++++++++++++
 .../projects/MSITE-842/src/site/show-properties.vm |  26 ++++++
 src/it/projects/MSITE-842/verify.groovy            |  44 +++++++++
 .../site/render/ReportDocumentRenderer.java        |  68 +++++++++++---
 9 files changed, 420 insertions(+), 10 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..470ef86
--- /dev/null
+++ b/src/it/projects/MSITE-842/pom.xml
@@ -0,0 +1,93 @@
+<?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..4aea73d
--- /dev/null
+++ b/src/it/projects/MSITE-842/src/it/MSITE-842.html
@@ -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 = 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..b95cde3
--- /dev/null
+++ b/src/it/projects/MSITE-842/src/it/another-page.html
@@ -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 = 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..94838ae
--- /dev/null
+++ b/src/it/projects/MSITE-842/src/it/sub/sub.html
@@ -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 = ../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..c00c6fc
--- /dev/null
+++ b/src/it/projects/MSITE-842/src/main/java/org/apache/maven/plugins/it/MyReport.java
@@ -0,0 +1,100 @@
+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..f51d49e
--- /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..dcf6e07 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;
 
@@ -65,7 +66,7 @@ public class ReportDocumentRenderer
     private final String reportMojoInfo;
 
     private final ClassLoader classLoader;
-    
+
     private final Log log;
 
     public ReportDocumentRenderer( MavenReportExecution mavenReportExecution, RenderingContext renderingContext,
@@ -95,7 +96,7 @@ public class ReportDocumentRenderer
 
     /**
      * Get plugin information from report's Manifest.
-     * 
+     *
      * @param report the Maven report
      * @return plugin information as Specification Title followed by Specification Version if set in Manifest and
      *         supported by JVM
@@ -108,7 +109,7 @@ public class ReportDocumentRenderer
         {
             String title = pkg.getSpecificationTitle();
             String version = pkg.getSpecificationVersion();
-            
+
             if ( title == null )
             {
                 return version;
@@ -133,9 +134,9 @@ public class ReportDocumentRenderer
 
         private String outputName;
 
-        MultiPageSubSink( File outputDir, String outputName, RenderingContext ctx )
+        MultiPageSubSink( File outputDir, String outputName, RenderingContext context )
         {
-            super( ctx );
+            super( context );
             this.outputName = outputName;
             this.outputDir = outputDir;
         }
@@ -155,22 +156,56 @@ public class ReportDocumentRenderer
     private static class MultiPageSinkFactory
         implements SinkFactory
     {
+        /**
+         * The report that is (maybe) generating multiple pages
+         */
+        private MavenReport report;
+
+        /**
+         * The main RenderingContext, which is the base for the RenderingContext of subpages
+         */
         private RenderingContext context;
 
+        /**
+         * List of sinks (subpages) associated to this report
+         */
         private List<MultiPageSubSink> sinks = new ArrayList<MultiPageSubSink>();
 
-        MultiPageSinkFactory( RenderingContext ctx )
+        MultiPageSinkFactory( MavenReport report, RenderingContext context )
         {
-            this.context = ctx;
+            this.report = report;
+            this.context = context;
         }
 
+        @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 subSinkContext = new RenderingContext(
+                context.getBasedir(),
+                context.getBasedirRelativePath(),
+                outputRelativeToTargetSite,
+                context.getParserId(),
+                context.getExtension(),
+                context.isEditable(),
+                context.getGenerator()
+            );
+
+            // Create a sink for this subpage, based on this new context
+            MultiPageSubSink sink = new MultiPageSubSink( outputDir, outputName, subSinkContext );
+
+            // Add it to the list of sinks associated to this report
             sinks.add( sink );
+
             return sink;
         }
 
+        @Override
         public Sink createSink( File arg0, String arg1, String arg2 )
             throws IOException
         {
@@ -178,6 +213,7 @@ public class ReportDocumentRenderer
             return null;
         }
 
+        @Override
         public Sink createSink( OutputStream arg0 )
             throws IOException
         {
@@ -185,6 +221,7 @@ public class ReportDocumentRenderer
             return null;
         }
 
+        @Override
         public Sink createSink( OutputStream arg0, String arg1 )
             throws IOException
         {
@@ -198,6 +235,7 @@ public class ReportDocumentRenderer
         }
     }
 
+    @Override
     public void renderDocument( Writer writer, Renderer renderer, SiteRenderingContext siteRenderingContext )
         throws RendererException, FileNotFoundException
     {
@@ -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,12 @@ 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() ) )
@@ -313,7 +357,7 @@ public class ReportDocumentRenderer
 
     /**
      * Try to generate report with extended multi-page API.
-     * 
+     *
      * @return <code>true</code> if the report was compatible with the extended API
      */
     private boolean generateMultiPage( Locale locale, SinkFactory sf, Sink sink )
@@ -344,16 +388,19 @@ public class ReportDocumentRenderer
         }
     }
 
+    @Override
     public String getOutputName()
     {
         return renderingContext.getOutputName();
     }
 
+    @Override
     public RenderingContext getRenderingContext()
     {
         return renderingContext;
     }
 
+    @Override
     public boolean isOverwrite()
     {
         // TODO: would be nice to query the report to see if it is modified
@@ -363,6 +410,7 @@ public class ReportDocumentRenderer
     /**
      * @return true if the current report is external, false otherwise
      */
+    @Override
     public boolean isExternalReport()
     {
         return report.isExternalReport();