View Javadoc

1   /**
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package org.apache.hadoop.hbase.util;
22  
23  import org.apache.commons.logging.LogFactory;
24  import java.io.PrintWriter;
25  
26  import org.apache.hadoop.hbase.VersionAnnotation;
27  import org.apache.hadoop.hbase.master.HMaster;
28  import org.apache.commons.logging.Log;
29  
30  /**
31   * This class finds the package info for hbase and the VersionAnnotation
32   * information.  Taken from hadoop.  Only name of annotation is different.
33   */
34  public class VersionInfo {
35    private static final Log LOG = LogFactory.getLog(VersionInfo.class.getName());
36    private static Package myPackage;
37    private static VersionAnnotation version;
38  
39    static {
40      myPackage = VersionAnnotation.class.getPackage();
41      version = myPackage.getAnnotation(VersionAnnotation.class);
42    }
43  
44    /**
45     * Get the meta-data for the hbase package.
46     * @return package
47     */
48    static Package getPackage() {
49      return myPackage;
50    }
51  
52    /**
53     * Get the hbase version.
54     * @return the hbase version string, eg. "0.6.3-dev"
55     */
56    public static String getVersion() {
57      return version != null ? version.version() : "Unknown";
58    }
59  
60    /**
61     * Get the subversion revision number for the root directory
62     * @return the revision number, eg. "451451"
63     */
64    public static String getRevision() {
65      return version != null ? version.revision() : "Unknown";
66    }
67  
68    /**
69     * The date that hbase was compiled.
70     * @return the compilation date in unix date format
71     */
72    public static String getDate() {
73      return version != null ? version.date() : "Unknown";
74    }
75  
76    /**
77     * The user that compiled hbase.
78     * @return the username of the user
79     */
80    public static String getUser() {
81      return version != null ? version.user() : "Unknown";
82    }
83  
84    /**
85     * Get the subversion URL for the root hbase directory.
86     * @return the url
87     */
88    public static String getUrl() {
89      return version != null ? version.url() : "Unknown";
90    }
91    
92    static String[] versionReport() {
93      return new String[] {
94        "HBase " + getVersion(),
95        "Subversion " + getUrl() + " -r " + getRevision(),
96        "Compiled by " + getUser() + " on " + getDate()
97        };
98    }
99  
100   public static void writeTo(PrintWriter out) {
101     for (String line : versionReport()) {
102       out.println(line);
103     }
104   }
105 
106   public static void logVersion() {
107     for (String line : versionReport()) {
108       LOG.info(line);
109     }
110   }
111 
112   public static void main(String[] args) {
113     logVersion();
114   }
115 }