View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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   * This class finds the Version information for HBase.
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     * Get the hbase version.
40     * @return the hbase version string, eg. "0.6.3-dev"
41     */
42    public static String getVersion() {
43      return Version.version;
44    }
45  
46    /**
47     * Get the subversion revision number for the root directory
48     * @return the revision number, eg. "451451"
49     */
50    public static String getRevision() {
51      return Version.revision;
52    }
53  
54    /**
55     * The date that hbase was compiled.
56     * @return the compilation date in unix date format
57     */
58    public static String getDate() {
59      return Version.date;
60    }
61  
62    /**
63     * The user that compiled hbase.
64     * @return the username of the user
65     */
66    public static String getUser() {
67      return Version.user;
68    }
69  
70    /**
71     * Get the subversion URL for the root hbase directory.
72     * @return the url
73     */
74    public static String getUrl() {
75      return Version.url;
76    }
77  
78    static String[] versionReport() {
79      return new String[] {
80        "HBase " + getVersion(),
81        "Source code repository " + getUrl() + " revision=" + getRevision(),
82        "Compiled by " + getUser() + " on " + getDate(),
83        "From source with checksum " + getSrcChecksum()
84        };
85    }
86  
87    /**
88     * Get the checksum of the source files from which Hadoop was compiled.
89     * @return a string that uniquely identifies the source
90     **/
91    public static String getSrcChecksum() {
92      return Version.srcChecksum;
93    }
94  
95    public static void writeTo(PrintWriter out) {
96      for (String line : versionReport()) {
97        out.println(line);
98      }
99    }
100 
101   public static void writeTo(PrintStream out) {
102     for (String line : versionReport()) {
103       out.println(line);
104     }
105   }
106 
107   public static void logVersion() {
108     for (String line : versionReport()) {
109       LOG.info(line);
110     }
111   }
112 
113   public static void main(String[] args) {
114     writeTo(System.out);
115   }
116 }