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.PrintWriter;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.hadoop.hbase.Version;
26  import org.apache.hadoop.hbase.classification.InterfaceAudience;
27  import org.apache.hadoop.hbase.classification.InterfaceStability;
28  
29  /**
30   * This class finds the Version information for HBase.
31   */
32  @InterfaceAudience.Public
33  @InterfaceStability.Evolving
34  public class VersionInfo {
35    private static final Log LOG = LogFactory.getLog(VersionInfo.class.getName());
36  
37    /**
38     * Get the hbase version.
39     * @return the hbase version string, eg. "0.6.3-dev"
40     */
41    public static String getVersion() {
42      return Version.version;
43    }
44  
45    /**
46     * Get the subversion revision number for the root directory
47     * @return the revision number, eg. "451451"
48     */
49    public static String getRevision() {
50      return Version.revision;
51    }
52  
53    /**
54     * The date that hbase was compiled.
55     * @return the compilation date in unix date format
56     */
57    public static String getDate() {
58      return Version.date;
59    }
60  
61    /**
62     * The user that compiled hbase.
63     * @return the username of the user
64     */
65    public static String getUser() {
66      return Version.user;
67    }
68  
69    /**
70     * Get the subversion URL for the root hbase directory.
71     * @return the url
72     */
73    public static String getUrl() {
74      return Version.url;
75    }
76  
77    static String[] versionReport() {
78      return new String[] {
79        "HBase " + getVersion(),
80        "Source code repository " + getUrl() + " revision=" + getRevision(),
81        "Compiled by " + getUser() + " on " + getDate(),
82        "From source with checksum " + getSrcChecksum()
83        };
84    }
85  
86    /**
87     * Get the checksum of the source files from which Hadoop was compiled.
88     * @return a string that uniquely identifies the source
89     **/
90    public static String getSrcChecksum() {
91      return Version.srcChecksum;
92    }
93  
94    public static void writeTo(PrintWriter out) {
95      for (String line : versionReport()) {
96        out.println(line);
97      }
98    }
99  
100   public static void logVersion() {
101     for (String line : versionReport()) {
102       LOG.info(line);
103     }
104   }
105 
106   public static void main(String[] args) {
107     logVersion();
108   }
109 }