
package uk.co.wingpath.util;

import java.io.*;

/**
* This class provides a single static method for getting the version
* string of a product.
*/
public class Version
{
    static String version = null;

    private Version ()
    {
    }

    /**
    * Gets the product version.
    * <p>The product version is assumed to be stored in a resource file called
    * <code>VERSION</code>.
    * A single line is read from the resource file and returned.
    * @return version string, or an empty string if the resource could not
    * be read.
    */
    public static String getProductVersion ()
    {
        if (version != null)
            return version;
        ClassLoader cl = ClassLoader.getSystemClassLoader ();
        InputStream is = cl.getResourceAsStream ("VERSION");
        if (is == null)
        {
// System.out.println ("getProductVersion: Can't get 'VERSION' resource");
            version = "";
        }
        else
        {
            BufferedReader bf = new BufferedReader (new InputStreamReader (is));
            try
            {
                version = bf.readLine ();
            }
            catch (IOException e)
            {
// System.out.println ("getProductVersion: exception " + e.getMessage ());
            }
        }
// System.out.println ("getProductVersion: version " + version);
        return version;
    }
}

