Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit cb6b5f3

Browse files
committed
start of fix for #1421
1 parent 57f4117 commit cb6b5f3

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

maven/src/main/java/org/owasp/dependencycheck/maven/BaseDependencyCheckMojo.java

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,15 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
371371
@Parameter(property = "artifactoryAnalyzerEnabled")
372372
private Boolean artifactoryAnalyzerEnabled;
373373
/**
374-
* The serverId inside the settings.xml containing the username and token to access artifactory
374+
* The serverId inside the settings.xml containing the username and token to
375+
* access artifactory
375376
*/
376377
@SuppressWarnings("CanBeFinal")
377378
@Parameter(property = "artifactoryAnalyzerServerId", defaultValue = "artifactory")
378379
private String artifactoryAnalyzerServerId;
379380
/**
380-
* The username (only used with API token) to connect to Artifactory instance
381+
* The username (only used with API token) to connect to Artifactory
382+
* instance
381383
*/
382384
@SuppressWarnings("CanBeFinal")
383385
@Parameter(property = "artifactoryAnalyzerUsername", defaultValue = "artifactory")
@@ -657,7 +659,6 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
657659

658660
// </editor-fold>
659661
//<editor-fold defaultstate="collapsed" desc="Base Maven implementation">
660-
661662
/**
662663
* Determines if the groupId, artifactId, and version of the Maven
663664
* dependency and artifact match.
@@ -676,7 +677,7 @@ private static boolean artifactsMatch(org.apache.maven.model.Dependency d, Artif
676677
* Compares two strings for equality; if both strings are null they are
677678
* considered equal.
678679
*
679-
* @param left the first string to compare
680+
* @param left the first string to compare
680681
* @param right the second string to compare
681682
* @return true if the strings are equal or if they are both null; otherwise
682683
* false.
@@ -689,8 +690,8 @@ private static boolean isEqualOrNull(String left, String right) {
689690
* Executes dependency-check.
690691
*
691692
* @throws MojoExecutionException thrown if there is an exception executing
692-
* the mojo
693-
* @throws MojoFailureException thrown if dependency-check failed the build
693+
* the mojo
694+
* @throws MojoFailureException thrown if dependency-check failed the build
694695
*/
695696
@Override
696697
public void execute() throws MojoExecutionException, MojoFailureException {
@@ -723,7 +724,7 @@ private void validateAggregate() throws MojoExecutionException {
723724
/**
724725
* Generates the Dependency-Check Site Report.
725726
*
726-
* @param sink the sink to write the report to
727+
* @param sink the sink to write the report to
727728
* @param locale the locale to use when generating the report
728729
* @throws MavenReportException if a maven report exception occurs
729730
* @deprecated use
@@ -766,7 +767,7 @@ protected boolean isFailOnError() {
766767
/**
767768
* Generates the Dependency-Check Site Report.
768769
*
769-
* @param sink the sink to write the report to
770+
* @param sink the sink to write the report to
770771
* @param locale the locale to use when generating the report
771772
* @throws MavenReportException if a maven report exception occurs
772773
*/
@@ -799,7 +800,7 @@ public void generate(Sink sink, Locale locale) throws MavenReportException {
799800
*
800801
* @return the directory to write the report(s)
801802
* @throws MojoExecutionException thrown if there is an error loading the
802-
* file path
803+
* file path
803804
*/
804805
protected File getCorrectOutputDirectory() throws MojoExecutionException {
805806
return getCorrectOutputDirectory(this.project);
@@ -829,7 +830,7 @@ protected File getCorrectOutputDirectory(MavenProject current) {
829830
* list.
830831
*
831832
* @param project the project to scan the dependencies of
832-
* @param engine the engine to use to scan the dependencies
833+
* @param engine the engine to use to scan the dependencies
833834
* @return a collection of exceptions that may have occurred while resolving
834835
* and scanning the dependencies
835836
*/
@@ -841,8 +842,8 @@ protected ExceptionCollection scanArtifacts(MavenProject project, Engine engine)
841842
* Scans the project's artifacts and adds them to the engine's dependency
842843
* list.
843844
*
844-
* @param project the project to scan the dependencies of
845-
* @param engine the engine to use to scan the dependencies
845+
* @param project the project to scan the dependencies of
846+
* @param engine the engine to use to scan the dependencies
846847
* @param aggregate whether the scan is part of an aggregate build
847848
* @return a collection of exceptions that may have occurred while resolving
848849
* and scanning the dependencies
@@ -864,17 +865,17 @@ protected ExceptionCollection scanArtifacts(MavenProject project, Engine engine,
864865
* Resolves the projects artifacts using Aether and scans the resulting
865866
* dependencies.
866867
*
867-
* @param engine the core dependency-check engine
868-
* @param project the project being scanned
869-
* @param nodes the list of dependency nodes, generally obtained via the
870-
* DependencyGraphBuilder
868+
* @param engine the core dependency-check engine
869+
* @param project the project being scanned
870+
* @param nodes the list of dependency nodes, generally obtained via the
871+
* DependencyGraphBuilder
871872
* @param buildingRequest the Maven project building request
872-
* @param aggregate whether the scan is part of an aggregate build
873+
* @param aggregate whether the scan is part of an aggregate build
873874
* @return a collection of exceptions that may have occurred while resolving
874875
* and scanning the dependencies
875876
*/
876877
private ExceptionCollection collectDependencies(Engine engine, MavenProject project,
877-
List<DependencyNode> nodes, ProjectBuildingRequest buildingRequest, boolean aggregate) {
878+
List<DependencyNode> nodes, ProjectBuildingRequest buildingRequest, boolean aggregate) {
878879
ExceptionCollection exCol = null;
879880
for (DependencyNode dependencyNode : nodes) {
880881
if (artifactScopeExcluded.passes(dependencyNode.getArtifact().getScope())
@@ -984,9 +985,9 @@ private ExceptionCollection collectDependencies(Engine engine, MavenProject proj
984985
}
985986
}
986987
}
987-
988-
// Define the default FileSets
988+
FileSet[] projectScan = scanSet;
989989
if (scanSet == null || scanSet.length == 0) {
990+
// Define the default FileSets
990991
final FileSet resourcesSet = new FileSet();
991992
final FileSet filtersSet = new FileSet();
992993
final FileSet webappSet = new FileSet();
@@ -1000,11 +1001,15 @@ private ExceptionCollection collectDependencies(Engine engine, MavenProject proj
10001001
}
10011002
exCol.addException(ex);
10021003
}
1003-
scanSet = new FileSet[]{resourcesSet, filtersSet, webappSet};
1004+
projectScan = new FileSet[]{resourcesSet, filtersSet, webappSet};
1005+
1006+
} else if (aggregate) {
1007+
//TODO build the correct scan set for the child project?
10041008
}
1009+
10051010
// Iterate through FileSets and scan included files
10061011
final FileSetManager fileSetManager = new FileSetManager();
1007-
for (FileSet fileSet : scanSet) {
1012+
for (FileSet fileSet : projectScan) {
10081013
final String[] includedFiles = fileSetManager.getIncludedFiles(fileSet);
10091014
for (String include : includedFiles) {
10101015
final File includeFile = new File(fileSet.getDirectory(), include).getAbsoluteFile();
@@ -1023,7 +1028,7 @@ private ExceptionCollection collectDependencies(Engine engine, MavenProject proj
10231028
* have not yet been built. If true a virtual dependency is created based on
10241029
* the evidence in the project.
10251030
*
1026-
* @param engine a reference to the engine being used to scan
1031+
* @param engine a reference to the engine being used to scan
10271032
* @param artifact the artifact being analyzed in the mojo
10281033
* @return <code>true</code> if the artifact is in the reactor; otherwise
10291034
* <code>false</code>
@@ -1117,9 +1122,9 @@ public ProjectBuildingRequest newResolveArtifactProjectBuildingRequest() {
11171122
* Executes the dependency-check scan and generates the necessary report.
11181123
*
11191124
* @throws MojoExecutionException thrown if there is an exception running
1120-
* the scan
1121-
* @throws MojoFailureException thrown if dependency-check is configured to
1122-
* fail the build
1125+
* the scan
1126+
* @throws MojoFailureException thrown if dependency-check is configured to
1127+
* fail the build
11231128
*/
11241129
protected void runCheck() throws MojoExecutionException, MojoFailureException {
11251130
try (Engine engine = initializeEngine()) {
@@ -1177,10 +1182,10 @@ protected void runCheck() throws MojoExecutionException, MojoFailureException {
11771182
* MojoExecutionException
11781183
*
11791184
* @param currentEx the primary exception collection
1180-
* @param newEx the new exception collection to add
1185+
* @param newEx the new exception collection to add
11811186
* @return the combined exception collection
11821187
* @throws MojoExecutionException thrown if dependency-check is configured
1183-
* to fail on errors
1188+
* to fail on errors
11841189
*/
11851190
private ExceptionCollection handleAnalysisExceptions(ExceptionCollection currentEx, ExceptionCollection newEx) throws MojoExecutionException {
11861191
ExceptionCollection returnEx = currentEx;
@@ -1382,7 +1387,6 @@ protected void populateSettings() {
13821387
settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_USES_PROXY, artifactoryAnalyzerUseProxy);
13831388
settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_PARALLEL_ANALYSIS, artifactoryAnalyzerParallelAnalysis);
13841389

1385-
13861390
if (Boolean.TRUE.equals(artifactoryAnalyzerEnabled)) {
13871391
if (artifactoryAnalyzerServerId != null) {
13881392
final Server server = settingsXml.getServer(artifactoryAnalyzerServerId);
@@ -1575,14 +1579,13 @@ protected Settings getSettings() {
15751579
}
15761580

15771581
//<editor-fold defaultstate="collapsed" desc="Methods to fail build or show summary">
1578-
15791582
/**
15801583
* Checks to see if a vulnerability has been identified with a CVSS score
15811584
* that is above the threshold set in the configuration.
15821585
*
15831586
* @param dependencies the list of dependency objects
15841587
* @throws MojoFailureException thrown if a CVSS score is found that is
1585-
* higher then the threshold set
1588+
* higher then the threshold set
15861589
*/
15871590
protected void checkForFailure(Dependency[] dependencies) throws MojoFailureException {
15881591
final StringBuilder ids = new StringBuilder();
@@ -1623,7 +1626,7 @@ protected void checkForFailure(Dependency[] dependencies) throws MojoFailureExce
16231626
* Generates a warning message listing a summary of dependencies and their
16241627
* associated CPE and CVE entries.
16251628
*
1626-
* @param mp the Maven project for which the summary is shown
1629+
* @param mp the Maven project for which the summary is shown
16271630
* @param dependencies a list of dependency objects
16281631
*/
16291632
protected void showSummary(MavenProject mp, Dependency[] dependencies) {
@@ -1664,7 +1667,6 @@ protected void showSummary(MavenProject mp, Dependency[] dependencies) {
16641667

16651668
//</editor-fold>
16661669
//<editor-fold defaultstate="collapsed" desc="Methods to read/write the serialized data file">
1667-
16681670
/**
16691671
* Returns the key used to store the path to the data file that is saved by
16701672
* <code>writeDataFile()</code>. This key is used in the

0 commit comments

Comments
 (0)