Codebase list findbugs / 77e952f src / antTask / edu / umd / cs / findbugs / anttask / FindBugsTask.java
77e952f

Tree @77e952f (Download .tar.gz)

FindBugsTask.java @77e952fraw · history · blame

  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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
/*
 * FindBugs - Find Bugs in Java programs
 * Copyright (C) 2003-2013 University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs.anttask;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;

import edu.umd.cs.findbugs.BugRanker;
import edu.umd.cs.findbugs.ExitCodes;

/**
 * FindBugs in Java class files. This task can take the following arguments:
 * <ul>
 * <li>adjustExperimental (boolean default false)
 * <li>adjustPriority (passed to -adjustPriority)
 * <li>applySuppression (exclude any warnings that match a suppression filter
 * supplied in a project file)
 * <li>auxAnalyzepath (class, jar, zip files or directories containing classes
 * to analyze)
 * <li>auxClasspath (classpath or classpathRef)
 * <li>baselineBugs (xml file containing baseline bugs)
 * <li>class (class, jar, zip or directory containing classes to analyze)
 * <li>classpath (classpath for running FindBugs)
 * <li>cloud (cloud id)
 * <li>conserveSpace (boolean - default false)</li>
 * <li>debug (boolean default false)
 * <li>effort (enum min|default|max)</li>
 * <li>excludeFilter (filter filename)
 * <li>excludePath (classpath or classpathRef to filters)
 * <li>failOnError (boolean - default false)
 * <li>home (findbugs install dir)
 * <li>includeFilter (filter filename)
 * <li>includePath (classpath or classpathRef to filters)
 * <li>maxRank (maximum rank issue to be reported)
 * <li>jvm (Set the command used to start the VM)
 * <li>jvmargs (any additional jvm arguments)
 * <li>omitVisitors (collection - comma separated)
 * <li>onlyAnalyze (restrict analysis to find bugs to given comma-separated list
 * of classes and packages - See the textui argument description for details)
 * <li>output (enum text|xml|xml:withMessages|html - default xml)
 * <li>outputFile (name of output file to create)
 * <li>nested (boolean default true)
 * <li>noClassOk (boolean default false)
 * <li>pluginList (list of plugin Jar files to load)
 * <li>projectFile (project filename)
 * <li>projectName (project name, for display in generated HTML)
 * <li>userPrefs (user preferences filename)
 * <li>quietErrors (boolean - default false)
 * <li>relaxed (boolean - default false)
 * <li>reportLevel (enum experimental|low|medium|high)
 * <li>sort (boolean default true)
 * <li>stylesheet (name of stylesheet to generate HTML: default is
 * "default.xsl")
 * <li>systemProperty (a system property to set)
 * <li>timestampNow (boolean - default false)
 * <li>visitors (collection - comma separated)
 * <li>chooseVisitors (selectively enable/disable visitors)
 * <li>workHard (boolean default false)
 * <li>setSetExitCode (boolean default true)
 * </ul>
 * Of these arguments, the <b>home</b> is required. <b>projectFile</b> is
 * required if nested &lt;class&gt; or &lt;auxAnalyzepath&gt elements are not
 * specified. the &lt;class&gt; tag defines the location of either a class, jar
 * file, zip file, or directory containing classes.
 * <p>
 *
 * @author Mike Fagan <a href="mailto:mfagan@tde.com">mfagan@tde.com</a>
 * @author Michael Tamm <a
 *         href="mailto:mail@michaeltamm.de">mail@michaeltamm.de</a>
 * @author Scott Wolk
 * @version $Revision: 1.56 $
 *
 * @since Ant 1.5
 *
 * @ant.task category="utility"
 */

public class FindBugsTask extends AbstractFindBugsTask {

    private String effort;

    private boolean conserveSpace;

    private boolean sorted = true;

    private boolean timestampNow = true;

    private boolean quietErrors;

    private String warningsProperty;

    private String cloudId;

    private int maxRank;

    private String projectName;

    private boolean workHard;

    private boolean relaxed;

    private boolean adjustExperimental;

    private String adjustPriority;

    private File projectFile;

    private File userPreferencesFile;

    private File baselineBugs;

    private boolean applySuppression;

    private File excludeFile;

    private Path excludePath;

    private File includeFile;

    private Path includePath;

    private Path auxClasspath;

    private Path auxAnalyzepath;

    private Path sourcePath;

    private String outputFormat = "xml";

    private String reportLevel;

    private String visitors;

    private String chooseVisitors;

    private String omitVisitors;

    private String outputFileName;

    private String stylesheet;

