org.codehaus.mojo.findbugs
Class FindBugsMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.apache.maven.reporting.AbstractMavenReport
          extended by org.codehaus.mojo.findbugs.FindBugsMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo, org.apache.maven.reporting.MavenReport

public final class FindBugsMojo
extends org.apache.maven.reporting.AbstractMavenReport

Generates a FindBugs report.

Version:
$Id: FindBugsMojo.java 4041 2007-05-07 02:55:00Z gleclaire $
Author:
Cyrill Ruettimann, Detlef Pleiss, Garvin LeClaire

Field Summary
 
Fields inherited from interface org.apache.maven.reporting.MavenReport
CATEGORY_PROJECT_INFORMATION, CATEGORY_PROJECT_REPORTS, ROLE
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
FindBugsMojo()
           
 
Method Summary
protected  void addClasspathEntriesToFindBugsProject(edu.umd.cs.findbugs.Project findBugsProject)
          Adds the dependend libraries of the project to the findbugs aux classpath.
protected  void addClassScreenerToFindBugs(edu.umd.cs.findbugs.FindBugs2 findBugs)
          Adds the specified plugins to findbugs.
protected  void addFiltersToFindBugs(edu.umd.cs.findbugs.FindBugs2 findBugs)
          Adds the specified filters of the project to the findbugs.
protected  void addJavaSourcesToFindBugsProject(List pSourceFiles, edu.umd.cs.findbugs.Project findBugsProject)
          Adds the source files to the find bugs project.
protected  void addPluginsToFindBugs(Locale pLocale)
          Adds the specified plugins to findbugs.
protected  void addVisitorsToFindBugs(edu.umd.cs.findbugs.config.UserPreferences preferences)
          Adds the specified visitors to findbugs.
 boolean canGenerateReport()
          Checks whether prerequisites for generating this report are given.
protected  void debugJavaSources(Locale pLocale, List pSourceFiles)
          Lists absolute paths of java source files for denugging purposes.
protected  void debugSourceDirectory(Locale pLocale, File pSourceDirectory)
          Prints out the source roots to the logger with severity debug.
protected  void executeReport(Locale pLocale)
          Executes the generation of the report.
protected static ResourceBundle getBundle(Locale pLocale)
          Returns the resource bundle for a specific locale.
protected  String getCorePlugin(Locale pLocale)
          Retrieve the coreplugin module name
protected  File getCorePluginPath(Locale pLocale)
          Get the File reference for the Findbugs core plugin.
 String getDescription(Locale pLocale)
          Returns the plugins description for the "generated reports" overview page.
protected  EffortParameter getEffortParameter()
          Returns the effort parameter to use.
protected  List getJavaSources(Locale pLocale, File pSourceDirectory)
          Collects the java sources from the source roots.
 String getName(Locale pLocale)
          Returns the plugins name for the "generated reports" overview page and the menu.
protected  String getOutputDirectory()
          Returns the report output directory.
 String getOutputName()
          Returns report output file name, without the extension.
protected  org.apache.maven.project.MavenProject getProject()
          Returns the maven project.
protected  org.apache.maven.doxia.siterenderer.Renderer getSiteRenderer()
          Returns the doxia site renderer.
protected  ThresholdParameter getThresholdParameter()
          Returns the threshold parameter to use.
protected  edu.umd.cs.findbugs.FindBugs2 initialiseFindBugs(Locale pLocale, List pSourceFiles)
          Initialise FindBugs.
protected  Reporter initialiseReporter(org.apache.maven.doxia.sink.Sink pSink, ResourceBundle pBundle, org.apache.maven.plugin.logging.Log pLog, EffortParameter pEffortParameter)
          Initialises a reporter.
protected  boolean isJXRPluginEnabled(ResourceBundle pBundle)
          Determines if the JXR-Plugin is included in the report section of the POM.
protected  void setFindBugsDebug(edu.umd.cs.findbugs.FindBugs2 findBugs)
          Sets the Debug Level
 
Methods inherited from class org.apache.maven.reporting.AbstractMavenReport
closeReport, execute, generate, getCategoryName, getReportOutputDirectory, getSink, isExternalReport, setReportOutputDirectory
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FindBugsMojo

public FindBugsMojo()
Method Detail

canGenerateReport

public boolean canGenerateReport()
Checks whether prerequisites for generating this report are given.

Specified by:
canGenerateReport in interface org.apache.maven.reporting.MavenReport
Overrides:
canGenerateReport in class org.apache.maven.reporting.AbstractMavenReport
Returns:
true if report can be generated, otherwise false
See Also:
MavenReport.canGenerateReport()

getDescription

public String getDescription(Locale pLocale)
Returns the plugins description for the "generated reports" overview page.

Parameters:
pLocale - the locale the report should be generated for
Returns:
description of the report
See Also:
MavenReport.getDescription(java.util.Locale)

