pmd/pmd_userdocs_tools_ant.html
Travis CI (pmd-bot) 2d14a5512c Update documentation
2018-06-17 01:53:59 +00:00

1639 lines
47 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="keywords" content="userdocstools, ">
<title>Ant Task Usage | PMD Source Code Analyzer</title>
<link rel="stylesheet" href="css/syntax.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">-->
<link rel="stylesheet" href="css/modern-business.css">
<link rel="stylesheet" href="css/lavish-bootstrap.css">
<link rel="stylesheet" href="css/customstyles.css">
<link rel="stylesheet" href="css/theme-blue.css">
<link rel="stylesheet" href="css/pmd-customstyles.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="js/jquery.navgoco.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/2.0.0/anchor.min.js"></script>
<script src="js/toc.js"></script>
<script src="js/customscripts.js"></script>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml" title="" href="https://pmd.github.io/pmd/feed.xml">
<script>
$(document).ready(function() {
// Initialize navgoco with default options
$("#mysidebar").navgoco({
caretHtml: '',
accordion: true,
openClass: 'active', // open
save: false, // leave false or nav highlighting doesn't work right
cookie: {
name: 'navgoco',
expires: false,
path: '/'
},
slide: {
duration: 400,
easing: 'swing'
}
});
$("#collapseAll").click(function(e) {
e.preventDefault();
$("#mysidebar").navgoco('toggle', false);
});
$("#expandAll").click(function(e) {
e.preventDefault();
$("#mysidebar").navgoco('toggle', true);
});
});
</script>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
<script>
$(document).ready(function() {
$("#tg-sb-link").click(function() {
$("#tg-sb-sidebar").toggle();
$("#tg-sb-content").toggleClass('col-md-9');
$("#tg-sb-content").toggleClass('col-md-12');
$("#tg-sb-icon").toggleClass('fa-toggle-on');
$("#tg-sb-icon").toggleClass('fa-toggle-off');
});
});
</script>
</head>
<body>
<!-- Content is offset by the height of the topnav bar. -->
<!-- There's already a padding-top rule in modern-business.css, but it apparently doesn't work on Firefox 60 and Chrome 67 -->
<div id="topbar-content-offset">
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container topnavlinks">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="fa fa-home fa-lg navbar-brand" href="index.html">&nbsp;<span class="projectTitle"> PMD Source Code Analyzer Project</span></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<!-- toggle sidebar button -->
<li><a id="tg-sb-link" href="#"><i id="tg-sb-icon" class="fa fa-toggle-on"></i> Nav</a></li>
<!-- entries without drop-downs appear here -->
<li><a href="https://github.com/pmd/pmd/releases/latest" target="_blank">Download</a></li>
<li><a href="https://github.com/pmd/pmd" target="_blank">Fork us on github</a></li>
<!-- entries with drop-downs appear here -->
<!-- conditional logic to control which topnav appears for the audience defined in the configuration file.-->
<!--comment out this block if you want to hide search-->
<li>
<!--start search-->
<div id="search-demo-container">
<input type="text" id="search-input" placeholder="search...">
<ul id="results-container"></ul>
</div>
<script src="js/jekyll-search.js" type="text/javascript"></script>
<script type="text/javascript">
SimpleJekyllSearch.init({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
dataSource: 'search.json',
searchResultTemplate: '<li><a href="{url}" title="Ant Task Usage">{title}</a></li>',
noResultsText: 'No results found.',
limit: 10,
fuzzy: true,
})
</script>
<!--end search-->
</li>
</ul>
</div>
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div class="col-lg-12">&nbsp;</div>
<!-- Content Row -->
<div class="row">
<!-- Sidebar Column -->
<div class="col-md-3" id="tg-sb-sidebar">
<ul id="mysidebar" class="nav">
<li class="sidebarTitle">PMD 6.5.0</li>
<li>
<a href="#">About</a>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="pmd_release_notes.html">Release notes</a></li>
<li><a href="pmd_about_help.html">Getting help</a></li>
</ul>
</li>
<li>
<a href="#">User Documentation</a>
<ul>
<li><a href="pmd_userdocs_installation.html">Installation and basic CLI usage</a></li>
<li><a href="pmd_userdocs_making_rulesets.html">Making rulesets</a></li>
<li><a href="pmd_userdocs_configuring_rules.html">Configuring rules</a></li>
<li><a href="pmd_userdocs_best_practices.html">Best practices</a></li>
<li><a href="pmd_userdocs_suppressing_warnings.html">Suppressing warnings</a></li>
<li><a href="pmd_userdocs_incremental_analysis.html">Incremental analysis</a></li>
<li><a href="pmd_userdocs_cli_reference.html">PMD CLI reference</a></li>
<li class="subfolders">
<a href="#">Extending PMD</a>
<ul>
<li><a href="pmd_userdocs_extending_writing_pmd_rules.html">Writing a rule</a></li>
<li><a href="pmd_userdocs_extending_writing_xpath_rules.html">Writing XPath rules</a></li>
<li><a href="pmd_userdocs_extending_defining_properties.html">Defining rule properties</a></li>
<li><a href="pmd_userdocs_extending_metrics_howto.html">Using and defining code metrics</a></li>
<li><a href="pmd_userdocs_extending_rule_guidelines.html">Rule guidelines</a></li>
<li><a href="pmd_userdocs_extending_testing.html">Testing your rules</a></li>
</ul>
</li>
<li><a href="pmd_userdocs_cpd.html">Copy-paste detection</a></li>
<li class="subfolders">
<a href="#">Tools / Integrations</a>
<ul>
<li><a href="pmd_userdocs_tools_maven.html">Maven PMD plugin</a></li>
<li class="active"><a href="pmd_userdocs_tools_ant.html">Ant</a></li>
<li><a href="pmd_userdocs_tools_ci.html">CI integrations</a></li>
<li><a href="pmd_userdocs_tools.html">Other Tools / Integrations</a></li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#">Rule Reference</a>
<ul>
<li class="subfolders">
<a href="#">Apex Rules</a>
<ul>
<li><a href="pmd_rules_apex.html">Index</a></li>
<li><a href="pmd_rules_apex_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_apex_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_apex_design.html">Design</a></li>
<li><a href="pmd_rules_apex_errorprone.html">Error Prone</a></li>
<li><a href="pmd_rules_apex_performance.html">Performance</a></li>
<li><a href="pmd_rules_apex_security.html">Security</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Ecmascript Rules</a>
<ul>
<li><a href="pmd_rules_ecmascript.html">Index</a></li>
<li><a href="pmd_rules_ecmascript_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_ecmascript_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_ecmascript_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Java Rules</a>
<ul>
<li><a href="pmd_rules_java.html">Index</a></li>
<li><a href="pmd_rules_java_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_java_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_java_design.html">Design</a></li>
<li><a href="pmd_rules_java_documentation.html">Documentation</a></li>
<li><a href="pmd_rules_java_errorprone.html">Error Prone</a></li>
<li><a href="pmd_rules_java_multithreading.html">Multithreading</a></li>
<li><a href="pmd_rules_java_performance.html">Performance</a></li>
<li><a href="pmd_rules_java_security.html">Security</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Java Server Pages Rules</a>
<ul>
<li><a href="pmd_rules_jsp.html">Index</a></li>
<li><a href="pmd_rules_jsp_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_jsp_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_jsp_design.html">Design</a></li>
<li><a href="pmd_rules_jsp_errorprone.html">Error Prone</a></li>
<li><a href="pmd_rules_jsp_security.html">Security</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Maven POM Rules</a>
<ul>
<li><a href="pmd_rules_pom.html">Index</a></li>
<li><a href="pmd_rules_pom_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">PLSQL Rules</a>
<ul>
<li><a href="pmd_rules_plsql.html">Index</a></li>
<li><a href="pmd_rules_plsql_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_plsql_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_plsql_design.html">Design</a></li>
<li><a href="pmd_rules_plsql_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Salesforce VisualForce Rules</a>
<ul>
<li><a href="pmd_rules_vf.html">Index</a></li>
<li><a href="pmd_rules_vf_security.html">Security</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">VM Rules</a>
<ul>
<li><a href="pmd_rules_vm.html">Index</a></li>
<li><a href="pmd_rules_vm_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_vm_design.html">Design</a></li>
<li><a href="pmd_rules_vm_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">XML Rules</a>
<ul>
<li><a href="pmd_rules_xml.html">Index</a></li>
<li><a href="pmd_rules_xml_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">XSL Rules</a>
<ul>
<li><a href="pmd_rules_xsl.html">Index</a></li>
<li><a href="pmd_rules_xsl_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_xsl_performance.html">Performance</a></li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#">Language Specific Documentation</a>
<ul>
<li><a href="pmd_languages_jsp.html">JSP Support</a></li>
<li><a href="pmd_java_metrics_index.html">Java code metrics</a></li>
<li><a href="pmd_apex_metrics_index.html">Apex code metrics</a></li>
</ul>
</li>
<li>
<a href="#">Developer Documentation</a>
<ul>
<li><a href="pmd_devdocs_development.html">Developer resources</a></li>
<li><a href="pmd_devdocs_building.html">Building PMD from source</a></li>
<li><a href="https://github.com/pmd/pmd/blob/master/CONTRIBUTING.md" target="_blank">Contributing</a></li>
<li><a href="pmd_devdocs_writing_documentation.html">Writing documentation</a></li>
<li><a href="pmd_devdocs_roadmap.html">Roadmap</a></li>
<li><a href="pmd_devdocs_how_pmd_works.html">How PMD works</a></li>
<li class="subfolders">
<a href="#">Major contributions</a>
<ul>
<li><a href="pmd_devdocs_major_adding_new_language.html">Adding a new language</a></li>
<li><a href="pmd_devdocs_major_adding_new_cpd_language.html">Adding a new CPD language</a></li>
<li><a href="pmd_devdocs_major_adding_new_metrics_framework.html">Adding metrics support to a language</a></li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#">Project documentation</a>
<ul>
<li class="subfolders">
<a href="#">Trivia about PMD</a>
<ul>
<li><a href="pmd_projectdocs_trivia_news.html">PMD in the press</a></li>
<li><a href="pmd_projectdocs_trivia_products.html">Products & books related to PMD</a></li>
<li><a href="pmd_projectdocs_trivia_similarprojects.html">Similar projects</a></li>
<li><a href="pmd_projectdocs_trivia_meaning.html">What does 'PMD' mean?</a></li>
</ul>
</li>
<li><a href="pmd_projectdocs_faq.html">FAQ</a></li>
<li><a href="license.html">License</a></li>
<li><a href="pmd_projectdocs_credits.html">Credits</a></li>
<li><a href="pmd_release_notes_old.html">Old release notes</a></li>
<li class="subfolders">
<a href="#">Project management</a>
<ul>
<li><a href="pmd_projectdocs_committers_releasing.html">Release process</a></li>
<li><a href="pmd_projectdocs_committers_merging_pull_requests.html">Merging pull requests</a></li>
</ul>
</li>
</ul>
</li>
<!-- if you aren't using the accordion, uncomment this block:
<p class="external">
<a href="#" id="collapseAll">Collapse All</a> | <a href="#" id="expandAll">Expand All</a>
</p>
-->
</ul>
<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above. Otherwise, if placed inside customscripts.js, the script runs before the sidebar code runs and the class never gets inserted.-->
<script>$("li.active").parents('li').toggleClass("active");</script>
</div>
<!-- Content Column -->
<div class="col-md-9" id="tg-sb-content">
<div class="post-header">
<h1 class="post-title-main">Ant Task Usage</h1>
</div>
<div class="post-content">
<!-- this handles the automatic toc. use ## for subheads to auto-generate the on-page minitoc. if you use html tags, you must supply an ID for the heading element in order for it to appear in the minitoc. -->
<script>
$( document ).ready(function() {
// Handler for .ready() called.
$('#toc').toc({ minimumHeaders: 0, listType: 'ul', showSpeed: 0, headers: 'h2,h3,h4' });
/* this offset helps account for the space taken up by the floating toolbar. */
$('#toc').on('click', 'a', function() {
var target = $(this.getAttribute('href'))
, scroll_target = target.offset().top
$(window).scrollTop(scroll_target - 10);
return false
})
});
</script>
<div id="toc"></div>
<a target="_blank" href="https://github.com/pmd/pmd/blob/master/docs/pages/pmd/userdocs/tools/ant.md" class="btn btn-default githubEditButton" role="button"><i class="fa fa-github fa-lg"></i> Edit me</a>
<h2 id="pmd">PMD</h2>
<h3 id="description">Description</h3>
<p>Runs a set of static code analysis rules on some source code files and generates a list of problems found.</p>
<h3 id="parameters">Parameters</h3>
<table>
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Required</th>
</tr>
<tr>
<td>rulesetfiles</td>
<td>
A comma delimited list of ruleset files ('rulesets/java/basic.xml,rulesets/java/design.xml').
If you write your own ruleset files, you can put them on the classpath and plug them in here.
</td>
<td>Yes, unless the ruleset nested element is used</td>
</tr>
<tr>
<td>failonerror</td>
<td>Whether or not to fail the build if any errors occur while processing the files</td>
<td>No</td>
</tr>
<tr>
<td>failOnRuleViolation</td>
<td>Whether or not to fail the build if PMD finds any problems</td>
<td>No</td>
</tr>
<tr>
<td>minimumPriority</td>
<td>The rule priority threshold; rules with lower priority than they will not be used</td>
<td>No</td>
</tr>
<tr>
<td>shortFilenames</td>
<td>Places truncated filenames in the report. This can reduce your report file size by 15%-20%.</td>
<td>No</td>
</tr>
<tr>
<td>failuresPropertyName</td>
<td>A property name to plug the number of rule violations into when the task finishes</td>
<td>No</td>
</tr>
<tr>
<td>encoding</td>
<td>The character set encoding (e.g. UTF-8) to use when reading the source code files</td>
<td>No</td>
</tr>
<tr>
<td>suppressMarker</td>
<td>The series of characters to use to tell PMD to skip lines - the default is NOPMD.</td>
<td>No</td>
</tr>
<tr>
<td>maxRuleViolations</td>
<td>
Whether or not to fail the build if PMD finds more than the value of this attribute.
Note that setting this attribute does not require to set the failOnRuleViolation to true.
</td>
<td>No</td>
</tr>
<tr>
<td>cacheLocation</td>
<td>
The location of the analysis cache file to be used.
Setting this property enables Incremental Analysis, which can greatly improve analysis time without loosing analysis quality.
<b>Its use is strongly recommended.</b>
</td>
<td>No</td>
</tr>
<tr>
<td>noCache</td>
<td>
Setting this property to true disables Incremental Analysis, even if <i>cacheLocation</i> is provided.
You can use this to explicitly turn off suggestions to use incremental analysis, or for testing purposes.
</td>
<td>No</td>
</tr>
</table>
<p><code class="highlighter-rouge">formatter</code> nested element - specifies the format of and the files to which the report is written.</p>
<table>
<tr><th>Name</th><th>Values</th></tr>
<tr>
<td>type</td>
<td>xml,ideaj,textcolor,text,textpad,emacs,csv,html,xslt,yahtml,summaryhtml,vbhtml,codeclimate</td>
</tr>
<tr>
<td>showSuppressed</td>
<td>Whether to show suppressed warnings; "false" is the default.</td>
</tr>
<tr>
<td>toFile</td>
<td>A filename to which to write the report</td>
</tr>
<tr>
<td>toConsole</td>
<td>Whether to output the report to the console; "false" is the default.</td>
</tr>
<tr>
<td colspan="2">
<p>The <code>formatter</code> element can contain nested <code>param</code> elements to configure the formatter in detail, e.g.</p>
<dl>
<dt>encoding</dt>
<dd>Specifies the encoding to be used in the generated report (only honored when used with `toFile`). When rendering `toConsole` PMD will automatically detect the terminal's encoding and use it, unless the output is being redirected / piped, in which case `file.encoding` is used. See example below.</dd>
<dt>linkPrefix</dt>
<dd>Used for linking to online HTMLized source (like <a href="xref/net/sourceforge/pmd/PMD.html">this</a>). See example below.</dd>
<dt>linePrefix</dt>
<dd>Used for linking to online HTMLized source (like <a href="xref/net/sourceforge/pmd/PMD.html#102">this</a>). See example below.</dd>
</dl>
</td>
</tr>
</table>
<p><code class="highlighter-rouge">classpath</code> nested element - useful for specifying custom rule. More details on the <code class="highlighter-rouge">classpath</code>
element are in the Ant documentation <a href="http://ant.apache.org/manual/using.html#path">here</a> and theres
an example below.</p>
<p><code class="highlighter-rouge">auxclasspath</code> nested element - extra classpath used for Type Resolution rules.</p>
<p><code class="highlighter-rouge">sourceLanguage</code> nested element - specify which language (Java, Ecmascript, XML,…)
and the associated version (1.5, 1.6,…)</p>
<p><code class="highlighter-rouge">ruleset</code> nested element - another way to specify rulesets. Heres an example:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;target name="pmd"&gt;
&lt;taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/&gt;
&lt;pmd shortFilenames="true"&gt;
&lt;sourceLanguage name="java" version="1.6"/&gt;
&lt;ruleset&gt;rulesets/java/design.xml&lt;/ruleset&gt;
&lt;ruleset&gt;java-basic&lt;/ruleset&gt;
&lt;formatter type="html" toFile="pmd_report.html"&gt;
&lt;param name="linkPrefix" value="http://pmd.sourceforge.net/xref/"/&gt;
&lt;/formatter&gt;
&lt;fileset dir="/usr/local/j2sdk1.4.1_01/src/"&gt;
&lt;include name="java/lang/*.java"/&gt;
&lt;/fileset&gt;
&lt;/pmd&gt;
&lt;/target&gt;
</code></pre></div></div>
<h3 id="language-version-selection">Language version selection</h3>
<p>The specific version of a language to be used for parsing is selected via the <code class="highlighter-rouge">sourceLanguage</code>
nested element. Possible values are:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;sourceLanguage name="apex" version=""/&gt;
&lt;sourceLanguage name="ecmascript" version="3"/&gt;
&lt;sourceLanguage name="java" version="1.3"/&gt;
&lt;sourceLanguage name="java" version="1.4"/&gt;
&lt;sourceLanguage name="java" version="1.5"/&gt;
&lt;sourceLanguage name="java" version="1.6"/&gt;
&lt;sourceLanguage name="java" version="1.7"/&gt;
&lt;sourceLanguage name="java" version="1.8"/&gt;
&lt;sourceLanguage name="java" version="9"/&gt;
&lt;sourceLanguage name="jsp" version=""/&gt;
&lt;sourceLanguage name="pom" version=""/&gt;
&lt;sourceLanguage name="plsql" version=""/&gt;
&lt;sourceLanguage name="xsl" version=""/&gt;
&lt;sourceLanguage name="xml" version=""/&gt;
&lt;sourceLanguage name="vf" version=""/&gt;
&lt;sourceLanguage name="vm" version=""/&gt;
</code></pre></div></div>
<h3 id="postprocessing-the-report-file-with-xslt">Postprocessing the report file with XSLT</h3>
<p>Several folks (most recently, Wouter Zelle) have written XSLT scripts
which you can use to transform the XML report into nifty HTML. To do this,
make sure you use the XML formatter in the PMD task invocation, i.e.:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;formatter type="xml" toFile="${tempbuild}/$report_pmd.xml"&gt;
&lt;param name="encoding" value="UTF-8" /&gt; &lt;!-- enforce UTF-8 encoding for the XML --&gt;
&lt;/formatter&gt;
</code></pre></div></div>
<p>Then, after the end of the PMD task, do this:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;xslt in="${tempbuild}/$report_pmd.xml" style="${pmdConfig}/wz-pmd-report.xslt" out="${pmdOutput}/$report_pmd.html" /&gt;
</code></pre></div></div>
<h3 id="examples">Examples</h3>
<p>Running one ruleset to produce a HTML report (and printing the report to the console as well) using a file cache</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/&gt;
&lt;target name="pmd"&gt;
&lt;taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/&gt;
&lt;pmd rulesetfiles="java-imports" cacheLocation="build/pmd/pmd.cache"&gt;
&lt;formatter type="html" toFile="pmd_report.html" toConsole="true"/&gt;
&lt;fileset dir="C:\j2sdk1.4.1_01\src\java\lang\"&gt;
&lt;include name="**/*.java"/&gt;
&lt;/fileset&gt;
&lt;/pmd&gt;
&lt;/target&gt;
</code></pre></div></div>
<p>Running multiple rulesets to produce an XML report with the same analysis cache</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/&gt;
&lt;target name="pmd"&gt;
&lt;taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/&gt;
&lt;pmd rulesetfiles="rulesets/java/imports.xml,java-unusedcode" cacheLocation="build/pmd/pmd.cache"&gt;
&lt;formatter type="xml" toFile="c:\pmd_report.xml"/&gt;
&lt;fileset dir="C:\j2sdk1.4.1_01\src\java\lang\"&gt;
&lt;include name="**/*.java"/&gt;
&lt;/fileset&gt;
&lt;/pmd&gt;
&lt;/target&gt;
</code></pre></div></div>
<p>Using a custom renderer</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/&gt;
&lt;target name="pmd"&gt;
&lt;pmd rulesetfiles="rulesets/java/design.xml"&gt;
&lt;formatter type="com.mycompany.MyRenderer" toFile="foo.html"/&gt;
&lt;fileset dir="/path/to/java/src"&gt;
&lt;include name="**/*.java"/&gt;
&lt;/fileset&gt;
&lt;/pmd&gt;
&lt;/target&gt;
</code></pre></div></div>
<p>Using a classpath reference in the taskdef</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;path id="pmd.classpath"&gt;
&lt;pathelement location="${build}"/&gt;
&lt;fileset dir="/path/to/my/pmd/lib/"&gt;
&lt;include name="*.jar"/&gt;
&lt;/fileset&gt;
&lt;/path&gt;
&lt;taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath"/&gt;
&lt;target name="pmd"&gt;
&lt;pmd rulesetfiles="rulesets/java/design.xml"&gt;
&lt;formatter type="net.sourceforge.pmd.renderers.HTMLRenderer" toFile="foo.html"/&gt;
&lt;fileset dir="/path/to/java/src"&gt;
&lt;include name="**/*.java"/&gt;
&lt;/fileset&gt;
&lt;/pmd&gt;
&lt;/target&gt;
</code></pre></div></div>
<p>Getting verbose output</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[tom@hal bin]$ ant -v pmd
Apache Ant version 1.6.2 compiled on July 16 2004
Buildfile: build.xml
Detected Java version: 1.4 in: /usr/local/j2sdk1.4.2_03/jre
Detected OS: Linux
parsing buildfile build.xml with URI = file:/home/tom/data/pmd/pmd/bin/build.xml
Project base dir set to: /home/tom/data/pmd/pmd
Build sequence for target `pmd' is [pmd]
Complete build sequence is [pmd, copy, cppjavacc, cpd, delete,
compile, clean, jar, dist, cpdjnlp, jjtree, javadoc, test, tomserver]
pmd:
[pmd] Using the normal ClassLoader
[pmd] Using these rulesets: rulesets/java/imports.xml
[pmd] Using rule DontImportJavaLang
[pmd] Using rule UnusedImports
[pmd] Using rule ImportFromSamePackage
[pmd] Using rule DuplicateImports
[pmd] Processing file /usr/local/java/src/java/lang/ref/Finalizer.java
[pmd] Processing file /usr/local/java/src/java/lang/ref/FinalReference.java
[pmd] Processing file /usr/local/java/src/java/lang/ref/PhantomReference.java
[pmd] Processing file /usr/local/java/src/java/lang/ref/Reference.java
[pmd] Processing file /usr/local/java/src/java/lang/ref/ReferenceQueue.java
[pmd] Processing file /usr/local/java/src/java/lang/ref/SoftReference.java
[pmd] Processing file /usr/local/java/src/java/lang/ref/WeakReference.java
[pmd] 0 problems found
BUILD SUCCESSFUL
Total time: 2 seconds
[tom@hal bin]$
</code></pre></div></div>
<p>An HTML report with the “linkPrefix” gizmo</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;target name="pmd"&gt;
&lt;taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/&gt;
&lt;pmd rulesetfiles="java-basic" shortFilenames="true"&gt;
&lt;formatter type="html" toFile="pmd_report.html"&gt;
&lt;param name="linkPrefix" value="http://pmd.sourceforge.net/xref/"/&gt;
&lt;/formatter&gt;
&lt;fileset dir="/usr/local/j2sdk1.4.1_01/src/"&gt;
&lt;include name="java/lang/*.java"/&gt;
&lt;/fileset&gt;
&lt;/pmd&gt;
&lt;/target&gt;
</code></pre></div></div>
<p>An HTML report with the “linePrefix” gizmo</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;target name="pmd"&gt;
&lt;taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/&gt;
&lt;pmd rulesetfiles="java-basic" shortFilenames="true"&gt;
&lt;formatter type="html" toFile="pmd_report.html"&gt;
&lt;param name="linePrefix" value=".line"/&gt;
&lt;/formatter&gt;
&lt;fileset dir="/usr/local/j2sdk1.4.1_01/src/"&gt;
&lt;include name="java/lang/*.java"/&gt;
&lt;/fileset&gt;
&lt;/pmd&gt;
&lt;/target&gt;
</code></pre></div></div>
<h3 id="memory-usage">Memory Usage</h3>
<p>Memory usage has been reduced significantly starting with the PMD 4.0 release.
When testing all Java rules on the jdk 1.6 source code (about 7000 classes),
the allocated heap space does not go over 60M.</p>
<p>However, on very large projects, the Ant task may still fail with a OutOfMemoryError.
To prevent this from happening, increase the maximum memory usable by ant using the ANT_OPTS variable
(adjust the size according to your available memory):</p>
<p>On Windows:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>set ANT_OPTS=-Xmx1024m -Xms512m
</code></pre></div></div>
<p>On Linux</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>export ANT_OPTS="-Xmx1024m -Xms512m"
</code></pre></div></div>
<div class="tags">
<b>Tags: </b>
<a href="tag_userdocs.html" class="btn btn-default navbar-btn cursorNorm" role="button">userdocs</a>
<a href="tag_tools.html" class="btn btn-default navbar-btn cursorNorm" role="button">tools</a>
</div>
</div>
<hr class="shaded"/>
<footer>
<div class="row">
<div class="col-lg-12 footer">
&copy;2018 PMD Open Source Project. All rights reserved. <br />
Site last generated: Jun 17, 2018 <br />
<p><img src="images/pmd-logo-small.png" alt="Company logo"/></p>
</div>
</div>
</footer>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
</div>
</div>
</body>
</html>