Skip to content

Commit d23a1e2

Browse files
authored
Merge branch 'main' into snyk-upgrade-949d7688f07f27edc7a4a751ca68b538
2 parents 70561af + 4f98774 commit d23a1e2

15 files changed

Lines changed: 121 additions & 86 deletions

.github/workflows/integration.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Integration
3+
4+
on:
5+
workflow_dispatch:
6+
pull_request:
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
call-shared:
16+
uses: trustification/exhort-integration-tests/.github/workflows/integration.yml@main
17+
with:
18+
language: java
19+
repo-url: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
20+
commit-sha: ${{ github.event.pull_request.head.sha || github.sha }}

.github/workflows/pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
checks: write
1515
pull-requests: write
1616
env:
17-
MAIN_JAVA_VER: 11
17+
MAIN_JAVA_VER: 17
1818
RUN_PYTHON_BIN: ${{ vars.RUN_PYTHON_BIN }}
1919
strategy:
2020
matrix:
21-
java: [11, 17, 21]
21+
java: [17, 21]
2222
steps:
2323
- name: Checkout sources
2424
uses: actions/checkout@v3

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ jobs:
3131
fetch-depth: 0
3232

3333

34-
- name: Setup Java 11
35-
uses: actions/setup-java@v3
34+
- name: Setup Java 17
35+
uses: actions/setup-java@v4
3636
with:
3737
distribution: temurin
38-
java-version: 11
38+
java-version: 17
3939
cache: maven
4040

4141
- name: create ssh agent

.github/workflows/stage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ jobs:
2525
- name: Checkout sources
2626
uses: actions/checkout@v3
2727

28-
- name: Setup Java 11
29-
uses: actions/setup-java@v3
28+
- name: Setup Java 17
29+
uses: actions/setup-java@v4
3030
with:
3131
distribution: temurin
32-
java-version: 11
32+
java-version: 17
3333
cache: maven
3434

3535
- name: Get pom specs

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ dependency-reduced-pom.xml
4141
# Node
4242
node_modules
4343

44+
# Python virtual envs
45+
.venv
46+
4447
# project stuff
4548
http_requests
4649
json_responses
4750
**/.DS_Store
4851
.idea/
52+

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<code.coverage.threshold>81%</code.coverage.threshold>
1717
<mutation.coverage.threshold>50</mutation.coverage.threshold>
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19-
<maven.compiler.release>11</maven.compiler.release>
19+
<maven.compiler.release>17</maven.compiler.release>
2020
<!-- Dependencies -->
2121
<exhort-api.version>1.0.6</exhort-api.version>
2222
<jackson.version>2.19.1</jackson.version>
@@ -30,7 +30,7 @@
3030
<mockito.version>5.17.0</mockito.version>
3131
<!-- Plugins -->
3232
<maven-clean-plugin.version>3.2.0</maven-clean-plugin.version>
33-
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
33+
<maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
3434
<maven-dependency-plugin.version>3.6.0</maven-dependency-plugin.version>
3535
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
3636
<maven-enforcer-plugin.version>3.3.0</maven-enforcer-plugin.version>

src/main/java/com/redhat/exhort/cli/App.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
import com.redhat.exhort.Api;
2626
import com.redhat.exhort.api.v4.AnalysisReport;
2727
import com.redhat.exhort.api.v4.ProviderReport;
28-
import com.redhat.exhort.api.v4.Source;
28+
import com.redhat.exhort.api.v4.SourceSummary;
2929
import com.redhat.exhort.impl.ExhortApi;
3030
import java.io.IOException;
3131
import java.nio.file.Files;
3232
import java.nio.file.Path;
3333
import java.nio.file.Paths;
34+
import java.util.HashMap;
35+
import java.util.Map;
3436
import java.util.concurrent.CompletableFuture;
3537
import java.util.concurrent.ExecutionException;
3638

@@ -161,7 +163,8 @@ private static CompletableFuture<String> executeComponentAnalysis(
161163
Api api = new ExhortApi();
162164
CompletableFuture<AnalysisReport> analysis = api.componentAnalysis(filePath);
163165
if (outputFormat.equals(OutputFormat.SUMMARY)) {
164-
analysis = analysis.thenApply(App::extractSummary);
166+
var summary = analysis.thenApply(App::extractSummary);
167+
return summary.thenApply(App::toJsonString);
165168
}
166169
return analysis.thenApply(App::toJsonString);
167170
}
@@ -174,9 +177,8 @@ private static String toJsonString(Object obj) {
174177
}
175178
}
176179

