1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.util;
20
21 import org.apache.commons.logging.LogFactory;
22 import java.io.PrintStream;
23 import java.io.PrintWriter;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.hadoop.hbase.Version;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.hadoop.hbase.classification.InterfaceStability;
29
30
31
32
33 @InterfaceAudience.Public
34 @InterfaceStability.Evolving
35 public class VersionInfo {
36 private static final Log LOG = LogFactory.getLog(VersionInfo.class.getName());
37
38
39
40 private static int VERY_LARGE_NUMBER = 100000;
41
42
43
44
45
46 public static String getVersion() {
47 return Version.version;
48 }
49
50
51
52
53
54 public static String getRevision() {
55 return Version.revision;
56 }
57
58
59
60
61
62 public static String getDate() {
63 return Version.date;
64 }
65
66
67
68
69
70 public static String getUser() {
71 return Version.user;
72 }
73
74
75
76
77
78 public static String getUrl() {
79 return Version.url;
80 }
81
82 static String[] versionReport() {
83 return new String[] {
84 "HBase " + getVersion(),
85 "Source code repository " + getUrl() + " revision=" + getRevision(),
86 "Compiled by " + getUser() + " on " + getDate(),
87 "From source with checksum " + getSrcChecksum()
88 };
89 }
90
91
92
93
94
95 public static String getSrcChecksum() {
96 return Version.srcChecksum;
97 }
98
99 public static void writeTo(PrintWriter out) {
100 for (String line : versionReport()) {
101 out.println(line);
102 }
103 }
104
105 public static void writeTo(PrintStream out) {
106 for (String line : versionReport()) {
107 out.println(line);
108 }
109 }
110
111 public static void logVersion() {
112 for (String line : versionReport()) {
113 LOG.info(line);
114 }
115 }
116
117 public static int compareVersion(String v1, String v2) {
118
119 if (v1.equals(v2)) {
120 return 0;
121 }
122
123 String s1[] = v1.split("\\.|-");
124 String s2[] = v2.split("\\.|-");
125 int index = 0;
126 while (index < s1.length && index < s2.length) {
127 int va = VERY_LARGE_NUMBER, vb = VERY_LARGE_NUMBER;
128 try {
129 va = Integer.parseInt(s1[index]);
130 } catch (Exception ingore) {
131 }
132 try {
133 vb = Integer.parseInt(s2[index]);
134 } catch (Exception ingore) {
135 }
136 if (va != vb) {
137 return va - vb;
138 }
139 if (va == VERY_LARGE_NUMBER) {
140
141 int c = s1[index].compareTo(s2[index]);
142 if (c != 0) {
143 return c;
144 }
145 }
146 index++;
147 }
148 if (index < s1.length) {
149
150 return 1;
151 }
152
153 return -1;
154 }
155
156
157 public static void main(String[] args) {
158 writeTo(System.out);
159 }
160 }