1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package oshi.software.os.linux.proc;
18
19 import java.io.FileNotFoundException;
20 import java.io.FileReader;
21 import java.util.Scanner;
22
23 import oshi.software.os.OperatingSystemVersion;
24
25
26
27
28
29
30
31
32 public class OSVersionInfoEx implements OperatingSystemVersion {
33
34 private String _version = null;
35 private String _codeName = null;
36 private String version = null;
37
38 public OSVersionInfoEx() {
39 try (Scanner in = new Scanner(new FileReader("/etc/os-release"))) {
40 in.useDelimiter("\n");
41 while (in.hasNext()) {
42 String[] splittedLine = in.next().split("=");
43 if (splittedLine[0].equals("VERSION_ID")) {
44
45
46 setVersion(splittedLine[1].replaceAll("^\"|\"$", ""));
47 }
48 if (splittedLine[0].equals("VERSION")) {
49
50 splittedLine[1] = splittedLine[1].replaceAll("^\"|\"$", "");
51
52
53
54
55
56
57 String[] split = splittedLine[1].split("[()]");
58 if (split.length <= 1)
59
60
61 split = splittedLine[1].split(", ");
62
63 if (split.length > 1) {
64 setCodeName(split[1]);
65 } else {
66 setCodeName(splittedLine[1]);
67 }
68 }
69 }
70 } catch (FileNotFoundException e) {
71 return;
72 }
73 }
74
75
76
77
78 public String getCodeName() {
79 return this._codeName;
80 }
81
82
83
84
85 public String getVersion() {
86 return this._version;
87 }
88
89
90
91
92
93 public void setCodeName(String _codeName) {
94 this._codeName = _codeName;
95 }
96
97
98
99
100
101 public void setVersion(String _version) {
102 this._version = _version;
103 }
104
105 @Override
106 public String toString() {
107 if (this.version == null) {
108 this.version = getVersion() + " (" + getCodeName() + ")";
109 }
110 return this.version;
111 }
112
113 }