Package patterntesting.runtime.util
Class Environment
- java.lang.Object
-
- patterntesting.runtime.util.Environment
-
- Direct Known Subclasses:
TestEnvironment
public class Environment extends java.lang.Object
This class provides some utilities for the access to the environment (e.g. the system properties).If you need different environments (e.g. for testing) this class is since 1.6 no longer final to be able to derive from it.
- Since:
- 1.0 (01.02.2010)
- Author:
- oliver
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DISABLE_THREADS
System property to disable multithreading.static Environment
INSTANCE
The only instance of this class.static java.lang.String
INTEGRATION_TEST
System property to enable integration tests.static boolean
INTEGRATION_TEST_ENABLED
True if property for integration test is set.static java.lang.String
RUN_SMOKE_TESTS
System property for annotation SmokeTest.static java.lang.String
RUN_TESTS_PARALLEL
System property for annotation RunTestsParallel.static boolean
SMOKE_TEST_ENABLED
True if SmokeTest property is set.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Environment()
To be able to use different "environment" this class can now be sub-classed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
areThreadsAllowed()
In some JEE environment like Google's App Engine (GAE) it is not allowed to use multi threading.static java.lang.ClassLoader
getClassLoader()
Gets the class loader.java.lang.String
getJavaVendor()
Gets the java vendor.java.lang.String
getJavaVersion()
Gets the java version.static java.io.File
getLocalMavenRepositoryDir()
Normally you'll find the local Maven repository at ~/.m2/repository.static java.lang.String
getName()
The name of an environment is derived from the classloader.java.lang.String
getOsArch()
Gets the os arch.java.lang.String
getOsName()
Gets the os name.java.lang.String
getOsVersion()
Gets the os version.java.lang.String
getUserName()
Gets the user name.static boolean
isGoogleAppEngine()
If we are in a Google App Engine (GAE) environment we will return true here.static boolean
isJamonAvailable()
It is only tested for Jamon 2.4 and 2.7 so we look for itstatic boolean
isPropertyEnabled(java.lang.String key)
Returns true if the given property is set as System property and the value of it is not false.static boolean
isWeblogicServer()
If we are inside a Weblogic Server (WLS) we will return true here.static java.util.Properties
loadProperties(java.io.InputStream istream)
Loads the properties from the given InputStream and provides them as system properties.static java.util.Properties
loadProperties(java.lang.String resource)
Loads the properties from the classpath and provides them as system properties.static boolean
matchesOneOf(java.lang.String[] props)
Looks if one of the given properties matches a system property.
-
-
-
Field Detail
-
INSTANCE
public static final Environment INSTANCE
The only instance of this class.
-
DISABLE_THREADS
public static final java.lang.String DISABLE_THREADS
System property to disable multithreading.- See Also:
- Constant Field Values
-
INTEGRATION_TEST
public static final java.lang.String INTEGRATION_TEST
System property to enable integration tests.- See Also:
- Constant Field Values
-
RUN_TESTS_PARALLEL
public static final java.lang.String RUN_TESTS_PARALLEL
System property for annotation RunTestsParallel.- See Also:
- Constant Field Values
-
RUN_SMOKE_TESTS
public static final java.lang.String RUN_SMOKE_TESTS
System property for annotation SmokeTest.- See Also:
- Constant Field Values
-
INTEGRATION_TEST_ENABLED
public static final boolean INTEGRATION_TEST_ENABLED
True if property for integration test is set.
-
SMOKE_TEST_ENABLED
public static final boolean SMOKE_TEST_ENABLED
True if SmokeTest property is set.
-
-
Method Detail
-
getOsName
public java.lang.String getOsName()
Gets the os name.- Returns:
- e.g. "Mac OS X"
-
getOsArch
public java.lang.String getOsArch()
Gets the os arch.- Returns:
- e.g. "x86_64"
-
getOsVersion
public java.lang.String getOsVersion()
Gets the os version.- Returns:
- e.g. "10.10.2"
-
getJavaVersion
public java.lang.String getJavaVersion()
Gets the java version.- Returns:
- e.g. "1.6.0_17"
-
getJavaVendor
public java.lang.String getJavaVendor()
Gets the java vendor.- Returns:
- e.g. "Apple Inc."
-
getUserName
public java.lang.String getUserName()
Gets the user name.- Returns:
- e.g. "oliver"
-
getName
public static java.lang.String getName()
The name of an environment is derived from the classloader. I.e. on a Tomcat server the name is "org.apache.catalina".- Returns:
- e.g. "com.google.apphosting" for Google App Enginge
-
getClassLoader
public static java.lang.ClassLoader getClassLoader()
Gets the class loader.- Returns:
- a valid classloader
-
matchesOneOf
public static boolean matchesOneOf(java.lang.String[] props)
Looks if one of the given properties matches a system property. If one system property is found and this system property is not "false" true is returned.- Parameters:
props
- the properties to be checked- Returns:
- true if one of the given properties exist (and are not "false")
-
isPropertyEnabled
public static boolean isPropertyEnabled(java.lang.String key)
Returns true if the given property is set as System property and the value of it is not false.- Parameters:
key
- e.g. "patterntesting.runTestsParallel"- Returns:
- true if property is set
-
loadProperties
public static java.util.Properties loadProperties(java.lang.String resource) throws java.io.IOException
Loads the properties from the classpath and provides them as system properties.- Parameters:
resource
- the name of the classpath resource- Returns:
- the loaded properties
- Throws:
java.io.IOException
- if properties can't be loaded- See Also:
loadProperties(InputStream)
-
loadProperties
public static java.util.Properties loadProperties(java.io.InputStream istream) throws java.io.IOException
Loads the properties from the given InputStream and provides them as system properties.Note: Setting it as system property is not guaranteed to run in a cluster or cloud. E.g. on Google's App Engine this seems not to work.
- Parameters:
istream
- from here the properties are loaded- Returns:
- the loaded properties
- Throws:
java.io.IOException
- if properties can't be loaded
-
areThreadsAllowed
public static boolean areThreadsAllowed()
In some JEE environment like Google's App Engine (GAE) it is not allowed to use multi threading. But you can also disable multi threading by setting the system propertyDISABLE_THREADS
.- Returns:
- normally true
-
isGoogleAppEngine
public static boolean isGoogleAppEngine()
If we are in a Google App Engine (GAE) environment we will return true here.- Returns:
- true if application runs on GAE
-
isWeblogicServer
public static boolean isWeblogicServer()
If we are inside a Weblogic Server (WLS) we will return true here. We look only for the system property "weblogic.Name" here. Another possibility (not realized) would be to look at the classloader.- Returns:
- true inside Weblogic Server
-
getLocalMavenRepositoryDir
public static java.io.File getLocalMavenRepositoryDir() throws java.io.IOException
Normally you'll find the local Maven repository at ~/.m2/repository. But on cloudbees it is the local .repository directory. So we try to find out here which one we should use.- Returns:
- the root dir of the local Maven repository
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
isJamonAvailable
public static boolean isJamonAvailable()
It is only tested for Jamon 2.4 and 2.7 so we look for it- Returns:
- true if Jamon 2.4 or 2.7 (or greater) was found
-
-