Class Environment
java.lang.Object
clazzfish.monitor.util.Environment
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 no longer final to be able to derive from it. This class was copied from PatternTesting.
- Author:
- oliver
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
System property to disable multithreading.static final Environment
The only instance of this class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
To be able to use different "environment" this class can now be sub-classed. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
In some JEE environment like Google's App Engine (GAE) it is not allowed to use multi threading.static ClassLoader
Gets the class loader.static File
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
If we are in a Google App Engine (GAE) environment we will return true here.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
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.
-
Field Details
-
INSTANCE
The only instance of this class. -
DISABLE_THREADS
-
-
Constructor Details
-
Environment
protected Environment()To be able to use different "environment" this class can now be sub-classed.
-
-
Method Details
-
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
-
matchesOneOf
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
Returns true if the given property is set as System property and the value of it is not false.- Parameters:
key
- e.g. "clazzfish.runTestsParallel"- Returns:
- true if property is set
-
loadProperties
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
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 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
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.
-