Skip to content

Commit

Permalink
[MSITE-842] $currentFileName and $alignedFileName are incorrect for M…
Browse files Browse the repository at this point in the history
…aven 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
  • Loading branch information
bertysentry authored and michael-o committed Jul 1, 2019
1 parent fd563ae commit 42617d0
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 10 deletions.
21 changes: 21 additions & 0 deletions src/it/projects/MSITE-842/invoker.properties
Original file line number Diff line number Diff line change
@@ -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+
93 changes: 93 additions & 0 deletions src/it/projects/MSITE-842/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
26 changes: 26 additions & 0 deletions src/it/projects/MSITE-842/src/it/MSITE-842.html
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions src/it/projects/MSITE-842/src/it/another-page.html
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions src/it/projects/MSITE-842/src/it/sub/sub.html
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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" );

}
}
26 changes: 26 additions & 0 deletions src/it/projects/MSITE-842/src/site/show-properties.vm
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions src/it/projects/MSITE-842/verify.groovy
Original file line number Diff line number Diff line change
@@ -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.normalize().equals(expectedFile.text.normalize())

// 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.normalize().equals(expectedFile.text.normalize())

// 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.normalize().equals(expectedFile.text.normalize())

Loading

0 comments on commit 42617d0

Please sign in to comment.