Package groovy.lang
Class GroovyCodeSource
java.lang.Object
groovy.lang.GroovyCodeSource
CodeSource wrapper class that allows specific security policies to be associated with a class
compiled from groovy source.
-
Constructor Summary
ConstructorsConstructorDescriptionGroovyCodeSource(File infile) GroovyCodeSource(File infile, String encoding) Creates a code source from a Groovy source file.GroovyCodeSource(Reader reader, String name, String codeBase) Construct a GroovyCodeSource for an inputStream of groovyCode that has an unknown provenance -- meaning it didn't come from a File or a URL (e.g. a String).GroovyCodeSource(String script, String name, String codeBase) Creates a code source from script text with an explicit logical name and code base.GroovyCodeSource(URI uri) Creates a code source from the Groovy source available at the supplied URI.GroovyCodeSource(URL url) Creates a code source from the Groovy source available at the supplied URL. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns theCodeSourceassociated with compiled script classes.getFile()Returns the backing file when this code source was created from a file.getName()Returns the logical name used for the script.Returns the Groovy source text.getURL()Returns the backing URL when this code source was created from a URL.inthashCode()booleanIndicates whether classes compiled from this source may be cached.voidsetCachable(boolean b) Controls whether classes compiled from this source may be cached byGroovyClassLoader.
-
Constructor Details
-
GroovyCodeSource
Creates a code source from script text with an explicit logical name and code base.- Parameters:
script- the Groovy source textname- the logical script namecodeBase- the code base used to create the backingCodeSource
-
GroovyCodeSource
Construct a GroovyCodeSource for an inputStream of groovyCode that has an unknown provenance -- meaning it didn't come from a File or a URL (e.g. a String). The supplied codeBase will be used to construct a File URL that should match up with a java Policy entry that determines the grants to be associated with the class that will be built from the InputStream.The permission groovy.security.GroovyCodeSourcePermission will be used to determine if the given codeBase may be specified. That is, the current Policy set must have a GroovyCodeSourcePermission that implies the codeBase, or an exception will be thrown. This is to prevent callers from hijacking existing codeBase policy entries unless explicitly authorized by the user.
-
GroovyCodeSource
Creates a code source from a Groovy source file.- Parameters:
infile- the source fileencoding- the character encoding used to read the file, ornullfor the default handling- Throws:
IOException- if the file cannot be read
-
GroovyCodeSource
- Parameters:
infile- the file to create a GroovyCodeSource for.- Throws:
IOException- if an issue arises opening and reading the file.
-
GroovyCodeSource
Creates a code source from the Groovy source available at the supplied URI.- Parameters:
uri- the source URI- Throws:
IOException- if the source cannot be read
-
GroovyCodeSource
Creates a code source from the Groovy source available at the supplied URL.- Parameters:
url- the source URL
-
-
Method Details
-
getCodeSource
Returns theCodeSourceassociated with compiled script classes.- Returns:
- the code source for this script
-
getScriptText
Returns the Groovy source text.- Returns:
- the script text
-
getName
Returns the logical name used for the script.- Returns:
- the script name
-
getFile
Returns the backing file when this code source was created from a file.- Returns:
- the backing file, or
nullif this source does not originate from a file
-
getURL
Returns the backing URL when this code source was created from a URL.- Returns:
- the backing URL, or
nullif this source does not originate from a URL
-
setCachable
public void setCachable(boolean b) Controls whether classes compiled from this source may be cached byGroovyClassLoader.- Parameters:
b-trueto allow caching,falseotherwise
-
isCachable
public boolean isCachable()Indicates whether classes compiled from this source may be cached.- Returns:
trueif the source is cacheable
-
equals
-
hashCode
public int hashCode()
-