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.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.classification.InterfaceStability;
27 import org.apache.hadoop.hbase.VersionAnnotation;
28 import org.apache.commons.logging.Log;
29
30
31
32
33
34 @InterfaceAudience.Public
35 @InterfaceStability.Evolving
36 public class VersionInfo {
37 private static final Log LOG = LogFactory.getLog(VersionInfo.class.getName());
38 private static Package myPackage;
39 private static VersionAnnotation version;
40
41 static {
42 myPackage = VersionAnnotation.class.getPackage();
43 version = myPackage.getAnnotation(VersionAnnotation.class);
44 }
45
46
47
48
49
50 static Package getPackage() {
51 return myPackage;
52 }
53
54
55
56
57
58 public static String getVersion() {
59 return version != null ? version.version() : "Unknown";
60 }
61
62
63
64
65
66 public static String getRevision() {
67 return version != null ? version.revision() : "Unknown";
68 }
69
70
71
72
73
74 public static String getDate() {
75 return version != null ? version.date() : "Unknown";
76 }
77
78
79
80
81
82 public static String getUser() {
83 return version != null ? version.user() : "Unknown";
84 }
85
86
87
88
89
90 public static String getUrl() {
91 return version != null ? version.url() : "Unknown";
92 }
93
94 static String[] versionReport() {
95 return new String[] {
96 "HBase " + getVersion(),
97 "Source code repository " + getUrl() + " revision=" + getRevision(),
98 "Compiled by " + getUser() + " on " + getDate(),
99 "From source with checksum " + getSrcChecksum()
100 };
101 }
102
103
104
105
106
107 public static String getSrcChecksum() {
108 return version != null ? version.srcChecksum() : "Unknown";
109 }
110
111 public static void writeTo(PrintWriter out) {
112 for (String line : versionReport()) {
113 out.println(line);
114 }
115 }
116
117 public static void writeTo(PrintStream out) {
118 for (String line : versionReport()) {
119 out.println(line);
120 }
121 }
122
123 public static void logVersion() {
124 for (String line : versionReport()) {
125 LOG.info(line);
126 }
127 }
128
129 public static void main(String[] args) {
130 writeTo(System.out);
131 }
132 }