View Javadoc
1   /*
2    * This file is part of dependency-check-maven.
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) 2014 Jeremy Long. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.maven;
19  
20  import com.github.packageurl.MalformedPackageURLException;
21  import com.github.packageurl.PackageURL.StandardTypes;
22  import com.github.packageurl.PackageURL;
23  import io.github.jeremylong.jcs3.slf4j.Slf4jAdapter;
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.DefaultArtifact;
26  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
27  import org.apache.maven.artifact.versioning.ArtifactVersion;
28  import org.apache.maven.doxia.sink.Sink;
29  import org.apache.maven.execution.MavenSession;
30  import org.apache.maven.model.License;
31  import org.apache.maven.plugin.AbstractMojo;
32  import org.apache.maven.plugin.MojoExecutionException;
33  import org.apache.maven.plugin.MojoFailureException;
34  import org.apache.maven.plugins.annotations.Component;
35  import org.apache.maven.plugins.annotations.Parameter;
36  import org.apache.maven.project.DefaultProjectBuildingRequest;
37  import org.apache.maven.project.MavenProject;
38  import org.apache.maven.project.ProjectBuildingRequest;
39  import org.apache.maven.reporting.MavenReport;
40  import org.apache.maven.reporting.MavenReportException;
41  import org.apache.maven.settings.Proxy;
42  import org.apache.maven.settings.Server;
43  import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
44  import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
45  import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
46  import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
47  import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
48  import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException;
49  import org.eclipse.aether.artifact.ArtifactType;
50  import org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter;
51  import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
52  import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
53  import org.apache.maven.shared.dependency.graph.DependencyNode;
54  import org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter;
55  import org.apache.maven.shared.dependency.graph.internal.DefaultDependencyNode;
56  import org.apache.maven.shared.model.fileset.FileSet;
57  import org.apache.maven.shared.model.fileset.util.FileSetManager;
58  import org.owasp.dependencycheck.Engine;
59  import org.owasp.dependencycheck.analyzer.JarAnalyzer;
60  import org.owasp.dependencycheck.data.nexus.MavenArtifact;
61  import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
62  import org.owasp.dependencycheck.dependency.Confidence;
63  import org.owasp.dependencycheck.dependency.Dependency;
64  import org.owasp.dependencycheck.dependency.EvidenceType;
65  import org.owasp.dependencycheck.dependency.Vulnerability;
66  import org.owasp.dependencycheck.exception.DependencyNotFoundException;
67  import org.owasp.dependencycheck.exception.ExceptionCollection;
68  import org.owasp.dependencycheck.exception.ReportException;
69  import org.owasp.dependencycheck.utils.Checksum;
70  import org.owasp.dependencycheck.utils.Filter;
71  import org.owasp.dependencycheck.utils.Downloader;
72  import org.owasp.dependencycheck.utils.InvalidSettingException;
73  import org.owasp.dependencycheck.utils.Settings;
74  import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
75  import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
76  import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException;
77  
78  import java.io.File;
79  import java.io.FileNotFoundException;
80  import java.io.IOException;
81  import java.io.InputStream;
82  import java.util.ArrayList;
83  import java.util.Arrays;
84  import java.util.Collections;
85  import java.util.HashSet;
86  import java.util.List;
87  import java.util.Locale;
88  import java.util.Map;
89  import java.util.Objects;
90  import java.util.Optional;
91  import java.util.Set;
92  import org.apache.maven.artifact.repository.ArtifactRepository;
93  
94  import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
95  import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
96  import org.apache.maven.artifact.versioning.Restriction;
97  import org.apache.maven.artifact.versioning.VersionRange;
98  
99  import org.owasp.dependencycheck.agent.DependencyCheckScanAgent;
100 import org.owasp.dependencycheck.dependency.naming.GenericIdentifier;
101 import org.owasp.dependencycheck.dependency.naming.Identifier;
102 import org.owasp.dependencycheck.dependency.naming.PurlIdentifier;
103 import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;
104 import org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor;
105 import org.apache.maven.shared.transfer.dependencies.DefaultDependableCoordinate;
106 import org.apache.maven.shared.transfer.dependencies.DependableCoordinate;
107 import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
108 import org.owasp.dependencycheck.reporting.ReportGenerator;
109 import org.owasp.dependencycheck.utils.SeverityUtil;
110 import org.owasp.dependencycheck.xml.pom.Model;
111 import org.owasp.dependencycheck.xml.pom.PomUtils;
112 
113 //CSOFF: FileLength
114 /**
115  * @author Jeremy Long
116  */
117 public abstract class BaseDependencyCheckMojo extends AbstractMojo implements MavenReport {
118 
119     //<editor-fold defaultstate="collapsed" desc="Private fields">
120     /**
121      * The properties file location.
122      */
123     private static final String PROPERTIES_FILE = "mojo.properties";
124     /**
125      * System specific new line character.
126      */
127     private static final String NEW_LINE = System.getProperty("line.separator", "\n").intern();
128     /**
129      * Pattern to include all files in a FileSet.
130      */
131     private static final String INCLUDE_ALL = "**/*";
132     /**
133      * A flag indicating whether or not the Maven site is being generated.
134      */
135     private boolean generatingSite = false;
136     /**
137      * The configured settings.
138      */
139     private Settings settings = null;
140     /**
141      * The list of files that have been scanned.
142      */
143     private final List<File> scannedFiles = new ArrayList<>();
144     //</editor-fold>
145     // <editor-fold defaultstate="collapsed" desc="Maven bound parameters and components">
146     /**
147      * Sets whether or not the mojo should fail if an error occurs.
148      */
149     @SuppressWarnings("CanBeFinal")
150     @Parameter(property = "failOnError", defaultValue = "true", required = true)
151     private boolean failOnError;
152 
153     /**
154      * The Maven Project Object.
155      */
156     @SuppressWarnings("CanBeFinal")
157     @Parameter(property = "project", required = true, readonly = true)
158     private MavenProject project;
159     /**
160      * List of Maven project of the current build
161      */
162     @SuppressWarnings("CanBeFinal")
163     @Parameter(readonly = true, required = true, property = "reactorProjects")
164     private List<MavenProject> reactorProjects;
165     /**
166      * The entry point towards a Maven version independent way of resolving
167      * artifacts (handles both Maven 3.0 Sonatype and Maven 3.1+ eclipse Aether
168      * implementations).
169      */
170     @SuppressWarnings("CanBeFinal")
171     @Component
172     private ArtifactResolver artifactResolver;
173     /**
174      * The entry point towards a Maven version independent way of resolving
175      * dependencies (handles both Maven 3.0 Sonatype and Maven 3.1+ eclipse
176      * Aether implementations). Contrary to the ArtifactResolver this resolver
177      * also takes into account the additional repositories defined in the
178      * dependency-path towards transitive dependencies.
179      */
180     @SuppressWarnings("CanBeFinal")
181     @Component
182     private DependencyResolver dependencyResolver;
183 
184     /**
185      * The Maven Session.
186      */
187     @SuppressWarnings("CanBeFinal")
188     @Parameter(defaultValue = "${session}", readonly = true, required = true)
189     private MavenSession session;
190 
191     /**
192      * Component within Maven to build the dependency graph.
193      */
194     @Component
195     private DependencyGraphBuilder dependencyGraphBuilder;
196 
197     /**
198      * The output directory. This generally maps to "target".
199      */
200     @SuppressWarnings("CanBeFinal")
201     @Parameter(defaultValue = "${project.build.directory}", required = true, property = "odc.outputDirectory")
202     private File outputDirectory;
203     /**
204      * This is a reference to the &gt;reporting&lt; sections
205      * <code>outputDirectory</code>. This cannot be configured in the
206      * dependency-check mojo directly. This generally maps to "target/site".
207      */
208     @Parameter(property = "project.reporting.outputDirectory", readonly = true)
209     private File reportOutputDirectory;
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.
214      */
215     @SuppressWarnings("CanBeFinal")
216     @Parameter(property = "failBuildOnCVSS", defaultValue = "11", required = true)
217     private float failBuildOnCVSS = 11f;
218     /**
219      * Specifies the CVSS score that is considered a "test" failure when
220      * generating a jUnit style report. The default value is 0 - all
221      * vulnerabilities are considered a failure.
222      */
223     @SuppressWarnings("CanBeFinal")
224     @Parameter(property = "junitFailOnCVSS", defaultValue = "0", required = true)
225     private float junitFailOnCVSS = 0;
226     /**
227      * Fail the build if any dependency has a vulnerability listed.
228      *
229      * @deprecated use {@link BaseDependencyCheckMojo#failBuildOnCVSS} with a
230      * value of 0 instead
231      */
232     @SuppressWarnings("CanBeFinal")
233     @Parameter(property = "failBuildOnAnyVulnerability", defaultValue = "false", required = true)
234     @Deprecated
235     private boolean failBuildOnAnyVulnerability = false;
236     /**
237      * Sets whether auto-updating of the NVD CVE data is enabled. It is not
238      * recommended that this be turned to false. Default is true.
239      */
240     @SuppressWarnings("CanBeFinal")
241     @Parameter(property = "autoUpdate")
242     private Boolean autoUpdate;
243     /**
244      * Sets whether Experimental analyzers are enabled. Default is false.
245      */
246     @SuppressWarnings("CanBeFinal")
247     @Parameter(property = "enableExperimental")
248     private Boolean enableExperimental;
249     /**
250      * Sets whether retired analyzers are enabled. Default is false.
251      */
252     @SuppressWarnings("CanBeFinal")
253     @Parameter(property = "enableRetired")
254     private Boolean enableRetired;
255     /**
256      * Sets whether the Golang Dependency analyzer is enabled. Default is true.
257      */
258     @SuppressWarnings("CanBeFinal")
259     @Parameter(property = "golangDepEnabled")
260     private Boolean golangDepEnabled;
261     /**
262      * Sets whether Golang Module Analyzer is enabled; this requires `go` to be
263      * installed. Default is true.
264      */
265     @SuppressWarnings("CanBeFinal")
266     @Parameter(property = "golangModEnabled")
267     private Boolean golangModEnabled;
268     /**
269      * Sets the path to `go`.
270      */
271     @SuppressWarnings("CanBeFinal")
272     @Parameter(property = "pathToGo")
273     private String pathToGo;
274 
275     /**
276      * Sets the path to `yarn`.
277      */
278     @SuppressWarnings("CanBeFinal")
279     @Parameter(property = "pathToYarn")
280     private String pathToYarn;
281     /**
282      * Sets the path to `pnpm`.
283      */
284     @SuppressWarnings("CanBeFinal")
285     @Parameter(property = "pathToPnpm")
286     private String pathToPnpm;
287     /**
288      * Use pom dependency information for snapshot dependencies that are part of
289      * the Maven reactor while aggregate scanning a multi-module project.
290      */
291     @Parameter(property = "dependency-check.virtualSnapshotsFromReactor", defaultValue = "true")
292     private Boolean virtualSnapshotsFromReactor;
293     /**
294      * The report format to be generated (HTML, XML, CSV, JSON, JUNIT, SARIF,
295      * JENKINS, GITLAB, ALL). Multiple formats can be selected using a comma
296      * delineated list.
297      */
298     @SuppressWarnings("CanBeFinal")
299     @Parameter(property = "format", defaultValue = "HTML", required = true)
300     private String format = "HTML";
301 
302     /**
303      * Whether or not the XML and JSON report formats should be pretty printed.
304      * The default is false.
305      */
306     @Parameter(property = "prettyPrint")
307     private Boolean prettyPrint;
308     /**
309      * The report format to be generated (HTML, XML, CSV, JSON, JUNIT, SARIF,
310      * JENKINS, GITLAB, ALL). Multiple formats can be selected using a comma
311      * delineated list.
312      */
313     @Parameter(property = "formats", required = true)
314     private String[] formats;
315     /**
316      * The Maven settings.
317      */
318     @SuppressWarnings("CanBeFinal")
319     @Parameter(property = "mavenSettings", defaultValue = "${settings}")
320     private org.apache.maven.settings.Settings mavenSettings;
321 
322     /**
323      * The maven settings proxy id.
324      */
325     @SuppressWarnings("CanBeFinal")
326     @Parameter(property = "mavenSettingsProxyId")
327     private String mavenSettingsProxyId;
328 
329     /**
330      * The Connection Timeout.
331      */
332     @SuppressWarnings("CanBeFinal")
333     @Parameter(property = "connectionTimeout")
334     private String connectionTimeout;
335     /**
336      * The Read Timeout.
337      */
338     @SuppressWarnings("CanBeFinal")
339     @Parameter(property = "readTimeout")
340     private String readTimeout;
341     /**
342      * Sets whether dependency-check should check if there is a new version
343      * available.
344      */
345     @SuppressWarnings("CanBeFinal")
346     @Parameter(property = "versionCheckEnabled", defaultValue = "true")
347     private boolean versionCheckEnabled;
348     /**
349      * The paths to the suppression files. The parameter value can be a local
350      * file path, a URL to a suppression file, or even a reference to a file on
351      * the class path (see
352      * https://github.com/jeremylong/DependencyCheck/issues/1878#issuecomment-487533799)
353      */
354     @SuppressWarnings("CanBeFinal")
355     @Parameter(property = "suppressionFiles")
356     private String[] suppressionFiles;
357     /**
358      * The paths to the suppression file. The parameter value can be a local
359      * file path, a URL to a suppression file, or even a reference to a file on
360      * the class path (see
361      * https://github.com/jeremylong/DependencyCheck/issues/1878#issuecomment-487533799)
362      */
363     @SuppressWarnings("CanBeFinal")
364     @Parameter(property = "suppressionFile")
365     private String suppressionFile;
366     /**
367      * The username used when connecting to the suppressionFiles.
368      */
369     @Parameter(property = "suppressionFileUser")
370     private String suppressionFileUser;
371     /**
372      * The password used when connecting to the suppressionFiles. The `suppressionFileServerId` should be used instead otherwise maven debug logging could expose the password.
373      */
374     @Parameter(property = "suppressionFilePassword")
375     private String suppressionFilePassword;
376     /**
377      * The server id in the settings.xml; used to retrieve encrypted passwords
378      * from the settings.xml for suppressionFile(s).
379      */
380     @SuppressWarnings("CanBeFinal")
381     @Parameter(property = "suppressionFileServerId")
382     private String suppressionFileServerId;
383     /**
384      * The path to the hints file.
385      */
386     @SuppressWarnings("CanBeFinal")
387     @Parameter(property = "hintsFile")
388     private String hintsFile;
389 
390     /**
391      * Flag indicating whether or not to show a summary in the output.
392      */
393     @SuppressWarnings("CanBeFinal")
394     @Parameter(property = "showSummary", defaultValue = "true")
395     private boolean showSummary = true;
396 
397     /**
398      * Whether or not the Jar Analyzer is enabled.
399      */
400     @SuppressWarnings("CanBeFinal")
401     @Parameter(property = "jarAnalyzerEnabled")
402     private Boolean jarAnalyzerEnabled;
403 
404     /**
405      * Sets whether the Dart analyzer is enabled. Default is true.
406      */
407     @SuppressWarnings("CanBeFinal")
408     @Parameter(property = "dartAnalyzerEnabled")
409     private Boolean dartAnalyzerEnabled;
410 
411     /**
412      * Whether or not the Archive Analyzer is enabled.
413      */
414     @SuppressWarnings("CanBeFinal")
415     @Parameter(property = "archiveAnalyzerEnabled")
416     private Boolean archiveAnalyzerEnabled;
417     /**
418      * Whether or not the Known Exploited Vulnerability Analyzer is enabled.
419      */
420     @SuppressWarnings("CanBeFinal")
421     @Parameter(property = "knownExploitedEnabled")
422     private Boolean knownExploitedEnabled;
423     /**
424      * The URL to the CISA Known Exploited Vulnerabilities JSON datafeed.
425      */
426     @SuppressWarnings("CanBeFinal")
427     @Parameter(property = "knownExploitedUrl")
428     private String knownExploitedUrl;
429     /**
430      * Sets whether the Python Distribution Analyzer will be used.
431      */
432     @SuppressWarnings("CanBeFinal")
433     @Parameter(property = "pyDistributionAnalyzerEnabled")
434     private Boolean pyDistributionAnalyzerEnabled;
435     /**
436      * Sets whether the Python Package Analyzer will be used.
437      */
438     @Parameter(property = "pyPackageAnalyzerEnabled")
439     private Boolean pyPackageAnalyzerEnabled;
440     /**
441      * Sets whether the Ruby Gemspec Analyzer will be used.
442      */
443     @SuppressWarnings("CanBeFinal")
444     @Parameter(property = "rubygemsAnalyzerEnabled")
445     private Boolean rubygemsAnalyzerEnabled;
446     /**
447      * Sets whether or not the openssl Analyzer should be used.
448      */
449     @SuppressWarnings("CanBeFinal")
450     @Parameter(property = "opensslAnalyzerEnabled")
451     private Boolean opensslAnalyzerEnabled;
452     /**
453      * Sets whether or not the CMake Analyzer should be used.
454      */
455     @SuppressWarnings("CanBeFinal")
456     @Parameter(property = "cmakeAnalyzerEnabled")
457     private Boolean cmakeAnalyzerEnabled;
458     /**
459      * Sets whether or not the autoconf Analyzer should be used.
460      */
461     @SuppressWarnings("CanBeFinal")
462     @Parameter(property = "autoconfAnalyzerEnabled")
463     private Boolean autoconfAnalyzerEnabled;
464     /**
465      * Sets whether or not the Maven install Analyzer should be used.
466      */
467     @SuppressWarnings("CanBeFinal")
468     @Parameter(property = "mavenInstallAnalyzerEnabled")
469     private Boolean mavenInstallAnalyzerEnabled;
470     /**
471      * Sets whether or not the pip Analyzer should be used.
472      */
473     @SuppressWarnings("CanBeFinal")
474     @Parameter(property = "pipAnalyzerEnabled")
475     private Boolean pipAnalyzerEnabled;
476     /**
477      * Sets whether or not the pipfile Analyzer should be used.
478      */
479     @SuppressWarnings("CanBeFinal")
480     @Parameter(property = "pipfileAnalyzerEnabled")
481     private Boolean pipfileAnalyzerEnabled;
482     /**
483      * Sets whether or not the poetry Analyzer should be used.
484      */
485     @SuppressWarnings("CanBeFinal")
486     @Parameter(property = "poetryAnalyzerEnabled")
487     private Boolean poetryAnalyzerEnabled;
488     /**
489      * Sets whether or not the PHP Composer Lock File Analyzer should be used.
490      */
491     @Parameter(property = "composerAnalyzerEnabled")
492     private Boolean composerAnalyzerEnabled;
493     /**
494      * Sets whether or not the PHP Composer Lock File Analyzer will scan "packages-dev".
495      */
496     @Parameter(property = "composerAnalyzerSkipDev")
497     private boolean composerAnalyzerSkipDev;
498     /**
499      * Whether or not the Perl CPAN File Analyzer is enabled.
500      */
501     @Parameter(property = "cpanfileAnalyzerEnabled")
502     private Boolean cpanfileAnalyzerEnabled;
503     /**
504      * Sets whether or not the Node.js Analyzer should be used.
505      */
506     @SuppressWarnings("CanBeFinal")
507     @Parameter(property = "nodeAnalyzerEnabled")
508     private Boolean nodeAnalyzerEnabled;
509     /**
510      * Sets whether or not the Node Audit Analyzer should be used.
511      */
512     @SuppressWarnings("CanBeFinal")
513     @Parameter(property = "nodeAuditAnalyzerEnabled")
514     private Boolean nodeAuditAnalyzerEnabled;
515 
516     /**
517      * The Node Audit API URL for the Node Audit Analyzer.
518      */
519     @SuppressWarnings("CanBeFinal")
520     @Parameter(property = "nodeAuditAnalyzerUrl")
521     private String nodeAuditAnalyzerUrl;
522 
523     /**
524      * Sets whether or not the Yarn Audit Analyzer should be used.
525      */
526     @SuppressWarnings("CanBeFinal")
527     @Parameter(property = "yarnAuditAnalyzerEnabled")
528     private Boolean yarnAuditAnalyzerEnabled;
529 
530     /**
531      * Sets whether or not the Pnpm Audit Analyzer should be used.
532      */
533     @SuppressWarnings("CanBeFinal")
534     @Parameter(property = "pnpmAuditAnalyzerEnabled")
535     private Boolean pnpmAuditAnalyzerEnabled;
536 
537     /**
538      * Sets whether or not the Node Audit Analyzer should use a local cache.
539      */
540     @SuppressWarnings("CanBeFinal")
541     @Parameter(property = "nodeAuditAnalyzerUseCache")
542     private Boolean nodeAuditAnalyzerUseCache;
543     /**
544      * Sets whether or not the Node Audit Analyzer should skip devDependencies.
545      */
546     @SuppressWarnings("CanBeFinal")
547     @Parameter(property = "nodeAuditSkipDevDependencies")
548     private Boolean nodeAuditSkipDevDependencies;
549     /**
550      * Sets whether or not the Node.js Analyzer should skip devDependencies.
551      */
552     @SuppressWarnings("CanBeFinal")
553     @Parameter(property = "nodePackageSkipDevDependencies")
554     private Boolean nodePackageSkipDevDependencies;
555     /**
556      * Sets whether or not the Retirejs Analyzer should be used.
557      */
558     @SuppressWarnings("CanBeFinal")
559     @Parameter(property = "retireJsAnalyzerEnabled")
560     private Boolean retireJsAnalyzerEnabled;
561     /**
562      * The Retire JS repository URL.
563      */
564     @SuppressWarnings("CanBeFinal")
565     @Parameter(property = "retireJsUrl")
566     private String retireJsUrl;
567     /**
568      * The username to use when connecting to the CVE-URL.
569      */
570     @Parameter(property = "retireJsUser")
571     private String retireJsUser;
572     /**
573      * The password to authenticate to the CVE-URL. The `retireJsUrlServerId` should be used instead otherwise maven debug logging could expose the password.
574      */
575     @Parameter(property = "retireJsPassword")
576     private String retireJsPassword;
577     /**
578      * The server id in the settings.xml; used to retrieve encrypted passwords
579      * from the settings.xml for cve-URLs.
580      */
581     @SuppressWarnings("CanBeFinal")
582     @Parameter(property = "retireJsUrlServerId")
583     private String retireJsUrlServerId;
584     /**
585      * Whether the Retire JS repository will be updated regardless of the
586      * `autoupdate` settings.
587      */
588     @SuppressWarnings("CanBeFinal")
589     @Parameter(property = "retireJsForceUpdate")
590     private Boolean retireJsForceUpdate;
591     /**
592      * Whether or not the .NET Assembly Analyzer is enabled.
593      */
594     @Parameter(property = "assemblyAnalyzerEnabled")
595     private Boolean assemblyAnalyzerEnabled;
596     /**
597      * Whether or not the MS Build Analyzer is enabled.
598      */
599     @Parameter(property = "msbuildAnalyzerEnabled")
600     private Boolean msbuildAnalyzerEnabled;
601     /**
602      * Whether or not the .NET Nuspec Analyzer is enabled.
603      */
604     @SuppressWarnings("CanBeFinal")
605     @Parameter(property = "nuspecAnalyzerEnabled")
606     private Boolean nuspecAnalyzerEnabled;
607 
608     /**
609      * Whether or not the .NET packages.config Analyzer is enabled.
610      */
611     @SuppressWarnings("CanBeFinal")
612     @Parameter(property = "nugetconfAnalyzerEnabled")
613     private Boolean nugetconfAnalyzerEnabled;
614 
615     /**
616      * Whether or not the Libman Analyzer is enabled.
617      */
618     @SuppressWarnings("CanBeFinal")
619     @Parameter(property = "libmanAnalyzerEnabled")
620     private Boolean libmanAnalyzerEnabled;
621 
622     /**
623      * Whether or not the Central Analyzer is enabled.
624      */
625     @SuppressWarnings("CanBeFinal")
626     @Parameter(property = "centralAnalyzerEnabled")
627     private Boolean centralAnalyzerEnabled;
628 
629     /**
630      * Whether or not the Central Analyzer should use a local cache.
631      */
632     @SuppressWarnings("CanBeFinal")
633     @Parameter(property = "centralAnalyzerUseCache")
634     private Boolean centralAnalyzerUseCache;
635 
636     /**
637      * Whether or not the Artifactory Analyzer is enabled.
638      */
639     @SuppressWarnings("CanBeFinal")
640     @Parameter(property = "artifactoryAnalyzerEnabled")
641     private Boolean artifactoryAnalyzerEnabled;
642     /**
643      * The serverId inside the settings.xml containing the username and token to
644      * access artifactory
645      */
646     @SuppressWarnings("CanBeFinal")
647     @Parameter(property = "artifactoryAnalyzerServerId")
648     private String artifactoryAnalyzerServerId;
649     /**
650      * The username (only used with API token) to connect to Artifactory
651      * instance
652      */
653     @SuppressWarnings("CanBeFinal")
654     @Parameter(property = "artifactoryAnalyzerUsername")
655     private String artifactoryAnalyzerUsername;
656     /**
657      * The API token to connect to Artifactory instance
658      */
659     @SuppressWarnings("CanBeFinal")
660     @Parameter(property = "artifactoryAnalyzerApiToken")
661     private String artifactoryAnalyzerApiToken;
662     /**
663      * The bearer token to connect to Artifactory instance
664      */
665     @SuppressWarnings("CanBeFinal")
666     @Parameter(property = "artifactoryAnalyzerBearerToken")
667     private String artifactoryAnalyzerBearerToken;
668     /**
669      * The Artifactory URL for the Artifactory analyzer.
670      */
671     @SuppressWarnings("CanBeFinal")
672     @Parameter(property = "artifactoryAnalyzerUrl")
673     private String artifactoryAnalyzerUrl;
674     /**
675      * Whether Artifactory should be accessed through a proxy or not
676      */
677     @SuppressWarnings("CanBeFinal")
678     @Parameter(property = "artifactoryAnalyzerUseProxy")
679     private Boolean artifactoryAnalyzerUseProxy;
680     /**
681      * Whether the Artifactory analyzer should be run in parallel or not.
682      */
683     @SuppressWarnings("CanBeFinal")
684     @Parameter(property = "artifactoryAnalyzerParallelAnalysis", defaultValue = "true")
685     private Boolean artifactoryAnalyzerParallelAnalysis;
686     /**
687      * Whether or not the Nexus Analyzer is enabled.
688      */
689     @SuppressWarnings("CanBeFinal")
690     @Parameter(property = "nexusAnalyzerEnabled")
691     private Boolean nexusAnalyzerEnabled;
692 
693     /**
694      * Whether or not the Sonatype OSS Index analyzer is enabled.
695      */
696     @SuppressWarnings("CanBeFinal")
697     @Parameter(property = "ossindexAnalyzerEnabled")
698     private Boolean ossindexAnalyzerEnabled;
699     /**
700      * Whether or not the Sonatype OSS Index analyzer should cache results.
701      */
702     @SuppressWarnings("CanBeFinal")
703     @Parameter(property = "ossindexAnalyzerUseCache")
704     private Boolean ossindexAnalyzerUseCache;
705     /**
706      * URL of the Sonatype OSS Index service.
707      */
708     @SuppressWarnings("CanBeFinal")
709     @Parameter(property = "ossindexAnalyzerUrl")
710     private String ossindexAnalyzerUrl;
711 
712     /**
713      * The id of a server defined in the settings.xml that configures the
714      * credentials (username and password) for a OSS Index service.
715      */
716     @SuppressWarnings("CanBeFinal")
717     @Parameter(property = "ossIndexServerId")
718     private String ossIndexServerId;
719 
720     /**
721      * Whether we should only warn about Sonatype OSS Index remote errors
722      * instead of failing the goal completely.
723      */
724     @SuppressWarnings("CanBeFinal")
725     @Parameter(property = "ossIndexWarnOnlyOnRemoteErrors")
726     private Boolean ossIndexWarnOnlyOnRemoteErrors;
727 
728     /**
729      * Whether or not the Elixir Mix Audit Analyzer is enabled.
730      */
731     @Parameter(property = "mixAuditAnalyzerEnabled")
732     private Boolean mixAuditAnalyzerEnabled;
733 
734     /**
735      * Sets the path for the mix_audit binary.
736      */
737     @SuppressWarnings("CanBeFinal")
738     @Parameter(property = "mixAuditPath")
739     private String mixAuditPath;
740 
741     /**
742      * Whether or not the Ruby Bundle Audit Analyzer is enabled.
743      */
744     @Parameter(property = "bundleAuditAnalyzerEnabled")
745     private Boolean bundleAuditAnalyzerEnabled;
746 
747     /**
748      * Sets the path for the bundle-audit binary.
749      */
750     @SuppressWarnings("CanBeFinal")
751     @Parameter(property = "bundleAuditPath")
752     private String bundleAuditPath;
753 
754     /**
755      * Sets the path for the working directory that the bundle-audit binary
756      * should be executed from.
757      */
758     @SuppressWarnings("CanBeFinal")
759     @Parameter(property = "bundleAuditWorkingDirectory")
760     private String bundleAuditWorkingDirectory;
761 
762     /**
763      * Whether or not the CocoaPods Analyzer is enabled.
764      */
765     @SuppressWarnings("CanBeFinal")
766     @Parameter(property = "cocoapodsAnalyzerEnabled")
767     private Boolean cocoapodsAnalyzerEnabled;
768 
769     /**
770      * Whether or not the Carthage Analyzer is enabled.
771      */
772     @SuppressWarnings("CanBeFinal")
773     @Parameter(property = "carthageAnalyzerEnabled")
774     private Boolean carthageAnalyzerEnabled;
775 
776     /**
777      * Whether or not the Swift package Analyzer is enabled.
778      */
779     @SuppressWarnings("CanBeFinal")
780     @Parameter(property = "swiftPackageManagerAnalyzerEnabled")
781     private Boolean swiftPackageManagerAnalyzerEnabled;
782     /**
783      * Whether or not the Swift package resolved Analyzer is enabled.
784      */
785     @SuppressWarnings("CanBeFinal")
786     @Parameter(property = "swiftPackageResolvedAnalyzerEnabled")
787     private Boolean swiftPackageResolvedAnalyzerEnabled;
788     /**
789      * The URL of a Nexus server's REST API end point
790      * (http://domain/nexus/service/local).
791      */
792     @SuppressWarnings("CanBeFinal")
793     @Parameter(property = "nexusUrl")
794     private String nexusUrl;
795     /**
796      * The id of a server defined in the settings.xml that configures the
797      * credentials (username and password) for a Nexus server's REST API end
798      * point. When not specified the communication with the Nexus server's REST
799      * API will be unauthenticated.
800      */
801     @SuppressWarnings("CanBeFinal")
802     @Parameter(property = "nexusServerId")
803     private String nexusServerId;
804     /**
805      * Whether or not the configured proxy is used to connect to Nexus.
806      */
807     @SuppressWarnings("CanBeFinal")
808     @Parameter(property = "nexusUsesProxy")
809     private Boolean nexusUsesProxy;
810     /**
811      * The database connection string.
812      */
813     @SuppressWarnings("CanBeFinal")
814     @Parameter(property = "connectionString")
815     private String connectionString;
816 
817     /**
818      * The database driver name. An example would be org.h2.Driver.
819      */
820     @SuppressWarnings("CanBeFinal")
821     @Parameter(property = "databaseDriverName")
822     private String databaseDriverName;
823     /**
824      * The path to the database driver if it is not on the class path.
825      */
826     @SuppressWarnings("CanBeFinal")
827     @Parameter(property = "databaseDriverPath")
828     private String databaseDriverPath;
829     /**
830      * A reference to the settings.xml settings.
831      */
832     @SuppressWarnings("CanBeFinal")
833     @Parameter(defaultValue = "${settings}", readonly = true, required = true)
834     private org.apache.maven.settings.Settings settingsXml;
835     /**
836      * The security dispatcher that can decrypt passwords in the settings.xml.
837      */
838     @Component(role = SecDispatcher.class, hint = "default")
839     private SecDispatcher securityDispatcher;
840     /**
841      * The database user name.
842      */
843     @Parameter(property = "databaseUser")
844     private String databaseUser;
845     /**
846      * The password to use when connecting to the database. The `serverId` should be used instead otherwise maven debug logging could expose the password.
847      */
848     @Parameter(property = "databasePassword")
849     private String databasePassword;
850     /**
851      * A comma-separated list of file extensions to add to analysis next to jar,
852      * zip, ....
853      */
854     @SuppressWarnings("CanBeFinal")
855     @Parameter(property = "zipExtensions")
856     private String zipExtensions;
857     /**
858      * Skip Dependency Check altogether.
859      */
860     @SuppressWarnings("CanBeFinal")
861     @Parameter(property = "dependency-check.skip", defaultValue = "false")
862     private boolean skip = false;
863     /**
864      * Skip Analysis for Test Scope Dependencies.
865      */
866     @SuppressWarnings("CanBeFinal")
867     @Parameter(property = "skipTestScope", defaultValue = "true")
868     private boolean skipTestScope = true;
869     /**
870      * Skip Analysis for Runtime Scope Dependencies.
871      */
872     @SuppressWarnings("CanBeFinal")
873     @Parameter(property = "skipRuntimeScope", defaultValue = "false")
874     private boolean skipRuntimeScope = false;
875     /**
876      * Skip Analysis for Provided Scope Dependencies.
877      */
878     @SuppressWarnings("CanBeFinal")
879     @Parameter(property = "skipProvidedScope", defaultValue = "false")
880     private boolean skipProvidedScope = false;
881 
882     /**
883      * Skip Analysis for System Scope Dependencies.
884      */
885     @SuppressWarnings("CanBeFinal")
886     @Parameter(property = "skipSystemScope", defaultValue = "false")
887     private boolean skipSystemScope = false;
888 
889     /**
890      * Skip Analysis for dependencyManagement section.
891      */
892     @SuppressWarnings("CanBeFinal")
893     @Parameter(property = "skipDependencyManagement", defaultValue = "true")
894     private boolean skipDependencyManagement = true;
895 
896     /**
897      * Skip analysis for dependencies which type matches this regular
898      * expression. This filters on the `type` of dependency as defined in the
899      * dependency section: jar, pom, test-jar, etc.
900      */
901     @SuppressWarnings("CanBeFinal")
902     @Parameter(property = "skipArtifactType")
903     private String skipArtifactType;
904 
905     /**
906      * The data directory, hold DC SQL DB.
907      */
908     @SuppressWarnings("CanBeFinal")
909     @Parameter(property = "dataDirectory")
910     private String dataDirectory;
911 
912     /**
913      * The name of the DC DB.
914      */
915     @SuppressWarnings("CanBeFinal")
916     @Parameter(property = "dbFilename")
917     private String dbFilename;
918     /**
919      * The server id in the settings.xml; used to retrieve encrypted passwords
920      * from the settings.xml. This is used for the database username and
921      * password.
922      */
923     @SuppressWarnings("CanBeFinal")
924     @Parameter(property = "serverId")
925     private String serverId;
926     /**
927      * The NVD API Key. The parameters {@link #nvdApiKeyEnvironmentVariable} or {@link #nvdApiServerId} should be used instead otherwise
928      * Maven debug logging could expose the API Key (see <a href="https://github.com/advisories/GHSA-qqhq-8r2c-c3f5">GHSA-qqhq-8r2c-c3f5</a>).
929      * This takes precedence over {@link #nvdApiServerId} and {@link #nvdApiKeyEnvironmentVariable}.
930      */
931     @SuppressWarnings("CanBeFinal")
932     @Parameter(property = "nvdApiKey")
933     private String nvdApiKey;
934     /**
935      * The maximum number of retry requests for a single call to the NVD API.
936      */
937     @SuppressWarnings("CanBeFinal")
938     @Parameter(property = "nvdMaxRetryCount")
939     private Integer nvdMaxRetryCount;
940     /**
941      * The server id in the settings.xml; used to retrieve encrypted API Key
942      * from the settings.xml for the NVD API Key. Note that the password is used
943      * as the API Key.
944      * Is potentially overwritten by {@link #nvdApiKeyEnvironmentVariable} or {@link #nvdApiKey}.
945      */
946     @SuppressWarnings("CanBeFinal")
947     @Parameter(property = "nvdApiServerId")
948     private String nvdApiServerId;
949     /**
950      * The environment variable from which to retrieve the API key for the NVD API.
951      * Takes precedence over {@link #nvdApiServerId} but is potentially overwritten by {@link #nvdApiKey}.
952      * This is the recommended option to pass the API key in CI builds.
953      */
954     @SuppressWarnings("CanBeFinal")
955     @Parameter(property = "nvdApiKeyEnvironmentVariable")
956     private String nvdApiKeyEnvironmentVariable;
957     /**
958      * The number of hours to wait before checking for new updates from the NVD.
959      */
960     @SuppressWarnings("CanBeFinal")
961     @Parameter(property = "nvdValidForHours")
962     private Integer nvdValidForHours;
963     /**
964      * The NVD API Endpoint; setting this is uncommon.
965      */
966     @SuppressWarnings("CanBeFinal")
967     @Parameter(property = "nvdApiEndpoint")
968     private String nvdApiEndpoint;
969     /**
970      * The NVD API Data Feed URL.
971      */
972     @SuppressWarnings("CanBeFinal")
973     @Parameter(property = "nvdDatafeedUrl")
974     private String nvdDatafeedUrl;
975 
976     /**
977      * The server id in the settings.xml; used to retrieve encrypted passwords
978      * from the settings.xml for the NVD Data Feed.
979      */
980     @SuppressWarnings("CanBeFinal")
981     @Parameter(property = "nvdDatafeedServerId")
982     private String nvdDatafeedServerId;
983     /**
984      * The username for basic auth to the NVD Data Feed.
985      */
986     @SuppressWarnings("CanBeFinal")
987     @Parameter(property = "nvdUser")
988     private String nvdUser;
989     /**
990      * The password for basic auth to the NVD Data Feed.
991      */
992     @SuppressWarnings("CanBeFinal")
993     @Parameter(property = "nvdPassword")
994     private String nvdPassword;
995     /**
996      * The time in milliseconds to wait between downloading NVD API data.
997      */
998     @SuppressWarnings("CanBeFinal")
999     @Parameter(property = "nvdApiDelay")
1000     private Integer nvdApiDelay;
1001 
1002     /**
1003      * The number records for a single page from NVD API (must be <=2000).
1004      */
1005     @SuppressWarnings("CanBeFinal")
1006     @Parameter(property = "nvdApiResultsPerPage")
1007     private Integer nvdApiResultsPerPage;
1008 
1009     /**
1010      * The path to dotnet core.
1011      */
1012     @SuppressWarnings("CanBeFinal")
1013     @Parameter(property = "pathToCore")
1014     private String pathToCore;
1015     /**
1016      * The hosted suppressions file URL.
1017      */
1018     @SuppressWarnings("CanBeFinal")
1019     @Parameter(property = "hostedSuppressionsUrl")
1020     private String hostedSuppressionsUrl;
1021     /**
1022      * Whether the hosted suppressions file will be updated regardless of the
1023      * `autoupdate` settings.
1024      */
1025     @SuppressWarnings("CanBeFinal")
1026     @Parameter(property = "hostedSuppressionsForceUpdate")
1027     private Boolean hostedSuppressionsForceUpdate;
1028     /**
1029      * Whether the hosted suppressions file will be used.
1030      */
1031     @SuppressWarnings("CanBeFinal")
1032     @Parameter(property = "hostedSuppressionsEnabled")
1033     private Boolean hostedSuppressionsEnabled;
1034     /**
1035      * Skip excessive hosted suppression file update checks for a designated
1036      * duration in hours (defaults to 2 hours).
1037      */
1038     @SuppressWarnings("CanBeFinal")
1039     @Parameter(property = "hostedSuppressionsValidForHours")
1040     private Integer hostedSuppressionsValidForHours;
1041 
1042     /**
1043      * The RetireJS Analyzer configuration:
1044      * <pre>
1045      *   filters: an array of filter patterns that are used to exclude JS files that contain a match
1046      *   filterNonVulnerable: a boolean that when true will remove non-vulnerable JS from the report
1047      *
1048      * Example:
1049      *   &lt;retirejs&gt;
1050      *     &lt;filters&gt;
1051      *       &lt;filter&gt;copyright 2018\(c\) Jeremy Long&lt;/filter&gt;
1052      *     &lt;/filters&gt;
1053      *     &lt;filterNonVulnerable&gt;true&lt;/filterNonVulnerable&gt;
1054      *   &lt;/retirejs&gt;
1055      * </pre>
1056      */
1057     @SuppressWarnings("CanBeFinal")
1058     @Parameter(property = "retirejs")
1059     private Retirejs retirejs;
1060 
1061     /**
1062      * The list of artifacts (and their transitive dependencies) to exclude from
1063      * the check.
1064      */
1065     @Parameter(property = "odc.excludes")
1066     private List<String> excludes;
1067 
1068     /**
1069      * The artifact scope filter.
1070      */
1071     private Filter<String> artifactScopeExcluded;
1072 
1073     /**
1074      * Filter for artifact type.
1075      */
1076     private Filter<String> artifactTypeExcluded;
1077 
1078     /**
1079      * An collection of <code>fileSet</code>s that specify additional files
1080      * and/or directories (from the basedir) to analyze as part of the scan. If
1081      * not specified, defaults to Maven conventions of: src/main/resources,
1082      * src/main/filters, and src/main/webapp. Note, this cannot be set via the
1083      * command line - use `scanDirectory` instead.
1084      */
1085     @Parameter
1086     private List<FileSet> scanSet;
1087     /**
1088      * A list of directories to scan. Note, this should only be used via the
1089      * command line - if configuring the directories to scan consider using the
1090      * `scanSet` instead.
1091      */
1092     @Parameter(property = "scanDirectory")
1093     private List<String> scanDirectory;
1094 
1095     /**
1096      * Whether the project's plugins should also be scanned.
1097      */
1098     @SuppressWarnings("CanBeFinal")
1099     @Parameter(property = "odc.plugins.scan", defaultValue = "false", required = false)
1100     private boolean scanPlugins = false;
1101     /**
1102      * Whether the project's dependencies should also be scanned.
1103      */
1104     @SuppressWarnings("CanBeFinal")
1105     @Parameter(property = "odc.dependencies.scan", defaultValue = "true", required = false)
1106     private boolean scanDependencies = true;
1107     /**
1108      * The proxy configuration.
1109      */
1110     @Parameter
1111     private ProxyConfig proxy;
1112 
1113     // </editor-fold>
1114     //<editor-fold defaultstate="collapsed" desc="Base Maven implementation">
1115     /**
1116      * Determines if the groupId, artifactId, and version of the Maven
1117      * dependency and artifact match.
1118      *
1119      * @param d the Maven dependency
1120      * @param a the Maven artifact
1121      * @return true if the groupId, artifactId, and version match
1122      */
1123     private static boolean artifactsMatch(org.apache.maven.model.Dependency d, Artifact a) {
1124         return isEqualOrNull(a.getArtifactId(), d.getArtifactId())
1125                 && isEqualOrNull(a.getGroupId(), d.getGroupId())
1126                 && isEqualOrNull(a.getVersion(), d.getVersion());
1127     }
1128 
1129     /**
1130      * Compares two strings for equality; if both strings are null they are
1131      * considered equal.
1132      *
1133      * @param left the first string to compare
1134      * @param right the second string to compare
1135      * @return true if the strings are equal or if they are both null; otherwise
1136      * false.
1137      */
1138     private static boolean isEqualOrNull(String left, String right) {
1139         return (left != null && left.equals(right)) || (left == null && right == null);
1140     }
1141 
1142     /**
1143      * Executes dependency-check.
1144      *
1145      * @throws MojoExecutionException thrown if there is an exception executing
1146      * the mojo
1147      * @throws MojoFailureException thrown if dependency-check failed the build
1148      */
1149     @Override
1150     public void execute() throws MojoExecutionException, MojoFailureException {
1151         generatingSite = false;
1152         final boolean shouldSkip = Boolean.parseBoolean(System.getProperty("dependency-check.skip", Boolean.toString(skip)));
1153         if (shouldSkip) {
1154             getLog().info("Skipping " + getName(Locale.US));
1155         } else {
1156             project.setContextValue("dependency-check-output-dir", this.outputDirectory);
1157             runCheck();
1158         }
1159     }
1160 
1161     /**
1162      * Returns true if the Maven site is being generated.
1163      *
1164      * @return true if the Maven site is being generated
1165      */
1166     protected boolean isGeneratingSite() {
1167         return generatingSite;
1168     }
1169 
1170     /**
1171      * Returns the connection string.
1172      *
1173      * @return the connection string
1174      */
1175     protected String getConnectionString() {
1176         return connectionString;
1177     }
1178 
1179     /**
1180      * Returns if the mojo should fail the build if an exception occurs.
1181      *
1182      * @return whether or not the mojo should fail the build
1183      */
1184     protected boolean isFailOnError() {
1185         return failOnError;
1186     }
1187 
1188     /**
1189      * Generates the Dependency-Check Site Report.
1190      *
1191      * @param sink the sink to write the report to
1192      * @param locale the locale to use when generating the report
1193      * @throws MavenReportException if a maven report exception occurs
1194      */
1195     public void generate(Sink sink, Locale locale) throws MavenReportException {
1196         final boolean shouldSkip = Boolean.parseBoolean(System.getProperty("dependency-check.skip", Boolean.toString(skip)));
1197         if (shouldSkip) {
1198             getLog().info("Skipping report generation " + getName(Locale.US));
1199             return;
1200         }
1201 
1202         generatingSite = true;
1203         project.setContextValue("dependency-check-output-dir", getReportOutputDirectory());
1204         try {
1205             runCheck();
1206         } catch (MojoExecutionException ex) {
1207             throw new MavenReportException(ex.getMessage(), ex);
1208         } catch (MojoFailureException ex) {
1209             getLog().warn("Vulnerabilities were identifies that exceed the CVSS threshold for failing the build");
1210         }
1211     }
1212 
1213     /**
1214      * Returns the correct output directory depending on if a site is being
1215      * executed or not.
1216      *
1217      * @return the directory to write the report(s)
1218      * @throws MojoExecutionException thrown if there is an error loading the
1219      * file path
1220      */
1221     protected File getCorrectOutputDirectory() throws MojoExecutionException {
1222         return getCorrectOutputDirectory(this.project);
1223     }
1224 
1225     /**
1226      * Returns the correct output directory depending on if a site is being
1227      * executed or not.
1228      *
1229      * @param current the Maven project to get the output directory from
1230      * @return the directory to write the report(s)
1231      */
1232     protected File getCorrectOutputDirectory(MavenProject current) {
1233         final Object obj = current.getContextValue("dependency-check-output-dir");
1234         if (obj != null && obj instanceof File) {
1235             return (File) obj;
1236         }
1237         //else we guess
1238         File target = new File(current.getBuild().getDirectory());
1239         if (target.getParentFile() != null && "target".equals(target.getParentFile().getName())) {
1240             target = target.getParentFile();
1241         }
1242         return target;
1243     }
1244 
1245     /**
1246      * Scans the project's artifacts and adds them to the engine's dependency
1247      * list.
1248      *
1249      * @param project the project to scan the dependencies of
1250      * @param engine the engine to use to scan the dependencies
1251      * @return a collection of exceptions that may have occurred while resolving
1252      * and scanning the dependencies
1253      */
1254     protected ExceptionCollection scanArtifacts(MavenProject project, Engine engine) {
1255         return scanArtifacts(project, engine, false);
1256     }
1257 
1258     /**
1259      * Scans the project's artifacts and adds them to the engine's dependency
1260      * list.
1261      *
1262      * @param project the project to scan the dependencies of
1263      * @param engine the engine to use to scan the dependencies
1264      * @param aggregate whether the scan is part of an aggregate build
1265      * @return a collection of exceptions that may have occurred while resolving
1266      * and scanning the dependencies
1267      */
1268     protected ExceptionCollection scanArtifacts(MavenProject project, Engine engine, boolean aggregate) {
1269         try {
1270             final List<String> filterItems = Collections.singletonList(String.format("%s:%s", project.getGroupId(), project.getArtifactId()));
1271             final ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest(project, project.getRemoteArtifactRepositories());
1272             //For some reason the filter does not filter out the project being analyzed
1273             //if we pass in the filter below instead of null to the dependencyGraphBuilder
1274             final DependencyNode dn = dependencyGraphBuilder.buildDependencyGraph(buildingRequest, null);
1275 
1276             final CollectingRootDependencyGraphVisitor collectorVisitor = new CollectingRootDependencyGraphVisitor();
1277 
1278             // exclude artifact by pattern and its dependencies
1279             final DependencyNodeVisitor transitiveFilterVisitor = new FilteringDependencyTransitiveNodeVisitor(collectorVisitor,
1280                     new ArtifactDependencyNodeFilter(new PatternExcludesArtifactFilter(getExcludes())));
1281             // exclude exact artifact but not its dependencies, this filter must be appied on the root for first otherwise
1282             // in case the exclude has the same groupId of the current bundle its direct dependencies are not visited
1283             final DependencyNodeVisitor artifactFilter = new FilteringDependencyNodeVisitor(transitiveFilterVisitor,
1284                     new ArtifactDependencyNodeFilter(new ExcludesArtifactFilter(filterItems)));
1285             dn.accept(artifactFilter);
1286 
1287             //collect dependencies with the filter - see comment above.
1288             final Map<DependencyNode, List<DependencyNode>> nodes = collectorVisitor.getNodes();
1289 
1290             return collectDependencies(engine, project, nodes, buildingRequest, aggregate);
1291         } catch (DependencyGraphBuilderException ex) {
1292             final String msg = String.format("Unable to build dependency graph on project %s", project.getName());
1293             getLog().debug(msg, ex);
1294             return new ExceptionCollection(ex);
1295         }
1296     }
1297 
1298     /**
1299      * Scans the project's artifacts for plugin-dependencies and adds them to
1300      * the engine's dependency list.
1301      *
1302      * @param project the project to scan the plugin-dependencies of
1303      * @param engine the engine to use to scan the plugin-dependencies
1304      * @param exCollection the collection of exceptions that have previously
1305      * occurred
1306      * @return a collection of exceptions that may have occurred while resolving
1307      * and scanning the plugins and their dependencies
1308      */
1309     protected ExceptionCollection scanPlugins(MavenProject project, Engine engine, ExceptionCollection exCollection) {
1310         ExceptionCollection exCol = exCollection;
1311         final Set<Artifact> plugins = new HashSet<>();
1312         final Set<Artifact> buildPlugins = getProject().getPluginArtifacts();
1313         final Set<Artifact> reportPlugins = getProject().getReportArtifacts();
1314         final Set<Artifact> extensions = getProject().getExtensionArtifacts();
1315 
1316         plugins.addAll(buildPlugins);
1317         plugins.addAll(reportPlugins);
1318         plugins.addAll(extensions);
1319 
1320         final ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest(project, project.getPluginArtifactRepositories());
1321         for (Artifact plugin : plugins) {
1322             try {
1323                 final Artifact resolved = artifactResolver.resolveArtifact(buildingRequest, plugin).getArtifact();
1324 
1325                 exCol = addPluginToDependencies(project, engine, resolved, "pom.xml (plugins)", exCol);
1326 
1327                 final DefaultDependableCoordinate pluginCoordinate = new DefaultDependableCoordinate();
1328                 pluginCoordinate.setGroupId(resolved.getGroupId());
1329                 pluginCoordinate.setArtifactId(resolved.getArtifactId());
1330                 pluginCoordinate.setVersion(resolved.getVersion());
1331 
1332                 final String parent = buildReference(resolved.getGroupId(), resolved.getArtifactId(), resolved.getVersion());
1333                 for (Artifact artifact : resolveArtifactDependencies(pluginCoordinate, project)) {
1334                     exCol = addPluginToDependencies(project, engine, artifact, parent, exCol);
1335                 }
1336             } catch (ArtifactResolverException ex) {
1337                 throw new RuntimeException(ex);
1338             } catch (IllegalArgumentException ex) {
1339                 throw new RuntimeException(ex);
1340             } catch (DependencyResolverException ex) {
1341                 throw new RuntimeException(ex);
1342             }
1343         }
1344 
1345         return null;
1346 
1347     }
1348 
1349     private ExceptionCollection addPluginToDependencies(MavenProject project, Engine engine, Artifact artifact, String parent, ExceptionCollection exCollection) {
1350         ExceptionCollection exCol = exCollection;
1351         final String groupId = artifact.getGroupId();
1352         final String artifactId = artifact.getArtifactId();
1353         final String version = artifact.getVersion();
1354         final File artifactFile = artifact.getFile();
1355         if (artifactFile.isFile()) {
1356             final List<ArtifactVersion> availableVersions = artifact.getAvailableVersions();
1357 
1358             final List<Dependency> deps = engine.scan(artifactFile.getAbsoluteFile(),
1359                     project.getName() + " (plugins)");
1360             if (deps != null) {
1361                 Dependency d = null;
1362                 if (deps.size() == 1) {
1363                     d = deps.get(0);
1364                 } else {
1365                     for (Dependency possible : deps) {
1366                         if (artifactFile.getAbsoluteFile().equals(possible.getActualFile())) {
1367                             d = possible;
1368                             break;
1369                         }
1370                     }
1371                     for (Dependency dep : deps) {
1372                         if (d != null && d != dep) {
1373                             final String includedBy = buildReference(groupId, artifactId, version);
1374                             dep.addIncludedBy(includedBy, "plugins");
1375                         }
1376                     }
1377                 }
1378                 if (d != null) {
1379                     final MavenArtifact ma = new MavenArtifact(groupId, artifactId, version);
1380                     d.addAsEvidence("pom", ma, Confidence.HIGHEST);
1381                     if (parent != null) {
1382                         d.addIncludedBy(parent, "plugins");
1383                     } else {
1384                         final String includedby = buildReference(
1385                                 project.getGroupId(),
1386                                 project.getArtifactId(),
1387                                 project.getVersion());
1388                         d.addIncludedBy(includedby, "plugins");
1389                     }
1390                     if (availableVersions != null) {
1391                         for (ArtifactVersion av : availableVersions) {
1392                             d.addAvailableVersion(av.toString());
1393                         }
1394                     }
1395                 }
1396             }
1397         } else {
1398             if (exCol == null) {
1399                 exCol = new ExceptionCollection();
1400             }
1401             exCol.addException(new DependencyNotFoundException("Unable to resolve plugin: "
1402                     + groupId + ":" + artifactId + ":" + version));
1403         }
1404 
1405         return exCol;
1406     }
1407 
1408     private String buildReference(final String groupId, final String artifactId, final String version) {
1409         String includedBy;
1410         try {
1411             final PackageURL purl = new PackageURL("maven", groupId, artifactId, version, null, null);
1412             includedBy = purl.toString();
1413         } catch (MalformedPackageURLException ex) {
1414             getLog().warn("Unable to generate build reference for " + groupId
1415                     + ":" + artifactId + ":" + version, ex);
1416             includedBy = groupId + ":" + artifactId + ":" + version;
1417         }
1418         return includedBy;
1419     }
1420 
1421     protected Set<Artifact> resolveArtifactDependencies(final DependableCoordinate artifact, MavenProject project)
1422             throws DependencyResolverException {
1423         final ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest(project, project.getRemoteArtifactRepositories());
1424 
1425         final Iterable<ArtifactResult> artifactResults = dependencyResolver.resolveDependencies(buildingRequest, artifact, null);
1426 
1427         final Set<Artifact> artifacts = new HashSet<>();
1428 
1429         for (ArtifactResult artifactResult : artifactResults) {
1430             artifacts.add(artifactResult.getArtifact());
1431         }
1432 
1433         return artifacts;
1434 
1435     }
1436 
1437     /**
1438      * Converts the dependency to a dependency node object.
1439      *
1440      * @param nodes the list of dependency nodes
1441      * @param buildingRequest the Maven project building request
1442      * @param parent the parent node
1443      * @param dependency the dependency to convert
1444      * @return the resulting dependency node
1445      * @throws ArtifactResolverException thrown if the artifact could not be
1446      * retrieved
1447      */
1448     private DependencyNode toDependencyNode(List<DependencyNode> nodes, ProjectBuildingRequest buildingRequest,
1449             DependencyNode parent, org.apache.maven.model.Dependency dependency) throws ArtifactResolverException {
1450 
1451         final DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
1452 
1453         coordinate.setGroupId(dependency.getGroupId());
1454         coordinate.setArtifactId(dependency.getArtifactId());
1455         String version = null;
1456         final VersionRange vr;
1457         try {
1458             vr = VersionRange.createFromVersionSpec(dependency.getVersion());
1459         } catch (InvalidVersionSpecificationException ex) {
1460             throw new ArtifactResolverException("Invalid version specification: "
1461                     + dependency.getGroupId() + ":"
1462                     + dependency.getArtifactId() + ":"
1463                     + dependency.getVersion(), ex);
1464         }
1465         if (vr.hasRestrictions()) {
1466             version = findVersion(nodes, dependency.getGroupId(), dependency.getArtifactId());
1467             if (version == null) {
1468                 //TODO - this still may fail if the restriction is not a valid version number (i.e. only 2.9 instead of 2.9.1)
1469                 //need to get available versions and filter on the restrictions.
1470                 if (vr.getRecommendedVersion() != null) {
1471                     version = vr.getRecommendedVersion().toString();
1472                 } else if (vr.hasRestrictions()) {
1473                     for (Restriction restriction : vr.getRestrictions()) {
1474                         if (restriction.getLowerBound() != null) {
1475                             version = restriction.getLowerBound().toString();
1476                         }
1477                         if (restriction.getUpperBound() != null) {
1478                             version = restriction.getUpperBound().toString();
1479                         }
1480                     }
1481                 } else {
1482                     version = vr.toString();
1483                 }
1484             }
1485         }
1486         if (version == null) {
1487             version = dependency.getVersion();
1488         }
1489         coordinate.setVersion(version);
1490 
1491         final ArtifactType type = session.getRepositorySession().getArtifactTypeRegistry().get(dependency.getType());
1492         coordinate.setExtension(type.getExtension());
1493         coordinate.setClassifier((null == dependency.getClassifier() || dependency.getClassifier().isEmpty())
1494                 ? type.getClassifier() : dependency.getClassifier());
1495         final Artifact artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact();
1496         artifact.setScope(dependency.getScope());
1497         return new DefaultDependencyNode(parent, artifact, dependency.getVersion(), dependency.getScope(), null);
1498     }
1499 
1500     /**
1501      * Returns the version from the list of nodes that match the given groupId
1502      * and artifactID.
1503      *
1504      * @param nodes the nodes to search
1505      * @param groupId the group id to find
1506      * @param artifactId the artifact id to find
1507      * @return the version from the list of nodes that match the given groupId
1508      * and artifactID; otherwise <code>null</code> is returned
1509      */
1510     private String findVersion(List<DependencyNode> nodes, String groupId, String artifactId) {
1511         final Optional<DependencyNode> f = nodes.stream().filter(p
1512                 -> groupId.equals(p.getArtifact().getGroupId())
1513                 && artifactId.equals(p.getArtifact().getArtifactId())).findFirst();
1514         if (f.isPresent()) {
1515             return f.get().getArtifact().getVersion();
1516         }
1517         return null;
1518     }
1519 
1520     /**
1521      * Collect dependencies from the dependency management section.
1522      *
1523      * @param engine reference to the ODC engine
1524      * @param buildingRequest the Maven project building request
1525      * @param project the project being analyzed
1526      * @param nodes the list of dependency nodes
1527      * @param aggregate whether or not this is an aggregate analysis
1528      * @return a collection of exceptions if any occurred; otherwise
1529      * <code>null</code>
1530      */
1531     private ExceptionCollection collectDependencyManagementDependencies(Engine engine, ProjectBuildingRequest buildingRequest,
1532             MavenProject project, List<DependencyNode> nodes, boolean aggregate) {
1533         if (skipDependencyManagement || project.getDependencyManagement() == null) {
1534             return null;
1535         }
1536 
1537         ExceptionCollection exCol = null;
1538         for (org.apache.maven.model.Dependency dependency : project.getDependencyManagement().getDependencies()) {
1539             try {
1540                 nodes.add(toDependencyNode(nodes, buildingRequest, null, dependency));
1541             } catch (ArtifactResolverException ex) {
1542                 getLog().debug(String.format("Aggregate : %s", aggregate));
1543                 boolean addException = true;
1544                 //CSOFF: EmptyBlock
1545                 if (!aggregate) {
1546                     // do nothing, exception is to be reported
1547                 } else if (addReactorDependency(engine,
1548                         new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(),
1549                                 dependency.getVersion(), dependency.getScope(), dependency.getType(), dependency.getClassifier(),
1550                                 new DefaultArtifactHandler()), project)) {
1551                     addException = false;
1552                 }
1553                 //CSON: EmptyBlock
1554                 if (addException) {
1555                     if (exCol == null) {
1556                         exCol = new ExceptionCollection();
1557                     }
1558                     exCol.addException(ex);
1559                 }
1560             }
1561         }
1562         return exCol;
1563     }
1564 
1565     /**
1566      * Resolves the projects artifacts using Aether and scans the resulting
1567      * dependencies.
1568      *
1569      * @param engine the core dependency-check engine
1570      * @param project the project being scanned
1571      * @param nodeMap the map of dependency nodes, generally obtained via the
1572      * DependencyGraphBuilder using the CollectingRootDependencyGraphVisitor
1573      * @param buildingRequest the Maven project building request
1574      * @param aggregate whether the scan is part of an aggregate build
1575      * @return a collection of exceptions that may have occurred while resolving
1576      * and scanning the dependencies
1577      */
1578     //CSOFF: OperatorWrap
1579     private ExceptionCollection collectMavenDependencies(Engine engine, MavenProject project,
1580             Map<DependencyNode, List<DependencyNode>> nodeMap, ProjectBuildingRequest buildingRequest, boolean aggregate) {
1581 
1582         final List<ArtifactResult> allResolvedDeps = new ArrayList<>();
1583 
1584         //dependency management
1585         final List<DependencyNode> dmNodes = new ArrayList<>();
1586         ExceptionCollection exCol = collectDependencyManagementDependencies(engine, buildingRequest, project, dmNodes, aggregate);
1587         for (DependencyNode dependencyNode : dmNodes) {
1588             exCol = scanDependencyNode(dependencyNode, null, engine, project, allResolvedDeps, buildingRequest, aggregate, exCol);
1589         }
1590 
1591         //dependencies
1592         for (Map.Entry<DependencyNode, List<DependencyNode>> entry : nodeMap.entrySet()) {
1593             exCol = scanDependencyNode(entry.getKey(), null, engine, project, allResolvedDeps, buildingRequest, aggregate, exCol);
1594             for (DependencyNode dependencyNode : entry.getValue()) {
1595                 exCol = scanDependencyNode(dependencyNode, entry.getKey(), engine, project, allResolvedDeps, buildingRequest, aggregate, exCol);
1596             }
1597         }
1598         return exCol;
1599     }
1600     //CSON: OperatorWrap
1601 
1602     /**
1603      * Utility method for a work-around to MSHARED-998
1604      *
1605      * @param allDeps The List of ArtifactResults for all dependencies
1606      * @param unresolvedArtifact The ArtifactCoordinate of the artifact we're
1607      * looking for
1608      * @param project The project in whose context resolution was attempted
1609      * @return the resolved artifact matching with {@code unresolvedArtifact}
1610      * @throws DependencyNotFoundException If {@code unresolvedArtifact} could
1611      * not be found within {@code allDeps}
1612      */
1613     private Artifact findInAllDeps(final List<ArtifactResult> allDeps, final Artifact unresolvedArtifact,
1614             final MavenProject project)
1615             throws DependencyNotFoundException {
1616         Artifact result = null;
1617         for (final ArtifactResult res : allDeps) {
1618             if (sameArtifact(res, unresolvedArtifact)) {
1619                 result = res.getArtifact();
1620                 break;
1621             }
1622         }
1623         if (result == null) {
1624             throw new DependencyNotFoundException(String.format("Expected dependency not found in resolved artifacts for "
1625                     + "dependency %s of project-artifact %s", unresolvedArtifact, project.getArtifactId()));
1626         }
1627         return result;
1628     }
1629 
1630     /**
1631      * Utility method for a work-around to MSHARED-998
1632      *
1633      * @param res A single ArtifactResult obtained from the DependencyResolver
1634      * @param unresolvedArtifact The unresolved Artifact from the
1635      * dependencyGraph that we try to find
1636      * @return {@code true} when unresolvedArtifact is non-null and matches with
1637      * the artifact of res
1638      */
1639     private boolean sameArtifact(final ArtifactResult res, final Artifact unresolvedArtifact) {
1640         if (res == null || res.getArtifact() == null || unresolvedArtifact == null) {
1641             return false;
1642         }
1643         boolean result = Objects.equals(res.getArtifact().getGroupId(), unresolvedArtifact.getGroupId());
1644         result &= Objects.equals(res.getArtifact().getArtifactId(), unresolvedArtifact.getArtifactId());
1645         // accept any version as matching "LATEST" and any non-snapshot version as matching "RELEASE" meta-version
1646         if ("RELEASE".equals(unresolvedArtifact.getBaseVersion())) {
1647             result &= !res.getArtifact().isSnapshot();
1648         } else if (!"LATEST".equals(unresolvedArtifact.getBaseVersion())) {
1649             result &= Objects.equals(res.getArtifact().getBaseVersion(), unresolvedArtifact.getBaseVersion());
1650         }
1651         result &= Objects.equals(res.getArtifact().getClassifier(), unresolvedArtifact.getClassifier());
1652         result &= Objects.equals(res.getArtifact().getType(), unresolvedArtifact.getType());
1653         return result;
1654     }
1655 
1656     /**
1657      * @param project the {@link MavenProject}
1658      * @param dependencyNode the {@link DependencyNode}
1659      * @return the name to be used when creating a
1660      * {@link Dependency#getProjectReferences() project reference} in a
1661      * {@link Dependency}. The behavior of this method returns {@link MavenProject#getName() project.getName()}<code> + ":" +
1662      * </code>
1663      * {@link DependencyNode#getArtifact() dependencyNode.getArtifact()}{@link Artifact#getScope() .getScope()}.
1664      */
1665     protected String createProjectReferenceName(MavenProject project, DependencyNode dependencyNode) {
1666         return project.getName() + ":" + dependencyNode.getArtifact().getScope();
1667     }
1668 
1669     /**
1670      * Scans the projects dependencies including the default (or defined)
1671      * FileSets.
1672      *
1673      * @param engine the core dependency-check engine
1674      * @param project the project being scanned
1675      * @param nodes the list of dependency nodes, generally obtained via the
1676      * DependencyGraphBuilder
1677      * @param buildingRequest the Maven project building request
1678      * @param aggregate whether the scan is part of an aggregate build
1679      * @return a collection of exceptions that may have occurred while resolving
1680      * and scanning the dependencies
1681      */
1682     private ExceptionCollection collectDependencies(Engine engine, MavenProject project,
1683             Map<DependencyNode, List<DependencyNode>> nodes, ProjectBuildingRequest buildingRequest, boolean aggregate) {
1684 
1685         ExceptionCollection exCol;
1686         exCol = collectMavenDependencies(engine, project, nodes, buildingRequest, aggregate);
1687 
1688         final List<FileSet> projectScan;
1689 
1690         if (scanDirectory != null && !scanDirectory.isEmpty()) {
1691             if (scanSet == null) {
1692                 scanSet = new ArrayList<>();
1693             }
1694             scanDirectory.forEach(d -> {
1695                 final FileSet fs = new FileSet();
1696                 fs.setDirectory(d);
1697                 fs.addInclude(INCLUDE_ALL);
1698                 scanSet.add(fs);
1699             });
1700         }
1701 
1702         if (scanSet == null || scanSet.isEmpty()) {
1703             // Define the default FileSets
1704             final FileSet resourcesSet = new FileSet();
1705             final FileSet filtersSet = new FileSet();
1706             final FileSet webappSet = new FileSet();
1707             final FileSet mixedLangSet = new FileSet();
1708             try {
1709                 resourcesSet.setDirectory(new File(project.getBasedir(), "src/main/resources").getCanonicalPath());
1710                 resourcesSet.addInclude(INCLUDE_ALL);
1711                 filtersSet.setDirectory(new File(project.getBasedir(), "src/main/filters").getCanonicalPath());
1712                 filtersSet.addInclude(INCLUDE_ALL);
1713                 webappSet.setDirectory(new File(project.getBasedir(), "src/main/webapp").getCanonicalPath());
1714                 webappSet.addInclude(INCLUDE_ALL);
1715                 mixedLangSet.setDirectory(project.getBasedir().getCanonicalPath());
1716                 mixedLangSet.addInclude("package.json");
1717                 mixedLangSet.addInclude("package-lock.json");
1718                 mixedLangSet.addInclude("npm-shrinkwrap.json");
1719                 mixedLangSet.addInclude("Gopkg.lock");
1720                 mixedLangSet.addInclude("go.mod");
1721                 mixedLangSet.addInclude("yarn.lock");
1722                 mixedLangSet.addInclude("pnpm-lock.yaml");
1723                 mixedLangSet.addExclude("/node_modules/");
1724             } catch (IOException ex) {
1725                 if (exCol == null) {
1726                     exCol = new ExceptionCollection();
1727                 }
1728                 exCol.addException(ex);
1729             }
1730             projectScan = new ArrayList<>();
1731             projectScan.add(resourcesSet);
1732             projectScan.add(filtersSet);
1733             projectScan.add(webappSet);
1734             projectScan.add(mixedLangSet);
1735 
1736         } else if (aggregate) {
1737             projectScan = new ArrayList<>();
1738             for (FileSet copyFrom : scanSet) {
1739                 //deep copy of the FileSet - modifying the directory if it is not absolute.
1740                 final FileSet fsCopy = new FileSet();
1741                 final File f = new File(copyFrom.getDirectory());
1742                 if (f.isAbsolute()) {
1743                     fsCopy.setDirectory(copyFrom.getDirectory());
1744                 } else {
1745                     try {
1746                         fsCopy.setDirectory(new File(project.getBasedir(), copyFrom.getDirectory()).getCanonicalPath());
1747                     } catch (IOException ex) {
1748                         if (exCol == null) {
1749                             exCol = new ExceptionCollection();
1750                         }
1751                         exCol.addException(ex);
1752                         fsCopy.setDirectory(copyFrom.getDirectory());
1753                     }
1754                 }
1755                 fsCopy.setDirectoryMode(copyFrom.getDirectoryMode());
1756                 fsCopy.setExcludes(copyFrom.getExcludes());
1757                 fsCopy.setFileMode(copyFrom.getFileMode());
1758                 fsCopy.setFollowSymlinks(copyFrom.isFollowSymlinks());
1759                 fsCopy.setIncludes(copyFrom.getIncludes());
1760                 fsCopy.setLineEnding(copyFrom.getLineEnding());
1761                 fsCopy.setMapper(copyFrom.getMapper());
1762                 fsCopy.setModelEncoding(copyFrom.getModelEncoding());
1763                 fsCopy.setOutputDirectory(copyFrom.getOutputDirectory());
1764                 fsCopy.setUseDefaultExcludes(copyFrom.isUseDefaultExcludes());
1765                 projectScan.add(fsCopy);
1766             }
1767         } else {
1768             projectScan = scanSet;
1769         }
1770 
1771         // Iterate through FileSets and scan included files
1772         final FileSetManager fileSetManager = new FileSetManager();
1773         for (FileSet fileSet : projectScan) {
1774             getLog().debug("Scanning fileSet: " + fileSet.getDirectory());
1775             final String[] includedFiles = fileSetManager.getIncludedFiles(fileSet);
1776             for (String include : includedFiles) {
1777                 final File includeFile = new File(fileSet.getDirectory(), include).getAbsoluteFile();
1778                 if (includeFile.exists()) {
1779                     engine.scan(includeFile, project.getName());
1780                 }
1781             }
1782         }
1783         return exCol;
1784     }
1785 
1786     /**
1787      * Checks if the current artifact is actually in the reactor projects that
1788      * have not yet been built. If true a virtual dependency is created based on
1789      * the evidence in the project.
1790      *
1791      * @param engine a reference to the engine being used to scan
1792      * @param artifact the artifact being analyzed in the mojo
1793      * @param depender The project that depends on this virtual dependency
1794      * @return <code>true</code> if the artifact is in the reactor; otherwise
1795      * <code>false</code>
1796      */
1797     private boolean addReactorDependency(Engine engine, Artifact artifact, final MavenProject depender) {
1798         return addVirtualDependencyFromReactor(engine, artifact, depender, "Unable to resolve %s as it has not been built yet "
1799                 + "- creating a virtual dependency instead.");
1800     }
1801 
1802     /**
1803      * Checks if the current artifact is actually in the reactor projects. If
1804      * true a virtual dependency is created based on the evidence in the
1805      * project.
1806      *
1807      * @param engine a reference to the engine being used to scan
1808      * @param artifact the artifact being analyzed in the mojo
1809      * @param depender The project that depends on this virtual dependency
1810      * @param infoLogTemplate the template for the infoLog entry written when a
1811      * virtual dependency is added. Needs a single %s placeholder for the
1812      * location of the displayName in the message
1813      * @return <code>true</code> if the artifact is in the reactor; otherwise
1814      * <code>false</code>
1815      */
1816     private boolean addVirtualDependencyFromReactor(Engine engine, Artifact artifact,
1817             final MavenProject depender, String infoLogTemplate) {
1818 
1819         getLog().debug(String.format("Checking the reactor projects (%d) for %s:%s:%s",
1820                 reactorProjects.size(),
1821                 artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()));
1822 
1823         for (MavenProject prj : reactorProjects) {
1824 
1825             getLog().debug(String.format("Comparing %s:%s:%s to %s:%s:%s",
1826                     artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(),
1827                     prj.getGroupId(), prj.getArtifactId(), prj.getVersion()));
1828 
1829             if (prj.getArtifactId().equals(artifact.getArtifactId())
1830                     && prj.getGroupId().equals(artifact.getGroupId())
1831                     && prj.getVersion().equals(artifact.getBaseVersion())) {
1832 
1833                 final String displayName = String.format("%s:%s:%s",
1834                         prj.getGroupId(), prj.getArtifactId(), prj.getVersion());
1835                 getLog().info(String.format(infoLogTemplate,
1836                         displayName));
1837                 final Dependency d = newDependency(prj);
1838                 final String key = String.format("%s:%s:%s", prj.getGroupId(), prj.getArtifactId(), prj.getVersion());
1839                 d.setSha1sum(Checksum.getSHA1Checksum(key));
1840                 d.setSha256sum(Checksum.getSHA256Checksum(key));
1841                 d.setMd5sum(Checksum.getMD5Checksum(key));
1842                 d.setEcosystem(JarAnalyzer.DEPENDENCY_ECOSYSTEM);
1843                 d.setDisplayFileName(displayName);
1844                 d.addProjectReference(depender.getName());
1845                 final String includedby = buildReference(
1846                         depender.getGroupId(),
1847                         depender.getArtifactId(),
1848                         depender.getVersion());
1849                 d.addIncludedBy(includedby);
1850                 d.addEvidence(EvidenceType.PRODUCT, "project", "artifactid", prj.getArtifactId(), Confidence.HIGHEST);
1851                 d.addEvidence(EvidenceType.VENDOR, "project", "artifactid", prj.getArtifactId(), Confidence.LOW);
1852 
1853                 d.addEvidence(EvidenceType.VENDOR, "project", "groupid", prj.getGroupId(), Confidence.HIGHEST);
1854                 d.addEvidence(EvidenceType.PRODUCT, "project", "groupid", prj.getGroupId(), Confidence.LOW);
1855                 d.setEcosystem(JarAnalyzer.DEPENDENCY_ECOSYSTEM);
1856                 Identifier id;
1857                 try {
1858                     id = new PurlIdentifier(StandardTypes.MAVEN, artifact.getGroupId(),
1859                             artifact.getArtifactId(), artifact.getVersion(), Confidence.HIGHEST);
1860                 } catch (MalformedPackageURLException ex) {
1861                     getLog().debug("Unable to create PackageURL object:" + key);
1862                     id = new GenericIdentifier("maven:" + key, Confidence.HIGHEST);
1863                 }
1864                 d.addSoftwareIdentifier(id);
1865                 //TODO unify the setName/version and package path - they are equivelent ideas submitted by two seperate committers
1866                 d.setName(String.format("%s:%s", prj.getGroupId(), prj.getArtifactId()));
1867                 d.setVersion(prj.getVersion());
1868                 d.setPackagePath(displayName);
1869                 if (prj.getDescription() != null) {
1870                     JarAnalyzer.addDescription(d, prj.getDescription(), "project", "description");
1871                 }
1872                 for (License l : prj.getLicenses()) {
1873                     final StringBuilder license = new StringBuilder();
1874                     if (l.getName() != null) {
1875                         license.append(l.getName());
1876                     }
1877                     if (l.getUrl() != null) {
1878                         license.append(" ").append(l.getUrl());
1879                     }
1880                     if (d.getLicense() == null) {
1881                         d.setLicense(license.toString());
1882                     } else if (!d.getLicense().contains(license)) {
1883                         d.setLicense(String.format("%s%n%s", d.getLicense(), license));
1884                     }
1885                 }
1886                 engine.addDependency(d);
1887                 return true;
1888             }
1889         }
1890         return false;
1891     }
1892 
1893     Dependency newDependency(MavenProject prj) {
1894         final File pom = new File(prj.getBasedir(), "pom.xml");
1895 
1896         if (pom.isFile()) {
1897             getLog().debug("Adding virtual dependency from pom.xml");
1898             return new Dependency(pom, true);
1899         } else if (prj.getFile().isFile()) {
1900             getLog().debug("Adding virtual dependency from file");
1901             return new Dependency(prj.getFile(), true);
1902         } else {
1903             return new Dependency(true);
1904         }
1905     }
1906 
1907     /**
1908      * Checks if the current artifact is actually in the reactor projects. If
1909      * true a virtual dependency is created based on the evidence in the
1910      * project.
1911      *
1912      * @param engine a reference to the engine being used to scan
1913      * @param artifact the artifact being analyzed in the mojo
1914      * @param depender The project that depends on this virtual dependency
1915      * @return <code>true</code> if the artifact is a snapshot artifact in the
1916      * reactor; otherwise <code>false</code>
1917      */
1918     private boolean addSnapshotReactorDependency(Engine engine, Artifact artifact, final MavenProject depender) {
1919         if (!artifact.isSnapshot()) {
1920             return false;
1921         }
1922         return addVirtualDependencyFromReactor(engine, artifact, depender, "Found snapshot reactor project in aggregate for %s - "
1923                 + "creating a virtual dependency as the snapshot found in the repository may contain outdated dependencies.");
1924     }
1925 
1926     /**
1927      * @param project The target project to create a building request for.
1928      * @param repos the artifact repositories to use.
1929      * @return Returns a new ProjectBuildingRequest populated from the current
1930      * session and the target project remote repositories, used to resolve
1931      * artifacts.
1932      */
1933     public ProjectBuildingRequest newResolveArtifactProjectBuildingRequest(MavenProject project, List<ArtifactRepository> repos) {
1934         final ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
1935         buildingRequest.setRemoteRepositories(repos);
1936         buildingRequest.setProject(project);
1937         return buildingRequest;
1938     }
1939 
1940     /**
1941      * Executes the dependency-check scan and generates the necessary report.
1942      *
1943      * @throws MojoExecutionException thrown if there is an exception running
1944      * the scan
1945      * @throws MojoFailureException thrown if dependency-check is configured to
1946      * fail the build
1947      */
1948     protected void runCheck() throws MojoExecutionException, MojoFailureException {
1949         muteNoisyLoggers();
1950         try (Engine engine = initializeEngine()) {
1951             ExceptionCollection exCol = null;
1952             if (scanDependencies) {
1953                 exCol = scanDependencies(engine);
1954             }
1955             if (scanPlugins) {
1956                 exCol = scanPlugins(engine, exCol);
1957             }
1958             try {
1959                 engine.analyzeDependencies();
1960             } catch (ExceptionCollection ex) {
1961                 exCol = handleAnalysisExceptions(exCol, ex);
1962             }
1963             if (exCol == null || !exCol.isFatal()) {
1964 
1965                 File outputDir = getCorrectOutputDirectory(this.getProject());
1966                 if (outputDir == null) {
1967                     //in some regards we shouldn't be writing this, but we are anyway.
1968                     //we shouldn't write this because nothing is configured to generate this report.
1969                     outputDir = new File(this.getProject().getBuild().getDirectory());
1970                 }
1971                 try {
1972                     final MavenProject p = this.getProject();
1973                     for (String f : getFormats()) {
1974                         engine.writeReports(p.getName(), p.getGroupId(), p.getArtifactId(), p.getVersion(), outputDir, f, exCol);
1975                     }
1976                 } catch (ReportException ex) {
1977                     if (exCol == null) {
1978                         exCol = new ExceptionCollection(ex);
1979                     } else {
1980                         exCol.addException(ex);
1981                     }
1982                     if (this.isFailOnError()) {
1983                         throw new MojoExecutionException("One or more exceptions occurred during dependency-check analysis", exCol);
1984                     } else {
1985                         getLog().debug("Error writing the report", ex);
1986                     }
1987                 }
1988                 showSummary(this.getProject(), engine.getDependencies());
1989                 checkForFailure(engine.getDependencies());
1990                 if (exCol != null && this.isFailOnError()) {
1991                     throw new MojoExecutionException("One or more exceptions occurred during dependency-check analysis", exCol);
1992                 }
1993             }
1994         } catch (DatabaseException ex) {
1995             if (getLog().isDebugEnabled()) {
1996                 getLog().debug("Database connection error", ex);
1997             }
1998             final String msg = "An exception occurred connecting to the local database. Please see the log file for more details.";
1999             if (this.isFailOnError()) {
2000                 throw new MojoExecutionException(msg, ex);
2001             }
2002             getLog().error(msg, ex);
2003         } finally {
2004             getSettings().cleanup();
2005         }
2006     }
2007 
2008     /**
2009      * Combines the two exception collections and if either are fatal, throw an
2010      * MojoExecutionException
2011      *
2012      * @param currentEx the primary exception collection
2013      * @param newEx the new exception collection to add
2014      * @return the combined exception collection
2015      * @throws MojoExecutionException thrown if dependency-check is configured
2016      * to fail on errors
2017      */
2018     private ExceptionCollection handleAnalysisExceptions(ExceptionCollection currentEx, ExceptionCollection newEx) throws MojoExecutionException {
2019         ExceptionCollection returnEx = currentEx;
2020         if (returnEx == null) {
2021             returnEx = newEx;
2022         } else {
2023             returnEx.getExceptions().addAll(newEx.getExceptions());
2024             if (newEx.isFatal()) {
2025                 returnEx.setFatal(true);
2026             }
2027         }
2028         if (returnEx.isFatal()) {
2029             final String msg = String.format("Fatal exception(s) analyzing %s", getProject().getName());
2030             if (this.isFailOnError()) {
2031                 throw new MojoExecutionException(msg, returnEx);
2032             }
2033             getLog().error(msg);
2034             if (getLog().isDebugEnabled()) {
2035                 getLog().debug(returnEx);
2036             }
2037         } else {
2038             final String msg = String.format("Exception(s) analyzing %s", getProject().getName());
2039             if (getLog().isDebugEnabled()) {
2040                 getLog().debug(msg, returnEx);
2041             }
2042         }
2043         return returnEx;
2044     }
2045 
2046     /**
2047      * Scans the dependencies of the projects.
2048      *
2049      * @param engine the engine used to perform the scanning
2050      * @return a collection of exceptions
2051      * @throws MojoExecutionException thrown if a fatal exception occurs
2052      */
2053     protected abstract ExceptionCollection scanDependencies(Engine engine) throws MojoExecutionException;
2054 
2055     /**
2056      * Scans the plugins of the projects.
2057      *
2058      * @param engine the engine used to perform the scanning
2059      * @param exCol the collection of any exceptions that have previously been
2060      * captured.
2061      * @return a collection of exceptions
2062      * @throws MojoExecutionException thrown if a fatal exception occurs
2063      */
2064     protected abstract ExceptionCollection scanPlugins(Engine engine, ExceptionCollection exCol) throws MojoExecutionException;
2065 
2066     /**
2067      * Returns the report output directory.
2068      *
2069      * @return the report output directory
2070      */
2071     @Override
2072     public File getReportOutputDirectory() {
2073         return reportOutputDirectory;
2074     }
2075 
2076     /**
2077      * Sets the Reporting output directory.
2078      *
2079      * @param directory the output directory
2080      */
2081     @Override
2082     public void setReportOutputDirectory(File directory) {
2083         reportOutputDirectory = directory;
2084     }
2085 
2086     /**
2087      * Returns the output directory.
2088      *
2089      * @return the output directory
2090      */
2091     public File getOutputDirectory() {
2092         return outputDirectory;
2093     }
2094 
2095     /**
2096      * Returns whether this is an external report. This method always returns
2097      * true.
2098      *
2099      * @return <code>true</code>
2100      */
2101     @Override
2102     public final boolean isExternalReport() {
2103         return true;
2104     }
2105 
2106     /**
2107      * Returns the output name.
2108      *
2109      * @return the output name
2110      */
2111     @Override
2112     public String getOutputName() {
2113         final Set<String> selectedFormats = getFormats();
2114         if (selectedFormats.contains("HTML") || selectedFormats.contains("ALL") || selectedFormats.size() > 1) {
2115             return "dependency-check-report";
2116         } else if (selectedFormats.contains("JENKINS")) {
2117             return "dependency-check-jenkins.html";
2118         } else if (selectedFormats.contains("XML")) {
2119             return "dependency-check-report.xml";
2120         } else if (selectedFormats.contains("JUNIT")) {
2121             return "dependency-check-junit.xml";
2122         } else if (selectedFormats.contains("JSON")) {
2123             return "dependency-check-report.json";
2124         } else if (selectedFormats.contains("SARIF")) {
2125             return "dependency-check-report.sarif";
2126         } else if (selectedFormats.contains("CSV")) {
2127             return "dependency-check-report.csv";
2128         } else {
2129             getLog().warn("Unknown report format used during site generation.");
2130             return "dependency-check-report";
2131         }
2132     }
2133 
2134     /**
2135      * Returns the category name.
2136      *
2137      * @return the category name
2138      */
2139     @Override
2140     public String getCategoryName() {
2141         return MavenReport.CATEGORY_PROJECT_REPORTS;
2142     }
2143     //</editor-fold>
2144 
2145     /**
2146      * Initializes a new <code>Engine</code> that can be used for scanning. This
2147      * method should only be called in a try-with-resources to ensure that the
2148      * engine is properly closed.
2149      *
2150      * @return a newly instantiated <code>Engine</code>
2151      * @throws DatabaseException thrown if there is a database exception
2152      * @throws MojoExecutionException on configuration errors when failOnError is true
2153      * @throws MojoFailureException on configuration errors when failOnError is false
2154      */
2155     protected Engine initializeEngine() throws DatabaseException, MojoExecutionException, MojoFailureException {
2156         populateSettings();
2157         try {
2158             Downloader.getInstance().configure(settings);
2159         } catch (InvalidSettingException e) {
2160             if (this.failOnError) {
2161                 throw new MojoFailureException(e.getMessage(), e);
2162             } else {
2163                 throw new MojoExecutionException(e.getMessage(), e);
2164             }
2165         }
2166         return new Engine(settings);
2167     }
2168 
2169     //CSOFF: MethodLength
2170     /**
2171      * Takes the properties supplied and updates the dependency-check settings.
2172      * Additionally, this sets the system properties required to change the
2173      * proxy URL, port, and connection timeout.
2174      */
2175     protected void populateSettings() {
2176         settings = new Settings();
2177         InputStream mojoProperties = null;
2178         try {
2179             mojoProperties = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE);
2180             settings.mergeProperties(mojoProperties);
2181         } catch (IOException ex) {
2182             getLog().warn("Unable to load the dependency-check maven mojo.properties file.");
2183             if (getLog().isDebugEnabled()) {
2184                 getLog().debug("", ex);
2185             }
2186         } finally {
2187             if (mojoProperties != null) {
2188                 try {
2189                     mojoProperties.close();
2190                 } catch (IOException ex) {
2191                     if (getLog().isDebugEnabled()) {
2192                         getLog().debug("", ex);
2193                     }
2194                 }
2195             }
2196         }
2197         settings.setStringIfNotEmpty(Settings.KEYS.MAVEN_LOCAL_REPO, mavenSettings.getLocalRepository());
2198         settings.setBooleanIfNotNull(Settings.KEYS.AUTO_UPDATE, autoUpdate);
2199         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, enableExperimental);
2200         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_RETIRED_ENABLED, enableRetired);
2201         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_GOLANG_DEP_ENABLED, golangDepEnabled);
2202         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_GOLANG_MOD_ENABLED, golangModEnabled);
2203         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_DART_ENABLED, dartAnalyzerEnabled);
2204         settings.setStringIfNotNull(Settings.KEYS.ANALYZER_GOLANG_PATH, pathToGo);
2205         settings.setStringIfNotNull(Settings.KEYS.ANALYZER_YARN_PATH, pathToYarn);
2206         settings.setStringIfNotNull(Settings.KEYS.ANALYZER_PNPM_PATH, pathToPnpm);
2207 
2208         // use global maven proxy if provided
2209         final Proxy mavenProxy = getMavenProxy();
2210         if (mavenProxy != null) {
2211             final String existing = System.getProperty("https.proxyHost");
2212             if (existing == null && mavenProxy.getHost() != null && !mavenProxy.getHost().isEmpty()) {
2213                 System.setProperty("https.proxyHost", mavenProxy.getHost());
2214                 if (mavenProxy.getPort() > 0) {
2215                     System.setProperty("https.proxyPort", String.valueOf(mavenProxy.getPort()));
2216                 }
2217                 if (mavenProxy.getUsername() != null && !mavenProxy.getUsername().isEmpty()) {
2218                     System.setProperty("https.proxyUser", mavenProxy.getUsername());
2219                 }
2220                 String password = mavenProxy.getPassword();
2221                 if (password != null && !password.isEmpty()) {
2222                     try {
2223                         password = decryptPasswordFromSettings(password);
2224                     } catch (SecDispatcherException ex) {
2225                         password = handleSecDispatcherException("proxy", mavenProxy.getId(), password, ex);
2226                     }
2227                     System.setProperty("https.proxyPassword", password);
2228                 }
2229                 if (mavenProxy.getNonProxyHosts() != null && !mavenProxy.getNonProxyHosts().isEmpty()) {
2230                     System.setProperty("http.nonProxyHosts", mavenProxy.getNonProxyHosts());
2231                 }
2232             }
2233         } else if (this.proxy != null && this.proxy.getHost() != null) {
2234             // or use configured <proxy>
2235             settings.setString(Settings.KEYS.PROXY_SERVER, this.proxy.getHost());
2236             settings.setString(Settings.KEYS.PROXY_PORT, Integer.toString(this.proxy.getPort()));
2237             // user name and password from <server> entry settings.xml
2238             configureServerCredentials(this.proxy.getServerId(), Settings.KEYS.PROXY_USERNAME, Settings.KEYS.PROXY_PASSWORD);
2239         }
2240 
2241         final String[] suppressions = determineSuppressions();
2242         settings.setArrayIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE, suppressions);
2243         settings.setBooleanIfNotNull(Settings.KEYS.UPDATE_VERSION_CHECK_ENABLED, versionCheckEnabled);
2244         settings.setStringIfNotEmpty(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout);
2245         settings.setStringIfNotEmpty(Settings.KEYS.CONNECTION_READ_TIMEOUT, readTimeout);
2246         settings.setStringIfNotEmpty(Settings.KEYS.HINTS_FILE, hintsFile);
2247         settings.setFloat(Settings.KEYS.JUNIT_FAIL_ON_CVSS, junitFailOnCVSS);
2248         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_JAR_ENABLED, jarAnalyzerEnabled);
2249         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NUSPEC_ENABLED, nuspecAnalyzerEnabled);
2250         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NUGETCONF_ENABLED, nugetconfAnalyzerEnabled);
2251         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_LIBMAN_ENABLED, libmanAnalyzerEnabled);
2252         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, centralAnalyzerEnabled);
2253         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CENTRAL_USE_CACHE, centralAnalyzerUseCache);
2254         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_ENABLED, artifactoryAnalyzerEnabled);
2255         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled);
2256         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ASSEMBLY_ENABLED, assemblyAnalyzerEnabled);
2257         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_MSBUILD_PROJECT_ENABLED, msbuildAnalyzerEnabled);
2258         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, archiveAnalyzerEnabled);
2259         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_KNOWN_EXPLOITED_ENABLED, knownExploitedEnabled);
2260         settings.setStringIfNotEmpty(Settings.KEYS.KEV_URL, knownExploitedUrl);
2261         settings.setStringIfNotEmpty(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, zipExtensions);
2262         settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_ASSEMBLY_DOTNET_PATH, pathToCore);
2263         settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl);
2264         configureServerCredentials(nexusServerId, Settings.KEYS.ANALYZER_NEXUS_USER, Settings.KEYS.ANALYZER_NEXUS_PASSWORD);
2265         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_USES_PROXY, nexusUsesProxy);
2266         settings.setStringIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_URL, artifactoryAnalyzerUrl);
2267         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_USES_PROXY, artifactoryAnalyzerUseProxy);
2268         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_PARALLEL_ANALYSIS, artifactoryAnalyzerParallelAnalysis);
2269         if (Boolean.TRUE.equals(artifactoryAnalyzerEnabled)) {
2270             if (artifactoryAnalyzerServerId != null) {
2271                 configureServerCredentials(artifactoryAnalyzerServerId, Settings.KEYS.ANALYZER_ARTIFACTORY_API_USERNAME,
2272                         Settings.KEYS.ANALYZER_ARTIFACTORY_API_TOKEN);
2273             } else {
2274                 settings.setStringIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_API_USERNAME, artifactoryAnalyzerUsername);
2275                 settings.setStringIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_API_TOKEN, artifactoryAnalyzerApiToken);
2276             }
2277             settings.setStringIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_BEARER_TOKEN, artifactoryAnalyzerBearerToken);
2278         }
2279         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_DISTRIBUTION_ENABLED, pyDistributionAnalyzerEnabled);
2280         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_PACKAGE_ENABLED, pyPackageAnalyzerEnabled);
2281         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_RUBY_GEMSPEC_ENABLED, rubygemsAnalyzerEnabled);
2282         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OPENSSL_ENABLED, opensslAnalyzerEnabled);
2283         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CMAKE_ENABLED, cmakeAnalyzerEnabled);
2284         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_AUTOCONF_ENABLED, autoconfAnalyzerEnabled);
2285         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_MAVEN_INSTALL_ENABLED, mavenInstallAnalyzerEnabled);
2286         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PIP_ENABLED, pipAnalyzerEnabled);
2287         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PIPFILE_ENABLED, pipfileAnalyzerEnabled);
2288         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_POETRY_ENABLED, poetryAnalyzerEnabled);
2289         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_COMPOSER_LOCK_ENABLED, composerAnalyzerEnabled);
2290         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_COMPOSER_LOCK_SKIP_DEV, composerAnalyzerSkipDev);
2291         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CPANFILE_ENABLED, cpanfileAnalyzerEnabled);
2292         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_PACKAGE_ENABLED, nodeAnalyzerEnabled);
2293         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_AUDIT_ENABLED, nodeAuditAnalyzerEnabled);
2294         settings.setStringIfNotNull(Settings.KEYS.ANALYZER_NODE_AUDIT_URL, nodeAuditAnalyzerUrl);
2295         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_AUDIT_USE_CACHE, nodeAuditAnalyzerUseCache);
2296         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_PACKAGE_SKIPDEV, nodePackageSkipDevDependencies);
2297         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_AUDIT_SKIPDEV, nodeAuditSkipDevDependencies);
2298         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_YARN_AUDIT_ENABLED, yarnAuditAnalyzerEnabled);
2299         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PNPM_AUDIT_ENABLED, pnpmAuditAnalyzerEnabled);
2300         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_RETIREJS_ENABLED, retireJsAnalyzerEnabled);
2301         settings.setStringIfNotNull(Settings.KEYS.ANALYZER_RETIREJS_REPO_JS_URL, retireJsUrl);
2302         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_RETIREJS_FORCEUPDATE, retireJsForceUpdate);
2303         if (retireJsUser == null && retireJsPassword == null && retireJsUrlServerId != null) {
2304             configureServerCredentials(retireJsUrlServerId, Settings.KEYS.ANALYZER_RETIREJS_REPO_JS_USER, Settings.KEYS.ANALYZER_RETIREJS_REPO_JS_PASSWORD);
2305         } else {
2306             settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_RETIREJS_REPO_JS_USER, retireJsUser);
2307             settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_RETIREJS_REPO_JS_PASSWORD, retireJsPassword);
2308         }
2309         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_MIX_AUDIT_ENABLED, mixAuditAnalyzerEnabled);
2310         settings.setStringIfNotNull(Settings.KEYS.ANALYZER_MIX_AUDIT_PATH, mixAuditPath);
2311         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_ENABLED, bundleAuditAnalyzerEnabled);
2312         settings.setStringIfNotNull(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_PATH, bundleAuditPath);
2313         settings.setStringIfNotNull(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_WORKING_DIRECTORY, bundleAuditWorkingDirectory);
2314         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_COCOAPODS_ENABLED, cocoapodsAnalyzerEnabled);
2315         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CARTHAGE_ENABLED, carthageAnalyzerEnabled);
2316         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_SWIFT_PACKAGE_MANAGER_ENABLED, swiftPackageManagerAnalyzerEnabled);
2317         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_SWIFT_PACKAGE_RESOLVED_ENABLED, swiftPackageResolvedAnalyzerEnabled);
2318         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_ENABLED, ossindexAnalyzerEnabled);
2319         settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_OSSINDEX_URL, ossindexAnalyzerUrl);
2320         configureServerCredentials(ossIndexServerId, Settings.KEYS.ANALYZER_OSSINDEX_USER, Settings.KEYS.ANALYZER_OSSINDEX_PASSWORD);
2321         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_USE_CACHE, ossindexAnalyzerUseCache);
2322         settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_WARN_ONLY_ON_REMOTE_ERRORS, ossIndexWarnOnlyOnRemoteErrors);
2323         if (retirejs != null) {
2324             settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_RETIREJS_FILTER_NON_VULNERABLE, retirejs.getFilterNonVulnerable());
2325             settings.setArrayIfNotEmpty(Settings.KEYS.ANALYZER_RETIREJS_FILTERS, retirejs.getFilters());
2326         }
2327         //Database configuration
2328         settings.setStringIfNotEmpty(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName);
2329         settings.setStringIfNotEmpty(Settings.KEYS.DB_DRIVER_PATH, databaseDriverPath);
2330         settings.setStringIfNotEmpty(Settings.KEYS.DB_CONNECTION_STRING, connectionString);
2331         if (databaseUser == null && databasePassword == null && serverId != null) {
2332             configureServerCredentials(serverId, Settings.KEYS.DB_USER, Settings.KEYS.DB_PASSWORD);
2333         } else {
2334             settings.setStringIfNotEmpty(Settings.KEYS.DB_USER, databaseUser);
2335             settings.setStringIfNotEmpty(Settings.KEYS.DB_PASSWORD, databasePassword);
2336         }
2337         settings.setStringIfNotEmpty(Settings.KEYS.DATA_DIRECTORY, dataDirectory);
2338         settings.setStringIfNotEmpty(Settings.KEYS.DB_FILE_NAME, dbFilename);
2339         settings.setStringIfNotNull(Settings.KEYS.NVD_API_ENDPOINT, nvdApiEndpoint);
2340         settings.setIntIfNotNull(Settings.KEYS.NVD_API_DELAY, nvdApiDelay);
2341         settings.setIntIfNotNull(Settings.KEYS.NVD_API_RESULTS_PER_PAGE, nvdApiResultsPerPage);
2342         settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_URL, nvdDatafeedUrl);
2343         settings.setIntIfNotNull(Settings.KEYS.NVD_API_VALID_FOR_HOURS, nvdValidForHours);
2344         settings.setIntIfNotNull(Settings.KEYS.NVD_API_MAX_RETRY_COUNT, nvdMaxRetryCount);
2345         if (nvdApiKey == null) {
2346             if (nvdApiKeyEnvironmentVariable != null) {
2347                 settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_KEY, System.getenv(nvdApiKeyEnvironmentVariable));
2348                 getLog().debug("Using NVD API key from environment variable " + nvdApiKeyEnvironmentVariable);
2349             } else if (nvdApiServerId != null) {
2350                 configureServerCredentialsApiKey(nvdApiServerId, Settings.KEYS.NVD_API_KEY);
2351                 getLog().debug("Using NVD API key from server's password with id " + nvdApiServerId + " in settings.xml");
2352             }
2353         } else {
2354             settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_KEY, nvdApiKey);
2355         }
2356         if (nvdUser == null && nvdPassword == null && nvdDatafeedServerId != null) {
2357             configureServerCredentials(nvdDatafeedServerId, Settings.KEYS.NVD_API_DATAFEED_USER, Settings.KEYS.NVD_API_DATAFEED_PASSWORD);
2358         } else {
2359             settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_USER, nvdUser);
2360             settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_PASSWORD, nvdPassword);
2361         }
2362         settings.setBooleanIfNotNull(Settings.KEYS.PRETTY_PRINT, prettyPrint);
2363         artifactScopeExcluded = new ArtifactScopeExcluded(skipTestScope, skipProvidedScope, skipSystemScope, skipRuntimeScope);
2364         artifactTypeExcluded = new ArtifactTypeExcluded(skipArtifactType);
2365         if (suppressionFileUser == null && suppressionFilePassword == null && suppressionFileServerId != null) {
2366             configureServerCredentials(suppressionFileServerId, Settings.KEYS.SUPPRESSION_FILE_USER, Settings.KEYS.SUPPRESSION_FILE_PASSWORD);
2367         } else {
2368             settings.setStringIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE_USER, suppressionFileUser);
2369             settings.setStringIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE_PASSWORD, suppressionFilePassword);
2370         }
2371         settings.setIntIfNotNull(Settings.KEYS.HOSTED_SUPPRESSIONS_VALID_FOR_HOURS, hostedSuppressionsValidForHours);
2372         settings.setStringIfNotNull(Settings.KEYS.HOSTED_SUPPRESSIONS_URL, hostedSuppressionsUrl);
2373         settings.setBooleanIfNotNull(Settings.KEYS.HOSTED_SUPPRESSIONS_FORCEUPDATE, hostedSuppressionsForceUpdate);
2374         settings.setBooleanIfNotNull(Settings.KEYS.HOSTED_SUPPRESSIONS_ENABLED, hostedSuppressionsEnabled);
2375     }
2376     //CSON: MethodLength
2377 
2378     /**
2379      * Retrieves the server credentials from the settings.xml, decrypts the
2380      * password, and places the values into the settings under the given key
2381      * names.
2382      *
2383      * @param serverId the server id
2384      * @param userSettingKey the property name for the username
2385      * @param passwordSettingKey the property name for the password
2386      */
2387     private void configureServerCredentials(String serverId, String userSettingKey, String passwordSettingKey) {
2388         if (serverId != null) {
2389             final Server server = settingsXml.getServer(serverId);
2390             if (server != null) {
2391                 final String username = server.getUsername();
2392                 String password = null;
2393                 try {
2394                     password = decryptPasswordFromSettings(server.getPassword());
2395                 } catch (SecDispatcherException ex) {
2396                     password = handleSecDispatcherException("server", serverId, server.getPassword(), ex);
2397                 }
2398                 settings.setStringIfNotEmpty(userSettingKey, username);
2399                 settings.setStringIfNotEmpty(passwordSettingKey, password);
2400             } else {
2401                 getLog().error(String.format("Server '%s' not found in the settings.xml file", serverId));
2402             }
2403         }
2404     }
2405 
2406     /**
2407      * Retrieves the server credentials from the settings.xml, decrypts the
2408      * password, and places the values into the settings under the given key
2409      * names. This is used to retrieve an encrypted password as an API key.
2410      *
2411      * @param serverId the server id
2412      * @param apiKeySetting the property name for the API key
2413      */
2414     private void configureServerCredentialsApiKey(String serverId, String apiKeySetting) {
2415         if (serverId != null) {
2416             final Server server = settingsXml.getServer(serverId);
2417             if (server != null) {
2418                 String password = null;
2419                 try {
2420                     password = decryptPasswordFromSettings(server.getPassword());
2421                 } catch (SecDispatcherException ex) {
2422                     password = handleSecDispatcherException("server", serverId, server.getPassword(), ex);
2423                 }
2424                 settings.setStringIfNotEmpty(apiKeySetting, password);
2425             } else {
2426                 getLog().error(String.format("Server '%s' not found in the settings.xml file", serverId));
2427             }
2428         }
2429     }
2430 
2431     /**
2432      * Decrypts a password from the Maven settings if it needs to be decrypted.
2433      * If it's not encrypted the input password will be returned unchanged.
2434      *
2435      * @param password the original password value from the settings.xml
2436      * @return the decrypted password from the Maven configuration
2437      * @throws SecDispatcherException thrown if there is an error decrypting the
2438      * password
2439      */
2440     private String decryptPasswordFromSettings(String password) throws SecDispatcherException {
2441         //The following fix was copied from:
2442         //   https://github.com/bsorrentino/maven-confluence-plugin/blob/master/maven-confluence-reporting-plugin/src/main/java/org/bsc/maven/confluence/plugin/AbstractBaseConfluenceMojo.java
2443         //
2444         // FIX to resolve
2445         // org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException:
2446         // java.io.FileNotFoundException: ~/.settings-security.xml (No such file or directory)
2447         //
2448         if (securityDispatcher instanceof DefaultSecDispatcher) {
2449             ((DefaultSecDispatcher) securityDispatcher).setConfigurationFile("~/.m2/settings-security.xml");
2450         }
2451 
2452         return securityDispatcher.decrypt(password);
2453     }
2454 
2455     /**
2456      * Handles a SecDispatcherException that was thrown at an attempt to decrypt
2457      * an encrypted password from the Maven settings.
2458      *
2459      * @param settingsElementName - "server" or "proxy"
2460      * @param settingsElementId - value of the id attribute of the proxy resp.
2461      * server element to which the password belongs
2462      * @param passwordValueFromSettings - original, undecrypted password value
2463      * from the settings
2464      * @param ex - the Exception to handle
2465      * @return the password fallback value to go on with, might be a not working
2466      * one.
2467      */
2468     private String handleSecDispatcherException(String settingsElementName, String settingsElementId, String passwordValueFromSettings,
2469             SecDispatcherException ex) {
2470         String password = passwordValueFromSettings;
2471         if (ex.getCause() instanceof FileNotFoundException
2472                 || (ex.getCause() != null && ex.getCause().getCause() instanceof FileNotFoundException)) {
2473             //maybe its not encrypted?
2474             final String tmp = passwordValueFromSettings;
2475             if (tmp.startsWith("{") && tmp.endsWith("}")) {
2476                 getLog().error(String.format(
2477                         "Unable to decrypt the %s password for %s id '%s' in settings.xml%n\tCause: %s",
2478                         settingsElementName, settingsElementName, settingsElementId, ex.getMessage()));
2479             } else {
2480                 password = tmp;
2481             }
2482         } else {
2483             getLog().error(String.format(
2484                     "Unable to decrypt the %s password for %s id '%s' in settings.xml%n\tCause: %s",
2485                     settingsElementName, settingsElementName, settingsElementId, ex.getMessage()));
2486         }
2487         return password;
2488     }
2489 
2490     /**
2491      * Combines the configured suppressionFile and suppressionFiles into a
2492      * single array.
2493      *
2494      * @return an array of suppression file paths
2495      */
2496     private String[] determineSuppressions() {
2497         String[] suppressions = suppressionFiles;
2498         if (suppressionFile != null) {
2499             if (suppressions == null) {
2500                 suppressions = new String[]{suppressionFile};
2501             } else {
2502                 suppressions = Arrays.copyOf(suppressions, suppressions.length + 1);
2503                 suppressions[suppressions.length - 1] = suppressionFile;
2504             }
2505         }
2506         return suppressions;
2507     }
2508 
2509     /**
2510      * Hacky method of muting the noisy logging from JCS
2511      */
2512     private void muteNoisyLoggers() {
2513         System.setProperty("jcs.logSystem", "slf4j");
2514         if (!getLog().isDebugEnabled()) {
2515             Slf4jAdapter.muteLogging(true);
2516         }
2517 
2518         final String[] noisyLoggers = {
2519             "org.apache.hc"
2520         };
2521         for (String loggerName : noisyLoggers) {
2522             System.setProperty("org.slf4j.simpleLogger.log." + loggerName, "error");
2523         }
2524     }
2525 
2526     /**
2527      * Returns the maven proxy.
2528      *
2529      * @return the maven proxy
2530      */
2531     private Proxy getMavenProxy() {
2532         if (mavenSettings != null) {
2533             final List<Proxy> proxies = mavenSettings.getProxies();
2534             if (proxies != null && !proxies.isEmpty()) {
2535                 if (mavenSettingsProxyId != null) {
2536                     for (Proxy proxy : proxies) {
2537                         if (mavenSettingsProxyId.equalsIgnoreCase(proxy.getId())) {
2538                             return proxy;
2539                         }
2540                     }
2541                 } else {
2542                     for (Proxy aProxy : proxies) {
2543                         if (aProxy.isActive()) {
2544                             return aProxy;
2545                         }
2546                     }
2547                 }
2548             }
2549         }
2550         return null;
2551     }
2552 
2553     /**
2554      * Returns a reference to the current project. This method is used instead
2555      * of auto-binding the project via component annotation in concrete
2556      * implementations of this. If the child has a
2557      * <code>@Component MavenProject project;</code> defined then the abstract
2558      * class (i.e. this class) will not have access to the current project (just
2559      * the way Maven works with the binding).
2560      *
2561      * @return returns a reference to the current project
2562      */
2563     protected MavenProject getProject() {
2564         return project;
2565     }
2566 
2567     /**
2568      * Returns the list of Maven Projects in this build.
2569      *
2570      * @return the list of Maven Projects in this build
2571      */
2572     protected List<MavenProject> getReactorProjects() {
2573         return reactorProjects;
2574     }
2575 
2576     /**
2577      * Combines the format and formats properties into a single collection.
2578      *
2579      * @return the selected report formats
2580      */
2581     private Set<String> getFormats() {
2582         final Set<String> invalid = new HashSet<>();
2583         final Set<String> selectedFormats = formats == null || formats.length == 0 ? new HashSet<>() : new HashSet<>(Arrays.asList(formats));
2584         selectedFormats.forEach((s) -> {
2585             try {
2586                 ReportGenerator.Format.valueOf(s.toUpperCase());
2587             } catch (IllegalArgumentException ex) {
2588                 invalid.add(s);
2589             }
2590         });
2591         invalid.forEach((s) -> getLog().warn("Invalid report format specified: " + s));
2592         if (selectedFormats.contains("true")) {
2593             selectedFormats.remove("true");
2594         }
2595         if (format != null && selectedFormats.isEmpty()) {
2596             selectedFormats.add(format);
2597         }
2598         return selectedFormats;
2599     }
2600 
2601     /**
2602      * Returns the list of excluded artifacts based on either artifact id or
2603      * group id and artifact id.
2604      *
2605      * @return a list of artifact to exclude
2606      */
2607     public List<String> getExcludes() {
2608         if (excludes == null) {
2609             excludes = new ArrayList<>();
2610         }
2611         return excludes;
2612     }
2613 
2614     /**
2615      * Returns the artifact scope excluded filter.
2616      *
2617      * @return the artifact scope excluded filter
2618      */
2619     protected Filter<String> getArtifactScopeExcluded() {
2620         return artifactScopeExcluded;
2621     }
2622 
2623     /**
2624      * Returns the configured settings.
2625      *
2626      * @return the configured settings
2627      */
2628     protected Settings getSettings() {
2629         return settings;
2630     }
2631 
2632     //<editor-fold defaultstate="collapsed" desc="Methods to fail build or show summary">
2633     /**
2634      * Checks to see if a vulnerability has been identified with a CVSS score
2635      * that is above the threshold set in the configuration.
2636      *
2637      * @param dependencies the list of dependency objects
2638      * @throws MojoFailureException thrown if a CVSS score is found that is
2639      * higher then the threshold set
2640      */
2641     protected void checkForFailure(Dependency[] dependencies) throws MojoFailureException {
2642         final StringBuilder ids = new StringBuilder();
2643         for (Dependency d : dependencies) {
2644             boolean addName = true;
2645             for (Vulnerability v : d.getVulnerabilities()) {
2646                 final Double cvssV2 = v.getCvssV2() != null && v.getCvssV2().getCvssData() != null && v.getCvssV2().getCvssData().getBaseScore() != null ? v.getCvssV2().getCvssData().getBaseScore() : -1;
2647                 final Double cvssV3 = v.getCvssV3() != null && v.getCvssV3().getCvssData() != null && v.getCvssV3().getCvssData().getBaseScore() != null ? v.getCvssV3().getCvssData().getBaseScore() : -1;
2648                 final Double unscoredCvss = v.getUnscoredSeverity() != null ? SeverityUtil.estimateCvssV2(v.getUnscoredSeverity()) : -1;
2649 
2650                 if (failBuildOnAnyVulnerability || cvssV2 >= failBuildOnCVSS
2651                         || cvssV3 >= failBuildOnCVSS
2652                         || unscoredCvss >= failBuildOnCVSS
2653                         //safety net to fail on any if for some reason the above misses on 0
2654                         || (failBuildOnCVSS <= 0.0)) {
2655                     String name = v.getName();
2656                     if (cvssV3 >= 0.0) {
2657                         name += "(" + cvssV3 + ")";
2658                     } else if (cvssV2 >= 0.0) {
2659                         name += "(" + cvssV2 + ")";
2660                     } else if (unscoredCvss >= 0.0) {
2661                         name += "(" + unscoredCvss + ")";
2662                     }
2663                     if (addName) {
2664                         addName = false;
2665                         ids.append(NEW_LINE).append(d.getFileName()).append(": ");
2666                         ids.append(name);
2667                     } else {
2668                         ids.append(", ").append(name);
2669                     }
2670                 }
2671             }
2672         }
2673         if (ids.length() > 0) {
2674             final String msg;
2675             if (showSummary) {
2676                 if (failBuildOnAnyVulnerability) {
2677                     msg = String.format("%n%nOne or more dependencies were identified with vulnerabilities: %n%s%n%n"
2678                             + "See the dependency-check report for more details.%n%n", ids);
2679                 } else {
2680                     msg = String.format("%n%nOne or more dependencies were identified with vulnerabilities that have a CVSS score greater than or "
2681                             + "equal to '%.1f': %n%s%n%nSee the dependency-check report for more details.%n%n", failBuildOnCVSS, ids);
2682                 }
2683             } else {
2684                 msg = String.format("%n%nOne or more dependencies were identified with vulnerabilities.%n%n"
2685                         + "See the dependency-check report for more details.%n%n");
2686             }
2687             throw new MojoFailureException(msg);
2688         }
2689     }
2690 
2691     /**
2692      * Generates a warning message listing a summary of dependencies and their
2693      * associated CPE and CVE entries.
2694      *
2695      * @param mp the Maven project for which the summary is shown
2696      * @param dependencies a list of dependency objects
2697      */
2698     protected void showSummary(MavenProject mp, Dependency[] dependencies) {
2699         if (showSummary) {
2700             DependencyCheckScanAgent.showSummary(mp.getName(), dependencies);
2701         }
2702     }
2703 
2704     //</editor-fold>
2705     //CSOFF: ParameterNumber
2706     private ExceptionCollection scanDependencyNode(DependencyNode dependencyNode, DependencyNode root,
2707             Engine engine, MavenProject project, List<ArtifactResult> allResolvedDeps,
2708             ProjectBuildingRequest buildingRequest, boolean aggregate, ExceptionCollection exceptionCollection) {
2709         ExceptionCollection exCol = exceptionCollection;
2710         if (artifactScopeExcluded.passes(dependencyNode.getArtifact().getScope())
2711                 || artifactTypeExcluded.passes(dependencyNode.getArtifact().getType())) {
2712             return exCol;
2713         }
2714 
2715         boolean isResolved = false;
2716         File artifactFile = null;
2717         String artifactId = null;
2718         String groupId = null;
2719         String version = null;
2720         List<ArtifactVersion> availableVersions = null;
2721         if (org.apache.maven.artifact.Artifact.SCOPE_SYSTEM.equals(dependencyNode.getArtifact().getScope())) {
2722             final Artifact a = dependencyNode.getArtifact();
2723             if (a.isResolved() && a.getFile().isFile()) {
2724                 artifactFile = a.getFile();
2725                 isResolved = artifactFile.isFile();
2726                 groupId = a.getGroupId();
2727                 artifactId = a.getArtifactId();
2728                 version = a.getVersion();
2729                 availableVersions = a.getAvailableVersions();
2730             } else {
2731                 for (org.apache.maven.model.Dependency d : project.getDependencies()) {
2732                     if (d.getSystemPath() != null && artifactsMatch(d, a)) {
2733                         artifactFile = new File(d.getSystemPath());
2734                         isResolved = artifactFile.isFile();
2735                         groupId = a.getGroupId();
2736                         artifactId = a.getArtifactId();
2737                         version = a.getVersion();
2738                         availableVersions = a.getAvailableVersions();
2739                         break;
2740                     }
2741                 }
2742             }
2743             Throwable ignored = null;
2744             if (!isResolved) {
2745                 // Issue #4969 Tycho appears to add System-scoped libraries in reactor projects in unresolved state
2746                 // so attempt to do a resolution for system-scoped too if still nothing found
2747                 try {
2748                     tryResolutionOnce(project, allResolvedDeps, buildingRequest);
2749                     final Artifact result = findInAllDeps(allResolvedDeps, dependencyNode.getArtifact(), project);
2750                     isResolved = result.isResolved();
2751                     artifactFile = result.getFile();
2752                     groupId = result.getGroupId();
2753                     artifactId = result.getArtifactId();
2754                     version = result.getVersion();
2755                     availableVersions = result.getAvailableVersions();
2756                 } catch (DependencyNotFoundException | DependencyResolverException e) {
2757                     getLog().warn("Error performing last-resort System-scoped dependency resolution: " + e.getMessage());
2758                     ignored = e;
2759                 }
2760             }
2761             if (!isResolved) {
2762                 final StringBuilder message = new StringBuilder("Unable to resolve system scoped dependency: ");
2763                 if (artifactFile != null) {
2764                     message.append(dependencyNode.toNodeString()).append(" at path ").append(artifactFile);
2765                 } else {
2766                     message.append(dependencyNode.toNodeString()).append(" at path ").append(a.getFile());
2767                 }
2768                 getLog().error(message);
2769                 if (exCol == null) {
2770                     exCol = new ExceptionCollection();
2771                 }
2772                 final Exception thrown = new DependencyNotFoundException(message.toString());
2773                 if (ignored != null) {
2774                     thrown.addSuppressed(ignored);
2775                 }
2776                 exCol.addException(thrown);
2777             }
2778         } else {
2779             final Artifact dependencyArtifact = dependencyNode.getArtifact();
2780             final Artifact result;
2781             if (dependencyArtifact.isResolved()) {
2782                 //All transitive dependencies, excluding reactor and dependencyManagement artifacts should
2783                 //have been resolved by Maven prior to invoking the plugin - resolving the dependencies
2784                 //manually is unnecessary, and does not work in some cases (issue-1751)
2785                 getLog().debug(String.format("Skipping artifact %s, already resolved", dependencyArtifact.getArtifactId()));
2786                 result = dependencyArtifact;
2787             } else {
2788                 try {
2789                     tryResolutionOnce(project, allResolvedDeps, buildingRequest);
2790                     result = findInAllDeps(allResolvedDeps, dependencyNode.getArtifact(), project);
2791                 } catch (DependencyNotFoundException | DependencyResolverException ex) {
2792                     getLog().debug(String.format("Aggregate : %s", aggregate));
2793                     boolean addException = true;
2794                     //CSOFF: EmptyBlock
2795                     if (!aggregate) {
2796                         // do nothing - the exception is to be reported
2797                     } else if (addReactorDependency(engine, dependencyNode.getArtifact(), project)) {
2798                         // successfully resolved as a reactor dependency - swallow the exception
2799                         addException = false;
2800                     }
2801                     if (addException) {
2802                         if (exCol == null) {
2803                             exCol = new ExceptionCollection();
2804                         }
2805                         exCol.addException(ex);
2806                     }
2807                     return exCol;
2808                 }
2809             }
2810             if (aggregate && virtualSnapshotsFromReactor
2811                     && dependencyNode.getArtifact().isSnapshot()
2812                     && addSnapshotReactorDependency(engine, dependencyNode.getArtifact(), project)) {
2813                 return exCol;
2814             }
2815             isResolved = result.isResolved();
2816             artifactFile = result.getFile();
2817             groupId = result.getGroupId();
2818             artifactId = result.getArtifactId();
2819             version = result.getVersion();
2820             availableVersions = result.getAvailableVersions();
2821         }
2822         if (isResolved && artifactFile != null) {
2823             final List<Dependency> deps = engine.scan(artifactFile.getAbsoluteFile(),
2824                     createProjectReferenceName(project, dependencyNode));
2825             if (deps != null) {
2826                 processResolvedArtifact(artifactFile, deps, groupId, artifactId, version, root, project, availableVersions, dependencyNode);
2827             } else if ("import".equals(dependencyNode.getArtifact().getScope())) {
2828                 final String msg = String.format("Skipping '%s:%s' in project %s as it uses an `import` scope",
2829                         dependencyNode.getArtifact().getId(), dependencyNode.getArtifact().getScope(), project.getName());
2830                 getLog().debug(msg);
2831             } else if ("pom".equals(dependencyNode.getArtifact().getType())) {
2832                 exCol = processPomArtifact(artifactFile, root, project, engine, exCol);
2833             } else {
2834                 if (!scannedFiles.contains(artifactFile)) {
2835                     final String msg = String.format("No analyzer could be found or the artifact has been scanned twice for '%s:%s' in project %s",
2836                             dependencyNode.getArtifact().getId(), dependencyNode.getArtifact().getScope(), project.getName());
2837                     getLog().warn(msg);
2838                 }
2839             }
2840         } else {
2841             final String msg = String.format("Unable to resolve '%s' in project %s",
2842                     dependencyNode.getArtifact().getId(), project.getName());
2843             getLog().debug(msg);
2844             if (exCol == null) {
2845                 exCol = new ExceptionCollection();
2846             }
2847         }
2848         return exCol;
2849     }
2850 
2851     /**
2852      * Try resolution of artifacts once, allowing for
2853      * DependencyResolutionException due to reactor-dependencies not being
2854      * resolvable.
2855      * <br>
2856      * The resolution is attempted only if allResolvedDeps is still empty. The
2857      * assumption is that for any given project at least one of the dependencies
2858      * will successfully resolve. If not, resolution will be attempted once for
2859      * every dependency (as allResolvedDeps remains empty).
2860      *
2861      * @param project The project to dependencies for
2862      * @param allResolvedDeps The collection of successfully resolved
2863      * dependencies, will be filled with the successfully resolved dependencies,
2864      * even in case of resolution failures.
2865      * @param buildingRequest The buildingRequest to hand to Maven's
2866      * DependencyResolver.
2867      * @throws DependencyResolverException For any DependencyResolverException
2868      * other than an Eclipse Aether DependencyResolutionException
2869      */
2870     private void tryResolutionOnce(MavenProject project, List<ArtifactResult> allResolvedDeps, ProjectBuildingRequest buildingRequest) throws DependencyResolverException {
2871         if (allResolvedDeps.isEmpty()) { // no (partially successful) resolution attempt done
2872             try {
2873                 final List<org.apache.maven.model.Dependency> dependencies = project.getDependencies();
2874                 final List<org.apache.maven.model.Dependency> managedDependencies = project
2875                         .getDependencyManagement() == null ? null : project.getDependencyManagement().getDependencies();
2876                 final Iterable<ArtifactResult> allDeps = dependencyResolver
2877                         .resolveDependencies(buildingRequest, dependencies, managedDependencies, null);
2878                 allDeps.forEach(allResolvedDeps::add);
2879             } catch (DependencyResolverException dre) {
2880                 if (dre.getCause() instanceof org.eclipse.aether.resolution.DependencyResolutionException) {
2881                     final List<ArtifactResult> successResults = Mshared998Util
2882                             .getResolutionResults((org.eclipse.aether.resolution.DependencyResolutionException) dre.getCause());
2883                     allResolvedDeps.addAll(successResults);
2884                 } else {
2885                     throw dre;
2886                 }
2887             }
2888         }
2889     }
2890     //CSON: ParameterNumber
2891 
2892     //CSOFF: ParameterNumber
2893     private void processResolvedArtifact(File artifactFile, final List<Dependency> deps,
2894             String groupId, String artifactId, String version, DependencyNode root,
2895             MavenProject project1, List<ArtifactVersion> availableVersions,
2896             DependencyNode dependencyNode) {
2897         scannedFiles.add(artifactFile);
2898         Dependency d = null;
2899         if (deps.size() == 1) {
2900             d = deps.get(0);
2901 
2902         } else {
2903             for (Dependency possible : deps) {
2904                 if (artifactFile.getAbsoluteFile().equals(possible.getActualFile())) {
2905                     d = possible;
2906                     break;
2907                 }
2908             }
2909             for (Dependency dep : deps) {
2910                 if (d != null && d != dep) {
2911                     final String includedBy = buildReference(groupId, artifactId, version);
2912                     dep.addIncludedBy(includedBy);
2913                 }
2914             }
2915         }
2916         if (d != null) {
2917             final MavenArtifact ma = new MavenArtifact(groupId, artifactId, version);
2918             d.addAsEvidence("pom", ma, Confidence.HIGHEST);
2919             if (root != null) {
2920                 final String includedby = buildReference(
2921                         root.getArtifact().getGroupId(),
2922                         root.getArtifact().getArtifactId(),
2923                         root.getArtifact().getVersion());
2924                 d.addIncludedBy(includedby);
2925             } else {
2926                 final String includedby = buildReference(project1.getGroupId(), project1.getArtifactId(), project1.getVersion());
2927                 d.addIncludedBy(includedby);
2928             }
2929             if (availableVersions != null) {
2930                 for (ArtifactVersion av : availableVersions) {
2931                     d.addAvailableVersion(av.toString());
2932                 }
2933             }
2934             getLog().debug(String.format("Adding project reference %s on dependency %s", project1.getName(), d.getDisplayFileName()));
2935         } else if (getLog().isDebugEnabled()) {
2936             final String msg = String.format("More than 1 dependency was identified in first pass scan of '%s' in project %s", dependencyNode.getArtifact().getId(), project1.getName());
2937             getLog().debug(msg);
2938         }
2939     }
2940     //CSON: ParameterNumber
2941 
2942     private ExceptionCollection processPomArtifact(File artifactFile, DependencyNode root,
2943             MavenProject project1, Engine engine, ExceptionCollection exCollection) {
2944         ExceptionCollection exCol = exCollection;
2945         try {
2946             final Dependency d = new Dependency(artifactFile.getAbsoluteFile());
2947             final Model pom = PomUtils.readPom(artifactFile.getAbsoluteFile());
2948             JarAnalyzer.setPomEvidence(d, pom, null, true);
2949             if (root != null) {
2950                 final String includedby = buildReference(
2951                         root.getArtifact().getGroupId(),
2952                         root.getArtifact().getArtifactId(),
2953                         root.getArtifact().getVersion());
2954                 d.addIncludedBy(includedby);
2955             } else {
2956                 final String includedby = buildReference(project1.getGroupId(), project1.getArtifactId(), project1.getVersion());
2957                 d.addIncludedBy(includedby);
2958             }
2959             engine.addDependency(d);
2960         } catch (AnalysisException ex) {
2961             if (exCol == null) {
2962                 exCol = new ExceptionCollection();
2963             }
2964             exCol.addException(ex);
2965             getLog().debug("Error reading pom " + artifactFile.getAbsoluteFile(), ex);
2966         }
2967         return exCol;
2968     }
2969 
2970 }
2971 //CSON: FileLength