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 class FindBugsMojo
extends org.apache.maven.reporting.AbstractMavenReport

Generates a FindBugs Report when the site plugin is run. The HTML report is generated for site commands only. The optional report formats are generated for both the site and findbugs:findbugs commands.

Version:
$Id: FindBugsMojo.groovy 6727 2008-04-09 02:18:10Z gleclaire $
Author:
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(FindBugs2Proxy findBugs)
          Adds the specified plugins to findbugs.
protected  void addFiltersToFindBugs(FindBugs2Proxy findBugs)
          Adds the specified filters of the project to the findbugs.
protected  void addPluginsToFindBugs(java.util.Locale locale)
          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(java.util.Locale locale, java.util.List sourceFiles)
          Lists absolute paths of java source files for debugging purposes.
protected  void executeReport(java.util.Locale locale)
          Executes the generation of the report.
protected  java.lang.Object fail(java.lang.Object msg)
           
protected  java.lang.Object fail(java.lang.Object msg, java.lang.Throwable cause)
           
 org.apache.maven.artifact.resolver.ArtifactResolver getArtifactResolver()
           
 edu.umd.cs.findbugs.BugReporter getBugReporter()
           
static java.lang.String getBUNDLE_NAME()
           
protected static java.util.ResourceBundle getBundle(java.util.Locale locale)
          Returns the resource bundle for a specific locale.
 java.io.File getClassFilesDirectory()
           
 edu.umd.cs.findbugs.ClassScreener getClassScreener()
           
protected  java.lang.String getCorePlugin(java.util.Locale locale)
          Retrieve the coreplugin module name
protected  java.io.File getCorePluginPath(java.util.Locale locale)
          Get the File reference for the Findbugs core plugin.
 java.lang.Boolean getDebug()
           
static java.lang.String getDESCRIPTION_KEY()
           
 java.lang.String getDescription(java.util.Locale locale)
          Returns the plugins description for the "generated reports" overview page.
 java.lang.String getEffort()
           
protected  EffortParameter getEffortParameter()
          Returns the effort parameter to use.
 java.lang.String getExcludeFilterFile()
           
static java.lang.String getFINDBUGS_COREPLUGIN()
           
 boolean getFindbugsXmlOutput()
           
 java.io.File getFindbugsXmlOutputDirectory()
           
 boolean getFindbugsXmlWithMessages()
           
 java.lang.String getIncludeFilterFile()
           
static java.lang.String getJAVA_REGEX_PATTERN()
           
static java.lang.String getJAVA_SOURCES_KEY()
           
protected  java.util.List getJavaSources(java.util.Locale locale, java.io.File pSourceDirectory)
          Collects the java sources from the source roots.
static java.lang.String getJXR_ARTIFACT_ID_KEY()
           
 org.apache.maven.artifact.repository.DefaultArtifactRepository getLocalRepository()
           
 groovy.lang.MetaClass getMetaClass()
           
static java.lang.String getNAME_KEY()
           
 java.lang.String getName(java.util.Locale locale)
          Returns the plugins name for the "generated reports" overview page and the menu.
 java.lang.String getOmitVisitors()
           
 java.lang.String getOnlyAnalyze()
           
protected  java.lang.String getOutputDirectory()
          Returns the report output directory.
 java.lang.String getOutputName()
          Returns report output file name, without the extension.
static java.lang.String getPLUGIN_NAME()
           
 java.util.ArrayList getPluginArtifacts()
           
 java.lang.String getPluginList()
           
static boolean getPluginLoaded()
           
protected  org.apache.maven.project.MavenProject getProject()
           
 java.lang.Object getProperty(java.lang.String name)
           
 java.lang.Boolean getRelaxed()
           
 java.util.List getRemoteArtifactRepositories()
           
protected  org.apache.maven.doxia.siterenderer.Renderer getSiteRenderer()
           
 boolean getSkip()
           
static java.lang.String getSOURCE_ROOT_KEY()
           
 java.lang.String getThreshold()
           
