View Javadoc
1   /*
2    * This file is part of dependency-check-ant.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.taskdefs;
19  
20  import org.apache.tools.ant.BuildException;
21  import org.apache.tools.ant.Project;
22  import org.apache.tools.ant.types.EnumeratedAttribute;
23  import org.apache.tools.ant.types.Reference;
24  import org.apache.tools.ant.types.Resource;
25  import org.apache.tools.ant.types.ResourceCollection;
26  import org.apache.tools.ant.types.resources.FileProvider;
27  import org.apache.tools.ant.types.resources.Resources;
28  import org.owasp.dependencycheck.Engine;
29  import org.owasp.dependencycheck.agent.DependencyCheckScanAgent;
30  import org.owasp.dependencycheck.ant.logging.AntTaskHolder;
31  import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
32  import org.owasp.dependencycheck.dependency.Dependency;
33  import org.owasp.dependencycheck.dependency.Vulnerability;
34  import org.owasp.dependencycheck.dependency.naming.Identifier;
35  import org.owasp.dependencycheck.exception.ExceptionCollection;
36  import org.owasp.dependencycheck.exception.ReportException;
37  import org.owasp.dependencycheck.reporting.ReportGenerator.Format;
38  import org.owasp.dependencycheck.utils.Downloader;
39  import org.owasp.dependencycheck.utils.InvalidSettingException;
40  import org.owasp.dependencycheck.utils.Settings;
41  import org.owasp.dependencycheck.utils.SeverityUtil;
42  import org.owasp.dependencycheck.utils.scarf.TelemetryCollector;
43  
44  import javax.annotation.concurrent.NotThreadSafe;
45  import java.io.File;
46  import java.util.ArrayList;
47  import java.util.List;
48  import java.util.stream.Collectors;
49  import java.util.stream.Stream;
50  
51  //CSOFF: MethodCount
52  /**
53   * An Ant task definition to execute dependency-check during an Ant build.
54   *
55   * @author Jeremy Long
56   */
57  @NotThreadSafe
58  public class Check extends Update {
59  
60      /**
61       * System specific new line character.
62       */
63      private static final String NEW_LINE = System.getProperty("line.separator", "\n").intern();
64  
65      /**
66       * Whether the ruby gemspec analyzer should be enabled.
67       */
68      private Boolean rubygemsAnalyzerEnabled;
69      /**
70       * Whether or not the Node Package Analyzer is enabled.
71       */
72      private Boolean nodeAnalyzerEnabled;
73      /**
74       * Whether or not the Node Audit Analyzer is enabled.
75       */
76      private Boolean nodeAuditAnalyzerEnabled;
77      /**
78       * Whether or not the Yarn Audit Analyzer is enabled.
79       */
80      private Boolean yarnAuditAnalyzerEnabled;
81      /**
82       * Whether or not the Pnpm Audit Analyzer is enabled.
83       */
84      private Boolean pnpmAuditAnalyzerEnabled;
85      /**
86       * Sets whether or not the Node Audit Analyzer should use a local cache.
87       */
88      private Boolean nodeAuditAnalyzerUseCache;
89      /**
90       * Sets whether or not the Node Package Analyzer should skip dev
91       * dependencies.
92       */
93      private Boolean nodePackageSkipDevDependencies;
94      /**
95       * Sets whether or not the Node Audit Analyzer should use a local cache.
96       */
97      private Boolean nodeAuditSkipDevDependencies;
98      /**
99       * The list of filters (regular expressions) used by the RetireJS Analyzer
100      * to exclude files that contain matching content..
101      */
102     @SuppressWarnings("CanBeFinal")
103     private final List<String> retireJsFilters = new ArrayList<>();
104     /**
105      * Whether or not the RetireJS Analyzer filters non-vulnerable JS files from
106      * the report; default is false.
107      */
108     private Boolean retireJsFilterNonVulnerable;
109     /**
110      * Whether or not the Ruby Bundle Audit Analyzer is enabled.
111      */
112     private Boolean bundleAuditAnalyzerEnabled;
113     /**
114      * Whether the CMake analyzer should be enabled.
115      */
116     private Boolean cmakeAnalyzerEnabled;
117     /**
118      * Whether or not the Open SSL analyzer is enabled.
119      */
120     private Boolean opensslAnalyzerEnabled;
121     /**
122      * Whether the python package analyzer should be enabled.
123      */
124     private Boolean pyPackageAnalyzerEnabled;
125     /**
126      * Whether the python distribution analyzer should be enabled.
127      */
128     private Boolean pyDistributionAnalyzerEnabled;
129     /**
130      * Whether or not the mix audit analyzer is enabled.
131      */
132     private Boolean mixAuditAnalyzerEnabled;
133     /**
134      * Whether or not the central analyzer is enabled.
135      */
136     private Boolean centralAnalyzerEnabled;
137     /**
138      * Whether or not the Central Analyzer should use a local cache.
139      */
140     private Boolean centralAnalyzerUseCache;
141     /**
142      * Whether or not the nexus analyzer is enabled.
143      */
144     private Boolean nexusAnalyzerEnabled;
145     /**
146      * Sets the Nexus Repository v3 API base URL (example <a href="https://domain.enterprise/nexus/">https://domain.enterprise/nexus/</a>).
147      */
148     private String nexusUrl;
149     /**
150      * The username to authenticate to the Nexus Server's REST API Endpoint.
151      */
152     private String nexusUser;
153     /**
154      * The password to authenticate to the Nexus Server's REST API Endpoint.
155      */
156     private String nexusPassword;
157     /**
158      * Whether or not the defined proxy should be used when connecting to Nexus.
159      */
160     private Boolean nexusUsesProxy;
161 
162     /**
163      * Sets whether the Golang Dependency analyzer is enabled. Default is true.
164      */
165     private Boolean golangDepEnabled;
166     /**
167      * Sets whether Golang Module Analyzer is enabled; this requires `go` to be
168      * installed. Default is true.
169      */
170     private Boolean golangModEnabled;
171     /**
172      * Sets the path to `go`.
173      */
174     private String pathToGo;
175     /**
176      * Sets whether the Dart analyzer is enabled. Default is true.
177      */
178     private Boolean dartAnalyzerEnabled;
179     /**
180      * The path to `yarn`.
181      */
182     private String pathToYarn;
183     /**
184      * The path to `pnpm`.
185      */
186     private String pathToPnpm;
187     /**
188      * Additional ZIP File extensions to add analyze. This should be a
189      * comma-separated list of file extensions to treat like ZIP files.
190      */
191     private String zipExtensions;
192     /**
193      * The path to dotnet core for .NET assembly analysis.
194      */
195     private String pathToCore;
196     /**
197      * The name of the project being analyzed.
198      */
199     private String projectName = "dependency-check";
200     /**
201      * Specifies the destination directory for the generated Dependency-Check
202      * report.
203      */
204     private String reportOutputDirectory;
205     /**
206      * If using the JUNIT report format the junitFailOnCVSS sets the CVSS score
207      * threshold that is considered a failure. The default is 0.
208      */
209     private float junitFailOnCVSS = 0;
210     /**
211      * Specifies if the build should be failed if a CVSS score above a specified
212      * level is identified. The default is 11 which means since the CVSS scores
213      * are 0-10, by default the build will never fail and the CVSS score is set
214      * to 11. The valid range for the fail build on CVSS is 0 to 11, where
215      * anything above 10 will not cause the build to fail.
216      */
217     private float failBuildOnCVSS = 11;
218     /**
219      * Sets whether auto-updating of the NVD CVE/CPE data is enabled. It is not
220      * recommended that this be turned to false. Default is true.
221      */
222     private Boolean autoUpdate;
223     /**
224      * The report format to be generated (HTML, XML, CSV, JSON, JUNIT, SARIF,
225      * JENKINS, GITLAB, ALL). Default is HTML.
226      */
227     private String reportFormat = "HTML";
228     /**
229      * The report format to be generated (HTML, XML, CSV, JSON, JUNIT, SARIF,
230      * JENKINS, GITLAB, ALL). Default is HTML.
231      */
232     private final List<String> reportFormats = new ArrayList<>();
233     /**
234      * Whether the JSON and XML reports should be pretty printed; the default is
235      * false.
236      */
237     private Boolean prettyPrint = null;
238 
239     /**
240      * Suppression file paths.
241      */
242     @SuppressWarnings("CanBeFinal")
243     private final List<String> suppressionFiles = new ArrayList<>();
244 
245     /**
246      * The path to the suppression file.
247      */
248     private String hintsFile;
249     /**
250      * flag indicating whether or not to show a summary of findings.
251      */
252     private boolean showSummary = true;
253     /**
254      * Whether experimental analyzers are enabled.
255      */
256     private Boolean enableExperimental;
257     /**
258      * Whether retired analyzers are enabled.
259      */
260     private Boolean enableRetired;
261     /**
262      * Whether or not the Jar Analyzer is enabled.
263      */
264     private Boolean jarAnalyzerEnabled;
265     /**
266      * Whether or not the Archive Analyzer is enabled.
267      */
268     private Boolean archiveAnalyzerEnabled;
269     /**
270      * Whether or not the .NET Nuspec Analyzer is enabled.
271      */
272     private Boolean nuspecAnalyzerEnabled;
273     /**
274      * Whether or not the .NET Nuget packages.config file Analyzer is enabled.
275      */
276     private Boolean nugetconfAnalyzerEnabled;
277     /**
278      * Whether or not the Libman Analyzer is enabled.
279      */
280     private Boolean libmanAnalyzerEnabled;
281     /**
282      * Whether or not the PHP Composer Analyzer is enabled.
283      */
284     private Boolean composerAnalyzerEnabled;
285     /**
286      * Whether or not the PHP Composer Analyzer will skip "packages-dev".
287      */
288     private Boolean composerAnalyzerSkipDev;
289     /**
290      * Whether or not the Perl CPAN File Analyzer is enabled.
291      */
292     private Boolean cpanfileAnalyzerEnabled;
293 
294     /**
295      * Whether or not the .NET Assembly Analyzer is enabled.
296      */
297     private Boolean assemblyAnalyzerEnabled;
298     /**
299      * Whether or not the MS Build Assembly Analyzer is enabled.
300      */
301     private Boolean msbuildAnalyzerEnabled;
302     /**
303      * Whether the autoconf analyzer should be enabled.
304      */
305     private Boolean autoconfAnalyzerEnabled;
306     /**
307      * Whether the pip analyzer should be enabled.
308      */
309     private Boolean pipAnalyzerEnabled;
310     /**
311      * Whether the Maven install.json analyzer should be enabled.
312      */
313     private Boolean mavenInstallAnalyzerEnabled;
314     /**
315      * Whether the pipfile analyzer should be enabled.
316      */
317     private Boolean pipfileAnalyzerEnabled;
318     /**
319      * Whether the Poetry analyzer should be enabled.
320      */
321     private Boolean poetryAnalyzerEnabled;
322     /**
323      * Sets the path for the mix_audit binary.
324      */
325     private String mixAuditPath;
326     /**
327      * Sets the path for the bundle-audit binary.
328      */
329     private String bundleAuditPath;
330     /**
331      * Sets the path for the working directory that the bundle-audit binary
332      * should be executed from.
333      */
334     private String bundleAuditWorkingDirectory;
335     /**
336      * Whether or not the CocoaPods Analyzer is enabled.
337      */
338     private Boolean cocoapodsAnalyzerEnabled;
339     /**
340      * Whether or not the Carthage Analyzer is enabled.
341      */
342     private Boolean carthageAnalyzerEnabled;
343 
344     /**
345      * Whether or not the Swift package Analyzer is enabled.
346      */
347     private Boolean swiftPackageManagerAnalyzerEnabled;
348     /**
349      * Whether or not the Swift package Analyzer is enabled.
350      */
351     private Boolean swiftPackageResolvedAnalyzerEnabled;
352 
353     /**
354      * Whether or not the Sonatype OSS Index analyzer is enabled.
355      */
356     private Boolean ossIndexAnalyzerEnabled;
357     /**
358      * Whether or not the Sonatype OSS Index analyzer should cache results.
359      */
360     private Boolean ossIndexAnalyzerUseCache;
361     /**
362      * The number of hours to wait before checking for new updates on individual packages/components from Sonatype OSS Index.
363      */
364     private Integer ossIndexAnalyzerCacheValidForHours;
365     /**
366      * URL of the Sonatype OSS Index service.
367      */
368     private String ossIndexAnalyzerUrl;
369     /**
370      * The username to use for the Sonatype OSS Index service.
371      */
372     private String ossIndexAnalyzerUsername;
373     /**
374      * The password to use for the Sonatype OSS Index service.
375      */
376     private String ossIndexAnalyzerPassword;
377     /**
378      * Whether we should only warn about Sonatype OSS Index remote errors
379      * instead of failing completely.
380      */
381     private Boolean ossIndexAnalyzerWarnOnlyOnRemoteErrors;
382 
383     /**
384      * Whether or not the Artifactory Analyzer is enabled.
385      */
386     private Boolean artifactoryAnalyzerEnabled;
387     /**
388      * The URL to Artifactory.
389      */
390     private String artifactoryAnalyzerUrl;
391     /**
392      * Whether or not Artifactory analysis should use the proxy..
393      */
394     private Boolean artifactoryAnalyzerUseProxy;
395     /**
396      * Whether or not Artifactory analysis should be parallelized.
397      */
398     private Boolean artifactoryAnalyzerParallelAnalysis;
399     /**
400      * The Artifactory username needed to connect.
401      */
402     private String artifactoryAnalyzerUsername;
403     /**
404      * The Artifactory API token needed to connect.
405      */
406     private String artifactoryAnalyzerApiToken;
407     /**
408      * The Artifactory bearer token.
409      */
410     private String artifactoryAnalyzerBearerToken;
411     /**
412      * Whether the version check is enabled
413      */
414     private Boolean versionCheckEnabled;
415 
416     /**
417      * whether an unused suppression rule should get force the build to fail
418      */
419     private boolean failBuildOnUnusedSuppressionRule = false;
420 
421     /**
422      * The username to download user-authored suppression files from an HTTP Basic auth protected location.
423      */
424     private String suppressionFileUser;
425     /**
426      * The password to download user-authored suppression files from an HTTP Basic auth protected location.
427      */
428     private String suppressionFilePassword;
429     /**
430      * The token to download user-authored suppression files from an HTTP Bearer auth protected location.
431      */
432     private String suppressionFileBearerToken;
433 
434     //region Code copied from org.apache.tools.ant.taskdefs.PathConvert
435     //The following code was copied Apache Ant PathConvert
436     /**
437      * Path to be converted
438      */
439     private Resources path = null;
440     /**
441      * Reference to path/file set to convert
442      */
443     private Reference refId = null;
444 
445     /**
446      * Add an arbitrary ResourceCollection.
447      *
448      * @param rc the ResourceCollection to add.
449      * @since Ant 1.7
450      */
451     public void add(ResourceCollection rc) {
452         if (isReference()) {
453             throw new BuildException("Nested elements are not allowed when using the refId attribute.");
454         }
455         getPath().add(rc);
456     }
457 
458     /**
459      * Returns the path. If the path has not been initialized yet, this class is
460      * synchronized, and will instantiate the path object.
461      *
462      * @return the path
463      */
464     private synchronized Resources getPath() {
465         if (path == null) {
466             path = new Resources(getProject());
467             path.setCache(true);
468         }
469         return path;
470     }
471 
472     /**
473      * Learn whether the refId attribute of this element been set.
474      *
475      * @return true if refId is valid.
476      */
477     public boolean isReference() {
478         return refId != null;
479     }
480 
481     /**
482      * Add a reference to a Path, FileSet, DirSet, or FileList defined
483      * elsewhere.
484      *
485      * @param r the reference to a path, fileset, dirset or filelist.
486      */
487     public synchronized void setRefId(Reference r) {
488         if (path != null) {
489             throw new BuildException("Nested elements are not allowed when using the refId attribute.");
490         }
491         refId = r;
492     }
493 
494     /**
495      * If this is a reference, this method will add the referenced resource
496      * collection to the collection of paths.
497      *
498      * @throws BuildException if the reference is not to a resource collection
499      */
500     //declaring a throw that extends runtime exception may be a bad practice
501     //but seems to be an ingrained practice within Ant as even the base `Task`
502     //contains an `execute() throws BuildExecption`.
503     @SuppressWarnings("squid:RedundantThrowsDeclarationCheck")
504     private void dealWithReferences() throws BuildException {
505         if (isReference()) {
506             final Object o = refId.getReferencedObject(getProject());
507             if (!(o instanceof ResourceCollection)) {
508                 throw new BuildException("refId '" + refId.getRefId()
509                         + "' does not refer to a resource collection.");
510             }
511             getPath().add((ResourceCollection) o);
512         }
513     }
514     //endregion COPIED from org.apache.tools.ant.taskdefs
515 
516     /**
517      * Construct a new DependencyCheckTask.
518      */
519     public Check() {
520         super();
521         // Call this before Dependency Check Core starts logging anything - this way, all SLF4J messages from
522         // core end up coming through this tasks logger
523         AntTaskHolder.setTask(this);
524     }
525 
526     /**
527      * Add a suppression file.
528      * <p>
529      * This is called by Ant with the configured {@link SuppressionFile}.
530      *
531      * @param suppressionFile the suppression file to add.
532      */
533     public void addConfiguredSuppressionFile(final SuppressionFile suppressionFile) {
534         suppressionFiles.add(resolveRelative(suppressionFile.getPath()));
535     }
536 
537     /**
538      * Add a report format.
539      * <p>
540      * This is called by Ant with the configured {@link ReportFormat}.
541      *
542      * @param reportFormat the reportFormat to add.
543      */
544     public void addConfiguredReportFormat(final ReportFormat reportFormat) {
545         reportFormats.add(reportFormat.getFormat());
546     }
547 
548     /**
549      * Sets whether the version check is enabled.
550      *
551      * @param versionCheckEnabled a Boolean indicating if the version check is
552      * enabled.
553      */
554     public void setVersionCheckEnabled(Boolean versionCheckEnabled) {
555         this.versionCheckEnabled = versionCheckEnabled;
556     }
557 
558     /**
559      * Get the value of projectName.
560      *
561      * @return the value of projectName
562      */
563     public String getProjectName() {
564         if (projectName == null) {
565             projectName = "";
566         }
567         return projectName;
568     }
569 
570     /**
571      * Set the value of projectName.
572      *
573      * @param projectName new value of projectName
574      */
575     public void setProjectName(String projectName) {
576         this.projectName = projectName;
577     }
578 
579     private String resolveRelative(String path) {
580         if (path == null) {
581             return null;
582         }
583 
584         File file = new File(path);
585         if (file.isAbsolute()) {
586             return path;
587         }
588 
589         return new File(getProject().getBaseDir(), path).getPath();
590     }
591 
592     /**
593      * Set the value of reportOutputDirectory.
594      *
595      * @param reportOutputDirectory new value of reportOutputDirectory
596      */
597     public void setReportOutputDirectory(String reportOutputDirectory) {
598         this.reportOutputDirectory = resolveRelative(reportOutputDirectory);
599     }
600 
601     /**
602      * Set the value of failBuildOnCVSS.
603      *
604      * @param failBuildOnCVSS new value of failBuildOnCVSS
605      */
606     public void setFailBuildOnCVSS(float failBuildOnCVSS) {
607         this.failBuildOnCVSS = failBuildOnCVSS;
608     }
609 
610     /**
611      * Set the value of junitFailOnCVSS.
612      *
613      * @param junitFailOnCVSS new value of junitFailOnCVSS
614      */
615     public void setJunitFailOnCVSS(float junitFailOnCVSS) {
616         this.junitFailOnCVSS = junitFailOnCVSS;
617     }
618 
619     /**
620      * Set the value of autoUpdate.
621      *
622      * @param autoUpdate new value of autoUpdate
623      */
624     public void setAutoUpdate(Boolean autoUpdate) {
625         this.autoUpdate = autoUpdate;
626     }
627 
628     /**
629      * Set the value of prettyPrint.
630      *
631      * @param prettyPrint new value of prettyPrint
632      */
633     public void setPrettyPrint(boolean prettyPrint) {
634         this.prettyPrint = prettyPrint;
635     }
636 
637     /**
638      * Set the value of reportFormat.
639      *
640      * @param reportFormat new value of reportFormat
641      */
642     public void setReportFormat(ReportFormats reportFormat) {
643         this.reportFormat = reportFormat.getValue();
644         this.reportFormats.add(this.reportFormat);
645     }
646 
647     /**
648      * Get the value of reportFormats.
649      *
650      * @return the value of reportFormats
651      */
652     public List<String> getReportFormats() {
653         if (reportFormats.isEmpty()) {
654             this.reportFormats.add(this.reportFormat);
655         }
656         return this.reportFormats;
657     }
658 
659     /**
660      * Set the value of suppressionFile.
661      *
662      * @param suppressionFile new value of suppressionFile
663      */
664     public void setSuppressionFile(String suppressionFile) {
665         suppressionFiles.add(resolveRelative(suppressionFile));
666     }
667 
668     /**
669      * Sets the username to download user-authored suppression files from an HTTP Basic auth protected location.
670      *
671      * @param suppressionFileUser The username
672      */
673     public void setSuppressionFileUser(String suppressionFileUser) {
674         this.suppressionFileUser = suppressionFileUser;
675     }
676 
677     /**
678      * Sets the password/token to download user-authored suppression files from an HTTP Basic auth protected location.
679      *
680      * @param suppressionFilePassword The password/token
681      */
682     public void setSuppressionFilePassword(String suppressionFilePassword) {
683         this.suppressionFilePassword = suppressionFilePassword;
684     }
685 
686     /**
687      * Sets the token to download user-authored suppression files from an HTTP Bearer auth protected location.
688      *
689      * @param suppressionFileBearerToken The token
690      */
691     public void setSuppressionFileBearerToken(String suppressionFileBearerToken) {
692         this.suppressionFileBearerToken = suppressionFileBearerToken;
693     }
694 
695     /**
696      * Set the value of hintsFile.
697      *
698      * @param hintsFile new value of hintsFile
699      */
700     public void setHintsFile(String hintsFile) {
701         this.hintsFile = hintsFile;
702     }
703 
704     /**
705      * Set the value of showSummary.
706      *
707      * @param showSummary new value of showSummary
708      */
709     public void setShowSummary(boolean showSummary) {
710         this.showSummary = showSummary;
711     }
712 
713     /**
714      * Set the value of enableExperimental.
715      *
716      * @param enableExperimental new value of enableExperimental
717      */
718     public void setEnableExperimental(Boolean enableExperimental) {
719         this.enableExperimental = enableExperimental;
720     }
721 
722     /**
723      * Set the value of enableRetired.
724      *
725      * @param enableRetired new value of enableRetired
726      */
727     public void setEnableRetired(Boolean enableRetired) {
728         this.enableRetired = enableRetired;
729     }
730 
731     /**
732      * Sets whether or not the analyzer is enabled.
733      *
734      * @param jarAnalyzerEnabled the value of the new setting
735      */
736     public void setJarAnalyzerEnabled(Boolean jarAnalyzerEnabled) {
737         this.jarAnalyzerEnabled = jarAnalyzerEnabled;
738     }
739 
740     /**
741      * Sets whether the analyzer is enabled.
742      *
743      * @param archiveAnalyzerEnabled the value of the new setting
744      */
745     public void setArchiveAnalyzerEnabled(Boolean archiveAnalyzerEnabled) {
746         this.archiveAnalyzerEnabled = archiveAnalyzerEnabled;
747     }
748 
749     /**
750      * Sets whether or not the analyzer is enabled.
751      *
752      * @param assemblyAnalyzerEnabled the value of the new setting
753      */
754     public void setAssemblyAnalyzerEnabled(Boolean assemblyAnalyzerEnabled) {
755         this.assemblyAnalyzerEnabled = assemblyAnalyzerEnabled;
756     }
757 
758     /**
759      * Sets whether or not the analyzer is enabled.
760      *
761      * @param msbuildAnalyzerEnabled the value of the new setting
762      */
763     public void setMSBuildAnalyzerEnabled(Boolean msbuildAnalyzerEnabled) {
764         this.msbuildAnalyzerEnabled = msbuildAnalyzerEnabled;
765     }
766 
767     /**
768      * Sets whether or not the analyzer is enabled.
769      *
770      * @param nuspecAnalyzerEnabled the value of the new setting
771      */
772     public void setNuspecAnalyzerEnabled(Boolean nuspecAnalyzerEnabled) {
773         this.nuspecAnalyzerEnabled = nuspecAnalyzerEnabled;
774     }
775 
776     /**
777      * Sets whether or not the analyzer is enabled.
778      *
779      * @param nugetconfAnalyzerEnabled the value of the new setting
780      */
781     public void setNugetconfAnalyzerEnabled(Boolean nugetconfAnalyzerEnabled) {
782         this.nugetconfAnalyzerEnabled = nugetconfAnalyzerEnabled;
783     }
784 
785     /**
786      * Sets whether or not the analyzer is enabled.
787      *
788      * @param libmanAnalyzerEnabled the value of the new setting
789      */
790     public void setLibmanAnalyzerEnabled(Boolean libmanAnalyzerEnabled) {
791         this.libmanAnalyzerEnabled = libmanAnalyzerEnabled;
792     }
793 
794     /**
795      * Set the value of composerAnalyzerEnabled.
796      *
797      * @param composerAnalyzerEnabled new value of composerAnalyzerEnabled
798      */
799     public void setComposerAnalyzerEnabled(Boolean composerAnalyzerEnabled) {
800         this.composerAnalyzerEnabled = composerAnalyzerEnabled;
801     }
802 
803     /**
804      * Set the value of composerAnalyzerSkipDev.
805      *
806      * @param composerAnalyzerSkipDev new value of composerAnalyzerSkipDev
807      */
808     public void setComposerAnalyzerSkipDev(Boolean composerAnalyzerSkipDev) {
809         this.composerAnalyzerSkipDev = composerAnalyzerSkipDev;
810     }
811 
812     /**
813      * Set the value of cpanfileAnalyzerEnabled.
814      *
815      * @param cpanfileAnalyzerEnabled new value of cpanfileAnalyzerEnabled
816      */
817     public void setCpanfileAnalyzerEnabled(Boolean cpanfileAnalyzerEnabled) {
818         this.cpanfileAnalyzerEnabled = cpanfileAnalyzerEnabled;
819     }
820 
821     /**
822      * Set the value of autoconfAnalyzerEnabled.
823      *
824      * @param autoconfAnalyzerEnabled new value of autoconfAnalyzerEnabled
825      */
826     public void setAutoconfAnalyzerEnabled(Boolean autoconfAnalyzerEnabled) {
827         this.autoconfAnalyzerEnabled = autoconfAnalyzerEnabled;
828     }
829 
830     /**
831      * Set the value of pipAnalyzerEnabled.
832      *
833      * @param pipAnalyzerEnabled new value of pipAnalyzerEnabled
834      */
835     public void setPipAnalyzerEnabled(Boolean pipAnalyzerEnabled) {
836         this.pipAnalyzerEnabled = pipAnalyzerEnabled;
837     }
838 
839     /**
840      * Set the value of pipfileAnalyzerEnabled.
841      *
842      * @param pipfileAnalyzerEnabled new value of pipfileAnalyzerEnabled
843      */
844     public void setPipfileAnalyzerEnabled(Boolean pipfileAnalyzerEnabled) {
845         this.pipfileAnalyzerEnabled = pipfileAnalyzerEnabled;
846     }
847 
848     /**
849      * Set the value of poetryAnalyzerEnabled.
850      *
851      * @param poetryAnalyzerEnabled new value of poetryAnalyzerEnabled
852      */
853     public void setPoetryAnalyzerEnabled(Boolean poetryAnalyzerEnabled) {
854         this.poetryAnalyzerEnabled = poetryAnalyzerEnabled;
855     }
856 
857     /**
858      * Sets if the Bundle Audit Analyzer is enabled.
859      *
860      * @param bundleAuditAnalyzerEnabled whether or not the analyzer should be
861      * enabled
862      */
863     public void setBundleAuditAnalyzerEnabled(Boolean bundleAuditAnalyzerEnabled) {
864         this.bundleAuditAnalyzerEnabled = bundleAuditAnalyzerEnabled;
865     }
866 
867     /**
868      * Sets the path to the bundle audit executable.
869      *
870      * @param bundleAuditPath the path to the bundle audit executable
871      */
872     public void setBundleAuditPath(String bundleAuditPath) {
873         this.bundleAuditPath = bundleAuditPath;
874     }
875 
876     /**
877      * Sets the path to the working directory that the bundle audit executable
878      * should be executed from.
879      *
880      * @param bundleAuditWorkingDirectory the path to the working directory that
881      * the bundle audit executable should be executed from.
882      */
883     public void setBundleAuditWorkingDirectory(String bundleAuditWorkingDirectory) {
884         this.bundleAuditWorkingDirectory = bundleAuditWorkingDirectory;
885     }
886 
887     /**
888      * Sets whether or not the cocoapods analyzer is enabled.
889      *
890      * @param cocoapodsAnalyzerEnabled the state of the cocoapods analyzer
891      */
892     public void setCocoapodsAnalyzerEnabled(Boolean cocoapodsAnalyzerEnabled) {
893         this.cocoapodsAnalyzerEnabled = cocoapodsAnalyzerEnabled;
894     }
895 
896     /**
897      * Sets whether or not the Carthage analyzer is enabled.
898      *
899      * @param carthageAnalyzerEnabled the state of the Carthage analyzer
900      */
901     public void setCarthageAnalyzerEnabled(Boolean carthageAnalyzerEnabled) {
902         this.carthageAnalyzerEnabled = carthageAnalyzerEnabled;
903     }
904 
905     /**
906      * Sets the enabled state of the swift package manager analyzer.
907      *
908      * @param swiftPackageManagerAnalyzerEnabled the enabled state of the swift
909      * package manager
910      */
911     public void setSwiftPackageManagerAnalyzerEnabled(Boolean swiftPackageManagerAnalyzerEnabled) {
912         this.swiftPackageManagerAnalyzerEnabled = swiftPackageManagerAnalyzerEnabled;
913     }
914 
915     /**
916      * Sets the enabled state of the swift package manager analyzer.
917      *
918      * @param swiftPackageResolvedAnalyzerEnabled the enabled state of the swift
919      * package resolved analyzer
920      */
921     public void setSwiftPackageResolvedAnalyzerEnabled(Boolean swiftPackageResolvedAnalyzerEnabled) {
922         this.swiftPackageResolvedAnalyzerEnabled = swiftPackageResolvedAnalyzerEnabled;
923     }
924 
925     /**
926      * Set the value of opensslAnalyzerEnabled.
927      *
928      * @param opensslAnalyzerEnabled new value of opensslAnalyzerEnabled
929      */
930     public void setOpensslAnalyzerEnabled(Boolean opensslAnalyzerEnabled) {
931         this.opensslAnalyzerEnabled = opensslAnalyzerEnabled;
932     }
933 
934     /**
935      * Set the value of nodeAnalyzerEnabled.
936      *
937      * @param nodeAnalyzerEnabled new value of nodeAnalyzerEnabled
938      */
939     public void setNodeAnalyzerEnabled(Boolean nodeAnalyzerEnabled) {
940         this.nodeAnalyzerEnabled = nodeAnalyzerEnabled;
941     }
942 
943     /**
944      * Set the value of nodeAuditAnalyzerEnabled.
945      *
946      * @param nodeAuditAnalyzerEnabled new value of nodeAuditAnalyzerEnabled
947      */
948     public void setNodeAuditAnalyzerEnabled(Boolean nodeAuditAnalyzerEnabled) {
949         this.nodeAuditAnalyzerEnabled = nodeAuditAnalyzerEnabled;
950     }
951 
952     /**
953      * Set the value of yarnAuditAnalyzerEnabled.
954      *
955      * @param yarnAuditAnalyzerEnabled new value of yarnAuditAnalyzerEnabled
956      */
957     public void setYarnAuditAnalyzerEnabled(Boolean yarnAuditAnalyzerEnabled) {
958         this.yarnAuditAnalyzerEnabled = yarnAuditAnalyzerEnabled;
959     }
960 
961     /**
962      * Set the value of pnpmAuditAnalyzerEnabled.
963      *
964      * @param pnpmAuditAnalyzerEnabled new value of pnpmAuditAnalyzerEnabled
965      */
966     public void setPnpmAuditAnalyzerEnabled(Boolean pnpmAuditAnalyzerEnabled) {
967         this.pnpmAuditAnalyzerEnabled = pnpmAuditAnalyzerEnabled;
968     }
969 
970     /**
971      * Set the value of nodeAuditAnalyzerUseCache.
972      *
973      * @param nodeAuditAnalyzerUseCache new value of nodeAuditAnalyzerUseCache
974      */
975     public void setNodeAuditAnalyzerUseCache(Boolean nodeAuditAnalyzerUseCache) {
976         this.nodeAuditAnalyzerUseCache = nodeAuditAnalyzerUseCache;
977     }
978 
979     /**
980      * Set the value of nodePackageSkipDevDependencies.
981      *
982      * @param nodePackageSkipDevDependencies new value of
983      * nodePackageSkipDevDependencies
984      */
985     public void setNodePackageSkipDevDependencies(Boolean nodePackageSkipDevDependencies) {
986         this.nodePackageSkipDevDependencies = nodePackageSkipDevDependencies;
987     }
988 
989     /**
990      * Set the value of nodeAuditSkipDevDependencies.
991      *
992      * @param nodeAuditSkipDevDependencies new value of
993      * nodeAuditSkipDevDependencies
994      */
995     public void setNodeAuditSkipDevDependencies(Boolean nodeAuditSkipDevDependencies) {
996         this.nodeAuditSkipDevDependencies = nodeAuditSkipDevDependencies;
997     }
998 
999     /**
1000      * Set the value of retireJsFilterNonVulnerable.
1001      *
1002      * @param retireJsFilterNonVulnerable new value of
1003      * retireJsFilterNonVulnerable
1004      */
1005     public void setRetireJsFilterNonVulnerable(Boolean retireJsFilterNonVulnerable) {
1006         this.retireJsFilterNonVulnerable = retireJsFilterNonVulnerable;
1007     }
1008 
1009 
1010     /**
1011      * Add a regular expression to the set of retire JS content filters.
1012      * <p>
1013      * This is called by Ant.
1014      *
1015      * @param retireJsFilter the regular expression used to filter based on file
1016      * content
1017      */
1018     public void addConfiguredRetireJsFilter(final RetirejsFilter retireJsFilter) {
1019         retireJsFilters.add(retireJsFilter.getRegex());
1020     }
1021 
1022     /**
1023      * Set the value of rubygemsAnalyzerEnabled.
1024      *
1025      * @param rubygemsAnalyzerEnabled new value of rubygemsAnalyzerEnabled
1026      */
1027     public void setRubygemsAnalyzerEnabled(Boolean rubygemsAnalyzerEnabled) {
1028         this.rubygemsAnalyzerEnabled = rubygemsAnalyzerEnabled;
1029     }
1030 
1031     /**
1032      * Set the value of pyPackageAnalyzerEnabled.
1033      *
1034      * @param pyPackageAnalyzerEnabled new value of pyPackageAnalyzerEnabled
1035      */
1036     public void setPyPackageAnalyzerEnabled(Boolean pyPackageAnalyzerEnabled) {
1037         this.pyPackageAnalyzerEnabled = pyPackageAnalyzerEnabled;
1038     }
1039 
1040     /**
1041      * Set the value of pyDistributionAnalyzerEnabled.
1042      *
1043      * @param pyDistributionAnalyzerEnabled new value of
1044      * pyDistributionAnalyzerEnabled
1045      */
1046     public void setPyDistributionAnalyzerEnabled(Boolean pyDistributionAnalyzerEnabled) {
1047         this.pyDistributionAnalyzerEnabled = pyDistributionAnalyzerEnabled;
1048     }
1049 
1050     /**
1051      * Set the value of mixAuditAnalyzerEnabled.
1052      *
1053      * @param mixAuditAnalyzerEnabled new value of mixAuditAnalyzerEnabled
1054      */
1055     public void setMixAuditAnalyzerEnabled(Boolean mixAuditAnalyzerEnabled) {
1056         this.mixAuditAnalyzerEnabled = mixAuditAnalyzerEnabled;
1057     }
1058 
1059     /**
1060      * Sets the path to the mix audit executable.
1061      *
1062      * @param mixAuditPath the path to the bundle audit executable
1063      */
1064     public void setMixAuditPath(String mixAuditPath) {
1065         this.mixAuditPath = mixAuditPath;
1066     }
1067     /**
1068      * Set the value of centralAnalyzerEnabled.
1069      *
1070      * @param centralAnalyzerEnabled new value of centralAnalyzerEnabled
1071      */
1072     public void setCentralAnalyzerEnabled(Boolean centralAnalyzerEnabled) {
1073         this.centralAnalyzerEnabled = centralAnalyzerEnabled;
1074     }
1075 
1076     /**
1077      * Set the value of centralAnalyzerUseCache.
1078      *
1079      * @param centralAnalyzerUseCache new value of centralAnalyzerUseCache
1080      */
1081     public void setCentralAnalyzerUseCache(Boolean centralAnalyzerUseCache) {
1082         this.centralAnalyzerUseCache = centralAnalyzerUseCache;
1083     }
1084 
1085     /**
1086      * Set the value of nexusAnalyzerEnabled.
1087      *
1088      * @param nexusAnalyzerEnabled new value of nexusAnalyzerEnabled
1089      */
1090     public void setNexusAnalyzerEnabled(Boolean nexusAnalyzerEnabled) {
1091         this.nexusAnalyzerEnabled = nexusAnalyzerEnabled;
1092     }
1093 
1094     /**
1095      * Set the value of golangDepEnabled.
1096      *
1097      * @param golangDepEnabled new value of golangDepEnabled
1098      */
1099     public void setGolangDepEnabled(Boolean golangDepEnabled) {
1100         this.golangDepEnabled = golangDepEnabled;
1101     }
1102 
1103     /**
1104      * Set the value of golangModEnabled.
1105      *
1106      * @param golangModEnabled new value of golangModEnabled
1107      */
1108     public void setGolangModEnabled(Boolean golangModEnabled) {
1109         this.golangModEnabled = golangModEnabled;
1110     }
1111 
1112     /**
1113      * Set the value of dartAnalyzerEnabled.
1114      *
1115      * @param dartAnalyzerEnabled new value of dartAnalyzerEnabled
1116      */
1117     public void setDartAnalyzerEnabled(Boolean dartAnalyzerEnabled) {
1118         this.dartAnalyzerEnabled = dartAnalyzerEnabled;
1119     }
1120 
1121     /**
1122      * Set the value of pathToYarn.
1123      *
1124      * @param pathToYarn new value of pathToYarn
1125      */
1126     public void setPathToYarn(String pathToYarn) {
1127         this.pathToYarn = pathToYarn;
1128     }
1129 
1130     /**
1131      * Set the value of pathToPnpm.
1132      *
1133      * @param pathToPnpm new value of pathToPnpm
1134      */
1135     public void setPathToPnpm(String pathToPnpm) {
1136         this.pathToPnpm = pathToPnpm;
1137     }
1138 
1139     /**
1140      * Set the value of pathToGo.
1141      *
1142      * @param pathToGo new value of pathToGo
1143      */
1144     public void setPathToGo(String pathToGo) {
1145         this.pathToGo = pathToGo;
1146     }
1147 
1148     /**
1149      * Set the value of nexusUrl.
1150      *
1151      * @param nexusUrl new value of nexusUrl
1152      */
1153     public void setNexusUrl(String nexusUrl) {
1154         this.nexusUrl = nexusUrl;
1155     }
1156 
1157     /**
1158      * Set the value of nexusUser.
1159      *
1160      * @param nexusUser new value of nexusUser
1161      */
1162     public void setNexusUser(String nexusUser) {
1163         this.nexusUser = nexusUser;
1164     }
1165 
1166     /**
1167      * Set the value of nexusPassword.
1168      *
1169      * @param nexusPassword new value of nexusPassword
1170      */
1171     public void setNexusPassword(String nexusPassword) {
1172         this.nexusPassword = nexusPassword;
1173     }
1174 
1175     /**
1176      * Set the value of nexusUsesProxy.
1177      *
1178      * @param nexusUsesProxy new value of nexusUsesProxy
1179      */
1180     public void setNexusUsesProxy(Boolean nexusUsesProxy) {
1181         this.nexusUsesProxy = nexusUsesProxy;
1182     }
1183 
1184     /**
1185      * Set the value of zipExtensions.
1186      *
1187      * @param zipExtensions new value of zipExtensions
1188      */
1189     public void setZipExtensions(String zipExtensions) {
1190         this.zipExtensions = zipExtensions;
1191     }
1192 
1193     /**
1194      * Set the value of pathToCore.
1195      *
1196      * @param pathToCore new value of pathToCore
1197      */
1198     public void setPathToDotnetCore(String pathToCore) {
1199         this.pathToCore = pathToCore;
1200     }
1201 
1202     /**
1203      * Set value of ossIndexAnalyzerEnabled.
1204      *
1205      * @param ossIndexAnalyzerEnabled new value of ossIndexAnalyzerEnabled
1206      */
1207     public void setOssIndexAnalyzerEnabled(Boolean ossIndexAnalyzerEnabled) {
1208         this.ossIndexAnalyzerEnabled = ossIndexAnalyzerEnabled;
1209     }
1210 
1211     /**
1212      * Set value of ossIndexAnalyzerUseCache.
1213      *
1214      * @param ossIndexAnalyzerUseCache new value of ossIndexAnalyzerUseCache
1215      */
1216     public void setOssIndexAnalyzerUseCache(Boolean ossIndexAnalyzerUseCache) {
1217         this.ossIndexAnalyzerUseCache = ossIndexAnalyzerUseCache;
1218     }
1219 
1220     /**
1221      * Set value of {@link #ossIndexAnalyzerCacheValidForHours}.
1222      *
1223      * @param ossIndexAnalyzerCacheValidForHours new value of ossIndexAnalyzerCacheValidForHours
1224      */
1225     public void setOssIndexAnalyzerCacheValidForHours(Integer ossIndexAnalyzerCacheValidForHours) {
1226         this.ossIndexAnalyzerCacheValidForHours = ossIndexAnalyzerCacheValidForHours;
1227     }
1228 
1229     /**
1230      * Set value of ossIndexAnalyzerUrl.
1231      *
1232      * @param ossIndexAnalyzerUrl new value of ossIndexAnalyzerUrl
1233      */
1234     public void setOssIndexAnalyzerUrl(String ossIndexAnalyzerUrl) {
1235         this.ossIndexAnalyzerUrl = ossIndexAnalyzerUrl;
1236     }
1237 
1238     /**
1239      * Set value of ossIndexAnalyzerUsername.
1240      *
1241      * @param ossIndexAnalyzerUsername new value of ossIndexAnalyzerUsername
1242      */
1243     public void setOssIndexAnalyzerUsername(String ossIndexAnalyzerUsername) {
1244         this.ossIndexAnalyzerUsername = ossIndexAnalyzerUsername;
1245     }
1246 
1247     /**
1248      * Set value of ossIndexAnalyzerPassword.
1249      *
1250      * @param ossIndexAnalyzerPassword new value of ossIndexAnalyzerPassword
1251      */
1252     public void setOssIndexAnalyzerPassword(String ossIndexAnalyzerPassword) {
1253         this.ossIndexAnalyzerPassword = ossIndexAnalyzerPassword;
1254     }
1255 
1256     /**
1257      * Set value of {@link #ossIndexAnalyzerWarnOnlyOnRemoteErrors}.
1258      *
1259      * @param ossIndexWarnOnlyOnRemoteErrors the value of
1260      * ossIndexWarnOnlyOnRemoteErrors
1261      */
1262     public void setOssIndexWarnOnlyOnRemoteErrors(Boolean ossIndexWarnOnlyOnRemoteErrors) {
1263         this.ossIndexAnalyzerWarnOnlyOnRemoteErrors = ossIndexWarnOnlyOnRemoteErrors;
1264     }
1265 
1266     /**
1267      * Set the value of cmakeAnalyzerEnabled.
1268      *
1269      * @param cmakeAnalyzerEnabled new value of cmakeAnalyzerEnabled
1270      */
1271     public void setCmakeAnalyzerEnabled(Boolean cmakeAnalyzerEnabled) {
1272         this.cmakeAnalyzerEnabled = cmakeAnalyzerEnabled;
1273     }
1274 
1275     /**
1276      * Set the value of artifactoryAnalyzerEnabled.
1277      *
1278      * @param artifactoryAnalyzerEnabled new value of artifactoryAnalyzerEnabled
1279      */
1280     public void setArtifactoryAnalyzerEnabled(Boolean artifactoryAnalyzerEnabled) {
1281         this.artifactoryAnalyzerEnabled = artifactoryAnalyzerEnabled;
1282     }
1283 
1284     /**
1285      * Set the value of artifactoryAnalyzerUrl.
1286      *
1287      * @param artifactoryAnalyzerUrl new value of artifactoryAnalyzerUrl
1288      */
1289     public void setArtifactoryAnalyzerUrl(String artifactoryAnalyzerUrl) {
1290         this.artifactoryAnalyzerUrl = artifactoryAnalyzerUrl;
1291     }
1292 
1293     /**
1294      * Set the value of artifactoryAnalyzerUseProxy.
1295      *
1296      * @param artifactoryAnalyzerUseProxy new value of
1297      * artifactoryAnalyzerUseProxy
1298      */
1299     public void setArtifactoryAnalyzerUseProxy(Boolean artifactoryAnalyzerUseProxy) {
1300         this.artifactoryAnalyzerUseProxy = artifactoryAnalyzerUseProxy;
1301     }
1302 
1303     /**
1304      * Set the value of artifactoryAnalyzerParallelAnalysis.
1305      *
1306      * @param artifactoryAnalyzerParallelAnalysis new value of
1307      * artifactoryAnalyzerParallelAnalysis
1308      */
1309     public void setArtifactoryAnalyzerParallelAnalysis(Boolean artifactoryAnalyzerParallelAnalysis) {
1310         this.artifactoryAnalyzerParallelAnalysis = artifactoryAnalyzerParallelAnalysis;
1311     }
1312 
1313     /**
1314      * Set the value of artifactoryAnalyzerUsername.
1315      *
1316      * @param artifactoryAnalyzerUsername new value of
1317      * artifactoryAnalyzerUsername
1318      */
1319     public void setArtifactoryAnalyzerUsername(String artifactoryAnalyzerUsername) {
1320         this.artifactoryAnalyzerUsername = artifactoryAnalyzerUsername;
1321     }
1322 
1323     /**
1324      * Set the value of artifactoryAnalyzerApiToken.
1325      *
1326      * @param artifactoryAnalyzerApiToken new value of
1327      * artifactoryAnalyzerApiToken
1328      */
1329     public void setArtifactoryAnalyzerApiToken(String artifactoryAnalyzerApiToken) {
1330         this.artifactoryAnalyzerApiToken = artifactoryAnalyzerApiToken;
1331     }
1332 
1333     /**
1334      * Set the value of artifactoryAnalyzerBearerToken.
1335      *
1336      * @param artifactoryAnalyzerBearerToken new value of
1337      * artifactoryAnalyzerBearerToken
1338      */
1339     public void setArtifactoryAnalyzerBearerToken(String artifactoryAnalyzerBearerToken) {
1340         this.artifactoryAnalyzerBearerToken = artifactoryAnalyzerBearerToken;
1341     }
1342 
1343     /**
1344      * Set the value of failBuildOnUnusedSuppressionRule.
1345      *
1346      * @param failBuildOnUnusedSuppressionRule new value of
1347      * failBuildOnUnusedSuppressionRule
1348      */
1349     public void setFailBuildOnUnusedSuppressionRule(boolean failBuildOnUnusedSuppressionRule) {
1350         this.failBuildOnUnusedSuppressionRule = failBuildOnUnusedSuppressionRule;
1351     }
1352 
1353     //see note on `dealWithReferences()` for information on this suppression
1354     @SuppressWarnings("squid:RedundantThrowsDeclarationCheck")
1355     @Override
1356     protected void executeWithContextClassloader() throws BuildException {
1357         dealWithReferences();
1358         validateConfiguration();
1359         populateSettings();
1360         try {
1361             Downloader.getInstance().configure(getSettings());
1362         } catch (InvalidSettingException e) {
1363             throw new BuildException(e);
1364         }
1365         TelemetryCollector.send(getSettings());
1366         try (Engine engine = new Engine(Check.class.getClassLoader(), getSettings())) {
1367             for (Resource resource : getPath()) {
1368                 final FileProvider provider = resource.as(FileProvider.class);
1369                 if (provider != null) {
1370                     final File file = provider.getFile();
1371                     if (file != null && file.exists()) {
1372                         engine.scan(file);
1373                     }
1374                 }
1375             }
1376             final ExceptionCollection exceptions = callExecuteAnalysis(engine);
1377             if (exceptions == null || !exceptions.isFatal()) {
1378                 for (String format : getReportFormats()) {
1379                     engine.writeReports(getProjectName(), new File(reportOutputDirectory), format, exceptions);
1380                 }
1381                 if (this.failBuildOnCVSS <= 10) {
1382                     checkForFailure(engine.getDependencies());
1383                 }
1384                 if (this.showSummary) {
1385                     DependencyCheckScanAgent.showSummary(engine.getDependencies());
1386                 }
1387             }
1388         } catch (DatabaseException ex) {
1389             final String msg = "Unable to connect to the dependency-check database; analysis has stopped";
1390             if (this.isFailOnError()) {
1391                 throw new BuildException(msg, ex);
1392             }
1393             log(msg, ex, Project.MSG_ERR);
1394         } catch (ReportException ex) {
1395             final String msg = "Unable to generate the dependency-check report";
1396             if (this.isFailOnError()) {
1397                 throw new BuildException(msg, ex);
1398             }
1399             log(msg, ex, Project.MSG_ERR);
1400         } finally {
1401             getSettings().cleanup();
1402         }
1403     }
1404 
1405     /**
1406      * Wraps the call to `engine.analyzeDependencies()` and correctly handles
1407      * any exceptions
1408      *
1409      * @param engine a reference to the engine
1410      * @return the collection of any exceptions that occurred; otherwise
1411      * <code>null</code>
1412      * @throws BuildException thrown if configured to fail the build on errors
1413      */
1414     //see note on `dealWithReferences()` for information on this suppression
1415     @SuppressWarnings("squid:RedundantThrowsDeclarationCheck")
1416     private ExceptionCollection callExecuteAnalysis(final Engine engine) throws BuildException {
1417         ExceptionCollection exceptions = null;
1418         try {
1419             engine.analyzeDependencies();
1420         } catch (ExceptionCollection ex) {
1421             if (this.isFailOnError()) {
1422                 throw new BuildException(ex);
1423             }
1424             exceptions = ex;
1425         }
1426         return exceptions;
1427     }
1428 
1429     /**
1430      * Validate the configuration to ensure the parameters have been properly
1431      * configured/initialized.
1432      *
1433      * @throws BuildException if the task was not configured correctly.
1434      */
1435     //see note on `dealWithReferences()` for information on this suppression
1436     @SuppressWarnings("squid:RedundantThrowsDeclarationCheck")
1437     private synchronized void validateConfiguration() throws BuildException {
1438         if (path == null) {
1439             throw new BuildException("No project dependencies have been defined to analyze.");
1440         }
1441         if (failBuildOnCVSS < 0 || failBuildOnCVSS > 11) {
1442             throw new BuildException("Invalid configuration, failBuildOnCVSS must be between 0 and 11.");
1443         }
1444     }
1445 
1446     /**
1447      * Takes the properties supplied and updates the dependency-check settings.
1448      * Additionally, this sets the system properties required to change the
1449      * proxy server, port, and connection timeout.
1450      *
1451      * @throws BuildException thrown when an invalid setting is configured.
1452      */
1453     //see note on `dealWithReferences()` for information on this suppression
1454     @SuppressWarnings("squid:RedundantThrowsDeclarationCheck")
1455     @Override
1456     protected void populateSettings() throws BuildException {
1457         super.populateSettings();
1458         getSettings().setBooleanIfNotNull(Settings.KEYS.AUTO_UPDATE, autoUpdate);
1459         getSettings().setArrayIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE, suppressionFiles);
1460         getSettings().setStringIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE_USER, suppressionFileUser);
1461         getSettings().setStringIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE_PASSWORD, suppressionFilePassword);
1462         getSettings().setStringIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE_BEARER_TOKEN, suppressionFileBearerToken);
1463         getSettings().setBooleanIfNotNull(Settings.KEYS.UPDATE_VERSION_CHECK_ENABLED, versionCheckEnabled);
1464         getSettings().setStringIfNotEmpty(Settings.KEYS.HINTS_FILE, hintsFile);
1465         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, enableExperimental);
1466         getSettings().setBooleanIfNotNull(Settings.KEYS.PRETTY_PRINT, prettyPrint);
1467         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_RETIRED_ENABLED, enableRetired);
1468         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_JAR_ENABLED, jarAnalyzerEnabled);
1469         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_DISTRIBUTION_ENABLED, pyDistributionAnalyzerEnabled);
1470         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_PACKAGE_ENABLED, pyPackageAnalyzerEnabled);
1471         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_RUBY_GEMSPEC_ENABLED, rubygemsAnalyzerEnabled);
1472         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_OPENSSL_ENABLED, opensslAnalyzerEnabled);
1473         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_CMAKE_ENABLED, cmakeAnalyzerEnabled);
1474 
1475         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_ENABLED, artifactoryAnalyzerEnabled);
1476         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_ARTIFACTORY_URL, artifactoryAnalyzerUrl);
1477         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_USES_PROXY, artifactoryAnalyzerUseProxy);
1478         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_PARALLEL_ANALYSIS, artifactoryAnalyzerParallelAnalysis);
1479         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_ARTIFACTORY_API_USERNAME, artifactoryAnalyzerUsername);
1480         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_ARTIFACTORY_API_TOKEN, artifactoryAnalyzerApiToken);
1481         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_ARTIFACTORY_BEARER_TOKEN, artifactoryAnalyzerBearerToken);
1482 
1483         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_SWIFT_PACKAGE_MANAGER_ENABLED, swiftPackageManagerAnalyzerEnabled);
1484         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_SWIFT_PACKAGE_RESOLVED_ENABLED, swiftPackageResolvedAnalyzerEnabled);
1485         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_COCOAPODS_ENABLED, cocoapodsAnalyzerEnabled);
1486         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_CARTHAGE_ENABLED, carthageAnalyzerEnabled);
1487         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_ENABLED, bundleAuditAnalyzerEnabled);
1488         getSettings().setStringIfNotNull(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_PATH, bundleAuditPath);
1489         getSettings().setStringIfNotNull(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_WORKING_DIRECTORY, bundleAuditWorkingDirectory);
1490         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_AUTOCONF_ENABLED, autoconfAnalyzerEnabled);
1491         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_MAVEN_INSTALL_ENABLED, mavenInstallAnalyzerEnabled);
1492         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_PIP_ENABLED, pipAnalyzerEnabled);
1493         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_PIPFILE_ENABLED, pipfileAnalyzerEnabled);
1494         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_POETRY_ENABLED, poetryAnalyzerEnabled);
1495         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_COMPOSER_LOCK_ENABLED, composerAnalyzerEnabled);
1496         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_COMPOSER_LOCK_SKIP_DEV, composerAnalyzerSkipDev);
1497         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_CPANFILE_ENABLED, cpanfileAnalyzerEnabled);
1498         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_PACKAGE_ENABLED, nodeAnalyzerEnabled);
1499         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_PACKAGE_SKIPDEV, nodePackageSkipDevDependencies);
1500         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_AUDIT_ENABLED, nodeAuditAnalyzerEnabled);
1501         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_YARN_AUDIT_ENABLED, yarnAuditAnalyzerEnabled);
1502         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_PNPM_AUDIT_ENABLED, pnpmAuditAnalyzerEnabled);
1503         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_AUDIT_USE_CACHE, nodeAuditAnalyzerUseCache);
1504         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_AUDIT_SKIPDEV, nodeAuditSkipDevDependencies);
1505         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_RETIREJS_FILTER_NON_VULNERABLE, retireJsFilterNonVulnerable);
1506         getSettings().setArrayIfNotEmpty(Settings.KEYS.ANALYZER_RETIREJS_FILTERS, retireJsFilters);
1507         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_GOLANG_DEP_ENABLED, golangDepEnabled);
1508         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_GOLANG_MOD_ENABLED, golangModEnabled);
1509         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_DART_ENABLED, dartAnalyzerEnabled);
1510         getSettings().setStringIfNotNull(Settings.KEYS.ANALYZER_GOLANG_PATH, pathToGo);
1511         getSettings().setStringIfNotNull(Settings.KEYS.ANALYZER_YARN_PATH, pathToYarn);
1512         getSettings().setStringIfNotNull(Settings.KEYS.ANALYZER_PNPM_PATH, pathToPnpm);
1513         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_MIX_AUDIT_ENABLED, mixAuditAnalyzerEnabled);
1514         getSettings().setStringIfNotNull(Settings.KEYS.ANALYZER_MIX_AUDIT_PATH, mixAuditPath);
1515         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_NUSPEC_ENABLED, nuspecAnalyzerEnabled);
1516         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_NUGETCONF_ENABLED, nugetconfAnalyzerEnabled);
1517         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_LIBMAN_ENABLED, libmanAnalyzerEnabled);
1518         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, centralAnalyzerEnabled);
1519         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_CENTRAL_USE_CACHE, centralAnalyzerUseCache);
1520         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled);
1521         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, archiveAnalyzerEnabled);
1522         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_ASSEMBLY_ENABLED, assemblyAnalyzerEnabled);
1523         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_MSBUILD_PROJECT_ENABLED, msbuildAnalyzerEnabled);
1524         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl);
1525         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_NEXUS_USER, nexusUser);
1526         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_NEXUS_PASSWORD, nexusPassword);
1527         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_USES_PROXY, nexusUsesProxy);
1528         getSettings().setStringIfNotEmpty(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, zipExtensions);
1529         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_ASSEMBLY_DOTNET_PATH, pathToCore);
1530         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_ENABLED, ossIndexAnalyzerEnabled);
1531         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_OSSINDEX_URL, ossIndexAnalyzerUrl);
1532         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_OSSINDEX_USER, ossIndexAnalyzerUsername);
1533         getSettings().setStringIfNotEmpty(Settings.KEYS.ANALYZER_OSSINDEX_PASSWORD, ossIndexAnalyzerPassword);
1534         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_USE_CACHE, ossIndexAnalyzerUseCache);
1535         getSettings().setIntIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_CACHE_VALID_FOR_HOURS, ossIndexAnalyzerCacheValidForHours);
1536         getSettings().setBooleanIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_WARN_ONLY_ON_REMOTE_ERRORS, ossIndexAnalyzerWarnOnlyOnRemoteErrors);
1537         getSettings().setFloat(Settings.KEYS.JUNIT_FAIL_ON_CVSS, junitFailOnCVSS);
1538         getSettings().setBooleanIfNotNull(Settings.KEYS.FAIL_ON_UNUSED_SUPPRESSION_RULE, failBuildOnUnusedSuppressionRule);
1539     }
1540 
1541     /**
1542      * Checks to see if a vulnerability has been identified with a CVSS score
1543      * that is above the threshold set in the configuration.
1544      *
1545      * @param dependencies the list of dependency objects
1546      * @throws BuildException thrown if a CVSS score is found that is higher
1547      * than the threshold set
1548      */
1549     //see note on `dealWithReferences()` for information on this suppression
1550     @SuppressWarnings("squid:RedundantThrowsDeclarationCheck")
1551     private void checkForFailure(Dependency[] dependencies) throws BuildException {
1552         final StringBuilder ids = new StringBuilder();
1553         for (Dependency d : dependencies) {
1554             boolean addName = true;
1555             for (Vulnerability v : d.getVulnerabilities()) {
1556                 final double cvssV2 = v.getCvssV2() != null && v.getCvssV2().getCvssData() != null
1557                         && v.getCvssV2().getCvssData().getBaseScore() != null ? v.getCvssV2().getCvssData().getBaseScore() : -1;
1558                 final double cvssV3 = v.getCvssV3() != null && v.getCvssV3().getCvssData() != null
1559                         && v.getCvssV3().getCvssData().getBaseScore() != null ? v.getCvssV3().getCvssData().getBaseScore() : -1;
1560                 final double cvssV4 = v.getCvssV4() != null && v.getCvssV4().getCvssData() != null
1561                         && v.getCvssV4().getCvssData().getBaseScore() != null ? v.getCvssV4().getCvssData().getBaseScore() : -1;
1562                 final boolean useUnscored = cvssV2 == -1 && cvssV3 == -1 && cvssV4 == -1;
1563                 final double unscoredCvss =
1564                         useUnscored && v.getUnscoredSeverity() != null ? SeverityUtil.estimateCvssV2(v.getUnscoredSeverity()) : -1;
1565 
1566                 if (cvssV2 >= failBuildOnCVSS
1567                         || cvssV3 >= failBuildOnCVSS
1568                         || cvssV4 >= failBuildOnCVSS
1569                         || unscoredCvss >= failBuildOnCVSS
1570                         //safety net to fail on any if for some reason the above misses on 0
1571                         || failBuildOnCVSS <= 0.0f
1572                 ) {
1573                     if (addName) {
1574                         addName = false;
1575                         ids.append(NEW_LINE).append(d.getFileName()).append(" (")
1576                            .append(Stream.concat(d.getSoftwareIdentifiers().stream(), d.getVulnerableSoftwareIdentifiers().stream())
1577                                          .map(Identifier::getValue)
1578                                          .collect(Collectors.joining(", ")))
1579                            .append("): ")
1580                            .append(v.getName());
1581                     } else {
1582                         ids.append(", ").append(v.getName());
1583                     }
1584                 }
1585             }
1586         }
1587         if (ids.length() > 0) {
1588             final String msg;
1589             if (showSummary) {
1590                 msg = String.format("%n%nDependency-Check Failure:%n"
1591                         + "One or more dependencies were identified with vulnerabilities that have a CVSS score greater than or equal to '%.1f': %s%n"
1592                         + "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids);
1593             } else {
1594                 msg = String.format("%n%nDependency-Check Failure:%n"
1595                         + "One or more dependencies were identified with vulnerabilities.%n%n"
1596                         + "See the dependency-check report for more details.%n%n");
1597             }
1598             throw new BuildException(msg);
1599         }
1600     }
1601 
1602     /**
1603      * An enumeration of supported report formats: "ALL", "HTML", "XML", "CSV",
1604      * "JSON", "JUNIT", "SARIF", 'JENkINS', etc..
1605      */
1606     public static class ReportFormats extends EnumeratedAttribute {
1607 
1608         /**
1609          * Returns the list of values for the report format.
1610          *
1611          * @return the list of values for the report format
1612          */
1613         @Override
1614         public String[] getValues() {
1615             int i = 0;
1616             final Format[] formats = Format.values();
1617             final String[] values = new String[formats.length];
1618             for (Format format : formats) {
1619                 values[i++] = format.name();
1620             }
1621             return values;
1622         }
1623     }
1624 
1625     /**
1626      * A class for Ant to represent the
1627      * {@code <reportFormat format="<format>"/>} nested element to define
1628      * multiple report formats for the ant-task.
1629      */
1630     public static class ReportFormat {
1631 
1632         /**
1633          * The format of this ReportFormat.
1634          */
1635         private ReportFormats format;
1636 
1637         /**
1638          * Gets the format as a String.
1639          *
1640          * @return the String representing a report format
1641          */
1642         public String getFormat() {
1643             return this.format.getValue();
1644         }
1645 
1646         /**
1647          * Sets the format.
1648          *
1649          * @param format the String value for one of the {@link ReportFormats}
1650          * @throws BuildException When the offered String is not one of the
1651          * valid values of the {@link ReportFormats} EnumeratedAttribute
1652          */
1653         public void setFormat(final String format) {
1654             this.format = (ReportFormats) EnumeratedAttribute.getInstance(ReportFormats.class, format);
1655         }
1656     }
1657 }
1658 //CSON: MethodCount