    private final List<ClassLocation> classLocations = new ArrayList<ClassLocation>();

    private String onlyAnalyze;

    private boolean noClassOk;

    private boolean nested = true;

    private boolean setExitCode = true;

    private final List<FileSet> filesets = new ArrayList<FileSet>();

    public FindBugsTask() {
        super("edu.umd.cs.findbugs.FindBugs2");
    }

    // define the inner class to store class locations
    public static class ClassLocation {
        File classLocation = null;

        public void setLocation(File location) {
            classLocation = location;
        }

        public File getLocation() {
            return classLocation;
        }

        @Override
        public String toString() {
            return classLocation != null ? classLocation.toString() : "";
        }

    }

    /**
     * Set the workHard flag.
     *
     * @param workHard
     *            true if we want findbugs to run with workHard option enabled
     */
    public void setWorkHard(boolean workHard) {
        this.workHard = workHard;
    }

    /**
     * Set the exit code flag.
     *
     * @param setExitCode
     *            If true then the exit code will be returned to
     *            the main ant job
     */
    public void setSetExitCode(boolean setExitCode) {
        this.setExitCode = setExitCode;
    }

    /**
     * Set the nested flag.
     *
     * @param nested
     *            This option enables or disables scanning of
     *            nested jar and zip files found in the list of files
     *            and directories to be analyzed. By default, scanning
     *            of nested jar/zip files is enabled
     */
    public void setNested(boolean nested) {
        this.nested = nested;
    }

    /**
     * Set the noClassOk flag.
     *
     * @param noClassOk
     *            true if we should generate no-error output if no classfiles
     *            are specified
     */
    public void setNoClassOk(boolean noClassOk) {
        this.noClassOk = noClassOk;
    }

    /**
     * Set the relaxed flag.
     *
     * @param relaxed
     *            true if we want findbugs to run with relaxed option enabled
     */
    public void setRelaxed(boolean relaxed) {
        this.relaxed = relaxed;
    }

    /**
     * Set the adjustExperimental flag
     *
     * @param adjustExperimental
     *            true if we want experimental bug patterns to have lower
     *            priority
     */
    public void setAdjustExperimental(boolean adjustExperimental) {
        this.adjustExperimental = adjustExperimental;
    }

    public void setAdjustPriority(String adjustPriorityString) {
        this.adjustPriority = adjustPriorityString;
    }

    /**
     * Set the specific visitors to use
     */
    public void setVisitors(String commaSeperatedString) {
        this.visitors = commaSeperatedString;
    }

    /**
     * Set the specific visitors to use
     */
    public void setChooseVisitors(String commaSeperatedString) {
        this.chooseVisitors = commaSeperatedString;
    }

    /**
     * Set the specific visitors to use
     */
    public void setOmitVisitors(String commaSeperatedString) {
        this.omitVisitors = commaSeperatedString;
    }

    /**
     * Set the output format
     */
    public void setOutput(String format) {
        this.outputFormat = format;
    }

    /**
     * Set the stylesheet filename for HTML generation.
     */
    public void setStylesheet(String stylesheet) {
        this.stylesheet = stylesheet;
    }

    /**
     * Set the report level
     */
    public void setReportLevel(String level) {
        this.reportLevel = level;
    }

    /**
     * Set the sorted flag
     */
    public void setSort(boolean flag) {
        this.sorted = flag;
    }

    /**
     * Set the timestampNow flag
     */
    public void setTimestampNow(boolean flag) {
        this.timestampNow = flag;
    }

    /**
     * Set the quietErrors flag
     */
    public void setQuietErrors(boolean flag) {
        this.quietErrors = flag;
    }

    /**
     * Set the quietErrors flag
     */
    public void setApplySuppression(boolean flag) {
        this.applySuppression = flag;
    }

    /**
     * Tells this task to set the property with the given name to "true" when
     * bugs were found.
     */
    public void setWarningsProperty(String name) {
        this.warningsProperty = name;
    }

    /**
     * Set effort level.
     *
     * @param effort
     *            the effort level
     */
    public void setEffort(String effort) {
        this.effort = effort;
    }

    public void setCloud(String cloudId) {
        this.cloudId = cloudId.trim();
    }

    public void setMaxRank(int maxRank) {
        this.maxRank = maxRank;
    }

    /**
     * Set project name
     *
     * @param projectName
     *            the project name
     */
    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    /**
     * Set the conserveSpace flag.
     */
    public void setConserveSpace(boolean flag) {
        this.conserveSpace = flag;
    }

