Griffon 1.2.0

org.codehaus.griffon.cli
[Java] Class GriffonScriptRunner

java.lang.Object
  org.codehaus.griffon.cli.GriffonScriptRunner

public class GriffonScriptRunner

Class that handles Griffon command line interface for running scripts

Authors:
Graeme Rocher (Grails 0.4)


Nested Class Summary
class GriffonScriptRunner.GantCustomizer

private static class GriffonScriptRunner.ScriptAndArgs

Contains details about a Griffon command invocation such as the name of the corresponding script, the environment (if specified), and the arguments to the command.

 
Field Summary
static Closure DO_NOTHING_CLOSURE

static String KEY_SCRIPT_ARGS

static String VAR_SCRIPT_ARGS_MAP

static String VAR_SCRIPT_ENV

static String VAR_SCRIPT_FILE

static String VAR_SCRIPT_NAME

static String VAR_SCRIPT_UNPARSED_ARGS

static String VAR_SYS_PROPERTIES

private List buildListeners

private GriffonScriptRunner.GantCustomizer gantCustomizer

private CommandLineHelper helper

private boolean isInteractive

private PrintStream out

private Map scriptCache

private static Pattern scriptFilePattern

private List scriptsAllowedOutsideOfProject

private BuildSettings settings

 
Constructor Summary
GriffonScriptRunner()

GriffonScriptRunner(String griffonHome)

GriffonScriptRunner(BuildSettings settings)

 
Method Summary
void addBuildEventListener(GriffonBuildListener listener)

private static void addDependenciesToURLs(Set excludes, List urls, List runtimeDeps)

private static void addUrlsToRootLoader(URLClassLoader loader, URL[] urls)

static String askUserForBestMatch(String scriptName, List topMatches)

private int attemptPrecompiledScriptExecute(GriffonScriptRunner.ScriptAndArgs script, GantBinding binding, Resource[] allScripts)

private int callPluginOrGriffonScript(GriffonScriptRunner.ScriptAndArgs script)

private URLClassLoader createClassLoader()

Gant createGantInstance(GantBinding binding)

private int doExecuteCommand(GriffonScriptRunner.ScriptAndArgs script)

int executeCommand(String name, String args)

int executeCommand(String name, String args, String env)

int executeWithGantInstance(Gant gant, GantBinding binding)

int executeWithGantInstance(Gant gant, GantBinding binding, List targets)

private int executeWithGantInstanceNoException(Gant gant, GantBinding binding)

private static void exitWithError(String error)

private List findPotentialScripts(GriffonScriptRunner.ScriptAndArgs script, Resource[] allScripts, GantBinding binding)

static String fixScriptName(String scriptName, Resource[] allScripts)

private static URL[] getClassLoaderUrls(BuildSettings settings, Set excludes)

Creates a new root loader with the Griffon libraries and the application's plugin libraries on the classpath.

static CommandLine getCommandLine(String[] args)

static CommandLineParser getCommandLineParser()

PrintStream getOut()

static String getScriptNameFromFile(File scriptPath)

BuildSettings getSettings()

GantBinding initBinding(GantBinding binding)

Prep the binding.

private void initializeProjectInputStream(GantBinding binding)

static boolean isCommandScript(File file)

static boolean isContextlessScriptName(String scriptName)

private boolean isExternalScript(File scriptFile)

private boolean isGriffonProject()

boolean isInteractive()

private void loadScriptClass(Gant gant, String scriptName)

static void main(String[] args)

Evaluate the arguments to get the name of the script to execute, which environment to run it in, and the arguments to pass to the script.

private static GriffonScriptRunner.ScriptAndArgs processAndReturnArguments(CommandLine commandLine, GriffonScriptRunner.ScriptAndArgs info)

private static GriffonScriptRunner.ScriptAndArgs processArgumentsAndReturnScriptName(CommandLine commandLine)

private static void processSystemArguments(CommandLine allArgs, GriffonScriptRunner.ScriptAndArgs info)

void setInteractive(boolean interactive)

void setLoggingOptions()

void setOut(PrintStream outputStream)

void setRunningEnvironment(String scriptName, String env)

void setup()

static String unquote(String s)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

DO_NOTHING_CLOSURE

public static final Closure DO_NOTHING_CLOSURE


KEY_SCRIPT_ARGS

public static final String KEY_SCRIPT_ARGS


VAR_SCRIPT_ARGS_MAP

public static final String VAR_SCRIPT_ARGS_MAP


VAR_SCRIPT_ENV

public static final String VAR_SCRIPT_ENV


VAR_SCRIPT_FILE

public static final String VAR_SCRIPT_FILE


VAR_SCRIPT_NAME

public static final String VAR_SCRIPT_NAME


VAR_SCRIPT_UNPARSED_ARGS

public static final String VAR_SCRIPT_UNPARSED_ARGS


VAR_SYS_PROPERTIES

public static final String VAR_SYS_PROPERTIES


buildListeners

private List buildListeners


gantCustomizer

private GriffonScriptRunner.GantCustomizer gantCustomizer


helper

private CommandLineHelper helper


isInteractive

private boolean isInteractive


out

private PrintStream out


scriptCache

private final Map scriptCache


