Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/main/java/com/redhat/exhort/providers/GoModulesProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Sbom getDependenciesSbom(Path manifestPath, boolean buildTree) throws IOExceptio
boolean matchManifestVersions =
Environment.getBoolean(Provider.PROP_MATCH_MANIFEST_VERSIONS, false);
if (matchManifestVersions) {
String[] goModGraphLines = goModulesResult.split(System.lineSeparator());
String[] goModGraphLines = goModulesResult.split(Operations.GENERIC_LINE_SEPARATOR);
performManifestVersionsCheck(goModGraphLines, manifestPath);
}
if (!buildTree) {
Expand All @@ -152,7 +152,7 @@ Sbom getDependenciesSbom(Path manifestPath, boolean buildTree) throws IOExceptio
private void performManifestVersionsCheck(String[] goModGraphLines, Path manifestPath) {
try {
String goModLines = Files.readString(manifestPath);
String[] lines = goModLines.split(System.lineSeparator());
String[] lines = goModLines.split(Operations.GENERIC_LINE_SEPARATOR);
String root = getParentVertex(goModGraphLines[0]);
List<String> comparisonLines =
Arrays.stream(goModGraphLines)
Expand Down Expand Up @@ -271,7 +271,8 @@ private Sbom buildSbomFromGraph(
// iterate over go mod graph line by line and create map , with each entry to contain module as
// a key , and
// value of list of that module' dependencies.
List<String> linesList = Arrays.asList(goModulesResult.split(System.lineSeparator()));
List<String> linesList =
Arrays.asList(goModulesResult.split(Operations.GENERIC_LINE_SEPARATOR));

int startingIndex = 0;
for (String line : linesList) {
Expand Down Expand Up @@ -325,7 +326,7 @@ private Map<String, List<String>> getFinalPackagesVersionsForModule(
String finalVersionsForAllModules =
Operations.runProcessGetOutput(manifestPath.getParent(), "go", "list", "-m", "all");
Map<String, String> finalModulesVersions =
Arrays.stream(finalVersionsForAllModules.split(System.lineSeparator()))
Arrays.stream(finalVersionsForAllModules.split(Operations.GENERIC_LINE_SEPARATOR))
.filter(string -> string.trim().split(" ").length == 2)
.collect(
Collectors.toMap(
Expand Down Expand Up @@ -437,7 +438,7 @@ private String buildGoModulesDependencies(Path manifestPath) {
}

private Sbom buildSbomFromList(String golangDeps, List<PackageURL> ignoredDeps) {
String[] allModulesFlat = golangDeps.split(System.lineSeparator());
String[] allModulesFlat = golangDeps.split(Operations.GENERIC_LINE_SEPARATOR);
String parentVertex = getParentVertex(allModulesFlat[0]);
PackageURL root = toPurl(parentVertex, "@", this.goEnvironmentVariableForPurl);
// Get only direct dependencies of root package/module, and that's it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.packageurl.PackageURL;
import com.redhat.exhort.providers.javascript.model.Manifest;
import com.redhat.exhort.sbom.Sbom;
import com.redhat.exhort.tools.Operations;
import java.nio.file.Path;
import java.util.Map;
import java.util.TreeMap;
Expand All @@ -36,6 +37,7 @@ public YarnBerryProcessor(String packageManager, Manifest manifest) {
super(packageManager, manifest);
}

@Override
public String[] installCmd(Path manifestDir) {
if (manifestDir != null) {
return new String[] {
Expand Down Expand Up @@ -89,7 +91,9 @@ private boolean isRoot(String name) {

@Override
public String parseDepTreeOutput(String output) {
return "[" + output.trim().replace(System.lineSeparator(), "").replace("}{", "},{") + "]";
return "["
+ output.trim().replaceAll(Operations.GENERIC_LINE_SEPARATOR, "").replace("}{", "},{")
+ "]";
}

private PackageURL purlFromNode(String normalizedLocator, JsonNode node) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/redhat/exhort/tools/Operations.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
/** Utility class used for executing process on the operating system. * */
public final class Operations {

// Some package providers might return Unix output in Windows, so we need to use a generic line
// separator
public static final String GENERIC_LINE_SEPARATOR = "\\r?\\n";
private static final Logger log = LoggersFactory.getLogger(Operations.class.getName());

private Operations() {
Expand Down
Loading