protected  ThresholdParameter getThresholdParameter()
          Returns the threshold parameter to use.
 java.lang.String getVisitors()
           
 java.lang.String getXmlEncoding()
           
 boolean getXmlOutput()
           
 java.io.File getXmlOutputDirectory()
           
protected  FindBugs2Proxy initialiseFindBugs(java.util.Locale locale, java.util.List sourceFiles)
          Initialise FindBugs.
protected  Reporter initialiseReporter(org.apache.maven.doxia.sink.Sink sink, java.util.ResourceBundle bundle, org.apache.maven.plugin.logging.Log log, EffortParameter effortParameter)
          Initialises a reporter.
 java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args)
           
 boolean isFindbugsXmlOutput()
           
 boolean isFindbugsXmlWithMessages()
           
protected  boolean isJXRPluginEnabled(java.util.ResourceBundle bundle)
          Determines if the JXR-Plugin is included in the report section of the POM.
static boolean isPluginLoaded()
           
 boolean isSkip()
           
 boolean isXmlOutput()
           
 void setArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver value)
           
 void setBugReporter(edu.umd.cs.findbugs.BugReporter value)
           
 void setClassFilesDirectory(java.io.File value)
           
 void setClassScreener(edu.umd.cs.findbugs.ClassScreener value)
           
 void setDebug(java.lang.Boolean value)
           
 void setEffort(java.lang.String value)
           
 void setExcludeFilterFile(java.lang.String value)
           
protected  void setFindBugsDebug(FindBugs2Proxy findBugs)
          Sets the Debug Level
 void setFindbugsXmlOutput(boolean value)
           
 void setFindbugsXmlOutputDirectory(java.io.File value)
           
 void setFindbugsXmlWithMessages(boolean value)
           
 void setIncludeFilterFile(java.lang.String value)
           
 void setLocalRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository value)
           
 void setMetaClass(groovy.lang.MetaClass metaClass)
           
 void setOmitVisitors(java.lang.String value)
           
 void setOnlyAnalyze(java.lang.String value)
           
 void setOutputDirectory(java.lang.String value)
           
 void setPluginArtifacts(java.util.ArrayList value)
           
 void setPluginList(java.lang.String value)
           
static void setPluginLoaded(boolean value)
           
 void setProject(org.apache.maven.project.MavenProject value)
           
 void setProperty(java.lang.String name, java.lang.Object value)
           
 void setRelaxed(java.lang.Boolean value)
           
 void setRemoteArtifactRepositories(java.util.List value)
           
 void setSiteRenderer(org.apache.maven.doxia.siterenderer.Renderer value)
           
 void setSkip(boolean value)
           
 void setThreshold(java.lang.String value)
           
 void setVisitors(java.lang.String value)
           
 void setXmlEncoding(java.lang.String value)
           
 void setXmlOutput(boolean value)
           
 void setXmlOutputDirectory(java.io.File value)
           
 
Methods inherited from class org.apache.maven.reporting.AbstractMavenReport
closeReport, execute, generate, generate, generate, getCategoryName, getReportOutputDirectory, getSink, getSinkFactory, 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

getPLUGIN_NAME

public static final java.lang.String getPLUGIN_NAME()

getBUNDLE_NAME

public static final java.lang.String getBUNDLE_NAME()

getNAME_KEY

public static final java.lang.String getNAME_KEY()

getDESCRIPTION_KEY

public static final java.lang.String getDESCRIPTION_KEY()

getSOURCE_ROOT_KEY

public static final java.lang.String getSOURCE_ROOT_KEY()

getJAVA_SOURCES_KEY

public static final java.lang.String getJAVA_SOURCES_KEY()

getJAVA_REGEX_PATTERN

public static final java.lang.String getJAVA_REGEX_PATTERN()

getJXR_ARTIFACT_ID_KEY

public static final java.lang.String getJXR_ARTIFACT_ID_KEY()

getFINDBUGS_COREPLUGIN

public static final java.lang.String getFINDBUGS_COREPLUGIN()

