/*
BuildInfo.java
Created: 12 September 2013
Module By: Jonathan Abbey, jonabbey@arlut.utexas.edu
-----------------------------------------------------------------------
Ganymede Directory Management System
Copyright (C) 1996-2013
The University of Texas at Austin
Ganymede is a registered trademark of The University of Texas at Austin
Contact information
Web site: http://www.arlut.utexas.edu/gash2
Author Email: ganymede_author@arlut.utexas.edu
Email mailing list: ganymede@arlut.utexas.edu
US Mail:
Computer Science Division
Applied Research Laboratories
The University of Texas at Austin
PO Box 8029, Austin TX 78713-8029
Telephone: (512) 835-3200
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package arlut.csd.ganymede.common;
import java.io.InputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import arlut.csd.Util.TranslationService;
/*------------------------------------------------------------------------------
class
BuildInfo
------------------------------------------------------------------------------*/
/**
* <p>Provides access to build-time metadata, including the time that
* the Ganymede code was compiled into jar files, the name of the
* system the build was done on, and the version of Java.</p>
*
* <p>The build.properties file used by this class is generated by the
* Ganymede 'ant jars' task in the top-level build.xml file.</p>
*/
public class BuildInfo {
/**
* <p>TranslationService object for handling string localization in
* the Ganymede server.</p>
*/
static final public TranslationService ts =
TranslationService.getTranslationService("arlut.csd.ganymede.common.BuildInfo");
private final static Properties properties = new Properties();
/**
* <p>Parses dates placed into the build.properties file at build
* time by Ant. Do not change format.</p>
*/
private static SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
// "EEE, dd MMM yyyy HH:mm:ss z"
private static SimpleDateFormat dateFormatter = new SimpleDateFormat(ts.l("date_format"));
private static Date buildDate = null;
private static String buildHost = null;
private static String buildJVM = null;
private static String releaseString = null;
private static String serverHost = null;
private static String serverPort = null;
// We're going to load all our properties and build all of our
// strings up front so that we can pop up the 'About Ganymede'
// dialog as fast as possible in the Ganymede client and admin
// console.
static
{
loadProps();
getBuildDate();
getBuildJVM();
getBuildHost();
getReleaseString();
getServerHost();
getServerPort();
}
// ---
private synchronized static void loadProps()
{
InputStream inStream = null;
try
{
inStream = BuildInfo.class.getResourceAsStream("build.properties");
properties.load(inStream);
getBuildDate();
}
catch (IOException ex)
{
}
finally
{
if (inStream != null)
{
try
{
inStream.close();
}
catch (IOException ex)
{
}
}
}
}
public synchronized static Date getBuildDate()
{
if (BuildInfo.buildDate == null)
{
String dateString = properties.getProperty("build_date");
try
{
BuildInfo.buildDate = dateParser.parse(dateString);
}
catch (ParseException ex)
{
}
}
if (BuildInfo.buildDate == null)
{
return null;
}
return new Date(BuildInfo.buildDate.getTime());
}
public synchronized static String getBuildJVM()
{
if (BuildInfo.buildJVM == null)
{
BuildInfo.buildJVM = properties.getProperty("build_jvm");
}
return BuildInfo.buildJVM;
}
public synchronized static String getBuildHost()
{
if (BuildInfo.buildHost == null)
{
BuildInfo.buildHost = properties.getProperty("build_host");
}
return BuildInfo.buildHost;
}
/**
* <p>Returns a release string suitable for inclusion in the About
* Ganymede dialog and elsewhere.</p>
*/
public synchronized static String getReleaseString()
{
if (BuildInfo.releaseString == null)
{
String dateString = dateFormatter.format(getBuildDate());
// "{0} on {2} with Java {1}"
BuildInfo.releaseString = ts.l("release_string", dateString, getBuildJVM(), getBuildHost());
}
return BuildInfo.releaseString;
}
public synchronized static String getServerHost()
{
if (BuildInfo.serverHost == null)
{
BuildInfo.serverHost = properties.getProperty("ganymede.serverhost");
}
return BuildInfo.serverHost;
}
public synchronized static String getServerPort()
{
if (BuildInfo.serverPort == null)
{
BuildInfo.serverPort = properties.getProperty("ganymede.serverPort");
}
return BuildInfo.serverPort;
}
}