Skip to content

Commit

Permalink
[MPLUGIN-529] Add new report goal 'report-no-fork' which will not inv…
Browse files Browse the repository at this point in the history
…oke process-classes

Co-authored-by: Michael Osipov <michaelo@apache.org>

This closes apache#310
  • Loading branch information
mattnelson committed Aug 1, 2024
1 parent d134a27 commit 6cceb85
Show file tree
Hide file tree
Showing 8 changed files with 530 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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 = clean verify site
136 changes: 136 additions & 0 deletions maven-plugin-report-plugin/src/it/plugin-no-fork-report/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?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.its</groupId>
<artifactId>plugin-no-fork-report</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>MPLUGIN-529</name>
<description>
Test non-forking goals to guard against regression of MPLUGIN-529.
</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>@maven3Version@</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>@maven3Version@</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>@maven3Version@</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>@reportingApiVersion@</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>@reportingImplVersion@</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>@compilerPluginVersion@</version>
<configuration>
<!-- old maven-parent, so fix it like this. -->
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<phase>validate</phase>
<configuration>
<rules>
<AlwaysPass />
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<goalPrefix>prefix</goalPrefix>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>@sitePluginVersion@</version>
<configuration>
<locales>en,de,fr</locales>
</configuration>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-report-plugin</artifactId>
<version>@project.version@</version>
<reportSets>
<reportSet>
<reports>
<report>report-no-fork</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* 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.
*/
package org;

import java.io.File;
import java.util.Locale;
import java.util.ResourceBundle;

import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.siterenderer.Renderer;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;

/**
* Dummy Reporting Plugin.
*
* @goal report
* @requiresReports true
* @execute phase="compile"
*/
public class DummyReport extends AbstractMavenReport {
/**
* Report output directory.
*
* @parameter default-value="${project.build.directory}/generated-site/xdoc"
*/
private File outputDirectory;

/**
* Doxia Site Renderer.
*
* @component
*/
private Renderer siteRenderer;

/**
* The Maven Project.
*
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;

/**
* The goal prefix that will appear before the ":".
*
* @parameter expression="${goalPrefix}"
* @since 2.4
*/
protected String goalPrefix;

/**
* Set this to "true" to skip invoking any goals or reports of the plugin.
*
* @parameter default-value="false" expression="${maven.plugin.skip}"
* @since 2.8
*/
private boolean skip;

/**
* Set this to "true" to skip generating the report.
*
* @parameter default-value="false" expression="${maven.plugin.report.skip}"
* @since 2.8
*/
private boolean skipReport;

/** {@inheritDoc} */
protected Renderer getSiteRenderer() {
return siteRenderer;
}

/** {@inheritDoc} */
protected String getOutputDirectory() {
return outputDirectory.getPath();
}

/** {@inheritDoc} */
protected MavenProject getProject() {
return project;
}

/** {@inheritDoc} */
public boolean canGenerateReport() {
if (skip || skipReport) {
getLog().info("Maven Plugin Plugin Report generation skipped.");
return false;
}

return true;
}

/** {@inheritDoc} */
protected void executeReport(Locale locale) throws MavenReportException {
// Generate the plugin's documentation
generatePluginDocumentation(locale);
}

/** {@inheritDoc} */
public String getDescription(Locale locale) {
return getBundle(locale).getString("report.plugin.description");
}

/** {@inheritDoc} */
public String getName(Locale locale) {
return getBundle(locale).getString("report.plugin.name");
}

/** {@inheritDoc} */
public String getOutputName() {
return "plugin-info";
}

/**
* @param pluginDescriptor not null
* @param locale not null
* @throws MavenReportException if any
*/
private void generatePluginDocumentation(Locale locale) throws MavenReportException {
File outputDir = new File(getOutputDirectory());
outputDir.mkdirs();
PluginOverviewRenderer r = new PluginOverviewRenderer(getSink(), locale);
r.render();
}

/**
* @param locale not null
* @return the bundle for this report
*/
protected static ResourceBundle getBundle(Locale locale) {
return ResourceBundle.getBundle("plugin-report", locale, DummyReport.class.getClassLoader());
}

/**
* Generates an overview page with the list of goals
* and a link to the goal's page.
*/
static class PluginOverviewRenderer extends AbstractMavenReportRenderer {
private final Locale locale;

/**
* @param sink not null
* @param locale not null
*/
PluginOverviewRenderer(Sink sink, Locale locale) {
super(sink);

this.locale = locale;
}

/** {@inheritDoc} */
public String getTitle() {
return getBundle(locale).getString("report.plugin.title");
}

/** {@inheritDoc} */
protected void renderBody() {
startSection(getTitle());
paragraph("This is a report.");
endSection();
}
}
}
Loading

0 comments on commit 6cceb85

Please sign in to comment.