org.codehaus.groovy.grails.cli.support
Class ClasspathConfigurer

java.lang.Object
  extended by org.codehaus.groovy.grails.cli.support.ClasspathConfigurer

public class ClasspathConfigurer
extends java.lang.Object

Support class that configures the Grails classpath when executing command line scripts.

Since:
2.0

Constructor Summary
ClasspathConfigurer(grails.util.BuildSettings build, boolean skipPlugins)
           
ClasspathConfigurer(PluginPathDiscoverySupport pluginPathSupport, grails.util.BuildSettings settings, boolean skipPlugins)
           
 
Method Summary
protected  void addDependenciesToURLs(java.util.Set<java.lang.String> excludes, java.util.List<java.net.URL> urls, java.util.List<java.io.File> runtimeDeps)
           
protected  void addLibs(java.io.File dir, java.util.List<java.net.URL> urls, java.util.Collection<?> excludes)
          Adds all the JAR files in the given directory to the list of URLs.
protected  void addPluginLibs(java.io.File pluginDir, java.util.List<java.net.URL> urls, grails.util.BuildSettings settings)
          Adds all the libraries in a plugin to the given list of URLs.
protected  void addUrlsToRootLoader(java.net.URLClassLoader loader, java.net.URL[] urls)
          A Groovy RootLoader should be used to load GrailsScriptRunner, but this leaves us with a problem.
static void cleanResolveCache(grails.util.BuildSettings settings)
           
 java.net.URLClassLoader configuredClassLoader()
           
protected  java.net.URL[] getClassLoaderUrls(grails.util.BuildSettings settings, java.io.File cacheDir, java.util.Set<java.lang.String> excludes, boolean skipPlugins)
          Creates a new root loader with the Grails libraries and the application's plugin libraries on the classpath.
 void setExitOnResolveError(boolean exitOnResolveError)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathConfigurer

public ClasspathConfigurer(PluginPathDiscoverySupport pluginPathSupport,
                           grails.util.BuildSettings settings,
                           boolean skipPlugins)

ClasspathConfigurer

public ClasspathConfigurer(grails.util.BuildSettings build,
                           boolean skipPlugins)
Method Detail

configuredClassLoader

public java.net.URLClassLoader configuredClassLoader()

getClassLoaderUrls

protected java.net.URL[] getClassLoaderUrls(grails.util.BuildSettings settings,
                                            java.io.File cacheDir,
                                            java.util.Set<java.lang.String> excludes,
                                            boolean skipPlugins)
                                     throws java.net.MalformedURLException
Creates a new root loader with the Grails libraries and the application's plugin libraries on the classpath.

Throws:
java.net.MalformedURLException

cleanResolveCache

public static void cleanResolveCache(grails.util.BuildSettings settings)

addDependenciesToURLs

protected void addDependenciesToURLs(java.util.Set<java.lang.String> excludes,
                                     java.util.List<java.net.URL> urls,
                                     java.util.List<java.io.File> runtimeDeps)
                              throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

addPluginLibs

protected void addPluginLibs(java.io.File pluginDir,
                             java.util.List<java.net.URL> urls,
                             grails.util.BuildSettings settings)
                      throws java.net.MalformedURLException
Adds all the libraries in a plugin to the given list of URLs.

Parameters:
pluginDir - The directory containing the plugin.
urls - The list of URLs to add the plugin JARs to.
settings -
Throws:
java.net.MalformedURLException

addLibs

protected void addLibs(java.io.File dir,
                       java.util.List<java.net.URL> urls,
                       java.util.Collection<?> excludes)
                throws java.net.MalformedURLException
Adds all the JAR files in the given directory to the list of URLs. Excludes any "standard-*.jar" and "jstl-*.jar" because these are added to the classpath in another place. They depend on the servlet version of the app and so need to be treated specially.

Throws:
java.net.MalformedURLException

addUrlsToRootLoader

protected void addUrlsToRootLoader(java.net.URLClassLoader loader,
                                   java.net.URL[] urls)

A Groovy RootLoader should be used to load GrailsScriptRunner, 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 GrailsScriptRunner'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.

setExitOnResolveError

public void setExitOnResolveError(boolean exitOnResolveError)