Skip to content

Commit 170147b

Browse files
bd-samratmukblackduck-serv-builder
andauthored
(fix)gradle: ignore (c) lines in the report (IDETECT-4760) (#1602)
* (fix)gradle - ignore (c) lines in the report * use constant GRADLE_CONSTRAINT_SUFFIX * add functional test cases * Release 11.1.0-SIGQA7-IDETECT-4760 * Using the next snapshot post release 11.1.0-SIGQA8-IDETECT-4760-SNAPSHOT --------- Co-authored-by: blackduck-serv-builder <[email protected]>
1 parent b199837 commit 170147b

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

detectable/src/main/java/com/blackduck/integration/detectable/detectables/gradle/inspection/parse/GradleReportConfigurationParser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
public class GradleReportConfigurationParser {
1313
private static final String UNRESOLVED_SUFFIX = "(n)";
14+
private static final String GRADLE_CONSTRAINT_SUFFIX = "(c)";
1415

1516
private final GradleReportLineParser parser = new GradleReportLineParser();
1617

@@ -21,7 +22,9 @@ public GradleConfiguration parse(String header, List<String> dependencyLines, Ma
2122
configuration.setUnresolved(parseUnresolved(header));
2223
List<GradleTreeNode> children = new ArrayList<>();
2324
for (String line: dependencyLines) {
24-
children.add(parser.parseLine(line, metadata));
25+
if (!line.trim().endsWith(GRADLE_CONSTRAINT_SUFFIX)) {
26+
children.add(parser.parseLine(line, metadata));
27+
}
2528
}
2629
configuration.setChildren(children);
2730

detectable/src/test/java/com/blackduck/integration/detectable/detectables/gradle/functional/GradleReportParserFunctionalTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,18 @@ void testUnresolvedConfigurations() {
114114

115115
System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(codeLocation.get()));
116116
}
117+
118+
@Test
119+
void testConstraintsAreFiltered() {
120+
Optional<CodeLocation> codeLocation = buildCodeLocation("/gradle/constraints_dependencyGraph.txt", true);
121+
Assertions.assertTrue(codeLocation.isPresent());
122+
DependencyGraph graph = codeLocation.get().getDependencyGraph();
123+
124+
MavenGraphAssert graphAssert = new MavenGraphAssert(graph);
125+
graphAssert.hasRootSize(1);
126+
graphAssert.hasRootDependency("com.google.code.gson:gson:2.8.9");
127+
graphAssert.hasNoDependency("org.apache.logging.log4j:log4j-api:2.17.1");
128+
graphAssert.hasNoDependency("org.apache.commons:commons-collections4:4.4");
129+
graphAssert.hasNoDependency("javax.servlet:javax.servlet-api:3.1.0");
130+
}
117131
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
------------------------------------------------------------
2+
Project :project
3+
------------------------------------------------------------
4+
5+
archives - Configuration for archive artifacts. (n)
6+
No dependencies
7+
8+
compile - Dependencies for source set 'main'. (n)
9+
+--- org.apache.logging.log4j:log4j-api:2.17.1 (c)
10+
+--- com.google.code.gson:gson:2.8.9
11+
| \--- org.apache.httpcomponents:httpclient:4.5.13
12+
| +--- commons-codec:commons-codec:1.11
13+
| \--- javax.servlet:javax.servlet-api:3.1.0 (c)
14+
\--- org.apache.commons:commons-collections4:4.4 (c)
15+
16+
(n) - Not resolved (configuration is not meant to be resolved)
17+

0 commit comments

Comments
 (0)