setOutputDirectory

public void setOutputDirectory(java.lang.String value)

getXmlOutput

public boolean getXmlOutput()

isXmlOutput

public boolean isXmlOutput()

setXmlOutput

public void setXmlOutput(boolean value)

getXmlOutputDirectory

public java.io.File getXmlOutputDirectory()

setXmlOutputDirectory

public void setXmlOutputDirectory(java.io.File value)

getFindbugsXmlOutput

public boolean getFindbugsXmlOutput()

isFindbugsXmlOutput

public boolean isFindbugsXmlOutput()

setFindbugsXmlOutput

public void setFindbugsXmlOutput(boolean value)

getFindbugsXmlOutputDirectory

public java.io.File getFindbugsXmlOutputDirectory()

setFindbugsXmlOutputDirectory

public void setFindbugsXmlOutputDirectory(java.io.File value)

getFindbugsXmlWithMessages

public boolean getFindbugsXmlWithMessages()

isFindbugsXmlWithMessages

public boolean isFindbugsXmlWithMessages()

setFindbugsXmlWithMessages

public void setFindbugsXmlWithMessages(boolean value)

setSiteRenderer

public void setSiteRenderer(org.apache.maven.doxia.siterenderer.Renderer value)

getClassFilesDirectory

public java.io.File getClassFilesDirectory()

setClassFilesDirectory

public void setClassFilesDirectory(java.io.File value)

getPluginArtifacts

public java.util.ArrayList getPluginArtifacts()

setPluginArtifacts

public void setPluginArtifacts(java.util.ArrayList value)

getLocalRepository

public org.apache.maven.artifact.repository.DefaultArtifactRepository getLocalRepository()

setLocalRepository

public void setLocalRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository value)

getRemoteArtifactRepositories

public java.util.List getRemoteArtifactRepositories()

setRemoteArtifactRepositories

public void setRemoteArtifactRepositories(java.util.List value)

setProject

public void setProject(org.apache.maven.project.MavenProject value)

getXmlEncoding

public java.lang.String getXmlEncoding()

setXmlEncoding

public void setXmlEncoding(java.lang.String value)

getThreshold

public java.lang.String getThreshold()

setThreshold

public void setThreshold(java.lang.String value)

getArtifactResolver

public org.apache.maven.artifact.resolver.ArtifactResolver getArtifactResolver()

setArtifactResolver

public void setArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver value)

getIncludeFilterFile

public java.lang.String getIncludeFilterFile()

setIncludeFilterFile

public void setIncludeFilterFile(java.lang.String value)

getExcludeFilterFile

public java.lang.String getExcludeFilterFile()

setExcludeFilterFile

public void setExcludeFilterFile(java.lang.String value)

getEffort

public java.lang.String getEffort()

setEffort

public void setEffort(java.lang.String value)

getDebug

public java.lang.Boolean getDebug()

setDebug

public void setDebug(java.lang.Boolean value)

getRelaxed

public java.lang.Boolean getRelaxed()

setRelaxed

public void setRelaxed(java.lang.Boolean value)

getVisitors

public java.lang.String getVisitors()

setVisitors

public void setVisitors(java.lang.String value)

getOmitVisitors

public java.lang.String getOmitVisitors()

setOmitVisitors

public void setOmitVisitors(java.lang.String value)

getPluginList

public java.lang.String getPluginList()

setPluginList

public void setPluginList(java.lang.String value)

getBugReporter

public edu.umd.cs.findbugs.BugReporter getBugReporter()

setBugReporter

public void setBugReporter(edu.umd.cs.findbugs.BugReporter value)

getOnlyAnalyze

public java.lang.String getOnlyAnalyze()

setOnlyAnalyze

public void setOnlyAnalyze(java.lang.String value)

getClassScreener

public edu.umd.cs.findbugs.ClassScreener getClassScreener()

setClassScreener

public void setClassScreener(edu.umd.cs.findbugs.ClassScreener value)

getPluginLoaded

public static boolean getPluginLoaded()

