Griffon 1.2.0

griffon.util
[Java] Class GriffonUtil

java.lang.Object
  GriffonNameUtils
      griffon.util.GriffonUtil

public class GriffonUtil
extends GriffonNameUtils

Griffon utility methods for command line and GUI applications

Authors:
Graeme Rocher (Grails 0.2)


Field Summary
private static String GRIFFON_IMPLEMENTATION_TITLE

private static String[] GRIFFON_PACKAGES

private static String GRIFFON_VERSION

private static Log LOG

private static Log STACK_LOG

 
Constructor Summary
private GriffonUtil()

 
Method Summary
static Throwable deepSanitize(Throwable t)

static void deprecated(Class clazz, String methodOrPropName)

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

static void deprecated(Class clazz, String methodOrPropName, String version)

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

static void deprecated(String message)

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

static Throwable extractRootCause(Throwable t)

static String getEnvironment()

Retrieves the current execution environment

static String getGriffonVersion()

static String getNameFromScript(String scriptName)

Calculates the class name from a script name in the form my-funk-griffon-script

static String getPluginName(String descriptorName)

Returns the name of a plugin given the name of the *GriffonPlugin.groovy descriptor file.

static String getScriptName(Class clazz)

Retrieves the script name representation of the supplied class.

static String getScriptName(String name)

Retrieves the script name representation of the given class name.

static boolean isApplicationClass(String className)

static boolean isDevelopmentEnv()

Retrieves whether the current execution environment is the development one

static void printSanitizedStackTrace(Throwable t, PrintWriter p)

static void printSanitizedStackTrace(Throwable t)

static Throwable sanitize(Throwable t)

static Throwable sanitizeRootCause(Throwable t)

static void warn(String message)

Logs warning message to griffon.util.GriffonUtil logger which is turned on in development mode.

static void writeSlurperResult(GPathResult result, Writer output)

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

 

Field Detail

GRIFFON_IMPLEMENTATION_TITLE

private static final String GRIFFON_IMPLEMENTATION_TITLE


GRIFFON_PACKAGES

private static final String[] GRIFFON_PACKAGES


GRIFFON_VERSION

private static final String GRIFFON_VERSION


LOG

private static final Log LOG


STACK_LOG

private static final Log STACK_LOG


 
Constructor Detail

GriffonUtil

private GriffonUtil()


 
Method Detail

deepSanitize

public static Throwable deepSanitize(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 griffon runtime classes


deprecated

public static void deprecated(Class clazz, 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(Class clazz, String methodOrPropName, 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 Griffon release in which property or method were deprecated


deprecated

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


extractRootCause

public static Throwable extractRootCause(Throwable t)

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

Parameters:
t - the throwable to sanitize
Returns:
The deepest cause of the exception that can be found


getEnvironment

public static String getEnvironment()
Retrieves the current execution environment
Returns:
The environment Griffon is executing under


getGriffonVersion

public static String getGriffonVersion()


getNameFromScript

public static String getNameFromScript(String scriptName)
Calculates the class name from a script name in the form my-funk-griffon-script
Parameters:
scriptName - The script name
Returns:
A class name


getPluginName

public static String getPluginName(String descriptorName)
Returns the name of a plugin given the name of the *GriffonPlugin.groovy descriptor file. For example, "DbUtilsGriffonPlugin.groovy" gives "db-utils".
throws:
IllegalArgumentException if the given descriptor name is not valid, i.e. if it doesn't end with "GriffonPlugin.groovy".
Parameters:
descriptorName - The simple name of the plugin descriptor.
Returns:
The plugin name for the descriptor, or null if descriptorName is null, or an empty string if descriptorName is an empty string.


getScriptName

public static String getScriptName(Class clazz)
Retrieves the script name representation of the supplied class. For example MyFunkyGriffonScript would be my-funky-griffon-script
Parameters:
clazz - The class to convert
Returns:
The script name representation


getScriptName

public static String getScriptName(String name)
Retrieves the script name representation of the given class name. For example MyFunkyGriffonScript would be my-funky-griffon-script.
Parameters:
name - The class name to convert.
Returns:
The script name representation.


isApplicationClass

public static boolean isApplicationClass(String className)


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(Throwable t, PrintWriter p)


printSanitizedStackTrace

public static void printSanitizedStackTrace(Throwable t)


sanitize

public static Throwable sanitize(Throwable t)

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

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

Parameters:
t
Returns:
The exception passed in, after cleaning the stack trace


sanitizeRootCause

public static Throwable sanitizeRootCause(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 - the throwable to sanitize
Returns:
The root cause exception instance, with its stace trace modified to filter out griffon runtime classes


warn

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


writeSlurperResult

public static void writeSlurperResult(GPathResult result, Writer output)
Writes out a GPathResult (i.e. the result of parsing XML using XmlSlurper) to the given writer.
throws:
java.io.IOException If the writing fails due to a closed stream or unwritable file.
Parameters:
result - The root node of the XML to write out.
output - Where to write the XML to.


 

Groovy Documentation