    /**
     * Set the exclude filter file
     */
    public void setExcludeFilter(File filterFile) {
        if (filterFile != null && filterFile.length() > 0) {
            this.excludeFile = filterFile;
        } else {
            this.excludeFile = null;
        }
    }

    /**
     * Set the exclude filter file
     */
    public void setIncludeFilter(File filterFile) {
        if (filterFile != null && filterFile.length() > 0) {
            this.includeFile = filterFile;
        } else {
            this.includeFile = null;
        }
    }

    /**
     * Set the exclude filter file
     */
    public void setBaselineBugs(File baselineBugs) {
        if (baselineBugs != null && baselineBugs.length() > 0) {
            this.baselineBugs = baselineBugs;
        } else {
            this.baselineBugs = null;
        }
    }

    /**
     * Set the project file
     */
    public void setProjectFile(File projectFile) {
        this.projectFile = projectFile;
    }

    /**
     * Set the project file
     */
    public void setUserPreferencesFile(File userPreferencesFile) {
        this.userPreferencesFile = userPreferencesFile;
    }

    /**
     * the auxclasspath to use.
     */
    public void setAuxClasspath(Path src) {
        boolean nonEmpty = false;

        String[] elementList = src.list();
        for (String anElementList : elementList) {
            if (!"".equals(anElementList)) {
                nonEmpty = true;
                break;
            }
        }

        if (nonEmpty) {
            if (auxClasspath == null) {
                auxClasspath = src;
            } else {
                auxClasspath.append(src);
            }
        }
    }

    /**
     * Path to use for auxclasspath.
     */
    public Path createAuxClasspath() {
        if (auxClasspath == null) {
            auxClasspath = new Path(getProject());
        }
        return auxClasspath.createPath();
    }

    /**
     * Adds a reference to a sourcepath defined elsewhere.
     */
    public void setAuxClasspathRef(Reference r) {
        Path path = createAuxClasspath();
        path.setRefid(r);
        path.toString(); // Evaluated for its side-effects (throwing a
        // BuildException)
    }

    /**
     * the auxAnalyzepath to use.
     */
    public void setAuxAnalyzepath(Path src) {
        boolean nonEmpty = false;

        String[] elementList = src.list();
        for (String anElementList : elementList) {
            if (!"".equals(anElementList)) {
                nonEmpty = true;
                break;
            }
        }

        if (nonEmpty) {
            if (auxAnalyzepath == null) {
                auxAnalyzepath = src;
            } else {
                auxAnalyzepath.append(src);
            }
        }
    }

    /**
     * Path to use for auxAnalyzepath.
     */
    public Path createAuxAnalyzepath() {
        if (auxAnalyzepath == null) {
            auxAnalyzepath = new Path(getProject());
        }
        return auxAnalyzepath.createPath();
    }

    /**
     * Adds a reference to a sourcepath defined elsewhere.
     */
    public void setAuxAnalyzepathRef(Reference r) {
        createAuxAnalyzepath().setRefid(r);
    }

    /**
     * the sourcepath to use.
     */
    public void setSourcePath(Path src) {
        if (sourcePath == null) {
            sourcePath = src;
        } else {
            sourcePath.append(src);
        }
    }

    /**
     * Path to use for sourcepath.
     */
    public Path createSourcePath() {
        if (sourcePath == null) {
            sourcePath = new Path(getProject());
        }
        return sourcePath.createPath();
    }

    /**
     * Adds a reference to a source path defined elsewhere.
     */
    public void setSourcePathRef(Reference r) {
        createSourcePath().setRefid(r);
    }

    /**
     * the sourcepath to use.
     */
    public void setExcludePath(Path src) {
        if (excludePath == null) {
            excludePath = src;
        } else {
            excludePath.append(src);
        }
    }

    /**
     * Path to use for sourcepath.
     */
    public Path createExcludePath() {
        if (excludePath == null) {
            excludePath = new Path(getProject());
        }
        return excludePath.createPath();
    }

    /**
     * Adds a reference to a source path defined elsewhere.
     */
    public void setExcludePathRef(Reference r) {
        createExcludePath().setRefid(r);
    }

    /**
     * the sourcepath to use.
     */
    public void setIncludePath(Path src) {
        if (includePath == null) {
            includePath = src;
        } else {
            includePath.append(src);
        }
    }

    /**
     * Path to use for sourcepath.
     */
    public Path createIncludePath() {
        if (includePath == null) {
            includePath = new Path(getProject());
        }
        return includePath.createPath();
    }

    /**
     * Adds a reference to a source path defined elsewhere.
     */
    public void setIncludePathRef(Reference r) {
        createIncludePath().setRefid(r);
    }