getName

public String getName(Locale pLocale)
Returns the plugins name for the "generated reports" overview page and the menu.

Parameters:
pLocale - the locale the report should be generated for
Returns:
name of the report
See Also:
MavenReport.getName(java.util.Locale)

getOutputName

public String getOutputName()
Returns report output file name, without the extension. Called by AbstractMavenReport.execute() for creating the sink.

Returns:
name of the generated page
See Also:
MavenReport.getOutputName()

addClasspathEntriesToFindBugsProject

protected void addClasspathEntriesToFindBugsProject(edu.umd.cs.findbugs.Project findBugsProject)
                                             throws org.apache.maven.artifact.DependencyResolutionRequiredException
Adds the dependend libraries of the project to the findbugs aux classpath.

Parameters:
findBugsProject - The find bugs project to add the aux classpath entries.
Throws:
org.apache.maven.artifact.DependencyResolutionRequiredException - Exception that occurs when an artifact file is used, but has not been resolved.

addFiltersToFindBugs

protected void addFiltersToFindBugs(edu.umd.cs.findbugs.FindBugs2 findBugs)
                             throws IOException,
                                    edu.umd.cs.findbugs.filter.FilterException
Adds the specified filters of the project to the findbugs.

Parameters:
findBugs - The find bugs to add the filters.
Throws:
IOException - If filter file could not be read.
edu.umd.cs.findbugs.filter.FilterException - If filter file was invalid.

addJavaSourcesToFindBugsProject

protected void addJavaSourcesToFindBugsProject(List pSourceFiles,
                                               edu.umd.cs.findbugs.Project findBugsProject)
Adds the source files to the find bugs project. The return value of the method call addFile is omited, because we are not interested if the java source is already added.

Parameters:
pSourceFiles - The java sources (Type java.io.File) to add to the project.
findBugsProject - The find bugs project to add the java source to.

addClassScreenerToFindBugs

protected void addClassScreenerToFindBugs(edu.umd.cs.findbugs.FindBugs2 findBugs)
Adds the specified plugins to findbugs. The coreplugin is always added first.

Parameters:
pLocale - The locale to print out the messages. Used here to get the nameof the coreplugin from the properties.
Throws:
org.apache.maven.artifact.resolver.ArtifactNotFoundException - If the coreplugin could not be found.
org.apache.maven.artifact.resolver.ArtifactResolutionException - If the coreplugin could not be resolved.
org.apache.maven.reporting.MavenReportException - If the findBugs plugins URL could not be resolved.

addPluginsToFindBugs

protected void addPluginsToFindBugs(Locale pLocale)
                             throws org.apache.maven.artifact.resolver.ArtifactNotFoundException,
                                    org.apache.maven.artifact.resolver.ArtifactResolutionException,
                                    org.apache.maven.reporting.MavenReportException
Adds the specified plugins to findbugs. The coreplugin is always added first.

Parameters:
pLocale - The locale to print out the messages. Used here to get the nameof the coreplugin from the properties.
Throws:
org.apache.maven.artifact.resolver.ArtifactNotFoundException - If the coreplugin could not be found.
org.apache.maven.artifact.resolver.ArtifactResolutionException - If the coreplugin could not be resolved.
org.apache.maven.reporting.MavenReportException - If the findBugs plugins URL could not be resolved.

addVisitorsToFindBugs

protected void addVisitorsToFindBugs(edu.umd.cs.findbugs.config.UserPreferences preferences)
Adds the specified visitors to findbugs.

Parameters:
preferences - The find bugs UserPreferences.

debugJavaSources

protected void debugJavaSources(Locale pLocale,
                                List pSourceFiles)
Lists absolute paths of java source files for denugging purposes.

Parameters:
pLocale - The locale to print out the messages.
pSourceFiles - List of source files.

debugSourceDirectory

protected void debugSourceDirectory(Locale pLocale,
                                    File pSourceDirectory)
Prints out the source roots to the logger with severity debug.

Parameters:
pLocale - The locale to print out the messages.
pSourceDirectory - The source directory to print.

executeReport

protected void executeReport(Locale pLocale)
                      throws org.apache.maven.reporting.MavenReportException
Executes the generation of the report. Callback from Maven Site Plugin or from AbstractMavenReport.execute() => generate().

Specified by:
executeReport in class org.apache.maven.reporting.AbstractMavenReport
Parameters:
pLocale - the locale the report should be generated for
Throws:
org.apache.maven.reporting.MavenReportException - if anything goes wrong
See Also:
#executeReport(java.util.Locale)

getCorePlugin

protected String getCorePlugin(Locale pLocale)
Retrieve the coreplugin module name

Parameters:
pLocale - The locale to print out the messages.
Returns:
corePluginName The coreplugin module name.

