Class Environment

java.lang.Object
clazzfish.monitor.util.Environment

public class Environment extends 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 no longer final to be able to derive from it. This class was copied from PatternTesting.

Author:
oliver
  • Field Details

    • INSTANCE

      public static final Environment INSTANCE
      The only instance of this class.
    • DISABLE_THREADS

      public static final String DISABLE_THREADS
      System property to disable multithreading.
      See Also:
  • Constructor Details

    • Environment

      protected Environment()
      To be able to use different "environment" this class can now be sub-classed.
  • Method Details

    • 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()
      Gets the class loader.
      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. "clazzfish.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

      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.