Groovy Documentation

grails.util
[Java] Class GrailsUtil

java.lang.Object
  grails.util.GrailsUtil

public class GrailsUtil
extends java.lang.Object

Grails utility methods for command line and GUI applications.

Authors:
Graeme Rocher
Since:
0.2


Method Summary
static org.springframework.context.ApplicationContext bootstrapGrailsFromApplication(GrailsApplication application)

Bootstraps Grails with the given GrailsApplication instance.

static org.springframework.context.ApplicationContext bootstrapGrailsFromClassPath()

static org.springframework.context.ApplicationContext bootstrapGrailsFromParentContext(org.springframework.context.ApplicationContext parent)

Bootstraps Grails from the given parent ApplicationContext which should contain a bean definition called "grailsApplication" of type GrailsApplication.

static java.lang.Throwable deepSanitize(java.lang.Throwable t)

static void deprecated(java.lang.Class clazz, java.lang.String methodOrPropName)

Logs warning message about deprecation of specified property or method of some class.

static void deprecated(java.lang.Class clazz, java.lang.String methodOrPropName, java.lang.String version)

Logs warning message about deprecation of specified property or method of some class.

static void deprecated(java.lang.String message)

Logs warning message about some deprecation and code style related hints.

static java.lang.Throwable extractRootCause(java.lang.Throwable t)

static java.lang.String getEnvironment()

Retrieves the current execution environment.

static java.lang.String getGrailsVersion()

static boolean isDevelopmentEnv()

Retrieves whether the current execution environment is the development one.

static void printSanitizedStackTrace(java.lang.Throwable t, java.io.PrintWriter p)

static void printSanitizedStackTrace(java.lang.Throwable t, java.io.PrintWriter p, StackTraceFilterer stackTraceFilterer)

static void printSanitizedStackTrace(java.lang.Throwable t)

static java.lang.Throwable sanitize(java.lang.Throwable t)

static java.lang.Throwable sanitizeRootCause(java.lang.Throwable t)

static void warn(java.lang.String message)

Logs warning message to grails.util.GrailsUtil logger which is turned on in development mode.

static void writeSlurperResult(groovy.util.slurpersupport.GPathResult result, java.io.Writer output)

Writes out a GPathResult (i.e. the result of parsing XML using XmlSlurper) to the given writer.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Method Detail

bootstrapGrailsFromApplication

public static org.springframework.context.ApplicationContext bootstrapGrailsFromApplication(GrailsApplication application)
Bootstraps Grails with the given GrailsApplication instance.
Parameters:
application - The GrailsApplication instance
Returns:
A Grails ApplicationContext


bootstrapGrailsFromClassPath

public static org.springframework.context.ApplicationContext bootstrapGrailsFromClassPath()

Bootstraps a Grails application from the current classpath. The method will look for an applicationContext.xml file in the classpath that must contain a bean of type GrailsApplication and id grailsApplication.

The method will then bootstrap Grails with the GrailsApplication and load all Grails plug-ins found in the path

Returns:
The Grails ApplicationContext instance


bootstrapGrailsFromParentContext

public static org.springframework.context.ApplicationContext bootstrapGrailsFromParentContext(org.springframework.context.ApplicationContext parent)
Bootstraps Grails from the given parent ApplicationContext which should contain a bean definition called "grailsApplication" of type GrailsApplication.


deepSanitize

public static java.lang.Throwable deepSanitize(java.lang.Throwable t)

Sanitize the exception and ALL nested causes

This will MODIFY the stacktrace of the exception instance and all its causes irreversibly

Parameters:
t
Returns:
The root cause exception instances, with stack trace modified to filter out grails runtime classes


deprecated

public static void deprecated(java.lang.Class clazz, java.lang.String methodOrPropName)
Logs warning message about deprecation of specified property or method of some class.
Parameters:
clazz - A class
methodOrPropName - Name of deprecated property or method


deprecated

public static void deprecated(java.lang.Class clazz, java.lang.String methodOrPropName, java.lang.String version)
Logs warning message about deprecation of specified property or method of some class.
Parameters:
clazz - A class
methodOrPropName - Name of deprecated property or method
version - Version of Grails release in which property or method were deprecated


deprecated

public static void deprecated(java.lang.String message)
Logs warning message about some deprecation and code style related hints.
Parameters:
message - Message to display


extractRootCause

public static java.lang.Throwable extractRootCause(java.lang.Throwable t)

Extracts the root cause of the exception, no matter how nested it is

Parameters:
t
Returns:
The deepest cause of the exception that can be found


getEnvironment

@Deprecated
public static java.lang.String getEnvironment()
Retrieves the current execution environment.
deprecated:
Use Environment.getCurrent() method instead
Returns:
The environment Grails is executing under


getGrailsVersion

public static java.lang.String getGrailsVersion()


isDevelopmentEnv

public static boolean isDevelopmentEnv()
Retrieves whether the current execution environment is the development one.
Returns:
true if it is the development environment


printSanitizedStackTrace

public static void printSanitizedStackTrace(java.lang.Throwable t, java.io.PrintWriter p)


printSanitizedStackTrace

public static void printSanitizedStackTrace(java.lang.Throwable t, java.io.PrintWriter p, StackTraceFilterer stackTraceFilterer)


printSanitizedStackTrace

public static void printSanitizedStackTrace(java.lang.Throwable t)


sanitize

@Deprecated
public static java.lang.Throwable sanitize(java.lang.Throwable t)

Remove all apparently Grails-internal trace entries from the exception instance

This modifies the original instance and returns it, it does not clone

deprecated:
Use StackTraceFilterer instead
Parameters:
t - The exception
Returns:
The exception passed in, after cleaning the stack trace


sanitizeRootCause

public static java.lang.Throwable sanitizeRootCause(java.lang.Throwable t)

Get the root cause of an exception and sanitize it for display to the user

This will MODIFY the stacktrace of the root cause exception object and return it

Parameters:
t
Returns:
The root cause exception instance, with its stace trace modified to filter out grails runtime classes


warn

public static void warn(java.lang.String message)
Logs warning message to grails.util.GrailsUtil logger which is turned on in development mode.
Parameters:
message - Message to display


writeSlurperResult

@Deprecated
public static void writeSlurperResult(groovy.util.slurpersupport.GPathResult result, java.io.Writer output)
Writes out a GPathResult (i.e. the result of parsing XML using XmlSlurper) to the given writer.
throws:
IOException If the writing fails due to a closed stream or unwritable file.
deprecated:
Will be removed in a future release
Parameters:
result - The root node of the XML to write out.
output - Where to write the XML to.


 

Groovy Documentation