■ ■ ■ ■ ■ ■
src/main/java/io/onedev/agent/ExecutorUtils.java
1 | 1 | | package io.onedev.agent; |
2 | 2 | | |
| 3 | + | import java.io.ByteArrayOutputStream; |
3 | 4 | | import java.nio.charset.StandardCharsets; |
4 | 5 | | import java.util.UUID; |
5 | | - | import java.util.concurrent.atomic.AtomicReference; |
6 | 6 | | |
7 | 7 | | import org.apache.commons.lang3.SystemUtils; |
8 | 8 | | import org.slf4j.Logger; |
9 | 9 | | import org.slf4j.LoggerFactory; |
10 | 10 | | |
11 | | - | import io.onedev.commons.utils.ExplicitException; |
12 | 11 | | import io.onedev.commons.utils.StringUtils; |
13 | 12 | | import io.onedev.commons.utils.TaskLogger; |
14 | 13 | | import io.onedev.commons.utils.command.Commandline; |
| skipped 41 lines |
56 | 55 | | |
57 | 56 | | public static OsInfo getOsInfo() { |
58 | 57 | | String osName; |
59 | | - | AtomicReference<String> osVersion = new AtomicReference<>(null); |
| 58 | + | String osVersion; |
60 | 59 | | if (SystemUtils.IS_OS_WINDOWS) { |
61 | 60 | | osName = "Windows"; |
62 | 61 | | |
63 | 62 | | logger.info("Checking Windows OS version..."); |
64 | 63 | | |
65 | | - | Commandline systemInfo = new Commandline("systemInfo"); |
| 64 | + | Commandline systemInfo = new Commandline("cmd").addArgs("/c", "ver"); |
66 | 65 | | |
67 | | - | systemInfo.execute(new LineConsumer() { |
68 | | - | |
69 | | - | @Override |
70 | | - | public void consume(String line) { |
71 | | - | if (line.startsWith("OS Version:")) |
72 | | - | osVersion.set(StringUtils.substringBefore(StringUtils.substringAfter(line, ":").trim(), " ")); |
73 | | - | } |
74 | | - | |
75 | | - | }, new LineConsumer() { |
| 66 | + | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 67 | + | systemInfo.execute(baos, new LineConsumer() { |
76 | 68 | | |
77 | 69 | | @Override |
78 | 70 | | public void consume(String line) { |
| skipped 2 lines |
81 | 73 | | |
82 | 74 | | }).checkReturnCode(); |
83 | 75 | | |
84 | | - | if (osVersion.get() == null) |
85 | | - | throw new ExplicitException("Unable to find Windows OS version"); |
| 76 | + | String output = baos.toString(); |
| 77 | + | osVersion = StringUtils.substringBeforeLast(output, "."); |
| 78 | + | osVersion = StringUtils.substringAfterLast(osVersion, " "); |
| 79 | + | logger.info("Windows OS version: " + osVersion); |
86 | 80 | | } else { |
87 | 81 | | osName = System.getProperty("os.name"); |
88 | | - | osVersion.set(System.getProperty("os.version")); |
| 82 | + | osVersion = System.getProperty("os.version"); |
89 | 83 | | } |
90 | 84 | | |
91 | | - | return new OsInfo(osName, osVersion.get(), System.getProperty("os.arch")); |
| 85 | + | return new OsInfo(osName, osVersion, System.getProperty("os.arch")); |
92 | 86 | | } |
93 | 87 | | |
94 | 88 | | } |
| skipped 1 lines |