177-
private static AnalysisReport extractSummary(AnalysisReport report) {
178-
AnalysisReport summary = new AnalysisReport();
179-
summary.setScanned(report.getScanned());
180+
private static Map<String, SourceSummary> extractSummary(AnalysisReport report) {
181+
Map<String, SourceSummary> summary = new HashMap<>();
180182
if (report.getProviders() == null) {
181183
return summary;
182184
}
@@ -194,12 +196,11 @@ private static AnalysisReport extractSummary(AnalysisReport report) {
194196
.entrySet()
195197
.forEach(
196198
sourceEntry -> {
197-
var source = new Source();
198-
source.setSummary(sourceEntry.getValue().getSummary());
199-
provider.putSourcesItem(sourceEntry.getKey(), source);
199+
if (sourceEntry.getValue().getSummary() != null) {
200+
summary.put(sourceEntry.getKey(), sourceEntry.getValue().getSummary());
201+
}
200202
});
201203
}
202-
summary.putProvidersItem(entry.getKey(), provider);
203204
});
204205
return summary;
205206
}

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

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import static com.redhat.exhort.impl.ExhortApi.debugLoggingIsNeeded;
1919

20+
import com.fasterxml.jackson.core.JsonProcessingException;
21+
import com.fasterxml.jackson.databind.JsonNode;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
2023
import com.github.packageurl.MalformedPackageURLException;
2124
import com.github.packageurl.PackageURL;
2225
import com.redhat.exhort.Api;
@@ -68,7 +71,7 @@ public String getMainModuleVersion() {
6871
public GoModulesProvider(Path manifest) {
6972
super(Type.GOLANG, manifest);
7073
this.goExecutable = Operations.getExecutable("go", "version");
71-
this.goEnvironmentVariableForPurl = getQualifiers(true);
74+
this.goEnvironmentVariableForPurl = getQualifiers();
7275
this.mainModuleVersion = getDefaultMainModuleVersion();
7376
}
7477

@@ -137,7 +140,7 @@ Sbom getDependenciesSbom(Path manifestPath, boolean buildTree) throws IOExceptio
137140
boolean matchManifestVersions =
138141
Environment.getBoolean(Provider.PROP_MATCH_MANIFEST_VERSIONS, false);
139142
if (matchManifestVersions) {
140-
String[] goModGraphLines = goModulesResult.split(System.lineSeparator());
143+
String[] goModGraphLines = goModulesResult.split(Operations.GENERIC_LINE_SEPARATOR);
141144
performManifestVersionsCheck(goModGraphLines, manifestPath);
142145
}
143146
if (!buildTree) {
@@ -151,7 +154,7 @@ Sbom getDependenciesSbom(Path manifestPath, boolean buildTree) throws IOExceptio
151154
private void performManifestVersionsCheck(String[] goModGraphLines, Path manifestPath) {
152155
try {
153156
String goModLines = Files.readString(manifestPath);
154-
String[] lines = goModLines.split(System.lineSeparator());
157+
String[] lines = goModLines.split(Operations.GENERIC_LINE_SEPARATOR);
155158
String root = getParentVertex(goModGraphLines[0]);
156159
List<String> comparisonLines =
157160
Arrays.stream(goModGraphLines)
@@ -270,7 +273,8 @@ private Sbom buildSbomFromGraph(
270273
// iterate over go mod graph line by line and create map , with each entry to contain module as
271274
// a key , and
272275
// value of list of that module' dependencies.
273-
List<String> linesList = Arrays.asList(goModulesResult.split(System.lineSeparator()));
276+
List<String> linesList =
277+
Arrays.asList(goModulesResult.split(Operations.GENERIC_LINE_SEPARATOR));
274278

275279
int startingIndex = 0;
276280
for (String line : linesList) {
@@ -324,7 +328,7 @@ private Map<String, List<String>> getFinalPackagesVersionsForModule(
324328
String finalVersionsForAllModules =
325329
Operations.runProcessGetOutput(manifestPath.getParent(), "go", "list", "-m", "all");
326330
Map<String, String> finalModulesVersions =
327-
Arrays.stream(finalVersionsForAllModules.split(System.lineSeparator()))
331+
Arrays.stream(finalVersionsForAllModules.split(Operations.GENERIC_LINE_SEPARATOR))
328332
.filter(string -> string.trim().split(" ").length == 2)
329333
.collect(
330334
Collectors.toMap(
@@ -378,26 +382,38 @@ private static List<String> collectAllDirectDependencies(List<String> targetLine
378382
.collect(Collectors.toList());
379383
}
380384

381-
private TreeMap<String, String> getQualifiers(boolean includeOsAndArch) {
382-
if (includeOsAndArch) {
383-
String goEnvironmentVariables = Operations.runProcessGetOutput(null, goExecutable, "env");
384-
String hostArch =
385-
getEnvironmentVariable(goEnvironmentVariables, GO_HOST_ARCHITECTURE_ENV_NAME);
386-
String hostOS =
387-
getEnvironmentVariable(goEnvironmentVariables, GO_HOST_OPERATION_SYSTEM_ENV_NAME);
388-
return new TreeMap<>(Map.of("type", "module", "goos", hostOS, "goarch", hostArch));
385+
private TreeMap<String, String> getQualifiers() {
386+
var goEnvironmentVariables = getGoEnvironmentVariables();
387+
var qualifiers = new TreeMap<String, String>();
388+
qualifiers.put("type", "module");
389+
if (goEnvironmentVariables.containsKey(GO_HOST_ARCHITECTURE_ENV_NAME)) {
390+
qualifiers.put("goarch", goEnvironmentVariables.get(GO_HOST_ARCHITECTURE_ENV_NAME));
391+
}
392+
if (goEnvironmentVariables.containsKey(GO_HOST_OPERATION_SYSTEM_ENV_NAME)) {
393+
qualifiers.put("goos", goEnvironmentVariables.get(GO_HOST_OPERATION_SYSTEM_ENV_NAME));
389394
}
390395

391-
return new TreeMap<>(Map.of("type", "module"));
396+
return qualifiers;
392397
}
393398

394-
private static String getEnvironmentVariable(String goEnvironmentVariables, String envName) {
395-
int i = goEnvironmentVariables.indexOf(String.format("%s=", envName));
396-
int beginIndex = i + String.format("%s=", envName).length();
397-
int endOfLineIndex =
398-
goEnvironmentVariables.substring(beginIndex).indexOf(System.lineSeparator());
399-
String envValue = goEnvironmentVariables.substring(beginIndex).substring(0, endOfLineIndex);
400-
return envValue.replaceAll("\"", "");
399+
private Map<String, String> getGoEnvironmentVariables() {
400+
String goEnvironmentVariables =
401+
Operations.runProcessGetOutput(null, goExecutable, "env", "--json");
402+
JsonNode tree;
403+
try {
404+
tree = new ObjectMapper().readTree(goEnvironmentVariables);
405+
} catch (JsonProcessingException e) {
406+
throw new RuntimeException("Failed to parse go environment variables: " + e.getMessage());
407+
}
408+
var envMap = new HashMap<String, String>();
409+
tree.fields()
410+
.forEachRemaining(
411+
entry -> {
412+
String key = entry.getKey();
413+
String value = entry.getValue().asText();
414+
envMap.put(key, value);
415+
});
416+
return envMap;
401417
}
402418

403419
private String buildGoModulesDependencies(Path manifestPath) {
@@ -417,7 +433,7 @@ private String buildGoModulesDependencies(Path manifestPath) {
417433
}
418434

419435
private Sbom buildSbomFromList(String golangDeps, List<PackageURL> ignoredDeps) {
420-
String[] allModulesFlat = golangDeps.split(System.lineSeparator());
436+
String[] allModulesFlat = golangDeps.split(Operations.GENERIC_LINE_SEPARATOR);
421437
String parentVertex = getParentVertex(allModulesFlat[0]);
422438
PackageURL root = toPurl(parentVertex, "@", this.goEnvironmentVariableForPurl);
423439
// Get only direct dependencies of root package/module, and that's it.

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public final class JavaMavenProvider extends BaseJavaProvider {
5454
private static final String PROP_JAVA_HOME = "JAVA_HOME";
5555
private static final Logger log = LoggersFactory.getLogger(JavaMavenProvider.class.getName());
5656
private final String mvnExecutable;
57-
private static final String MVN = "mvn";
57+
private static final String MVN = Operations.isWindows() ? "mvn.cmd" : "mvn";
5858
private static final String ARG_VERSION = "-v";
5959

6060
public JavaMavenProvider(Path manifest) {
@@ -65,7 +65,8 @@ public JavaMavenProvider(Path manifest) {
6565

6666
@Override
6767
public Content provideStack() throws IOException {
68-
var mvnCleanCmd = new String[] {mvnExecutable, "clean", "-f", manifest.toString()};
68+
var mvnCleanCmd =
69+
new String[] {mvnExecutable, "clean", "-f", manifest.toString(), "--batch-mode", "-q"};
6970
var mvnEnvs = getMvnExecEnvs();
7071
// execute the clean command
7172
Operations.runProcess(manifest.getParent(), mvnCleanCmd, mvnEnvs);
@@ -82,6 +83,8 @@ public Content provideStack() throws IOException {
8283
add(String.format("-DoutputFile=%s", tmpFile.toString()));
8384
add("-f");
8485
add(manifest.toString());
86+
add("--batch-mode");
87+
add("-q");
8588
}
8689
};
8790
// if we have dependencies marked as ignored, exclude them from the tree command
@@ -136,7 +139,9 @@ private Content generateSbomFromEffectivePom() throws IOException {
136139
"help:effective-pom",
137140
String.format("-Doutput=%s", tmpEffPom.toString()),
138141
"-f",
139-
manifest.toString()
142+
manifest.toString(),
143+
"--batch-mode",
144+
"-q"
140145
};
141146
// execute the effective pom command
142147
Operations.runProcess(manifest.getParent(), mvnEffPomCmd, getMvnExecEnvs());
@@ -372,13 +377,13 @@ public int hashCode() {
372377
private String selectMvnRuntime(final Path manifestPath) {
373378
boolean preferWrapper = Operations.getWrapperPreference(MVN);
374379
if (preferWrapper) {
375-
String wrapperName = isWindows() ? "mvnw.cmd" : "mvnw";
380+
String wrapperName = Operations.isWindows() ? "mvnw.cmd" : "mvnw";
376381
String mvnw = traverseForMvnw(wrapperName, manifestPath.toString());
377382
if (mvnw != null) {
378383
try {
379384
// verify maven wrapper is accessible
380385
Operations.runProcess(manifest.getParent(), mvnw, ARG_VERSION);
381-
log.fine("using maven wrapper from : " + mvnw);
386+
log.fine(String.format("using maven wrapper from : %s", mvnw));
382387
return mvnw;
383388
} catch (Exception e) {
384389
log.warning(
@@ -388,7 +393,7 @@ private String selectMvnRuntime(final Path manifestPath) {
388393
}
389394
// If maven wrapper is not requested or not accessible, fall back to use mvn
390395
String mvn = Operations.getExecutable(MVN, ARG_VERSION);
391-
log.fine("using mvn executable from : " + mvn);
396+
log.fine(String.format("using mvn executable from : %s", mvn));
392397
return mvn;
393398
}
394399

@@ -423,13 +428,9 @@ public static String traverseForMvnw(
423428
public static String normalizePath(String thePath) {
424429
Path normalized = Paths.get(thePath).toAbsolutePath().normalize();
425430
String result = normalized.toString();
426-
if (isWindows()) {
431+
if (Operations.isWindows()) {
427432
result = result.toLowerCase();
428433
}
429434
return result;
430435
}
431-
432-
private static boolean isWindows() {
433-
return System.getProperty("os.name").toLowerCase().contains("win");
434-
}
435436
}

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.redhat.exhort.providers;
1717

1818
import com.redhat.exhort.tools.Ecosystem;
19+
import com.redhat.exhort.tools.Operations;
1920
import java.nio.file.Path;
2021

2122
/**
@@ -25,7 +26,7 @@
2526
public final class JavaScriptNpmProvider extends JavaScriptProvider {
2627

2728
public static final String LOCK_FILE = "package-lock.json";
28-
public static final String CMD_NAME = "npm";
29+
public static final String CMD_NAME = Operations.isWindows() ? "npm.cmd" : "npm";
2930

3031
public JavaScriptNpmProvider(Path manifest) {
3132
super(manifest, Ecosystem.Type.NPM, CMD_NAME);
@@ -38,25 +39,11 @@ protected String lockFileName() {
3839

3940
@Override
4041
protected String[] updateLockFileCmd(Path manifestDir) {
41-
return new String[] {
42-
packageManager(), "i", "--package-lock-only", "--prefix", manifestDir.toString()
43-
};
42+
return new String[] {packageManager(), "i", "--package-lock-only"};
4443
}
4544

4645
@Override
4746
protected String[] listDepsCmd(boolean includeTransitive, Path manifestDir) {
48-
if (manifestDir != null) {
49-
return new String[] {
50-
packageManager(),
51-
"ls",
52-
includeTransitive ? "--all" : "--depth=0",
53-
"--omit=dev",
54-
"--package-lock-only",
55-
"--json",
56-
"--prefix",
57-
manifestDir.toString()
58-
};
59-
}
6047
return new String[] {
6148
packageManager(),
6249
"ls",

0 commit comments

Comments
 (0)