Top Description Fields Constructors Methods
org.codehaus.groovy.tools

public Class LoaderConfiguration

extends Object
Class Inheritance
Imports
org.apache.groovy.util.SystemUtil, java.io.BufferedReader, .File, .IOException, .InputStream, .InputStreamReader, java.net.MalformedURLException, .URL, java.util.ArrayList, .List, java.util.regex.Matcher, .Pattern

Class used to configure a RootLoader from a stream or by using its 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 required unless setRequireMain(boolean) is 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.

See Also
RootLoader

Field Summary

Modifier and TypeField and Description
private static final String
private final List<URL>
private static final String
private final List<String>
private static final String
private final List<String>
private static final String
private String
private static final String
private static final String
private static final String
private static final String
private boolean
private static final char

Constructor Summary

AccessConstructor and Description
public
LoaderConfiguration()

creates a new loader configuration

Method Summary

Modifier and TypeMethod and Description
public void
addClassPath(String
the path as a path separator delimited string
path
)

Adds a classpath to this configuration.

public void
addFile(File
the file to add
file
)

Adds a file to the classpath if it exists.

public void
addFile(String
the name of the file to add
filename
)

Adds a file to the classpath if it exists.

private static String
public void
configure(InputStream
stream used to read the configuration
is
)

configures this loader with a stream

private static String
correctDoubleSlash(String propertyValue, int propertyIndexEnd, String str)

private void
findMatchingFiles(File[] files, Pattern pattern, boolean recursive)

public URL[]

Returns:

the classpath
getClassPathUrls
()

The classpath as URL[] from this configuration.

public List<String>

Returns:

the list of grab urls
getGrabUrls
()

The extra grab configuration.

public String

Returns:

the name of the main class or null if not defined
getMainClass
()

Returns the name of the main class for this configuration.

private static String
getSlashyPath(final String path)

private void
public void
setMainClass(String
the name to become the main class
classname
)

Sets the main class.

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

Determines if a main class is required when calling.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALL_WILDCARDback to summary
private static final String ALL_WILDCARD
classPathback to summary
private final List<URL> classPath
CONFIGSCRIPT_PREFIXback to summary
private static final String CONFIGSCRIPT_PREFIX
configScriptsback to summary
private final List<String> configScripts
GRAB_PREFIXback to summary
private static final String GRAB_PREFIX
grabListback to summary
private final List<String> grabList
LOAD_PREFIXback to summary
private static final String LOAD_PREFIX
mainback to summary
private String main
MAIN_PREFIXback to summary
private static final String MAIN_PREFIX
MATCH_ALLback to summary
private static final String MATCH_ALL
MATCH_FILE_NAMEback to summary
private static final String MATCH_FILE_NAME
PROP_PREFIXback to summary
private static final String PROP_PREFIX
requireMainback to summary
private boolean requireMain
WILDCARDback to summary
private static final char WILDCARD

Constructor Detail

LoaderConfigurationback to summary
public LoaderConfiguration()

creates a new loader configuration

Method Detail

addClassPathback to summary
public void addClassPath(String path)

Adds a classpath to this configuration. It expects a string with multiple paths, separated by the system dependent path separator. Expands wildcards, e.g. dir/* into all the jars in dir.

Parameters
path:String

the path as a path separator delimited string

See Also
java.io.File#pathSeparator
addFileback to summary
public void addFile(File file)

Adds a file to the classpath if it exists.

Parameters
file:File

the file to add

addFileback to summary
public void addFile(String filename)

Adds a file to the classpath if it exists.

Parameters
filename:String

the name of the file to add

assignPropertiesback to summary
private static String assignProperties(String str)
configureback to summary
public void configure(InputStream is) throws IOException

configures this loader with a stream

Parameters
is:InputStream

stream used to read the configuration

Exceptions
IOException:
if reading or parsing the contents of the stream fails
correctDoubleSlashback to summary
private static String correctDoubleSlash(String propertyValue, int propertyIndexEnd, String str)
findMatchingFilesback to summary
private void findMatchingFiles(File[] files, Pattern pattern, boolean recursive)
getClassPathUrlsback to summary
public URL[] getClassPathUrls()

The classpath as URL[] from this configuration. This can be used to construct a class loader.

Returns:URL[]

the classpath

See Also
java.net.URLClassLoader
getGrabUrlsback to summary
public List<String> getGrabUrls()

The extra grab configuration.

Returns:List<String>

the list of grab urls

getMainClassback to summary
public String getMainClass()

Returns the name of the main class for this configuration.

Returns:String

the name of the main class or null if not defined

getSlashyPathback to summary
private static String getSlashyPath(final String path)
loadFilteredPathback to summary
private void loadFilteredPath(String filter)
setMainClassback to summary
public void setMainClass(String classname)

Sets the main class. If there is already a main class it is overwritten. Calling configure(InputStream) after calling this method does not require a main class definition inside the stream.

Parameters
classname:String

the name to become the main class

setRequireMainback to summary
public void setRequireMain(boolean requireMain)

Determines if a main class is required when calling.

Parameters
requireMain:boolean

set to false if no main class is required

See Also
configure(InputStream)