/*---------------------------------------------------------------------------*\
$Id: 2dc5eb1e465acfe9f7c9b20904776857e969f184 $
---------------------------------------------------------------------------
This software is released under a BSD-style license:
Copyright (c) 2007 Brian M. Clapper. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. The end-user documentation included with the redistribution, if any,
must include the following acknowlegement:
"This product includes software developed by Brian M. Clapper
(bmc@clapper.org, http://www.clapper.org/bmc/). That software is
copyright (c) 2007 Brian M. Clapper."
Alternately, this acknowlegement may appear in the software itself,
if wherever such third-party acknowlegements normally appear.
3. Neither the names "clapper.org", "clapper.org Java Utility Library",
nor any of the names of the project contributors may be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
bmc@clapper.org.
4. Products derived from this software may not be called "clapper.org
Java Utility Library", nor may "clapper.org" appear in their names
without prior written permission of Brian M. Clapper.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL BRIAN M. CLAPPER BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\*---------------------------------------------------------------------------*/
package org.clapper.util.misc;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* Base class for classes that want to access and display version information
* that's stored in a resource bundle generated by
* {@link BuildInfo#makeBuildInfoBundle BuildInfo.makeBuildInfoBundle()}
* as well as a static resource bundle containing non-build related strings.
*
* @version $Revision$
*/
public abstract class VersionBase
{
/*----------------------------------------------------------------------*\
Private Constants
\*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*\
Private Instance Data
\*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*\
Constructor
\*----------------------------------------------------------------------*/
/**
* Creates a new instance of VersionBase
*/
protected VersionBase()
{
}
/*----------------------------------------------------------------------*\
Public Methods
\*----------------------------------------------------------------------*/
/**
* Get the version number.
*
* @return the version number
*/
public String getVersion()
{
return BundleUtil.getString(getVersionBundleName(),
getVersionKey(),
"?");
}
/**
* Get the copyright string.
*
* @return the copyright string.
*/
public String getCopyright()
{
return BundleUtil.getString(getVersionBundleName(),
getCopyrightKey(),
"?");
}
/**
* Get the application name.
*
* @return the application name
*/
public String getApplicationName()
{
return BundleUtil.getString(getVersionBundleName(),
getApplicationNameKey(),
"?");
}
/**
* Get the multiline version output. The returned string will have
* embedded newlines, but no trailing newline.
*
* @return the multiline version output.
*/
public String getVersionDisplay()
{
BuildInfo buildInfo = new BuildInfo(getBuildInfoBundleName());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
String versionBundle = getVersionBundleName();
pw.print(BundleUtil.getString(versionBundle,
getApplicationNameKey(),
"Unknown application"));
pw.print(", version ");
pw.println(getVersion());
pw.println(getCopyright());
pw.println();
pw.println("Build: " + buildInfo.getBuildID());
pw.println("Build date: " + buildInfo.getBuildDate());
pw.println("Built by: " + buildInfo.getBuildUserID());
pw.println("Built on: " +
buildInfo.getBuildOperatingSystem());
pw.println("Build Java VM: " +
buildInfo.getBuildJavaVM());
pw.println("Build compiler: " +
buildInfo.getBuildJavaCompiler());
pw.print("Ant version: " +
buildInfo.getBuildAntVersion());
return sw.getBuffer().toString();
}
/*----------------------------------------------------------------------*\
Protected Abstract Methods
\*----------------------------------------------------------------------*/
/**
* Get the class name of the version resource bundle, which contains
* values for the product version, copyright, etc.
*
* @return the name of the version resource bundle
*/
protected abstract String getVersionBundleName();
/**
* Get the class name of the build info resource bundle, which contains
* data about when the product was built, generated (presumably)
* during the build by
* {@link BuildInfo#makeBuildInfoBundle BuildInfo.makeBuildInfoBundle()}.
*
* @return the name of the build info resource bundle
*/
protected abstract String getBuildInfoBundleName();
/**
* Get the key for the version string. This key is presumed to be
* in the version resource bundle.
*
* @return the version string key
*/
protected abstract String getVersionKey();
/**
* Get the key for the copyright string. This key is presumed to be
* in the version resource bundle.
*
* @return the copyright string key
*/
protected abstract String getCopyrightKey();
/**
* Get the key for the name of the utility or application.
*
* @return the key
*/
protected abstract String getApplicationNameKey();
/*----------------------------------------------------------------------*\
Private Methods
\*----------------------------------------------------------------------*/
}
Ads help maintain this website.