Skip to content

Commit e53b921

Browse files
authored
fix: problem with gradle version resolution (#141)
## Description Refactor how the Gradle dependencies are resolved because as the full tree is available in both component and stack analysis we can use the right trees instead of just the api / implementation listings. This helps resolving the correct versions. With that it is also possible to include the correct scope (required / optional) to the sbom **Related issue (if any):** - fixes: #138 - fixes: #139 - fixes: #140 Signed-off-by: Chao Wang <chaowan@redhat.com>
1 parent 1db5b9b commit e53b921

40 files changed

Lines changed: 12756 additions & 6196 deletions

license-header

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 Red Hat, Inc.
2+
* Copyright © $YEAR Red Hat, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright © 2023 Red Hat, Inc.
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+
package com.redhat.exhort.providers;
17+
18+
public enum AnalysisType {
19+
STACK,
20+
COMPONENT
21+
}

src/main/java/com/redhat/exhort/providers/BaseJavaProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected BaseJavaProvider(Ecosystem.Type ecosystem, Path manifest) {
3232
super(ecosystem, manifest);
3333
}
3434

35-
void parseDependencyTree(String src, int srcDepth, String[] lines, Sbom sbom) {
35+
void parseDependencyTree(String src, int srcDepth, String[] lines, Sbom sbom, String scope) {
3636
if (lines.length == 0) {
3737
return;
3838
}
@@ -47,11 +47,12 @@ void parseDependencyTree(String src, int srcDepth, String[] lines, Sbom sbom) {
4747
PackageURL from = parseDep(src);
4848
PackageURL to = parseDep(target);
4949
if (dependencyIsNotTestScope(from) && dependencyIsNotTestScope(to)) {
50-
sbom.addDependency(from, to);
50+
sbom.addDependency(from, to, scope);
5151
}
5252
} else {
5353
String[] modifiedLines = Arrays.copyOfRange(lines, index, lines.length);
54-
parseDependencyTree(lines[index - 1], getDepth(lines[index - 1]), modifiedLines, sbom);
54+
parseDependencyTree(
55+
lines[index - 1], getDepth(lines[index - 1]), modifiedLines, sbom, scope);
5556
}
5657
if (index < lines.length - 1) {
5758
target = lines[++index];

src/main/java/com/redhat/exhort/providers/GoModulesProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private Sbom buildSbomFromGraph(
300300
dep -> {
301301
PackageURL targetPurl =
302302
toPurl((String) dep, "@", this.goEnvironmentVariableForPurl);
303-
sbom.addDependency(source, targetPurl);
303+
sbom.addDependency(source, targetPurl, null);
304304
});
305305
});
306306
List<String> ignoredDepsPurl =
@@ -433,7 +433,7 @@ private Sbom buildSbomFromList(String golangDeps, List<PackageURL> ignoredDeps)
433433
dep -> {
434434
PackageURL targetPurl = toPurl(dep, "@", this.goEnvironmentVariableForPurl);
435435
if (dependencyNotToBeIgnored(ignoredDeps, targetPurl)) {
436-
sbom.addDependency(root, targetPurl);
436+
sbom.addDependency(root, targetPurl, null);
437437
}
438438
});
439439
List<String> ignoredDepsByName = new ArrayList<>();

0 commit comments

Comments
 (0)