-
Notifications
You must be signed in to change notification settings - Fork 9
/
anttask.html
727 lines (540 loc) · 23.6 KB
/
anttask.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.11.1 from src/xdocs/anttask.xml.vm at 2024-12-28
| Rendered using Apache Maven Default Skin
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 1.11.1" />
<title>checkstyle – Ant Task</title>
<link rel="stylesheet" href="./css/maven-base.css" />
<link rel="stylesheet" href="./css/maven-theme.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script type="text/javascript" src="./js/checkstyle.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="./js/anchors.js"></script>
<script type="text/javascript" src="./js/google-analytics.js"></script>
<link rel="icon" href="./images/favicon.png" type="image/x-icon" />
<link rel="shortcut icon" href="./images/favicon.ico" type="image/ico" />
</head>
<body class="composite">
<div id="banner">
<a href="./" id="bannerLeft" title="Checkstyle"><img src="images/header-checkstyle-logo.png" alt="Checkstyle"/></a><a href="./" id="bannerRight" title="Checkstyle"><img src="images/header-right-ruller.png" alt="Checkstyle"/></a> <div class="clear">
<hr/>
</div>
</div>
<div id="breadcrumbs">
<div class="xright"><a href="" title="toTop">toTop</a> | <span id="publishDate">Last Published: 2024-12-28</span>
| <span id="projectVersion">Version: 10.21.1</span>
</div>
<div class="clear">
<hr/>
</div>
</div>
<div id="leftColumn">
<div id="navcolumn">
<h5>About</h5>
<ul>
<li class="none"><a href="index.html" title="Checkstyle">Checkstyle</a></li>
<li class="none"><a href="releasenotes.html" title="Release Notes">Release Notes</a></li>
<li class="none"><a href="consulting.html" title="Consulting">Consulting</a></li>
<li class="none"><a href="sponsoring.html" title="Sponsoring">Sponsoring</a></li>
</ul>
<h5>Documentation</h5>
<ul>
<li class="expanded"><a href="config.html" title="Configuration">Configuration</a>
<ul>
<li class="none"><a href="property_types.html" title="Property Types">Property Types</a></li>
<li class="none"><a href="config_system_properties.html" title="System Properties">System Properties</a></li>
</ul></li>
<li class="expanded"><a href="running.html" title="Running">Running</a>
<ul>
<li class="none"><strong>Ant Task</strong></li>
<li class="none"><a href="cmdline.html" title="Command Line">Command Line</a></li>
</ul></li>
<li class="expanded"><a href="checks.html" title="Checks">Checks</a>
<ul>
<li class="collapsed"><a href="checks/annotation/index.html" title="Annotations">Annotations</a></li>
<li class="collapsed"><a href="checks/blocks/index.html" title="Block Checks">Block Checks</a></li>
<li class="collapsed"><a href="checks/design/index.html" title="Class Design">Class Design</a></li>
<li class="collapsed"><a href="checks/coding/index.html" title="Coding">Coding</a></li>
<li class="collapsed"><a href="checks/header/index.html" title="Headers">Headers</a></li>
<li class="collapsed"><a href="checks/imports/index.html" title="Imports">Imports</a></li>
<li class="collapsed"><a href="checks/javadoc/index.html" title="Javadoc Comments">Javadoc Comments</a></li>
<li class="collapsed"><a href="checks/metrics/index.html" title="Metrics">Metrics</a></li>
<li class="collapsed"><a href="checks/misc/index.html" title="Miscellaneous">Miscellaneous</a></li>
<li class="collapsed"><a href="checks/modifier/index.html" title="Modifiers">Modifiers</a></li>
<li class="collapsed"><a href="checks/naming/index.html" title="Naming Conventions">Naming Conventions</a></li>
<li class="collapsed"><a href="checks/regexp/index.html" title="Regexp">Regexp</a></li>
<li class="collapsed"><a href="checks/sizes/index.html" title="Size Violations">Size Violations</a></li>
<li class="collapsed"><a href="checks/whitespace/index.html" title="Whitespace">Whitespace</a></li>
</ul></li>
<li class="collapsed"><a href="filters/index.html" title="Filters">Filters</a></li>
<li class="collapsed"><a href="filefilters/index.html" title="File Filters">File Filters</a></li>
<li class="expanded"><a href="style_configs.html" title="Style Configurations">Style Configurations</a>
<ul>
<li class="none"><a href="google_style.html" title="Google's Style">Google's Style</a></li>
<li class="none"><a href="sun_style.html" title="Sun's Style">Sun's Style</a></li>
</ul></li>
</ul>
<h5>Developers</h5>
<ul>
<li class="expanded"><a href="extending.html" title="Extending Checkstyle">Extending Checkstyle</a>
<ul>
<li class="none"><a href="writingchecks.html" title="Writing Checks">Writing Checks</a></li>
<li class="none"><a href="writingjavadocchecks.html" title="Writing Javadoc Checks">Writing Javadoc Checks</a></li>
<li class="none"><a href="writingfilters.html" title="Writing Filters">Writing Filters</a></li>
<li class="none"><a href="writingfilefilters.html" title="Writing File Filters">Writing File Filters</a></li>
<li class="none"><a href="writinglisteners.html" title="Writing Listeners">Writing Listeners</a></li>
</ul></li>
<li class="none"><a href="contributing.html" title="Contributing">Contributing</a></li>
<li class="expanded"><a href="beginning_development.html" title="Beginning Development">Beginning Development</a>
<ul>
<li class="none"><a href="eclipse.html" title="Eclipse IDE">Eclipse IDE</a></li>
<li class="none"><a href="netbeans.html" title="NetBeans IDE">NetBeans IDE</a></li>
<li class="none"><a href="idea.html" title="IntelliJ IDE">IntelliJ IDE</a></li>
</ul></li>
<li class="none"><a href="apidocs/index.html" title="Javadoc">Javadoc</a></li>
</ul>
<h5>Project Documentation</h5>
<ul>
<li class="collapsed"><a href="project-info.html" title="Project Information">Project Information</a></li>
<li class="collapsed"><a href="project-reports.html" title="Project Reports">Project Reports</a></li>
</ul>
<a href="https://github.com/checkstyle/checkstyle" title="GitHub" class="poweredBy">
<img class="poweredBy" alt="GitHub" src="images/github_logo_social_coding_outlined.png" />
</a>
<a href="https://twitter.com/checkstyle_java/" title="Twitter" class="poweredBy">
<img class="poweredBy" alt="Twitter" src="images/twitter_button.png" />
</a>
<a href="https://stackoverflow.com/questions/tagged/checkstyle" title="Stackoverflow" class="poweredBy">
<img class="poweredBy" alt="Stackoverflow" src="images/stackoverflow.jpeg" />
</a>
<a href="https://groups.google.com/forum/#!forum/checkstyle" title="GoogleGroups" class="poweredBy">
<img class="poweredBy" alt="GoogleGroups" src="images/groups.png" />
</a>
<a href="https://www.ej-technologies.com/products/jprofiler/overview.html" title="JProfiler" class="poweredBy">
<img class="poweredBy" alt="JProfiler" src="https://www.ej-technologies.com/images/product_banners/jprofiler_medium.png" />
</a>
</div>
</div>
<div id="bodyColumn">
<div id="contentBox">
<section>
<h2><a name="Content"></a>Content</h2>
<ul>
<li><a href="#Content">Content</a></li>
<li><a href="#Description">Description</a></li>
<li><a href="#Installation">Installation</a></li>
<li><a href="#Parameters">Parameters</a></li>
<li><a href="#Nested_Elements">Nested Elements</a></li>
<li><a href="#Examples">Examples</a></li></ul>
</section>
<section>
<h2><a name="Description"></a>Description</h2>
<p>
This task runs Checkstyle over specified Java files.
The latest version of checkstyle can be found at
<a href="./index.html">https://checkstyle.org/</a>.
This task is included in the checkstyle distribution.
</p>
</section>
<section>
<h2><a name="Installation"></a>Installation</h2>
<p>
The easiest way is to include
<code>checkstyle-10.21.1-all.jar</code> in the
classpath. This contains all the classes required to run
Checkstyle. Alternatively, you must include the
<code>compile</code> third party dependencies listed in <a href="dependencies.html">Project Dependencies</a> in the
classpath.
</p>
<p>
To use the task in a build file, you will need the following
<code>taskdef</code> declaration:
</p>
<div class="source">
<pre>
<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"
classpath="/path/to/checkstyle-10.21.1-all.jar"/>
</pre></div>
<p>
Or, assuming that Checkstyle is in the global classpath (not
recommended), then you will need the following <code>taskdef</code>
declaration:
</p>
<div class="source">
<pre>
<taskdef
resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"/>
</pre></div>
<p>
Or if you use Ant 1.6 and later and assuming that Checkstyle
is in the library search path, then you may use antlib feature
of Ant (see <a class="externalLink" href="https://ant.apache.org/manual/Types/antlib.html">https://ant.apache.org/manual/Types/antlib.html</a>
for more details). For example:
</p>
<div class="source">
<pre>
<project name="foo" ...
xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant">
...
<cs:checkstyle>
...
</cs:checkstyle>
...
</project>
</pre></div>
</section>
<section>
<h2><a name="Parameters"></a>Parameters</h2>
<div class="wrapper">
<table border="0" class="bodyTable" summary="parameters">
<tr class="a">
<td align="left"><b>Attribute</b></td>
<td><b>Description</b></td>
<td><b>Required</b></td>
</tr>
<tr class="b">
<td align="left">file</td>
<td>File to run checkstyle on.</td>
<td>
One of either <i>file</i> or at least one nested <i>fileset</i> or <i>path</i>
element
</td>
</tr>
<tr class="a">
<td align="left">fileset</td>
<td>
A set of files to run checkstyle on. Nested attribute.
See <a class="externalLink" href="https://ant.apache.org/manual/Types/fileset.html">fileset</a>
ant documentation for details
</td>
<td>
One of either <i>file</i> or at least one nested <i>fileset</i> or <i>path</i>
element
</td>
</tr>
<tr class="b">
<td align="left">path</td>
<td>
A set of path to run checkstyle on. Nested attribute.
See <a class="externalLink" href="https://ant.apache.org/manual/using.html#path">path</a>
ant documentation for details
</td>
<td>
One of either <i>file</i> or at least one nested <i>fileset</i> or <i>path</i>
element
</td>
</tr>
<tr class="a">
<td align="left">config</td>
<td>
Specifies the location of the file, URL, or Java resource that defines the
configuration modules.
<br />
<a href="config.html">See here</a> for a description of how to
define a configuration.
</td>
<td>Exactly one config location</td>
</tr>
<tr class="b">
<td align="left">properties</td>
<td>
Specifies a file that contains properties for <a href="config.html#Properties"> expanded property values</a> of the
configuration. Ant properties (like ${basedir}) and nested
property elements override the properties in this file.
</td>
<td>No</td>
</tr>
<tr class="a">
<td align="left">failOnViolation</td>
<td>
Specifies whether the build will continue even if there are
violations. Defaults to <code>"true"</code>.
</td>
<td>No</td>
</tr>
<tr class="b">
<td align="left">failureProperty</td>
<td>The name of a property to set in the event of a violation.</td>
<td>No</td>
</tr>
<tr class="a">
<td align="left">maxErrors</td>
<td>
The maximum number of errors that are tolerated before
breaking the build or setting the failure property. Defaults
to <code>"0"</code>.
</td>
<td>No</td>
</tr>
<tr class="b">
<td align="left">maxWarnings</td>
<td>
The maximum number of warnings that are tolerated before
breaking the build or setting the failure property. Defaults
to <code>"2147483647"</code>, i.e.
<a class="externalLink" href="https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#MAX_VALUE">
Integer.MAX_VALUE</a>.
</td>
<td>No</td>
</tr>
<tr class="a">
<td align="left">executeIgnoredModules</td>
<td>
For efficiency, Checkstyle does not invoke modules with a configured severity of
"ignore" (since their output would be ignored anyway). A small number of modules
may choose to log above their configured severity level and so always need to be
invoked. These settings specify that behaviour.
Defaults to <code>"false"</code>.
</td>
<td>No</td>
</tr>
</table>
</div>
<p>
Note that the <code>packageNamesFile</code>
parameter has been dropped for Checkstyle 5.0, because of
significant changes regarding package name file handling. See <a href="config.html#Packages"></a> for details.
</p>
<p>
Also note, that checkstyle ignores all duplicate files,
specified in the <i>file</i>, <i>fileset</i> or <i>path</i> parameters
</p>
</section>
<section>
<h2><a name="Nested_Elements"></a>Nested Elements</h2>
<p>
This task supports the nested elements <a class="externalLink" href="https://ant.apache.org/manual/Types/fileset.html"><fileset></a>,
<a class="externalLink" href="https://ant.apache.org/manual/using.html#path"><classpath></a>,
<a class="externalLink" href="https://ant.apache.org/manual/using.html#path"><path></a>,
<code><formatter></code>, and <code><property></code>.
</p>
<p>
The parameters for the <code><formatter></code>
element are:
</p>
<div class="wrapper">
<table border="0" class="bodyTable" summary="nested elements">
<tr class="a">
<td align="left"><b>Attribute</b></td>
<td><b>Description</b></td>
<td><b>Required</b></td>
</tr>
<tr class="b">
<td align="left">type</td>
<td>
<p>The type of output to generate. The valid values are:</p>
<ul>
<li>
<code>plain</code> - specifies the <a href="apidocs/com/puppycrawl/tools/checkstyle/DefaultLogger.html">
DefaultLogger</a>
</li>
<li>
<code>xml</code> - specifies the <a href="apidocs/com/puppycrawl/tools/checkstyle/XMLLogger.html">XMLLogger</a>
</li>
<li>
<code>sarif</code> - specifies the <a href="apidocs/com/puppycrawl/tools/checkstyle/SarifLogger.html">SarifLogger</a>
</li>
</ul>
<p>Defaults to <code>"plain"</code>.</p>
</td>
<td>No</td>
</tr>
<tr class="a">
<td align="left">toFile</td>
<td>
The file to write output to. Defaults to standard output. Note,
there is no way to explicitly specify standard output.
</td>
<td>No</td>
</tr>
<tr class="b">
<td align="left">useFile</td>
<td>Boolean that determines whether output should be sent to
a file. Default is <code>true</code>.</td>
<td>No</td>
</tr>
</table>
</div>
<p>
A <code><property></code> element provides a property for
<a href="config.html#Properties">expanded property values</a> of
the configuration. The parameters for the
<code><property></code> element are:
</p>
<div class="wrapper">
<table border="0" class="bodyTable" summary="nested elements">
<tr class="a">
<td align="left"><b>Attribute</b></td>
<td><b>Description</b></td>
<td><b>Required</b></td>
</tr>
<tr class="b">
<td align="left">key</td>
<td>
<p>The key for the property.</p></td>
<td>Yes</td>
</tr>
<tr class="a">
<td align="left">value</td>
<td>The value of the property specified as a string.</td>
<td>Either <i>value</i> or <i>file</i></td>
</tr>
<tr class="b">
<td align="left">file</td>
<td>
The value of the property specified as a file. This is great for
specifying file names relative to the ANT build file.
</td>
<td>Either <i>value</i> or <i>file</i></td>
</tr>
</table>
</div>
</section>
<section>
<h2><a name="Examples"></a>Examples</h2>
<p>
An example project can be found
<a class="externalLink" href="https://github.com/sevntu-checkstyle/checkstyle-samples/tree/master/ant-project">
here</a>.
</p>
<p>
<b>
Checkstyle use ant configuration to validate its own code. See example is our git
repository -
<a class="externalLink" href="https://github.com/checkstyle/checkstyle/blob/master/config/ant-phase-verify.xml#L25">
config/ant-phase-verify.xml</a>.
</b>
</p>
<p>
<b>
Run checkstyle with configuration file
<code>docs/sun_checks.xml</code> on a single file
</b>
</p>
<div class="source">
<pre>
<checkstyle config="docs/sun_checks.xml" file="Check.java"/>
</pre></div>
<p>
<b>
Run checkstyle on a set of Java files using site-wide configuration
and an expanded property value
</b>
</p>
<div class="source">
<pre>
<checkstyle config="/path/to/site/sun_checks.xml">
<fileset dir="src/checkstyle" includes="**/*.java"/>
<!-- Location of cache-file. Something that is project specific -->
<property key="checkstyle.cache.file" file="target/cachefile"/>
</checkstyle>
</pre></div>
<p>
<b>
Run checkstyle on a previously defined source path.
</b>
</p>
<div class="source">
<pre>
<!-- Somewhere in your config -->
<path id="project.sourcepath">
<fileset dir="src"
includes="**/*"
excludes="it/resources/**/*,test/resources/**/*,test/resources-noncompilable/**/*"/>
</path>
<!-- Actual checkstyle config -->
<checkstyle config="/path/to/site/sun_checks.xml">
<!-- Refer to a previously defined source path -->
<path refid="project.sourcepath" />
</checkstyle>
</pre></div>
<p>
<b>
Run checkstyle on a set of files and output messages to standard
output in plain format, and files in XML & SARIF format
</b>
</p>
<div class="source">
<pre>
<checkstyle config="docs/sun_checks.xml">
<fileset dir="src/checkstyle" includes="**/*.java"/>
<formatter type="plain"/>
<formatter type="xml" toFile="build/checkstyle_errors.xml"/>
<formatter type="sarif" toFile="build/checkstyle_errors.sarif"/>
</checkstyle>
</pre></div>
<p>
<b>
Run checkstyle with configuration file
<code>docs/sun_checks.xml</code> on a file and provide a package
names file
</b>
</p>
<div class="source">
<pre>
<checkstyle config="docs/sun_checks.xml"
packageNamesFile="myPackageNames.xml"
file="Check.java"/>
</pre></div>
<p>
<b>
Run checkstyle in an automated build and send an email report if
style violations are detected
</b>
</p>
<div class="source">
<pre>
<target name="checkstyle"
description="Generates a report of code convention violations.">
<checkstyle config="docs/sun_checks.xml"
failureProperty="checkstyle.failure"
failOnViolation="false">
<formatter type="xml" tofile="checkstyle_report.xml"/>
<fileset dir="src" includes="**/*.java"/>
</checkstyle>
<style in="checkstyle_report.xml" out="checkstyle_report.html"
style="checkstyle.xsl"/>
</target>
<!-- run this target as part of automated build -->
<target name="checkstyle-nightly"
depends="checkstyle"
if="checkstyle.failure"
description="Sends email if checkstyle detected code conventions violations.">
<!-- use your own server and email addresses below. See Ant documentation for details -->
<mail from="qa@some.domain"
tolist="someone@some.domain,someoneelse@some.domain"
mailhost="mailbox.some.domain"
subject="Checkstyle violation(s) in project ${ant.project.name}"
files="checkstyle_report.html"/>
</target>
</pre></div>
<p>
<b>
To run checkstyle with a custom JAR with implementation of custom Checks
be sure the custom JAR is found on the classpath. An example can be found at
<a class="externalLink" href="https://github.com/sevntu-checkstyle/checkstyle-samples/tree/master/ant-project">
checkstyle-samples</a>.
</b>
</p>
</section>
</div>
</div>
<div class="clear">
<hr/>
</div>
<div id="footer">
<div class="xright">
Copyright © 2001–2024.. </div>
<div class="clear">
<hr/>
</div>
</div>
</body>
</html>