    /**
     * Add a class location
     */
    public ClassLocation createClass() {
        ClassLocation cl = new ClassLocation();
        classLocations.add(cl);
        return cl;
    }

    /**
     * Set name of output file.
     */
    public void setOutputFile(String outputFileName) {
        if (outputFileName != null && outputFileName.length() > 0) {
            this.outputFileName = outputFileName;
        }
    }

    /**
     * Set the packages or classes to analyze
     */
    public void setOnlyAnalyze(String filter) {
        this.onlyAnalyze = filter;
    }

    /**
     * Add a nested fileset of classes or jar files.
     */
    public void addFileset(FileSet fs) {
        filesets.add(fs);
    }

    /**
     * Check that all required attributes have been set
     */
    @Override
    protected void checkParameters() {
        super.checkParameters();

        if (projectFile == null && classLocations.size() == 0 && filesets.size() == 0 && auxAnalyzepath == null) {
            throw new BuildException("either projectfile, <class/>, <fileset/> or <auxAnalyzepath/> child "
                    + "elements must be defined for task <" + getTaskName() + "/>", getLocation());
        }

        if (cloudId != null && cloudId.contains(" ")) {
            throw new BuildException("cloudId must not contain spaces: '" + cloudId + "'");
        }

        if (outputFormat != null
                && !("xml".equalsIgnoreCase(outputFormat.trim()) || "xml:withMessages".equalsIgnoreCase(outputFormat.trim())
                        || "html".equalsIgnoreCase(outputFormat.trim()) || "text".equalsIgnoreCase(outputFormat.trim())
                        || "xdocs".equalsIgnoreCase(outputFormat.trim()) || "emacs".equalsIgnoreCase(outputFormat.trim()))) {
            throw new BuildException("output attribute must be either " + "'text', 'xml', 'html', 'xdocs' or 'emacs' for task <"
                    + getTaskName() + "/>", getLocation());
        }

        if (reportLevel != null
                && !("experimental".equalsIgnoreCase(reportLevel.trim()) || "low".equalsIgnoreCase(reportLevel.trim())
                        || "medium".equalsIgnoreCase(reportLevel.trim()) || "high".equalsIgnoreCase(reportLevel.trim()))) {
            throw new BuildException("reportlevel attribute must be either "
                    + "'experimental' or 'low' or 'medium' or 'high' for task <" + getTaskName() + "/>", getLocation());
        }

        // FindBugs allows both, so there's no apparent reason for this check
        // if ( excludeFile != null && includeFile != null ) {
        // throw new BuildException("only one of excludeFile and includeFile " +
        // " attributes may be used in task <" + getTaskName() + "/>",
        // getLocation());
        // }

        List<String> efforts = Arrays.asList( "min", "less", "default", "more", "max");
        if (effort != null && !efforts.contains(effort)) {
            throw new BuildException("effort attribute must be one of " + efforts);
        }
    }

    /*
     * (non-Javadoc)
     *
     * @see
     * edu.umd.cs.findbugs.anttask.AbstractFindBugsTask#beforeExecuteJavaProcess
     * ()
     */
    @Override
    protected void beforeExecuteJavaProcess() {
        log("Running FindBugs...");
    }

    /*
     * (non-Javadoc)
     *
     * @see
     * edu.umd.cs.findbugs.anttask.AbstractFindBugsTask#afterExecuteJavaProcess
     * (int)
     */
    @Override
    protected void afterExecuteJavaProcess(int rc) {
        if ((rc & ExitCodes.ERROR_FLAG) != 0) {
            throw new BuildException("Execution of findbugs failed.");
        }
        if ((rc & ExitCodes.MISSING_CLASS_FLAG) != 0) {
            log("Classes needed for analysis were missing");
        }
        if (warningsProperty != null && (rc & ExitCodes.BUGS_FOUND_FLAG) != 0) {
            getProject().setProperty(warningsProperty, "true");
        }

        if (outputFileName != null) {
            log("Output saved to " + outputFileName);
        }
    }

