1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.migration.commands;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.PrintStream;
22 import java.nio.charset.Charset;
23 import java.util.Locale;
24 import java.util.Properties;
25
26 public final class InfoCommand implements Command {
27 private final PrintStream out;
28
29 public InfoCommand(PrintStream out) {
30 this.out = out;
31 }
32
33 @Override
34 public void execute(String... params) {
35 Properties properties = new Properties();
36 try (InputStream is = getClass().getResourceAsStream("/mybatis-migrations.properties")) {
37 if (is != null) {
38 properties.load(is);
39 }
40 } catch (IOException e) {
41
42 }
43
44 out.printf("%s %s (%s)%n", properties.getProperty("name"), properties.getProperty("version"),
45 properties.getProperty("build"));
46 out.printf("Java version: %s, vendor: %s%n", System.getProperty("java.version"), System.getProperty("java.vendor"));
47 out.printf("Java home: %s%n", System.getProperty("java.home"));
48 out.printf("Default locale: %s, platform encoding: %s%n", Locale.getDefault().toLanguageTag(),
49 Charset.defaultCharset().name());
50 out.printf("OS name: \"%s\", version: \"%s\", arch: \"%s\", family: \"%s\"%n", System.getProperty("os.name"),
51 System.getProperty("os.version"), System.getProperty("os.arch"), getOsFamily());
52 }
53
54 private static String getOsFamily() {
55 String osName = System.getProperty("os.name").toLowerCase();
56 String pathSep = File.pathSeparator;
57
58 if (osName.indexOf("windows") != -1) {
59 return "windows";
60 }
61
62 if (osName.indexOf("os/2") != -1) {
63 return "os/2";
64 }
65
66 if (osName.indexOf("z/os") != -1 || osName.indexOf("os/390") != -1) {
67 return "z/os";
68 }
69
70 if (osName.indexOf("os/400") != -1) {
71 return "os/400";
72 }
73
74 if (pathSep.equals(";")) {
75 return "dos";
76 }
77
78 if (osName.indexOf("mac") != -1) {
79 if (osName.endsWith("x")) {
80 return "mac";
81 }
82 return "unix";
83 }
84
85 if (osName.indexOf("nonstop_kernel") != -1) {
86 return "tandem";
87 }
88
89 if (osName.indexOf("openvms") != -1) {
90 return "openvms";
91 }
92
93 if (pathSep.equals(":")) {
94 return "unix";
95 }
96
97 return "undefined";
98 }
99
100 }