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-ffa450edef68master
parent
b123530814
commit
4abefe4080
|
|
@ -0,0 +1 @@
|
||||||
|
invoker.goals = clean site -DskipTests
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
<?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>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.apache.maven.its</groupId>
|
||||||
|
<artifactId>plugin-report</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>maven-plugin</packaging>
|
||||||
|
|
||||||
|
<name>MPLUGIN-105</name>
|
||||||
|
<description>
|
||||||
|
Test basic site generation to guard against regression.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-plugin-api</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||||
|
<artifactId>maven-plugin-annotations</artifactId>
|
||||||
|
<version>@project.version@</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.reporting</groupId>
|
||||||
|
<artifactId>maven-reporting-impl</artifactId>
|
||||||
|
<version>2.0.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.reporting</groupId>
|
||||||
|
<artifactId>maven-reporting-api</artifactId>
|
||||||
|
<version>3.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-plugin-plugin</artifactId>
|
||||||
|
<version>@project.version@</version>
|
||||||
|
<configuration>
|
||||||
|
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>mojo-descriptor</id>
|
||||||
|
<goals>
|
||||||
|
<goal>descriptor</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>@sitePluginVersion@</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<reportSets>
|
||||||
|
<reportSet>
|
||||||
|
<reports>
|
||||||
|
<report>index</report>
|
||||||
|
</reports>
|
||||||
|
</reportSet>
|
||||||
|
</reportSets>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-plugin-plugin</artifactId>
|
||||||
|
<version>@project.version@</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
|
</project>
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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}/</markup-must-be-escaped>" )
|
||||||
|
private String string;
|
||||||
|
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
// intentional do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -19,6 +19,8 @@ package org.apache.maven.plugin.plugin;
|
||||||
* under the License.
|
* 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.sink.Sink;
|
||||||
import org.apache.maven.doxia.siterenderer.Renderer;
|
import org.apache.maven.doxia.siterenderer.Renderer;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
|
|
@ -48,6 +50,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the Plugin's documentation report.
|
* Generates the Plugin's documentation report.
|
||||||
|
|
@ -56,7 +59,7 @@ import java.util.ResourceBundle;
|
||||||
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
|
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
* @goal report
|
* @goal report
|
||||||
* @execute phase="compile"
|
* @execute phase="process-classes"
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class PluginReport
|
public class PluginReport
|
||||||
|
|
@ -158,6 +161,36 @@ public class PluginReport
|
||||||
*/
|
*/
|
||||||
private boolean skipReport;
|
private boolean skipReport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The set of dependencies for the current project
|
||||||
|
*
|
||||||
|
* @parameter default-value = "${project.artifacts}"
|
||||||
|
* @required
|
||||||
|
* @readonly
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
protected Set<Artifact> dependencies;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of Remote Repositories used by the resolver
|
||||||
|
*
|
||||||
|
* @parameter expression="${project.remoteArtifactRepositories}"
|
||||||
|
* @readonly
|
||||||
|
* @required
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
protected List<ArtifactRepository> remoteRepos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Location of the local repository.
|
||||||
|
*
|
||||||
|
* @parameter expression="${localRepository}"
|
||||||
|
* @readonly
|
||||||
|
* @required
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
protected ArtifactRepository local;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -236,6 +269,11 @@ public class PluginReport
|
||||||
|
|
||||||
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
|
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
|
||||||
request.setEncoding( encoding );
|
request.setEncoding( encoding );
|
||||||
|
request.setSkipErrorNoDescriptorsFound( true );
|
||||||
|
request.setDependencies( dependencies );
|
||||||
|
request.setLocal( this.local );
|
||||||
|
request.setRemoteRepos( this.remoteRepos );
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue