|
40 | 40 | import java.util.List; |
41 | 41 | import java.util.Map; |
42 | 42 | import java.util.Objects; |
| 43 | +import java.util.Optional; |
43 | 44 | import java.util.TreeMap; |
44 | 45 | import java.util.logging.Logger; |
45 | 46 | import java.util.regex.Pattern; |
@@ -381,23 +382,42 @@ private static List<String> collectAllDirectDependencies(List<String> targetLine |
381 | 382 | private TreeMap<String, String> getQualifiers(boolean includeOsAndArch) { |
382 | 383 | if (includeOsAndArch) { |
383 | 384 | String goEnvironmentVariables = Operations.runProcessGetOutput(null, goExecutable, "env"); |
384 | | - String hostArch = |
| 385 | + var qualifiers = new TreeMap<String, String>(); |
| 386 | + qualifiers.put("type", "module"); |
| 387 | + Optional<String> hostArch = |
385 | 388 | getEnvironmentVariable(goEnvironmentVariables, GO_HOST_ARCHITECTURE_ENV_NAME); |
386 | | - String hostOS = |
| 389 | + Optional<String> hostOS = |
387 | 390 | getEnvironmentVariable(goEnvironmentVariables, GO_HOST_OPERATION_SYSTEM_ENV_NAME); |
388 | | - return new TreeMap<>(Map.of("type", "module", "goos", hostOS, "goarch", hostArch)); |
| 391 | + if (hostArch.isPresent()) { |
| 392 | + qualifiers.put("goarch", hostArch.get()); |
| 393 | + } |
| 394 | + if (hostOS.isPresent()) { |
| 395 | + qualifiers.put("goos", hostOS.get()); |
| 396 | + } |
| 397 | + return qualifiers; |
389 | 398 | } |
390 | 399 |
|
391 | 400 | return new TreeMap<>(Map.of("type", "module")); |
392 | 401 | } |
393 | 402 |
|
394 | | - private static String getEnvironmentVariable(String goEnvironmentVariables, String envName) { |
| 403 | + private static Optional<String> getEnvironmentVariable( |
| 404 | + String goEnvironmentVariables, String envName) { |
395 | 405 | int i = goEnvironmentVariables.indexOf(String.format("%s=", envName)); |
| 406 | + if (i == -1) { |
| 407 | + return Optional.empty(); |
| 408 | + } |
396 | 409 | int beginIndex = i + String.format("%s=", envName).length(); |
397 | 410 | int endOfLineIndex = |
398 | 411 | goEnvironmentVariables.substring(beginIndex).indexOf(System.lineSeparator()); |
399 | | - String envValue = goEnvironmentVariables.substring(beginIndex).substring(0, endOfLineIndex); |
400 | | - return envValue.replaceAll("\"", ""); |
| 412 | + |
| 413 | + String envValue; |
| 414 | + if (endOfLineIndex == -1) { |
| 415 | + envValue = goEnvironmentVariables.substring(beginIndex); |
| 416 | + } else { |
| 417 | + envValue = goEnvironmentVariables.substring(beginIndex).substring(0, endOfLineIndex); |
| 418 | + } |
| 419 | + |
| 420 | + return Optional.of(envValue.replaceAll("\"", "")); |
401 | 421 | } |
402 | 422 |
|
403 | 423 | private String buildGoModulesDependencies(Path manifestPath) { |
|
0 commit comments