scriptFilePattern

private static final Pattern scriptFilePattern


scriptsAllowedOutsideOfProject

private final List scriptsAllowedOutsideOfProject


settings

private BuildSettings settings


 
Constructor Detail

GriffonScriptRunner

public GriffonScriptRunner()


GriffonScriptRunner

public GriffonScriptRunner(String griffonHome)


GriffonScriptRunner

public GriffonScriptRunner(BuildSettings settings)


 
Method Detail

addBuildEventListener

public void addBuildEventListener(GriffonBuildListener listener)


addDependenciesToURLs

private static void addDependenciesToURLs(Set excludes, List urls, List runtimeDeps)


addUrlsToRootLoader

private static void addUrlsToRootLoader(URLClassLoader loader, URL[] urls)

A Groovy RootLoader should be used to load GriffonScriptRunner, but this leaves us with a problem. If we want to extend its classpath by adding extra URLs, we have to use the addURL() method that is only public on RootLoader (it's protected on URLClassLoader). Unfortunately, due to the nature of Groovy's RootLoader a declared type of RootLoader in this class is not the same type as GriffonScriptRunner's class loader because the two are loaded by different class loaders.

In other words, we can't add URLs via the addURL() method because we can't "see" it from Java. Instead, we use reflection to invoke it.

Parameters:
loader - The root loader whose classpath we want to extend.
urls - The URLs to add to the root loader's classpath.


askUserForBestMatch

public static String askUserForBestMatch(String scriptName, List topMatches)


attemptPrecompiledScriptExecute

private int attemptPrecompiledScriptExecute(GriffonScriptRunner.ScriptAndArgs script, GantBinding binding, Resource[] allScripts)


callPluginOrGriffonScript

private int callPluginOrGriffonScript(GriffonScriptRunner.ScriptAndArgs script)


createClassLoader

private URLClassLoader createClassLoader()


createGantInstance

public Gant createGantInstance(GantBinding binding)


doExecuteCommand

private int doExecuteCommand(GriffonScriptRunner.ScriptAndArgs script)


executeCommand

public int executeCommand(String name, String args)


executeCommand

public int executeCommand(String name, String args, String env)


executeWithGantInstance

public int executeWithGantInstance(Gant gant, GantBinding binding)


executeWithGantInstance

public int executeWithGantInstance(Gant gant, GantBinding binding, List targets)


executeWithGantInstanceNoException

private int executeWithGantInstanceNoException(Gant gant, GantBinding binding)


exitWithError

private static void exitWithError(String error)


findPotentialScripts

private List findPotentialScripts(GriffonScriptRunner.ScriptAndArgs script, Resource[] allScripts, GantBinding binding)


fixScriptName

public static String fixScriptName(String scriptName, Resource[] allScripts)


getClassLoaderUrls

private static URL[] getClassLoaderUrls(BuildSettings settings, Set excludes)
Creates a new root loader with the Griffon libraries and the application's plugin libraries on the classpath.


getCommandLine

public static CommandLine getCommandLine(String[] args)


getCommandLineParser

public static CommandLineParser getCommandLineParser()


getOut

public PrintStream getOut()


getScriptNameFromFile

public static String getScriptNameFromFile(File scriptPath)


getSettings

public BuildSettings getSettings()


initBinding

public GantBinding initBinding(GantBinding binding)
Prep the binding. We add the location of Griffon_HOME under the variable name "griffonHome". We also add a closure that should be used with "includeTargets &<<" - it takes a string and returns either a file containing the named Griffon script or the script class.

So, this:

includeTargets &<< griffonScript("Init")

will load the "Init" script from $Griffon_HOME/scripts if it exists there; otherwise it will load the Init class.


initializeProjectInputStream

private void initializeProjectInputStream(GantBinding binding)


isCommandScript

public static boolean isCommandScript(File file)


isContextlessScriptName

public static boolean isContextlessScriptName(String scriptName)


isExternalScript

private boolean isExternalScript(File scriptFile)


isGriffonProject

private boolean isGriffonProject()


isInteractive

public boolean isInteractive()


loadScriptClass

private void loadScriptClass(Gant gant, String scriptName)


main

public static void main(String[] args)
Evaluate the arguments to get the name of the script to execute, which environment to run it in, and the arguments to pass to the script. This also evaluates arguments of the form "-Dprop=value" and creates system properties from each one.
Parameters:
args


processAndReturnArguments

private static GriffonScriptRunner.ScriptAndArgs processAndReturnArguments(CommandLine commandLine, GriffonScriptRunner.ScriptAndArgs info)


processArgumentsAndReturnScriptName

private static GriffonScriptRunner.ScriptAndArgs processArgumentsAndReturnScriptName(CommandLine commandLine)


processSystemArguments

private static void processSystemArguments(CommandLine allArgs, GriffonScriptRunner.ScriptAndArgs info)


setInteractive

public void setInteractive(boolean interactive)


setLoggingOptions

public void setLoggingOptions()


setOut

public void setOut(PrintStream outputStream)


setRunningEnvironment

public void setRunningEnvironment(String scriptName, String env)


setup

public void setup()


unquote

public static String unquote(String s)


 

Groovy Documentation