getCorePluginPath

protected File getCorePluginPath(Locale pLocale)
                          throws org.apache.maven.artifact.resolver.ArtifactNotFoundException,
                                 org.apache.maven.artifact.resolver.ArtifactResolutionException
Get the File reference for the Findbugs core plugin.

Parameters:
pLocale - The locale of the messages.
Returns:
The File reference to the coreplugin JAR
Throws:
org.apache.maven.artifact.resolver.ArtifactNotFoundException - If the coreplugin could not be found.
org.apache.maven.artifact.resolver.ArtifactResolutionException - If the coreplugin could not be resolved.

getEffortParameter

protected EffortParameter getEffortParameter()
Returns the effort parameter to use.

Returns:
A valid effort parameter.

getJavaSources

protected List getJavaSources(Locale pLocale,
                              File pSourceDirectory)
                       throws IOException
Collects the java sources from the source roots.

Parameters:
pSourceDirectory - The source directory to search for java sources.
pLocale - The locale to print out the messages.
Returns:
A list containing the java sources or an empty list if no java sources are found.
Throws:
IOException - If there are problems searching for java sources.

getOutputDirectory

protected String getOutputDirectory()
Returns the report output directory. Called by AbstractMavenReport.execute() for creating the sink.

Specified by:
getOutputDirectory in class org.apache.maven.reporting.AbstractMavenReport
Returns:
full path to the directory where the files in the site get copied to
See Also:
AbstractMavenReport.getOutputDirectory()

getProject

protected org.apache.maven.project.MavenProject getProject()
Returns the maven project.

Specified by:
getProject in class org.apache.maven.reporting.AbstractMavenReport
Returns:
the maven project
See Also:
AbstractMavenReport.getProject()

getSiteRenderer

protected org.apache.maven.doxia.siterenderer.Renderer getSiteRenderer()
Returns the doxia site renderer.

Specified by:
getSiteRenderer in class org.apache.maven.reporting.AbstractMavenReport
Returns:
the doxia Renderer
See Also:
AbstractMavenReport.getSiteRenderer()

getThresholdParameter

protected ThresholdParameter getThresholdParameter()
Returns the threshold parameter to use.

Returns:
A valid threshold parameter.

initialiseFindBugs

protected edu.umd.cs.findbugs.FindBugs2 initialiseFindBugs(Locale pLocale,
                                                           List pSourceFiles)
                                                    throws org.apache.maven.artifact.DependencyResolutionRequiredException,
                                                           IOException,
                                                           edu.umd.cs.findbugs.filter.FilterException,
                                                           org.apache.maven.artifact.resolver.ArtifactNotFoundException,
                                                           org.apache.maven.artifact.resolver.ArtifactResolutionException,
                                                           org.apache.maven.reporting.MavenReportException
Initialise FindBugs.

Parameters:
pLocale - The locale.
pSourceFiles - The source files FindBugs should analyse.
Returns:
An initialised FindBugs object.
Throws:
org.apache.maven.artifact.DependencyResolutionRequiredException - Exception that occurs when an artifact file is used, but has not been resolved.
IOException - If filter file could not be read.
edu.umd.cs.findbugs.filter.FilterException - If filter file was invalid.
org.apache.maven.artifact.resolver.ArtifactNotFoundException - If the coreplugin could not be found.
org.apache.maven.artifact.resolver.ArtifactResolutionException - If the coreplugin could not be resolved.
org.apache.maven.reporting.MavenReportException - If the findBugs plugins cannot be initialized

initialiseReporter

protected Reporter initialiseReporter(org.apache.maven.doxia.sink.Sink pSink,
                                      ResourceBundle pBundle,
                                      org.apache.maven.plugin.logging.Log pLog,
                                      EffortParameter pEffortParameter)
Initialises a reporter.

Parameters:
pSink - The sink to write the report to.
pBundle - The bundle to get messages from.
pLog - The logger to write logs to.
pEffortParameter - The effort to use.
Returns:
An initialised reporter.

isJXRPluginEnabled

protected boolean isJXRPluginEnabled(ResourceBundle pBundle)
Determines if the JXR-Plugin is included in the report section of the POM.

Parameters:
pBundle - The bundle to load the artifactIf of the jxr plugin.
Returns:
True if the JXR-Plugin is included in the POM, false otherwise.

setFindBugsDebug

protected void setFindBugsDebug(edu.umd.cs.findbugs.FindBugs2 findBugs)
Sets the Debug Level

Parameters:
findBugs - The find bugs to add debug level information.

getBundle

protected static ResourceBundle getBundle(Locale pLocale)
Returns the resource bundle for a specific locale.

Parameters:
pLocale - The locale to get the bundle for.
Returns:
A resource Bundle.


Copyright © 2005-2007 CodeHaus. All Rights Reserved.