001/* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2015 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 029package edu.wisc.ssec.mcidasv.util; 030 031import static edu.wisc.ssec.mcidasv.Constants.PROP_VERSION_MAJOR; 032import static edu.wisc.ssec.mcidasv.Constants.PROP_VERSION_MINOR; 033import static edu.wisc.ssec.mcidasv.Constants.PROP_VERSION_RELEASE; 034import static edu.wisc.ssec.mcidasv.Constants.PROP_BUILD_DATE; 035 036import java.io.InputStream; 037import java.util.Properties; 038 039/** 040 * This class is really just a wrapper around {@link #getVersion()}. 041 */ 042public class GetVer { 043 044 /** 045 * Open for reading, a resource of the specified name from the search path 046 * used to load classes. This method locates the resource through the 047 * system class loader. 048 * 049 * @param name Resource to read. 050 * 051 * @return An {@code InputStream} for reading the resource given by 052 * {@code name}, or {@code null}. 053 */ 054 public InputStream getResourceAsStream(String name) { 055 return ClassLoader.getSystemResourceAsStream(name); 056 } 057 058 /** 059 * Extracts and returns McIDAS-V version information. 060 * 061 * @return {@code String} formatted like {@literal "McIDAS-V version VERSIONHERE built BUILDDATEHERE"}. 062 * 063 * @throws Exception 064 */ 065 public static String getVersion() throws Exception { 066 GetVer nonStaticInstance = new GetVer(); 067 String version = "Unknown"; 068 String date = "Unknown"; 069 Properties props = new Properties(); 070 InputStream is = nonStaticInstance.getResourceAsStream("edu/wisc/ssec/mcidasv/resources/build.properties"); 071 if (is != null) { 072 props.load(is); 073 String maj = props.getProperty(PROP_VERSION_MAJOR, "0"); 074 String min = props.getProperty(PROP_VERSION_MINOR, "0"); 075 String rel = props.getProperty(PROP_VERSION_RELEASE, ""); 076 date = props.getProperty(PROP_BUILD_DATE, ""); 077 version = maj.concat(".").concat(min).concat(rel); 078 } 079 return "McIDAS-V version "+version+" built "+date; 080 } 081 082 /** 083 * The main. Get McIDAS-V version and build data and print it out. 084 * 085 * @param args Ignored. 086 */ 087 public static void main(String[] args) { 088 try { 089 System.out.println(getVersion()); 090 } catch (Exception e) { 091 System.err.println("Error getting McIDAS-V version: "+e); 092 } 093 } 094}