001    
002    /*
003     * Copyright (C) 2011 Archie L. Cobbs. All rights reserved.
004     *
005     * $Id: Version.java 2 2011-02-05 21:51:43Z archie.cobbs $
006     */
007    
008    package org.dellroad.stuff;
009    
010    import java.io.IOException;
011    import java.io.InputStream;
012    import java.util.Properties;
013    
014    /**
015     * Contains library version information.
016     */
017    public final class Version {
018    
019        /**
020         * The version of this library.
021         */
022        public static final String DELLROAD_STUFF_VERSION;
023    
024        private static final String PROPERTIES_RESOURCE = "/dellroad-stuff.properties";
025        private static final String VERSION_PROPERTY_NAME = "dellroad-stuff.version";
026    
027        static {
028            Properties properties = new Properties();
029            InputStream input = Version.class.getResourceAsStream(PROPERTIES_RESOURCE);
030            if (input == null)
031                throw new RuntimeException("can't find resource " + PROPERTIES_RESOURCE);
032            try {
033                properties.load(input);
034            } catch (IOException e) {
035                throw new RuntimeException("unexpected exception", e);
036            } finally {
037                try {
038                    input.close();
039                } catch (IOException e) {
040                    // ignore
041                }
042            }
043            DELLROAD_STUFF_VERSION = properties.getProperty(VERSION_PROPERTY_NAME, "?");
044        }
045    
046        private Version() {
047        }
048    }