org.codehaus.groovy.tools
Class LoaderConfiguration

java.lang.Object
  extended by org.codehaus.groovy.tools.LoaderConfiguration

public class LoaderConfiguration
extends java.lang.Object

class used to configure a RootLoader from a stream or by using it's methods.

The stream can be for example a FileInputStream from a file with the following format:

 # comment
 main is classname
 load path
 load file
 load pathWith${property}
 load pathWith!{required.property}
 load path/*.jar
 load path/**/*.jar
 

Defining the main class is optional if setRequireMain(boolean) was called with false, before reading the configuration. You can use the wildcard "*" to filter the path, but only for files, not directories. to match directories use "**". The ${propertyname} is replaced by the value of the system's property name. You can use user.home here for example. If the property does not exist, an empty string will be used. If the path or file after the load command does not exist, the path will be ignored.

Version:
$Revision: 10259 $
Author:
Jochen Theodorou
See Also:
RootLoader

Field Summary
private static java.lang.String ALL_WILDCARD
           
private  java.util.List classPath
           
private static java.lang.String LOAD_PREFIX
           
private  java.lang.String main
           
private static java.lang.String MAIN_PREFIX
           
private static java.lang.String MATCH_ALL
           
private static java.lang.String MATCH_FILE_NAME
           
private  boolean requireMain
           
private static char WILDCARD
           
 
Constructor Summary
LoaderConfiguration()
          creates a new loader configuration
 
Method Summary
 void addClassPath(java.lang.String path)
          adds a classpath to this configuration.
 void addFile(java.io.File f)
          adds a file to the classpath if it does exist
 void addFile(java.lang.String s)
          adds a file to the classpath if it does exist
private  java.lang.String assignProperties(java.lang.String str)
          exapands the properties inside the given string to it's values
 void configure(java.io.InputStream is)
          configures this loader with a stream
private  void findMatchingFiles(java.io.File[] files, java.util.regex.Pattern pattern, boolean recursive)
           
 java.net.URL[] getClassPathUrls()
          gets a classpath as URL[] from this configuration.
 java.lang.String getMainClass()
          returns the main class or null is no is defined
private  java.lang.String getParentPath(java.lang.String filter)
          seperates the given path at the last '/'
private  java.lang.String getSlashyPath(java.lang.String path)
           
private  void loadFilteredPath(java.lang.String filter)
          load a possible filtered path.
private  boolean parentPathDoesExist(java.lang.String path)
          return true if the parent of the path inside the given string does exist
 void setMainClass(java.lang.String clazz)
          sets the main class.
 void setRequireMain(boolean requireMain)
          if set to false no main class is required when calling
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAIN_PREFIX

private static final java.lang.String MAIN_PREFIX
See Also:
Constant Field Values

LOAD_PREFIX

private static final java.lang.String LOAD_PREFIX
See Also:
Constant Field Values

classPath

private java.util.List classPath

main

private java.lang.String main

requireMain

private boolean requireMain

WILDCARD

private static final char WILDCARD
See Also:
Constant Field Values

ALL_WILDCARD

private static final java.lang.String ALL_WILDCARD
See Also:
Constant Field Values

MATCH_FILE_NAME

private static final java.lang.String MATCH_FILE_NAME
See Also:
Constant Field Values

MATCH_ALL

private static final java.lang.String MATCH_ALL
See Also:
Constant Field Values
Constructor Detail

LoaderConfiguration

public LoaderConfiguration()
creates a new loader configuration

Method Detail

configure

public void configure(java.io.InputStream is)
               throws java.io.IOException
configures this loader with a stream

Parameters:
is - stream used to read the configuration
Throws:
java.io.IOException - if reading or parsing the contents of the stream fails

assignProperties

private java.lang.String assignProperties(java.lang.String str)
exapands the properties inside the given string to it's values


loadFilteredPath

private void loadFilteredPath(java.lang.String filter)
load a possible filtered path. Filters are defined by using the * wildcard like in any shell


findMatchingFiles

private void findMatchingFiles(java.io.File[] files,
                               java.util.regex.Pattern pattern,
                               boolean recursive)

getSlashyPath

private java.lang.String getSlashyPath(java.lang.String path)

parentPathDoesExist

private boolean parentPathDoesExist(java.lang.String path)
return true if the parent of the path inside the given string does exist


getParentPath

private java.lang.String getParentPath(java.lang.String filter)
seperates the given path at the last '/'


addFile

public void addFile(java.io.File f)
adds a file to the classpath if it does exist


addFile

public void addFile(java.lang.String s)
adds a file to the classpath if it does exist


addClassPath

public void addClassPath(java.lang.String path)
adds a classpath to this configuration. It expects a string with multiple paths, seperated by the system dependent

See Also:
File.pathSeparator

getClassPathUrls

public java.net.URL[] getClassPathUrls()
gets a classpath as URL[] from this configuration. This can be used to construct a @see java.net.URLClassLoader


getMainClass

public java.lang.String getMainClass()
returns the main class or null is no is defined


setMainClass

public void setMainClass(java.lang.String clazz)
sets the main class. If there is already a main class it is overwritten. Calling @see #configure(InputStream) after calling this method does not require a main class definition inside the stream


setRequireMain

public void setRequireMain(boolean requireMain)
if set to false no main class is required when calling

See Also:
configure(InputStream)


Copyright © ${year} The Codehaus. All Rights Reserved.