com.techempower.Version Maven / Gradle / Ivy
Show all versions of gemini Show documentation
/*******************************************************************************
* Copyright (c) 2018, TechEmpower, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name TechEmpower, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS 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 TECHEMPOWER, INC. 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 com.techempower;
import java.io.*;
import java.net.*;
import java.util.*;
import com.techempower.helper.*;
/**
* Contains simple constants regarding the name, client, version number,
* etc. of the current build of the application.
*
* When building an application, subclass this class and provide an instance
* of the object in your application's constructVersion() method.
*
* Note that for Gemini applications, the GeminiApplication object will
* populate the deployment description (e.g., "Production", "Test", etc.)
* from the configuration variable "DeploymentDescription".
*/
public class Version
{
//
// Constants.
//
public static final int ENV_DEVELOPMENT = 0;
public static final int ENV_TEST = 1;
public static final int ENV_PRODUCTION = 2;
//
// Member variables.
//
private String versionString;
private String buildDate = null;
private String deploymentDescription = "Default";
private int environment = ENV_DEVELOPMENT;
//
// Member methods.
//
/**
* Constructor. This builds the version string for later calls to
* getVersionString.
*/
public Version()
{
this.versionString = getMajorVersion() + "."
+ getMinorVersion() + "."
+ getMicroVersion();
}
/**
* Get the version levels.
*/
public int getMajorVersion() { return 1; }
public int getMinorVersion() { return 1; }
public int getMicroVersion() { return 0; }
/**
* Gets the two-letter product code. The default is "GA" for "Gemini
* Application". However, applications are highly encouraged to overload
* this to provide a custom product code.
*/
public String getProductCode()
{
return "GA";
}
/**
* Gets the product name.
*/
public String getProductName()
{
return "Example";
}
/**
* Gets an abbreviated version of the product name. By default, this returns
* the product name unchanged.
*/
public String getAbbreviatedProductName()
{
return getProductName();
}
/**
* Gets the client's name.
*/
public String getClientName()
{
return "Example";
}
/**
* Gets the developer's name.
*/
public String getDeveloperName()
{
return "TechEmpower, Inc.";
}
/**
* Gets the copyright years.
*/
public String getCopyrightYears()
{
return "2018";
}
/**
* Gets the version as a readable string. The format is MAJOR.MINOR.MICRO,
* as in "1.03.15".
*/
public String getVersionString()
{
return this.versionString;
}
/**
* Sets the version string. This is usually called by the constructor only.
*/
public void setVersionString(String versionString)
{
this.versionString = versionString;
}
/**
* Gets a verbose version description composed of the application/product
* name, version number, and the build date:
*
* [abbr-product-name] [version-string] build [build-date]
*
* Example Product 1.02.03 build 2009-03-27 11:00:23
*/
public String getVerboseDescription()
{
return getAbbreviatedProductName() + " " + getVersionString() + " build " + getBuildDate();
}
/**
* Gets the Java Runtime's version information as a nice String.
*/
public String getJavaVersion()
{
return System.getProperty("java.version")
+ " (" + System.getProperty("java.vendor") + ")"
+ " on " + System.getProperty("os.name")
+ " " + System.getProperty("os.version");
}
/**
* @return Returns the deploymentDescription.
*/
public String getDeploymentDescription()
{
return this.deploymentDescription;
}
/**
* @param description The deploymentDescription to set.
*/
public void setDeploymentDescription(String description, String machineName)
{
this.deploymentDescription = description + "/" + machineName;
// Parse common words to describe environments (production, test,
// development) and set the flags accordingly.
int env = ENV_DEVELOPMENT;
if ( (StringHelper.containsIgnoreCase(description, "Test"))
|| (StringHelper.containsIgnoreCase(description, "QA"))
|| (StringHelper.containsIgnoreCase(description, "Staging"))
)
{
env = ENV_TEST;
}
if (StringHelper.containsIgnoreCase(description, "Production"))
{
env = ENV_PRODUCTION;
}
setEnvironment(env);
}
/**
* Gets the application name and the deployment description, if available.
* This returns the format of "MyApplication (Production/Some-box)" or
* "MyApplication (Development/Some-other-box)".
*/
public String getNameAndDeployment()
{
return getProductName()
+ (StringHelper.isNonEmpty(getDeploymentDescription()) ? " (" + getDeploymentDescription() + ")" : "");
}
/**
* Sets the environment type (See constants defined in this class).
*
* @param environmentType either ENV_DEVELOPMENT, ENV_TEST, or
* ENV_PRODUCTION.
*/
public void setEnvironment(int environmentType)
{
if ( (environmentType >= ENV_DEVELOPMENT)
&& (environmentType <= ENV_PRODUCTION)
)
{
this.environment = environmentType;
}
}
/**
* Gets the environment type.
*/
public int getEnvironment()
{
return this.environment;
}
/**
* Creates and returns a set of deployment environment flags. These flags
* are provided in this seemingly odd form in order to make them available
* for use in Mustache templates as conditional checks.
*
* This method constructs a new map on each call, so it is safe for callers
* to append more values to the map.
*/
public Map