|
1 | 1 | /* |
2 | | - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
37 | 37 | */ |
38 | 38 | import java.util.List; |
39 | 39 | import java.util.concurrent.TimeUnit; |
| 40 | +import java.util.regex.Pattern; |
| 41 | +import java.util.regex.Matcher; |
40 | 42 | import java.util.stream.Collectors; |
41 | 43 | import jdk.test.lib.Container; |
42 | 44 | import jdk.test.lib.JDKToolFinder; |
@@ -264,14 +266,16 @@ public int compareTo(PodmanVersion other) { |
264 | 266 | } |
265 | 267 |
|
266 | 268 | private static PodmanVersion fromVersionString(String version) { |
267 | | - try { |
268 | | - // Example 'podman version 3.2.1' |
269 | | - String versNums = version.split("\\s+", 3)[2]; |
270 | | - String[] numbers = versNums.split("\\.", 3); |
271 | | - return new PodmanVersion(Integer.parseInt(numbers[0]), |
272 | | - Integer.parseInt(numbers[1]), |
273 | | - Integer.parseInt(numbers[2])); |
274 | | - } catch (Exception e) { |
| 269 | + // Examples: 'podman version 3.2.1', 'podman version 4.9.4-rhel' |
| 270 | + final Pattern pattern = Pattern.compile("podman version (\\d+)\\.(\\d+)\\.(\\d+).*"); |
| 271 | + final Matcher matcher = pattern.matcher(version); |
| 272 | + |
| 273 | + if (matcher.matches()) { |
| 274 | + return new PodmanVersion( |
| 275 | + Integer.parseInt(matcher.group(1)), |
| 276 | + Integer.parseInt(matcher.group(2)), |
| 277 | + Integer.parseInt(matcher.group(3))); |
| 278 | + } else { |
275 | 279 | System.out.println("Failed to parse podman version: " + version); |
276 | 280 | return DEFAULT; |
277 | 281 | } |
|
0 commit comments