xref: /OpenGrok/opengrok-indexer/src/main/java/org/opengrok/indexer/Info.java (revision 82105c7daea2ce6ea1053c2c4b934e54bf71b9e7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * See LICENSE.txt included in this distribution for the specific
9  * language governing permissions and limitations under the License.
10  *
11  * When distributing Covered Code, include this CDDL HEADER in each
12  * file and include the License file at LICENSE.txt.
13  * If applicable, add the following below this CDDL HEADER, with the
14  * fields enclosed by brackets "[]" replaced with your own identifying
15  * information: Portions Copyright [yyyy] [name of copyright owner]
16  *
17  * CDDL HEADER END
18  */
19 
20 /*
21  * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
22  */
23 package org.opengrok.indexer;
24 
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.Properties;
28 
29 /**
30  * Utility class to get information of the OpenGrok version.
31  *
32  * @author Trond Norbye
33  */
34 @SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
35 public final class Info {
36     private static final Properties properties = new Properties();
37 
38     private static final String VERSION;
39     private static final String REVISION;
40     private static final String REVISION_SHORT;
41 
42     private static final String UNKNOWN = "unknown";
43 
44     static {
try(InputStream in = Info.class.getResourceAsStream("info.properties"))45         try (InputStream in = Info.class.getResourceAsStream("info.properties")) {
46             if (in != null) {
47                 properties.load(in);
48             }
49             VERSION = properties.getProperty("version", UNKNOWN);
50             REVISION = properties.getProperty("changeset", UNKNOWN);
51             REVISION_SHORT = properties.getProperty("changeset_short", UNKNOWN);
52         } catch (IOException ioe) {
53             throw new RuntimeException(ioe);
54         }
55     }
56 
57     /**
58      * Get major version.
59      *
60      * @return major version
61      */
getVersion()62     public static String getVersion() {
63         return VERSION;
64     }
65 
66     /**
67      * Get full version (product vMajor revMinor).
68      *
69      * @return full version
70      */
getFullVersion()71     public static String getFullVersion() {
72         return "OpenGrok v" + VERSION + " rev " + REVISION;
73     }
74 
75     /**
76      * Get minor version.
77      *
78      * @return minor version
79      */
getRevision()80     public static String getRevision() {
81         return REVISION;
82     }
83 
84 
85     /**
86      * Get short minor version.
87      *
88      * @return short minor version
89      */
getShortRevision()90     public static String getShortRevision() {
91         return REVISION_SHORT;
92     }
93 
94 
Info()95     private Info() {
96     }
97 }
98