<!--
  ~ Copyright 2017 the original author or authors.
  ~
  ~ Licensed 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.
  -->
<chapter id="findbugs_plugin">
    <title>The FindBugs Plugin</title>
    <para>The FindBugs plugin performs quality checks on your project's Java source files using <ulink url="http://findbugs.sourceforge.net">FindBugs</ulink>
        and generates reports from these checks.
    </para>

    <section id="sec:findbugs_usage">
        <title>Usage</title>
        <para>To use the FindBugs plugin, include the following in your build script:</para>
        <sample id="useFindBugsPlugin" dir="codeQuality" title="Using the FindBugs plugin">
            <sourcefile file="build.gradle" snippet="use-findbugs-plugin"/>
        </sample>
        <para>The plugin adds a number of tasks to the project that perform the quality checks. You can execute the checks by running <userinput>gradle check</userinput>.</para>
        <para>Note that Findbugs will run with the same Java version used to run Gradle.</para>
    </section>

    <section id="sec:findbugs_tasks">
        <title>Tasks</title>
        <para>The FindBugs plugin adds the following tasks to the project:</para>
        <table>
            <title>FindBugs plugin - tasks</title>
            <thead>
                <tr>
                    <td>Task name</td>
                    <td>Depends on</td>
                    <td>Type</td>
                    <td>Description</td>
                </tr>
            </thead>
            <tr>
                <td>
                    <literal>findbugsMain</literal>
                </td>
                <td><literal>classes</literal></td>
                <td><apilink class="org.gradle.api.plugins.quality.FindBugs"/></td>
                <td>Runs FindBugs against the production Java source files.</td>
            </tr>
            <tr>
                <td>
                    <literal>findbugsTest</literal>
                </td>
                <td><literal>testClasses</literal></td>
                <td><apilink class="org.gradle.api.plugins.quality.FindBugs"/></td>
                <td>Runs FindBugs against the test Java source files.</td>
            </tr>
            <tr>
                <td>
                    <literal>findbugs<replaceable>SourceSet</replaceable></literal>
                </td>
                <td>
                    <literal><replaceable>sourceSet</replaceable>Classes</literal>
                </td>
                <td><apilink class="org.gradle.api.plugins.quality.FindBugs"/></td>
                <td>Runs FindBugs against the given source set's Java source files.</td>
            </tr>
        </table>

        <para>The FindBugs plugin adds the following dependencies to tasks defined by the Java plugin.</para>
        <table>
            <title>FindBugs plugin - additional task dependencies</title>
            <thead>
                <td>Task name</td>
                <td>Depends on</td>
            </thead>
            <tr>
                <td><literal>check</literal></td>
                <td>All FindBugs tasks, including <literal>findbugsMain</literal> and <literal>findbugsTest</literal>.</td>
            </tr>
        </table>
    </section>

    <section id="sec:findbugs_dependency_management">
        <title>Dependency management</title>
        <para>The FindBugs plugin adds the following dependency configurations:</para>
        <table>
            <title>FindBugs plugin - dependency configurations</title>
            <thead>
                <tr>
                    <td>Name</td>
                    <td>Meaning</td>
                </tr>
            </thead>
            <tr>
                <td>
                    <filename>findbugs</filename>
                </td>
                <td>The FindBugs libraries to use</td>
            </tr>
        </table>
    </section>

    <section id="sec:findbugs_configuration">
        <title>Configuration</title>
        <para>See the <apilink class="org.gradle.api.plugins.quality.FindBugsExtension"/> class in the API documentation.</para>
    </section>

    <section id="sec:findbugs_customize_xsl">
        <title>Customizing the HTML report</title>
        <para>The HTML report generated by the <apilink class="org.gradle.api.plugins.quality.FindBugs"/> task
            can be customized using a XSLT stylesheet, for example to highlight specific errors or change its
            appearance:
        </para>
        <sample id="customizeFindbugsReport" dir="codeQuality" title="Customizing the HTML report">
            <sourcefile file="build.gradle" snippet="customize-findbugs-report"/>
        </sample>
        <para>
            <ulink url="https://github.com/findbugsproject/findbugs/tree/master/findbugs/src/xsl">View a sample FindBugs stylesheet.</ulink>
        </para>
    </section>

</chapter>
