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

Commit 9e6c9f6

Browse files
committed
patch and test for #1421
1 parent d0581d1 commit 9e6c9f6

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

maven/src/it/740-aggregate/pom.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Copyright (c) 2018 Jeremy Long. All Rights Reserved.
2525
<modules>
2626
<module>first</module>
2727
<module>second</module>
28-
<module>third</module>
28+
<module>third</module>
2929
</modules>
3030
<build>
3131
<plugins>
@@ -37,6 +37,12 @@ Copyright (c) 2018 Jeremy Long. All Rights Reserved.
3737
<configuration>
3838
<format>ALL</format>
3939
<centralAnalyzerEnabled>false</centralAnalyzerEnabled>
40+
<enableExperimental>true</enableExperimental>
41+
<scanSet>
42+
<fileSet>
43+
<directory>src/test</directory>
44+
</fileSet>
45+
</scanSet>
4046
</configuration>
4147
<executions>
4248
<execution>

maven/src/it/740-aggregate/postbuild.groovy

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ if (count == 0) {
2828
}
2929
count = StringUtils.countMatches(report, "org.apache.james:apache-mime4j-core:0.7.2");
3030
if (count == 0) {
31-
System.out.println(String.format("org.apache.james:apache-mime4j-core:0.7.2 was not identified and is a dependency of fourth-1.0.0-SNAPSHOT"));
31+
System.out.println("org.apache.james:apache-mime4j-core:0.7.2 was not identified and is a dependency of fourth-1.0.0-SNAPSHOT");
3232
return false;
3333
}
34+
count = StringUtils.countMatches(report, "HelloWorld.js");
35+
if (count == 0) {
36+
System.out.println("HelloWorld.js was not included via ScanSet and is found in `second/srt/test`");
37+
return false;
38+
}
39+
3440
return true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
Copyright (c) 2018 The OWAS Foundation. All Rights Reserved.
3+
*/
4+
alert('hello world');

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

+56-2
Original file line numberDiff line numberDiff line change
@@ -874,15 +874,15 @@ protected ExceptionCollection scanArtifacts(MavenProject project, Engine engine,
874874
* @return a collection of exceptions that may have occurred while resolving
875875
* and scanning the dependencies
876876
*/
877-
private ExceptionCollection collectDependencies(Engine engine, MavenProject project,
877+
private ExceptionCollection collectMavenDependencies(Engine engine, MavenProject project,
878878
List<DependencyNode> nodes, ProjectBuildingRequest buildingRequest, boolean aggregate) {
879879
ExceptionCollection exCol = null;
880880
for (DependencyNode dependencyNode : nodes) {
881881
if (artifactScopeExcluded.passes(dependencyNode.getArtifact().getScope())
882882
|| artifactTypeExcluded.passes(dependencyNode.getArtifact().getType())) {
883883
continue;
884884
}
885-
exCol = collectDependencies(engine, project, dependencyNode.getChildren(), buildingRequest, aggregate);
885+
exCol = collectMavenDependencies(engine, project, dependencyNode.getChildren(), buildingRequest, aggregate);
886886
boolean isResolved = false;
887887
File artifactFile = null;
888888
String artifactId = null;
@@ -985,6 +985,28 @@ private ExceptionCollection collectDependencies(Engine engine, MavenProject proj
985985
}
986986
}
987987
}
988+
return exCol;
989+
}
990+
991+
/**
992+
* Scans the projects dependencies including the default (or defined)
993+
* FileSets.
994+
*
995+
* @param engine the core dependency-check engine
996+
* @param project the project being scanned
997+
* @param nodes the list of dependency nodes, generally obtained via the
998+
* DependencyGraphBuilder
999+
* @param buildingRequest the Maven project building request
1000+
* @param aggregate whether the scan is part of an aggregate build
1001+
* @return a collection of exceptions that may have occurred while resolving
1002+
* and scanning the dependencies
1003+
*/
1004+
private ExceptionCollection collectDependencies(Engine engine, MavenProject project,
1005+
List<DependencyNode> nodes, ProjectBuildingRequest buildingRequest, boolean aggregate) {
1006+
1007+
ExceptionCollection exCol = null;
1008+
exCol = collectMavenDependencies(engine, project, nodes, buildingRequest, aggregate);
1009+
9881010
FileSet[] projectScan = scanSet;
9891011
if (scanSet == null || scanSet.length == 0) {
9901012
// Define the default FileSets
@@ -1005,6 +1027,38 @@ private ExceptionCollection collectDependencies(Engine engine, MavenProject proj
10051027

10061028
} else if (aggregate) {
10071029
//TODO build the correct scan set for the child project?
1030+
projectScan = new FileSet[scanSet.length];
1031+
for (int x = 0; x < scanSet.length; x++) {
1032+
//deep copy of the FileSet - modifying the directory if it is not absolute.
1033+
FileSet copyFrom = scanSet[x];
1034+
FileSet fsCopy = new FileSet();
1035+
1036+
File f = new File(copyFrom.getDirectory());
1037+
if (f.isAbsolute()) {
1038+
fsCopy.setDirectory(copyFrom.getDirectory());
1039+
} else {
1040+
try {
1041+
fsCopy.setDirectory(new File(project.getBasedir(), copyFrom.getDirectory()).getCanonicalPath());
1042+
} catch (IOException ex) {
1043+
if (exCol == null) {
1044+
exCol = new ExceptionCollection();
1045+
}
1046+
exCol.addException(ex);
1047+
fsCopy.setDirectory(copyFrom.getDirectory());
1048+
}
1049+
}
1050+
fsCopy.setDirectoryMode(copyFrom.getDirectoryMode());
1051+
fsCopy.setExcludes(copyFrom.getExcludes());
1052+
fsCopy.setFileMode(copyFrom.getFileMode());
1053+
fsCopy.setFollowSymlinks(copyFrom.isFollowSymlinks());
1054+
fsCopy.setIncludes(copyFrom.getIncludes());
1055+
fsCopy.setLineEnding(copyFrom.getLineEnding());
1056+
fsCopy.setMapper(copyFrom.getMapper());
1057+
fsCopy.setModelEncoding(copyFrom.getModelEncoding());
1058+
fsCopy.setOutputDirectory(copyFrom.getOutputDirectory());
1059+
fsCopy.setUseDefaultExcludes(copyFrom.isUseDefaultExcludes());
1060+
projectScan[x] = fsCopy;
1061+
}
10081062
}
10091063

10101064
// Iterate through FileSets and scan included files

0 commit comments

Comments
 (0)