package org.jboss;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
public final class Version
{
public final static String VERSION_MAJOR = "version.major";
public final static String VERSION_MINOR = "version.minor";
public final static String VERSION_REVISION = "version.revision";
public final static String VERSION_TAG = "version.tag";
public final static String VERSION_NAME = "version.name";
public final static String VERSION_CVSTAG = "version.cvstag";
public final static String BUILD_NUMBER = "build.number";
public final static String BUILD_ID = "build.id";
public final static String BUILD_DATE = "build.day";
public final static String BUILD_JVM_VERSION = "java.vm.version";
public final static String BUILD_JVM_VENDOR = "java.vendor";
public final static String BUILD_OS = "os.name";
public final static String BUILD_OS_ARCH = "os.arch";
public final static String BUILD_OS_VERSION = "os.version";
private static Version instance = null;
private Properties props;
private Version()
{
props = loadProperties();
}
public static Version getInstance()
{
if (instance == null)
{
instance = new Version();
}
return instance;
}
public Map getProperties()
{
return Collections.unmodifiableMap(props);
}
public String getProperty(final String name)
{
return props.getProperty(name);
}
public int getMajor()
{
return getIntProperty(VERSION_MAJOR);
}
public int getMinor()
{
return getIntProperty(VERSION_MINOR);
}
public int getRevision()
{
return getIntProperty(VERSION_REVISION);
}
public String getTag()
{
return props.getProperty(VERSION_TAG);
}
public String getCvsTag()
{
return props.getProperty(VERSION_CVSTAG);
}
public String getName()
{
return props.getProperty(VERSION_NAME);
}
public String getBuildID()
{
return props.getProperty(BUILD_ID);
}
public String getBuildNumber()
{
return props.getProperty(BUILD_NUMBER);
}
public String getBuildDate()
{
return props.getProperty(BUILD_DATE);
}
public String getBuildJVM()
{
String vm = props.getProperty(BUILD_JVM_VERSION);
String vendor = props.getProperty(BUILD_JVM_VENDOR);
return vm + '(' + vendor + ')';
}
public String getBuildOS()
{
String os = props.getProperty(BUILD_OS);
String arch = props.getProperty(BUILD_OS_ARCH);
String version = props.getProperty(BUILD_OS_VERSION);
return os + '(' + arch +',' + version + ')';
}
public String toString()
{
StringBuffer buff = new StringBuffer();
buff.append(getMajor()).append(".");
buff.append(getMinor()).append(".");
buff.append(getRevision()).append(getTag());
buff.append("(build: CVSTag=");
buff.append(getCvsTag());
buff.append(" date=");
buff.append(getBuildID());
buff.append(")");
return buff.toString();
}
private int getIntProperty(final String name)
{
try
{
return Integer.valueOf(props.getProperty(name)).intValue();
}
catch (Exception e)
{
return -1;
}
}
private Properties loadProperties()
{
props = new Properties();
try
{
InputStream in =
Version.class.getResourceAsStream("/org/jboss/version.properties");
props.load(in);
in.close();
}
catch (IOException e)
{
throw new Error("Missing version.properties");
}
return props;
}
}