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 2285 2006-08-28 18:19:09Z carlos $
Author:
Cyrill Ruettimann, Detlef Pleiss

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 pFindBugsProject)
          Adds the dependend libraries of the project to the findbugs aux classpath.
protected  void addFiltersToFindBugs(edu.umd.cs.findbugs.FindBugs pFindBugs)
          Adds the specified filters of the project to the findbugs.
protected  void addJavaSourcesToFindBugsProject(List pSourceFiles, edu.umd.cs.findbugs.Project pFindBugsProject)
          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.codehaus.doxia.site.renderer.SiteRenderer getSiteRenderer()
          Returns the doxia site renderer.
protected  edu.umd.cs.findbugs.FindBugs initialiseFindBugs(Locale pLocale, List pSourceFiles)
          Initialise FindBugs.
protected  Reporter initialiseReporter(org.codehaus.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.
 
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

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()

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)

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)

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()

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()

getSiteRenderer

protected org.codehaus.doxia.site.renderer.SiteRenderer getSiteRenderer()
Returns the doxia site renderer.

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

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)

initialiseFindBugs

protected edu.umd.cs.findbugs.FindBugs 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
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.

initialiseReporter

protected Reporter initialiseReporter(org.codehaus.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.

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.

addJavaSourcesToFindBugsProject

protected void addJavaSourcesToFindBugsProject(List pSourceFiles,
                                               edu.umd.cs.findbugs.Project pFindBugsProject)
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.
pFindBugsProject - The find bugs project to add the java source to.

addClasspathEntriesToFindBugsProject

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

Parameters:
pFindBugsProject - 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.FindBugs pFindBugs)
                             throws IOException,
                                    edu.umd.cs.findbugs.filter.FilterException
Adds the specified filters of the project to the findbugs.

Parameters:
pFindBugs - 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.

addPluginsToFindBugs

protected void addPluginsToFindBugs(Locale pLocale)
                             throws org.apache.maven.artifact.resolver.ArtifactNotFoundException,
                                    org.apache.maven.artifact.resolver.ArtifactResolutionException
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.

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.

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.

addVisitorsToFindBugs

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

Parameters:
preferences - The find bugs UserPreferences.

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()

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.

getEffortParameter

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

Returns:
A valid effort parameter.

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.

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.

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.


Copyright © 2006 null. All Rights Reserved.