isPluginLoaded

public static boolean isPluginLoaded()

setPluginLoaded

public static void setPluginLoaded(boolean value)

getSkip

public boolean getSkip()

isSkip

public boolean isSkip()

setSkip

public void setSkip(boolean value)

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 java.lang.String getDescription(java.util.Locale locale)
Returns the plugins description for the "generated reports" overview page.

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

getName

public java.lang.String getName(java.util.Locale locale)
Returns the plugins name for the "generated reports" overview page and the menu.

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

getOutputName

public java.lang.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)
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(FindBugs2Proxy findBugs)
Adds the specified filters of the project to the findbugs.

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

addClassScreenerToFindBugs

protected void addClassScreenerToFindBugs(FindBugs2Proxy findBugs)
Adds the specified plugins to findbugs. The coreplugin is always added first.

Parameters:
locale - 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.
MavenReportException - If the findBugs plugins URL could not be resolved.

addPluginsToFindBugs

protected void addPluginsToFindBugs(java.util.Locale locale)
Adds the specified plugins to findbugs. The coreplugin is always added first.

Parameters:
locale - 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.
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(java.util.Locale locale,
                                java.util.List sourceFiles)
Lists absolute paths of java source files for debugging purposes.

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

executeReport

protected void executeReport(java.util.Locale locale)
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:
locale - the locale the report should be generated for
Throws:
MavenReportException - if anything goes wrong
See Also:
#executeReport(java.util.Locale)

getCorePlugin

protected java.lang.String getCorePlugin(java.util.Locale locale)
Retrieve the coreplugin module name

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

getCorePluginPath

protected java.io.File getCorePluginPath(java.util.Locale locale)
Get the File reference for the Findbugs core plugin.

Parameters:
locale - 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 java.util.List getJavaSources(java.util.Locale locale,
                                        java.io.File pSourceDirectory)
Collects the java sources from the source roots.

Parameters:
pSourceDirectory - The source directory to search for java sources.
locale - 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:
java.io.IOException - If there are problems searching for java sources.

getOutputDirectory

protected java.lang.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()

getThresholdParameter

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

Returns:
A valid threshold parameter.

initialiseFindBugs

protected FindBugs2Proxy initialiseFindBugs(java.util.Locale locale,
                                            java.util.List sourceFiles)
Initialise FindBugs.

Parameters:
locale - The locale.
sourceFiles - 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.
java.io.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.
MavenReportException - If the findBugs plugins cannot be initialized

initialiseReporter

protected Reporter initialiseReporter(org.apache.maven.doxia.sink.Sink sink,
                                      java.util.ResourceBundle bundle,
                                      org.apache.maven.plugin.logging.Log log,
                                      EffortParameter effortParameter)
Initialises a reporter.

Parameters:
sink - The sink to write the report to.
bundle - The bundle to get messages from.
log - The logger to write logs to.
effortParameter - The effort to use.
Returns:
An initialised reporter.

isJXRPluginEnabled

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

Parameters:
bundle - 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(FindBugs2Proxy findBugs)
Sets the Debug Level

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

getBundle

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

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

fail

protected java.lang.Object fail(java.lang.Object msg)

fail

protected java.lang.Object fail(java.lang.Object msg,
                                java.lang.Throwable cause)

getProject

protected org.apache.maven.project.MavenProject getProject()
Specified by:
getProject in class org.apache.maven.reporting.AbstractMavenReport

getSiteRenderer

protected org.apache.maven.doxia.siterenderer.Renderer getSiteRenderer()
Specified by:
getSiteRenderer in class org.apache.maven.reporting.AbstractMavenReport

getMetaClass

public groovy.lang.MetaClass getMetaClass()

setMetaClass

public void setMetaClass(groovy.lang.MetaClass metaClass)

invokeMethod

public java.lang.Object invokeMethod(java.lang.String name,
                                     java.lang.Object args)

getProperty

public java.lang.Object getProperty(java.lang.String name)

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)


Copyright © 2005-2009. All Rights Reserved.