patterntesting.runtime.util
Class Environment

Package class diagram package Environment
java.lang.Object
  extended by patterntesting.runtime.util.Environment

public final class Environment
extends Object

This class provides some utilities for the access to the environment (e.g. the system properties).
TODO: Use common.lang.SystemUtils for OS_NAME or other system properties

Since:
1.0 (01.02.2010)
Author:
oliver

Field Summary
static String DISABLE_THREADS
          System property to disable multithreading.
static String INTEGRATION_TEST
          System property to enable integration tests
static boolean integrationTestEnabled
          True if property for integration test is set.
static String JAVA_VENDOR
          Java vendor (e.g.
static String JAVA_VERSION
          JDK version (e.g. "1.6.0_17").
static String OS_ARCH
          architecture (e.g.
static String OS_NAME
          operating system (e.g.
static String OS_VERSION
          os version (e.g. "10.6.2").
static String RUN_SMOKE_TESTS
          System property for annotation SmokeTest.
static String RUN_TESTS_PARALLEL
          System property for annotation RunTestsParallel.
static boolean smokeTestEnabled
          True if SmokeTest property is set.
static String USER_NAME
          User (e.g.
 
Method Summary
static boolean areThreadsAllowed()
          In some JEE environment like Google's App Engine (GAE) it is not allowed to use multi threading.
static ClassLoader getClassLoader()
           
static File getLocalMavenRepositoryDir()
          Normally you'll find the local Maven repository at ~/.m2/repository.
static String getName()
          The name of an environment is derived from the classloader.
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 it
static boolean isPropertyEnabled(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 Properties loadProperties(InputStream istream)
          Loads the properties from the given InputStream and provides them as system properties.
static Properties loadProperties(String resource)
          Loads the properties from the classpath and provides them as system properties.
static boolean matchesOneOf(String[] props)
          Looks if one of the given properties matches a system property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OS_NAME

public static final String OS_NAME
operating system (e.g. "Mac OS X").


OS_ARCH

public static final String OS_ARCH
architecture (e.g. "x86_64").


OS_VERSION

public static final String OS_VERSION
os version (e.g. "10.6.2").


JAVA_VERSION

public static final String JAVA_VERSION
JDK version (e.g. "1.6.0_17").


JAVA_VENDOR

public static final String JAVA_VENDOR
Java vendor (e.g. "Apple Inc.").


USER_NAME

public static final String USER_NAME
User (e.g. "oliver")


DISABLE_THREADS

public static final String DISABLE_THREADS
System property to disable multithreading.

See Also:
Constant Field Values

INTEGRATION_TEST

public static final String INTEGRATION_TEST
System property to enable integration tests

See Also:
Constant Field Values

RUN_TESTS_PARALLEL

public static final String RUN_TESTS_PARALLEL
System property for annotation RunTestsParallel.

See Also:
Constant Field Values

RUN_SMOKE_TESTS

public static final String RUN_SMOKE_TESTS
System property for annotation SmokeTest.

See Also:
Constant Field Values

integrationTestEnabled

public static final boolean integrationTestEnabled
True if property for integration test is set.


smokeTestEnabled

public static final boolean smokeTestEnabled
True if SmokeTest property is set.

Method Detail

getName

public static 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 ClassLoader getClassLoader()
Returns:
a valid classloader

matchesOneOf

public static boolean matchesOneOf(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(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 Properties loadProperties(String resource)
                                 throws 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:
IOException - if properties can't be loaded
See Also:
loadProperties(InputStream)

loadProperties

public static Properties loadProperties(InputStream istream)
                                 throws 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:
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 property DISABLE_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 File getLocalMavenRepositoryDir()
                                       throws 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:
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


Copyright © 2002–2014 PatternTesting Team. All rights reserved.