Package: groovy.lang

## [Java] Class GroovyClassLoader.InnerLoader

- groovy.lang.GroovyClassLoader.InnerLoader

-     public static class GroovyClassLoader.InnerLoader
      extends GroovyClassLoader

  Loader used while defining classes during a compilation round.

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class GroovyClassLoader` | `classCache, sourceCache`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `InnerLoader(GroovyClassLoader delegate)` Creates an inner loader delegating to the supplied outer Groovy class loader.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addClasspath(String path)` adds a classpath to this classloader. Parameters: `path` - is a jar file or a directory. See Also: addURL(URL)
    `` | `public void` | `addURL(URL url)` adds a URL to the classloader. Parameters: `url` - the new classpath element
    `` | `public void` | `clearAssertionStatus()` {@inheritDoc}
    `` | `public void` | `clearCache()` Removes all classes from the class cache. In addition to internal caches this method also clears any previously set MetaClass information for the given set of classes being removed. See Also: getClassCacheEntry(String) setClassCacheEntry(Class) removeClassCacheEntry(String)
    `` | `public void` | `close()` Closes this GroovyClassLoader and clears any caches it maintains. No use should be made of this instance after this method is invoked. Any classes that are already loaded are still accessible. throws: IOException See Also: URLClassLoader.close clearCache() Since: 2.5.0
    `` | `public Class` | `defineClass(ClassNode classNode, String file, String newCodeBase)` Compiles the given `ClassNode` returning the resulting `Class`. WARNING: compilation is not synchronized
    `` | `public Class` | `defineClass(String name, byte[] b)` Converts an array of bytes into an instance of `Class`. Before the class can be used it must be resolved.
    `` | `public URL` | `findResource(String name)` {@inheritDoc}
    `` | `public Enumeration<URL>` | `findResources(String name)` {@inheritDoc}
    `` | `public String` | `generateScriptName()` Generates a unique script name for unnamed parsed sources. Returns: a unique script name ending in `.groovy`
    `` | `public Class[]` | `getLoadedClasses()` Returns all Groovy classes loaded by this class loader. Returns: all classes loaded by this class loader
    `` | `public URL` | `getResource(String name)` {@inheritDoc}
    `` | `public InputStream` | `getResourceAsStream(String name)` {@inheritDoc}
    `` | `public GroovyResourceLoader` | `getResourceLoader()` Returns the resource loader used to resolve Groovy source by script name. Returns: the current resource loader
    `` | `public Enumeration<URL>` | `getResources(String name)` {@inheritDoc}
    `` | `public long` | `getTimeStamp()` Returns the creation timestamp of this inner loader.
    `` | `public URL[]` | `getURLs()` {@inheritDoc}
    `` | `public Boolean` | `isShouldRecompile()` gets the currently set recompilation mode. null means, the compiler configuration is used. False means no recompilation and true means that recompilation will be done if needed. Returns: the recompilation mode
    `` | `public Class<?>` | `loadClass(String name)` {@inheritDoc} See Also: ClassLoader#loadClass(java.lang.String,boolean)
    `` | `public Class` | `loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript)` Loads a class from a file or a parent loader. This method delegates to:
         loadClass(name, lookupScriptFiles, preferClassOverScript, false);
    throws: ClassNotFoundException if class could not be found throws: CompilationFailedException if compilation of script failed
    `` | `public Class` | `loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve)` Loads a class from a file or a parent loader. throws: ClassNotFoundException if class could not be found throws: CompilationFailedException if compilation of script failed Parameters: `name` - of the class to be loaded `lookupScriptFiles` - if false no lookup at files is done at all `preferClassOverScript` - if true the file lookup is only done if there is no class `resolve` - see ClassLoader.loadClass Returns: the class found or the class created from a file lookup
    `` | `public Class` | `parseClass(File file)` Parses the given file into a Java class capable of being run Parameters: `file` - the file name to parse Returns: the main class defined in the given script
    `` | `public Class` | `parseClass(GroovyCodeSource codeSource)` Parses Groovy source described by a GroovyCodeSource. throws: CompilationFailedException if compilation fails Parameters: `codeSource` - the code source to compile Returns: the main class defined by the source
    `` | `public Class` | `parseClass(GroovyCodeSource codeSource, boolean shouldCache)` Parses the given code source into a Java class. If there is a class file for the given code source, then no parsing is done, instead the cached class is returned. Parameters: `shouldCacheSource` - if true then the generated class will be stored in the source cache Returns: the main class defined in the given script
    `` | `public Class` | `parseClass(Reader reader, String fileName)` Parses Groovy source read from a Reader. throws: CompilationFailedException if compilation fails Parameters: `reader` - the reader supplying source text `fileName` - the logical script name Returns: the main class defined by the source
    `` | `public Class` | `parseClass(String text)` Parses the given text into a Java class capable of being run Parameters: `text` - the text of the script/class to parse Returns: the main class defined in the given script
    `` | `public Class` | `parseClass(String text, String fileName)` Parses the given text into a Java class capable of being run Parameters: `text` - the text of the script/class to parse `fileName` - the file name to use as the name of the class Returns: the main class defined in the given script
    `` | `public void` | `setClassAssertionStatus(String className, boolean enabled)` {@inheritDoc}
    `` | `public void` | `setDefaultAssertionStatus(boolean enabled)` {@inheritDoc}
    `` | `public void` | `setPackageAssertionStatus(String packageName, boolean enabled)` {@inheritDoc}
    `` | `public void` | `setResourceLoader(GroovyResourceLoader resourceLoader)` Sets the resource loader used to resolve Groovy source by script name. Parameters: `resourceLoader` - the resource loader to use
    `` | `public void` | `setShouldRecompile(Boolean mode)` sets if the recompilation should be enabled. There are 3 possible values for this. Any value different from null overrides the value from the compiler configuration. true means to recompile if needed false means to never recompile. Parameters: `mode` - the recompilation mode See Also: CompilerConfiguration

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class GroovyClassLoader` | `addClasspath, addURL, clearCache, close, createCollector, createCompilationUnit, defineClass, defineClass, genEncodingString, generateScriptName, getClassCacheEntry, getClassPath, getLoadedClasses, getPermissions, getResourceLoader, getTimeStamp, hasCompatibleConfiguration, isRecompilable, isShouldRecompile, isSourceNewer, loadClass, loadClass, loadClass, loadClass, parseClass, parseClass, parseClass, parseClass, parseClass, parseClass, recompile, removeClassCacheEntry, setClassCacheEntry, setResourceLoader, setShouldRecompile`

- - ### Constructor Detail

    - #### public InnerLoader(GroovyClassLoader delegate)

      Creates an inner loader delegating to the supplied outer Groovy class loader.

      Parameters:
        `delegate` - the outer loader that owns caches and resources

  - ### Method Detail

    - #### public void addClasspath(String path)

      adds a classpath to this classloader.

      Parameters:
        `path` - is a jar file or a directory.
      See Also:
        addURL(URL)

    - #### public void addURL(URL url)

      adds a URL to the classloader.

      Parameters:
        `url` - the new classpath element

    - #### public void clearAssertionStatus()

      {@inheritDoc}

    - #### public void clearCache()

      Removes all classes from the class cache.

      In addition to internal caches this method also clears any previously set MetaClass information for the given set of classes being removed.

      See Also:
        getClassCacheEntry(String)
        setClassCacheEntry(Class)
        removeClassCacheEntry(String)

    - #### public void close()

      Closes this GroovyClassLoader and clears any caches it maintains.

      No use should be made of this instance after this method is invoked. Any classes that are already loaded are still accessible.

      throws:
        IOException
      See Also:
        URLClassLoader.close
        clearCache()
      Since:
        2.5.0

    - #### public Class defineClass(ClassNode classNode, String file, String newCodeBase)

      Compiles the given `ClassNode` returning the resulting `Class`.

      WARNING: compilation is not synchronized

    - #### public Class defineClass(String name, byte[] b)

      Converts an array of bytes into an instance of `Class`. Before the class can be used it must be resolved.

    - #### public URL findResource(String name)

      {@inheritDoc}

    - #### public Enumeration<URL> findResources(String name)

      {@inheritDoc}

    - #### public String generateScriptName()

      Generates a unique script name for unnamed parsed sources.

      Returns:
        a unique script name ending in `.groovy`

    - #### public Class[] getLoadedClasses()

      Returns all Groovy classes loaded by this class loader.

      Returns:
        all classes loaded by this class loader

    - #### public URL getResource(String name)

      {@inheritDoc}

    - #### public InputStream getResourceAsStream(String name)

      {@inheritDoc}

    - #### public GroovyResourceLoader getResourceLoader()

      Returns the resource loader used to resolve Groovy source by script name.

      Returns:
        the current resource loader

    - #### public Enumeration<URL> getResources(String name)

      {@inheritDoc}

    - #### public long getTimeStamp()

      Returns the creation timestamp of this inner loader.

      Returns:
        the timestamp captured when the loader was created

    - #### public URL[] getURLs()

      {@inheritDoc}

    - #### public Boolean isShouldRecompile()

      gets the currently set recompilation mode. null means, the compiler configuration is used. False means no recompilation and true means that recompilation will be done if needed.

      Returns:
        the recompilation mode

    - #### public Class<?> loadClass(String name)

      {@inheritDoc}

      See Also:
        ClassLoader#loadClass(java.lang.String,boolean)

    - #### public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript)

      Loads a class from a file or a parent loader. This method delegates to:

           loadClass(name, lookupScriptFiles, preferClassOverScript, false);

      throws:
        ClassNotFoundException if class could not be found
      throws:
        CompilationFailedException if compilation of script failed

    - #### public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve)

      Loads a class from a file or a parent loader.

      throws:
        ClassNotFoundException if class could not be found
      throws:
        CompilationFailedException if compilation of script failed
      Parameters:
        `name` - of the class to be loaded
        `lookupScriptFiles` - if false no lookup at files is done at all
        `preferClassOverScript` - if true the file lookup is only done if there is no class
        `resolve` - see ClassLoader.loadClass
      Returns:
        the class found or the class created from a file lookup

    - #### public Class parseClass(File file)

      Parses the given file into a Java class capable of being run

      Parameters:
        `file` - the file name to parse
      Returns:
        the main class defined in the given script

    - #### public Class parseClass(GroovyCodeSource codeSource)

      Parses Groovy source described by a GroovyCodeSource.

      throws:
        CompilationFailedException if compilation fails
      Parameters:
        `codeSource` - the code source to compile
      Returns:
        the main class defined by the source

    - #### public Class parseClass(GroovyCodeSource codeSource, boolean shouldCache)

      Parses the given code source into a Java class. If there is a class file for the given code source, then no parsing is done, instead the cached class is returned.

      Parameters:
        `shouldCacheSource` - if true then the generated class will be stored in the source cache
      Returns:
        the main class defined in the given script

    - #### public Class parseClass(Reader reader, String fileName)

      Parses Groovy source read from a Reader.

      throws:
        CompilationFailedException if compilation fails
      Parameters:
        `reader` - the reader supplying source text
        `fileName` - the logical script name
      Returns:
        the main class defined by the source

    - #### public Class parseClass(String text)

      Parses the given text into a Java class capable of being run

      Parameters:
        `text` - the text of the script/class to parse
      Returns:
        the main class defined in the given script

    - #### public Class parseClass(String text, String fileName)

      Parses the given text into a Java class capable of being run

      Parameters:
        `text` - the text of the script/class to parse
        `fileName` - the file name to use as the name of the class
      Returns:
        the main class defined in the given script

    - #### public void setClassAssertionStatus(String className, boolean enabled)

      {@inheritDoc}

    - #### public void setDefaultAssertionStatus(boolean enabled)

      {@inheritDoc}

    - #### public void setPackageAssertionStatus(String packageName, boolean enabled)

      {@inheritDoc}

    - #### public void setResourceLoader(GroovyResourceLoader resourceLoader)

      Sets the resource loader used to resolve Groovy source by script name.

      Parameters:
        `resourceLoader` - the resource loader to use

    - #### public void setShouldRecompile(Boolean mode)

      sets if the recompilation should be enabled. There are 3 possible values for this. Any value different from null overrides the value from the compiler configuration. true means to recompile if needed false means to never recompile.

      Parameters:
        `mode` - the recompilation mode
      See Also:
        CompilerConfiguration