From 4abefe4080a51de1b09e2b022b358645bc9181ac Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 14 May 2012 21:33:29 +0000 Subject: [PATCH] add it test for plugin report with annotations git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1338439 13f79535-47bb-0310-9956-ffa450edef68 --- .../invoker.properties | 1 + .../src/it/plugin-report-annotations/pom.xml | 110 +++++++++ .../src/main/java/org/DummyReport.java | 227 ++++++++++++++++++ .../src/main/java/org/MyMojo.java | 65 +++++ .../it/plugin-report-annotations/verify.bsh | 36 +++ .../maven/plugin/plugin/PluginReport.java | 40 ++- 6 files changed, 478 insertions(+), 1 deletion(-) create mode 100644 maven-plugin-plugin/src/it/plugin-report-annotations/invoker.properties create mode 100644 maven-plugin-plugin/src/it/plugin-report-annotations/pom.xml create mode 100644 maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/DummyReport.java create mode 100644 maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/MyMojo.java create mode 100644 maven-plugin-plugin/src/it/plugin-report-annotations/verify.bsh diff --git a/maven-plugin-plugin/src/it/plugin-report-annotations/invoker.properties b/maven-plugin-plugin/src/it/plugin-report-annotations/invoker.properties new file mode 100644 index 0000000..8a7b3cb --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-report-annotations/invoker.properties @@ -0,0 +1 @@ +invoker.goals = clean site -DskipTests diff --git a/maven-plugin-plugin/src/it/plugin-report-annotations/pom.xml b/maven-plugin-plugin/src/it/plugin-report-annotations/pom.xml new file mode 100644 index 0000000..88a3e29 --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-report-annotations/pom.xml @@ -0,0 +1,110 @@ + + + + + + 4.0.0 + + org.apache.maven.its + plugin-report + 1.0-SNAPSHOT + maven-plugin + + MPLUGIN-105 + + Test basic site generation to guard against regression. + + + + UTF-8 + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven.plugin-tools + maven-plugin-annotations + @project.version@ + compile + + + org.apache.maven.reporting + maven-reporting-impl + 2.0.5 + + + org.apache.maven.reporting + maven-reporting-api + 3.0 + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + true + + + + mojo-descriptor + + descriptor + + + + + + org.apache.maven.plugins + maven-site-plugin + @sitePluginVersion@ + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.4 + + + + index + + + + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + + + diff --git a/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/DummyReport.java b/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/DummyReport.java new file mode 100644 index 0000000..f7ed0c5 --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/DummyReport.java @@ -0,0 +1,227 @@ +package org; + +/* + * 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.doxia.siterenderer.Renderer; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.maven.reporting.AbstractMavenReport; +import org.apache.maven.reporting.AbstractMavenReportRenderer; +import org.apache.maven.reporting.MavenReportException; + +import java.io.File; +import java.util.Locale; +import java.util.ResourceBundle; + +/** + * Dummy Reporting Plugin. + */ +@Mojo( name = "report", requiresReports = true ) +@Execute( phase = LifecyclePhase.COMPILE ) +public class DummyReport + extends AbstractMavenReport +{ + /** + * Report output directory. + */ + @Parameter( defaultValue = "${project.build.directory}/generated-site/xdoc" ) + private File outputDirectory; + + /** + * Doxia Site Renderer. + */ + @Component + private Renderer siteRenderer; + + /** + * The Maven Project. + */ + @Parameter( expression = "${project}", readonly = true, required = true ) + private MavenProject project; + + + /** + * The goal prefix that will appear before the ":". + * + * @since 2.4 + */ + @Parameter( expression = "${goalPrefix}" ) + protected String goalPrefix; + + /** + * Set this to "true" to skip invoking any goals or reports of the plugin. + * + * @since 2.8 + */ + @Parameter( defaultValue = "false", expression = "${maven.plugin.skip}" ) + private boolean skip; + + /** + * Set this to "true" to skip generating the report. + * + * @since 2.8 + */ + @Parameter( defaultValue = "false", expression = "${maven.plugin.report.skip}" ) + 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() + { + return true; + } + + /** + * {@inheritDoc} + */ + protected void executeReport( Locale locale ) + throws MavenReportException + { + if ( !canGenerateReport() ) + { + return; + } + if ( skip || skipReport ) + { + getLog().info( "Maven Plugin Plugin Report generation skipped." ); + return; + } + + // 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 project not null + * @param sink not null + * @param locale not null + */ + public PluginOverviewRenderer( Sink sink, Locale locale ) + { + super( sink ); + + this.locale = locale; + } + + /** + * {@inheritDoc} + */ + public String getTitle() + { + return getBundle( locale ).getString( "report.plugin.title" ); + } + + /** + * {@inheritDoc} + */ + public void renderBody() + { + startSection( getTitle() ); + paragraph( "This is a report." ); + endSection(); + } + } +} diff --git a/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/MyMojo.java b/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/MyMojo.java new file mode 100644 index 0000000..a65c175 --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/MyMojo.java @@ -0,0 +1,65 @@ +package org; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.DependencyScope; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Does nothing. + * + * @since 1.0 + * @deprecated You don't use test goals, do you? + */ +@Mojo( name = "noop", defaultPhase = LifecyclePhase.PROCESS_SOURCES, + requiresDependencyResolution = DependencyScope.TEST, + requiresDirectInvocation = true, requiresOnline = true, inheritByDefault = false, aggregator = true ) +@Execute( phase = LifecyclePhase.COMPILE ) +public class MyMojo + extends AbstractMojo +{ + + /** + * This is a test. + */ + @SuppressWarnings( "unused" ) + @Parameter( required = true ) + private String required; + + /** + * This is a test. + * + * @since 1.1 + * @deprecated Just testing. + */ + @SuppressWarnings( "unused" ) + @Parameter( expression = "${string}", defaultValue = "${project.version}/" ) + private String string; + + public void execute() + { + // intentional do nothing + } + +} diff --git a/maven-plugin-plugin/src/it/plugin-report-annotations/verify.bsh b/maven-plugin-plugin/src/it/plugin-report-annotations/verify.bsh new file mode 100644 index 0000000..f6a85d5 --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-report-annotations/verify.bsh @@ -0,0 +1,36 @@ +import java.io.*; +import java.util.*; +import java.util.regex.*; + +try +{ + File siteDir = new File( basedir, "target/site" ); + System.out.println( "Checking for existence of site directory: " + siteDir ); + if ( !siteDir.isDirectory() ) + { + System.out.println( "FAILED!" ); + return false; + } + + String[] expectedFiles = { + "noop-mojo.html", + "report-mojo.html", + }; + for ( String path : expectedFiles ) + { + File file = new File( siteDir, path ); + System.out.println( "Checking for existence of doc file: " + file ); + if ( !file.isFile() || file.length() <= 0 ) + { + System.out.println( "FAILED!" ); + return false; + } + } +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java index c74fd95..26aee7c 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java @@ -19,6 +19,8 @@ package org.apache.maven.plugin.plugin; * under the License. */ +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.siterenderer.Renderer; import org.apache.maven.model.Plugin; @@ -48,6 +50,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; +import java.util.Set; /** * Generates the Plugin's documentation report. @@ -56,7 +59,7 @@ import java.util.ResourceBundle; * @author Vincent Siveton * @version $Id$ * @goal report - * @execute phase="compile" + * @execute phase="process-classes" * @since 2.0 */ public class PluginReport @@ -158,6 +161,36 @@ public class PluginReport */ private boolean skipReport; + /** + * The set of dependencies for the current project + * + * @parameter default-value = "${project.artifacts}" + * @required + * @readonly + * @since 3.0 + */ + protected Set dependencies; + + /** + * List of Remote Repositories used by the resolver + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @readonly + * @required + * @since 3.0 + */ + protected List remoteRepos; + + /** + * Location of the local repository. + * + * @parameter expression="${localRepository}" + * @readonly + * @required + * @since 3.0 + */ + protected ArtifactRepository local; + /** * {@inheritDoc} */ @@ -236,6 +269,11 @@ public class PluginReport PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor ); request.setEncoding( encoding ); + request.setSkipErrorNoDescriptorsFound( true ); + request.setDependencies( dependencies ); + request.setLocal( this.local ); + request.setRemoteRepos( this.remoteRepos ); + try {