001 /*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2013
005 * Space Science and Engineering Center (SSEC)
006 * University of Wisconsin - Madison
007 * 1225 W. Dayton Street, Madison, WI 53706, USA
008 * https://www.ssec.wisc.edu/mcidas
009 *
010 * All Rights Reserved
011 *
012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013 * some McIDAS-V source code is based on IDV and VisAD source code.
014 *
015 * McIDAS-V is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU Lesser Public License as published by
017 * the Free Software Foundation; either version 3 of the License, or
018 * (at your option) any later version.
019 *
020 * McIDAS-V is distributed in the hope that it will be useful,
021 * but WITHOUT ANY WARRANTY; without even the implied warranty of
022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023 * GNU Lesser Public License for more details.
024 *
025 * You should have received a copy of the GNU Lesser Public License
026 * along with this program. If not, see http://www.gnu.org/licenses.
027 */
028 package edu.wisc.ssec.mcidasv.util;
029
030 import static edu.wisc.ssec.mcidasv.Constants.PROP_VERSION_MAJOR;
031 import static edu.wisc.ssec.mcidasv.Constants.PROP_VERSION_MINOR;
032 import static edu.wisc.ssec.mcidasv.Constants.PROP_VERSION_RELEASE;
033 import static edu.wisc.ssec.mcidasv.Constants.PROP_BUILD_DATE;
034
035 import java.io.InputStream;
036 import java.util.Properties;
037
038 /**
039 * This class is really just a wrapper around {@link #getVersion()}.
040 */
041 public class GetVer {
042
043 /**
044 * Open for reading, a resource of the specified name from the search path
045 * used to load classes. This method locates the resource through the
046 * system class loader.
047 *
048 * @param name Resource to read.
049 *
050 * @return An {@code InputStream} for reading the resource given by
051 * {@code name}, or {@code null}.
052 */
053 public InputStream getResourceAsStream(String name) {
054 return ClassLoader.getSystemResourceAsStream(name);
055 }
056
057 /**
058 * Extracts and returns McIDAS-V version information.
059 *
060 * @return {@code String} formatted like {@literal "McIDAS-V version VERSIONHERE built BUILDDATEHERE"}.
061 *
062 * @throws Exception
063 */
064 public static String getVersion() throws Exception {
065 GetVer nonStaticInstance = new GetVer();
066 String version = "Unknown";
067 String date = "Unknown";
068 Properties props = new Properties();
069 InputStream is = nonStaticInstance.getResourceAsStream("edu/wisc/ssec/mcidasv/resources/build.properties");
070 if (is != null) {
071 props.load(is);
072 String maj = props.getProperty(PROP_VERSION_MAJOR, "0");
073 String min = props.getProperty(PROP_VERSION_MINOR, "0");
074 String rel = props.getProperty(PROP_VERSION_RELEASE, "");
075 date = props.getProperty(PROP_BUILD_DATE, "");
076 version = maj.concat(".").concat(min).concat(rel);
077 }
078 return "McIDAS-V version "+version+" built "+date;
079 }
080
081 /**
082 * The main. Get McIDAS-V version and build data and print it out.
083 *
084 * @param args Ignored.
085 */
086 public static void main(String[] args) {
087 try {
088 System.out.println(getVersion());
089 } catch (Exception e) {
090 System.err.println("Error getting McIDAS-V version: "+e);
091 }
092 }
093 }