Groovy load java class

Содержание
  1. Groovy load java class
  2. Nested Class Summary
  3. Field Summary
  4. Constructor Summary
  5. Method Summary
  6. Methods inherited from class java.net.URLClassLoader
  7. Methods inherited from class java.security.SecureClassLoader
  8. Methods inherited from class java.lang.ClassLoader
  9. Methods inherited from class java.lang.Object
  10. Field Detail
  11. classCache
  12. sourceCache
  13. Constructor Detail
  14. GroovyClassLoader
  15. GroovyClassLoader
  16. GroovyClassLoader
  17. GroovyClassLoader
  18. GroovyClassLoader
  19. Method Detail
  20. setResourceLoader
  21. getResourceLoader
  22. defineClass
  23. parseClass
  24. parseClass
  25. parseClass
  26. generateScriptName
  27. parseClass
  28. parseClass
  29. parseClass
  30. getClassPath
  31. getPermissions
  32. createCompilationUnit
  33. createCollector
  34. defineClass
  35. loadClass
  36. getClassCacheEntry
  37. setClassCacheEntry
  38. removeClassCacheEntry
  39. addURL
  40. isRecompilable
  41. setShouldRecompile
  42. isShouldRecompile
  43. loadClass
  44. recompile
  45. loadClass
  46. loadClass
  47. getTimeStamp
  48. isSourceNewer
  49. addClasspath
  50. getLoadedClasses
  51. clearCache
  52. Class GroovyClassLoader
  53. Nested Class Summary
  54. Field Summary
  55. Constructor Summary
  56. Method Summary
  57. Methods inherited from class java.net.URLClassLoader
  58. Methods inherited from class java.security.SecureClassLoader
  59. Methods inherited from class java.lang.ClassLoader
  60. Methods inherited from class java.lang.Object
  61. Field Details
  62. classCache
  63. sourceCache
  64. Constructor Details
  65. GroovyClassLoader
  66. GroovyClassLoader
  67. GroovyClassLoader
  68. GroovyClassLoader
  69. GroovyClassLoader
  70. Method Details
  71. setResourceLoader
  72. getResourceLoader
  73. defineClass
  74. hasCompatibleConfiguration
  75. parseClass
  76. parseClass
  77. parseClass
  78. generateScriptName
  79. parseClass
  80. parseClass
  81. parseClass
  82. getClassPath
  83. getPermissions
  84. createCompilationUnit
  85. createCollector
  86. defineClass
  87. loadClass
  88. getClassCacheEntry
  89. setClassCacheEntry
  90. removeClassCacheEntry
  91. addURL
  92. isRecompilable
  93. setShouldRecompile
  94. isShouldRecompile
  95. loadClass
  96. recompile
  97. loadClass
  98. loadClass
  99. getTimeStamp
  100. isSourceNewer
  101. addClasspath
  102. getLoadedClasses
  103. clearCache
  104. close

Groovy load java class

A ClassLoader which can load Groovy classes. The loaded classes are cached, classes from other classloaders should not be cached. To be able to load a script that was asked for earlier but was created later it is essential not to keep anything like a «class not found» information for that class name. This includes possible parent loaders. Classes that are not cached are always reloaded.

Nested Class Summary

Field Summary

Constructor Summary

Method Summary

Methods inherited from class java.net.URLClassLoader

Methods inherited from class java.security.SecureClassLoader

Methods inherited from class java.lang.ClassLoader

Methods inherited from class java.lang.Object

Field Detail

classCache

protected final java.util.Map classCache

sourceCache

protected final java.util.Map sourceCache

Constructor Detail

GroovyClassLoader

GroovyClassLoader

public GroovyClassLoader(java.lang.ClassLoader loader)

GroovyClassLoader

creates a GroovyClassLoader using the given GroovyClassLoader as parent. This loader will get the parent’s CompilerConfiguration

Читайте также:  Кожи питона на ощупь

GroovyClassLoader

public GroovyClassLoader(java.lang.ClassLoader parent, CompilerConfiguration config, boolean useConfigurationClasspath)

GroovyClassLoader

Method Detail

setResourceLoader

getResourceLoader

defineClass

public java.lang.Class defineClass(ClassNode classNode, java.lang.String file, java.lang.String newCodeBase)

Loads the given class node returning the implementation Class. WARNING: this compilation is not synchronized

parseClass

parseClass

parseClass

generateScriptName

public java.lang.String generateScriptName()

parseClass

Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.

parseClass

public java.lang.Class parseClass(GroovyCodeSource codeSource) throws CompilationFailedException

parseClass

public java.lang.Class parseClass(GroovyCodeSource codeSource, boolean shouldCacheSource) throws CompilationFailedException

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.

getClassPath

protected java.lang.String[] getClassPath()

getPermissions

protected java.security.PermissionCollection getPermissions(java.security.CodeSource codeSource)

createCompilationUnit

protected CompilationUnit createCompilationUnit(CompilerConfiguration config, java.security.CodeSource source)

creates a new CompilationUnit. If you want to add additional phase operations to the CompilationUnit (for example to inject additional methods, variables, fields), then you should overwrite this method.

createCollector

protected GroovyClassLoader.ClassCollector createCollector(CompilationUnit unit, SourceUnit su)

defineClass

public java.lang.Class defineClass(java.lang.String name, byte[] b)

loadClass