    @Override
    protected void configureFindbugsEngine() {
        if (projectName != null) {
            addArg("-projectName");
            addArg(projectName);
        }
        if (adjustExperimental) {
            addArg("-adjustExperimental");
        }

        if (cloudId != null) {
            addArg("-cloud");
            addArg(cloudId);
        }
        if (conserveSpace) {
            addArg("-conserveSpace");
        }
        if (workHard) {
            addArg("-workHard");
        }
        if (effort != null) {
            addArg("-effort:" + effort);
        }
        if (maxRank >= BugRanker.VISIBLE_RANK_MIN && maxRank <= BugRanker.VISIBLE_RANK_MAX) {
            addArg("-maxRank ");
            addArg(Integer.toString(maxRank));
        }
        if (adjustPriority != null) {
            addArg("-adjustPriority");
            addArg(adjustPriority);
        }

        if (sorted) {
            addArg("-sortByClass");
        }
        if (timestampNow) {
            addArg("-timestampNow");
        }

        if (outputFormat != null && !"text".equalsIgnoreCase(outputFormat.trim())) {
            outputFormat = outputFormat.trim();
            String outputArg = "-";
            int colon = outputFormat.indexOf(':');
            if (colon >= 0) {
                outputArg += outputFormat.substring(0, colon).toLowerCase();
                outputArg += ":";
                outputArg += outputFormat.substring(colon + 1);
            } else {
                outputArg += outputFormat.toLowerCase();
                if (stylesheet != null) {
                    outputArg += ":";
                    outputArg += stylesheet.trim();
                }
            }
            addArg(outputArg);
        }
        if (quietErrors) {
            addArg("-quiet");
        }
        if (reportLevel != null) {
            addArg("-" + reportLevel.trim().toLowerCase());
        }
        if (projectFile != null) {
            addArg("-project");
            addArg(projectFile.getPath());
        }
        if (userPreferencesFile != null) {
            addArg("-userPrefs");
            addArg(userPreferencesFile.getPath());
        }
        if (applySuppression) {
            addArg("-applySuppression");
        }

        if (baselineBugs != null) {
            addArg("-excludeBugs");
            addArg(baselineBugs.getPath());
        }
        if (excludeFile != null) {
            addArg("-exclude");
            addArg(excludeFile.getPath());
        }
        if (excludePath != null) {
            String[] result = excludePath.toString().split(java.io.File.pathSeparator);
            for (int x = 0; x < result.length; x++) {
                addArg("-exclude");
                addArg(result[x]);
            }
        }
        if (includeFile != null) {
            addArg("-include");
            addArg(includeFile.getPath());
        }
        if (includePath != null) {
            String[] result = includePath.toString().split(java.io.File.pathSeparator);
            for (int x = 0; x < result.length; x++) {
                addArg("-include");
                addArg(result[x]);
            }
        }
        if (visitors != null) {
            addArg("-visitors");
            addArg(visitors);
        }
        if (omitVisitors != null) {
            addArg("-omitVisitors");
            addArg(omitVisitors);
        }
        if (chooseVisitors != null) {
            addArg("-chooseVisitors");
            addArg(chooseVisitors);
        }

        if (auxClasspath != null) {
            try {
                // Try to dereference the auxClasspath.
                // If it throws an exception, we know it
                // has an invalid path entry, so we complain
                // and tolerate it.
                @SuppressWarnings("unused")
                String unreadReference = auxClasspath.toString();
                String auxClasspathString = auxClasspath.toString();
                if (!auxClasspathString.isEmpty()) {
                    if (auxClasspathString.length() > 100) {
                        addArg("-auxclasspathFromInput");
                        setInputString(auxClasspathString);
                    } else {
                        addArg("-auxclasspath");
                        addArg(auxClasspathString);
                    }
                }
            } catch (Throwable t) {
                log("Warning: auxClasspath " + t + " not found.");
            }
        }
        if (sourcePath != null) {
            addArg("-sourcepath");
            addArg(sourcePath.toString());
        }
        if (outputFileName != null) {
            addArg("-outputFile");
            addArg(outputFileName);
        }
        if (relaxed) {
            addArg("-relaxed");
        }
        if (!nested) {
            addArg("-nested:false");
        }
        if (noClassOk) {
            addArg("-noClassOk");
        }

        if (onlyAnalyze != null) {
            addArg("-onlyAnalyze");
            addArg(onlyAnalyze);
        }

        if (setExitCode) {
            addArg("-exitcode");
        }

        for (ClassLocation classLocation : classLocations) {
            addArg(classLocation.toString());
        }

        for (FileSet fs : filesets) {
            DirectoryScanner ds = fs.getDirectoryScanner();
            for (String fileName : ds.getIncludedFiles()) {
                File file = new File(ds.getBasedir(), fileName);
                addArg(file.toString());
            }
        }

        if (auxAnalyzepath != null) {
            String[] result = auxAnalyzepath.toString().split(java.io.File.pathSeparator);
            for (int x = 0; x < result.length; x++) {
                addArg(result[x]);
            }
        }
    }
}