loads a class from a file or a parent classloader. This method does call loadClass(String, boolean, boolean, boolean) with the last parameter set to false.

getClassCacheEntry

protected java.lang.Class getClassCacheEntry(java.lang.String name)

gets a class from the class cache. This cache contains only classes loaded through this class loader or an InnerLoader instance. If no class is stored for a specific name, then the method should return null.

setClassCacheEntry

protected void setClassCacheEntry(java.lang.Class cls)

removeClassCacheEntry

protected void removeClassCacheEntry(java.lang.String name)

addURL

public void addURL(java.net.URL url)

isRecompilable

protected boolean isRecompilable(java.lang.Class cls)

Indicates if a class is recompilable. Recompilable means, that the classloader will try to locate a groovy source file for this class and then compile it again, adding the resulting class as entry to the cache. Giving null as class is like a recompilation, so the method should always return true here. Only classes that are implementing GroovyObject are compilable and only if the timestamp in the class is lower than Long.MAX_VALUE. NOTE: First the parent loaders will be asked and only if they don’t return a class the recompilation will happen. Recompilation also only happen if the source file is newer.

setShouldRecompile

public void setShouldRecompile(java.lang.Boolean mode)

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

isShouldRecompile

public java.lang.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.

loadClass

recompile

(Re)Compiles the given source. This method starts the compilation of a given source, if the source has changed since the class was created. For this isSourceNewer is called.

loadClass

public java.lang.Class loadClass(java.lang.String name) throws java.lang.ClassNotFoundException

loadClass

protected java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException

getTimeStamp

protected long getTimeStamp(java.lang.Class cls)

gets the time stamp of a given class. For groovy generated classes this usually means to return the value of the static field __timeStamp. If the parameter doesn’t have such a field, then Long.MAX_VALUE is returned

isSourceNewer

protected boolean isSourceNewer(java.net.URL source, java.lang.Class cls) throws java.io.IOException

addClasspath

public void addClasspath(java.lang.String path)

getLoadedClasses

public java.lang.Class[] getLoadedClasses()

clearCache

Источник

Class GroovyClassLoader

A ClassLoader which can load Groovy classes. The loaded classes are cached, classes from other classloaders should not be cached. To be able to load a script that was asked for earlier but was created later it is essential not to keep anything like a «class not found» information for that class name. This includes possible parent loaders. Classes that are not cached are always reloaded.

Nested Class Summary

Field Summary

Constructor Summary

Method Summary

Methods inherited from class java.net.URLClassLoader

Methods inherited from class java.security.SecureClassLoader

Methods inherited from class java.lang.ClassLoader

Methods inherited from class java.lang.Object

Field Details

classCache

sourceCache

Constructor Details

GroovyClassLoader

GroovyClassLoader

GroovyClassLoader

creates a GroovyClassLoader using the given GroovyClassLoader as parent. This loader will get the parent’s CompilerConfiguration

GroovyClassLoader

public GroovyClassLoader (ClassLoader parent, CompilerConfiguration config, boolean useConfigurationClasspath)

GroovyClassLoader

Method Details

setResourceLoader

getResourceLoader

defineClass

Loads the given class node returning the implementation Class. WARNING: this compilation is not synchronized

hasCompatibleConfiguration

parseClass

parseClass

parseClass

generateScriptName

parseClass

parseClass

parseClass

public Class parseClass (GroovyCodeSource codeSource, boolean shouldCacheSource) throws CompilationFailedException

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.

getClassPath

getPermissions

createCompilationUnit

creates a new CompilationUnit. If you want to add additional phase operations to the CompilationUnit (for example to inject additional methods, variables, fields), then you should overwrite this method.

createCollector

defineClass

loadClass

public Class loadClass (String name, boolean lookupScriptFiles, boolean preferClassOverScript) throws ClassNotFoundException, CompilationFailedException

loads a class from a file or a parent classloader. This method does call loadClass(String, boolean, boolean, boolean) with the last parameter set to false.

getClassCacheEntry

gets a class from the class cache. This cache contains only classes loaded through this class loader or an InnerLoader instance. If no class is stored for a specific name, then the method should return null.

setClassCacheEntry

removeClassCacheEntry

addURL

isRecompilable

Indicates if a class is recompilable. Recompilable means, that the classloader will try to locate a groovy source file for this class and then compile it again, adding the resulting class as entry to the cache. Giving null as class is like a recompilation, so the method should always return true here. Only classes that are implementing GroovyObject are compilable and only if the timestamp in the class is lower than Long.MAX_VALUE. NOTE: First the parent loaders will be asked and only if they don’t return a class the recompilation will happen. Recompilation also only happen if the source file is newer.

setShouldRecompile

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.

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.

loadClass

public Class loadClass (String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve) throws ClassNotFoundException, CompilationFailedException

recompile

(Re)Compiles the given source. This method starts the compilation of a given source, if the source has changed since the class was created. For this isSourceNewer is called.

loadClass

loadClass

getTimeStamp

gets the time stamp of a given class. For groovy generated classes this usually means to return the value of the static field __timeStamp. If the parameter doesn’t have such a field, then Long.MAX_VALUE is returned

isSourceNewer

addClasspath

getLoadedClasses

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.

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.

Copyright © 2003-2022 The Apache Software Foundation. All rights reserved.

Источник

Оцените статью