Package org.codehaus.gmavenplus.util
Class ClassWrangler
- java.lang.Object
-
- org.codehaus.gmavenplus.util.ClassWrangler
-
public class ClassWrangler extends java.lang.ObjectHandles getting Groovy classes and version from the specified classpath.- Since:
- 1.2
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassLoaderclassLoaderClassLoader to use for class wrangling.private java.lang.StringgroovyVersionCached Groovy version.private java.lang.BooleanisIndyCached whether Groovy supports invokedynamic (indy jar).private org.apache.maven.plugin.logging.LoglogPlugin log.
-
Constructor Summary
Constructors Constructor Description ClassWrangler(java.util.List<?> classpath, java.lang.ClassLoader parentClassLoader, org.apache.maven.plugin.logging.Log pluginLog)Creates a new ClassWrangler using the specified parent ClassLoader, loaded with the items from the specified classpath.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.ClassLoadercreateNewClassLoader(java.util.List<?> classpath, java.lang.ClassLoader classLoader)Creates a new ClassLoader with the specified classpath.java.lang.Class<?>getClass(java.lang.String className)Gets a class for the given class name.java.lang.ClassLoadergetClassLoader()Returns the classloader used for loading classes.protected java.lang.StringgetGroovyJar()Returns the filename of the Groovy jar on the classpath.VersiongetGroovyVersion()Gets the version of Groovy used from the classpath.java.lang.StringgetGroovyVersionString()Gets the version string of Groovy used from classpath.protected java.lang.StringgetJarPath()Returns the path of the Groovy jar on the classpath.static booleangroovyAtLeast(Version detectedVersion, Version compareToVersion)Determines whether the detected Groovy version is the specified version or newer.static booleangroovyIs(Version detectedVersion, Version compareToVersion)Determines whether the detected Groovy version is the specified version.static booleangroovyNewerThan(Version detectedVersion, Version compareToVersion)Determines whether the detected Groovy version is newer than the specified version.static booleangroovyOlderThan(Version detectedVersion, Version compareToVersion)Determines whether the detected Groovy version is older than the specified version.booleanisGroovyIndy()Gets whether the version of Groovy on the classpath supports invokedynamic.voidlogGroovyVersion(java.lang.String goal)Logs the version of groovy used by this mojo.
-
-
-
Field Detail
-
groovyVersion
private java.lang.String groovyVersion
Cached Groovy version.
-
isIndy
private java.lang.Boolean isIndy
Cached whether Groovy supports invokedynamic (indy jar).
-
classLoader
private final java.lang.ClassLoader classLoader
ClassLoader to use for class wrangling.
-
log
private final org.apache.maven.plugin.logging.Log log
Plugin log.
-
-
Constructor Detail
-
ClassWrangler
public ClassWrangler(java.util.List<?> classpath, java.lang.ClassLoader parentClassLoader, org.apache.maven.plugin.logging.Log pluginLog) throws java.net.MalformedURLExceptionCreates a new ClassWrangler using the specified parent ClassLoader, loaded with the items from the specified classpath.- Parameters:
classpath- the classpath to load the new ClassLoader withparentClassLoader- the parent for the new ClassLoader used to use to load classespluginLog- the Maven log to use for logging- Throws:
java.net.MalformedURLException- when a classpath element provides a malformed URL
-
-
Method Detail
-
getGroovyVersionString
public java.lang.String getGroovyVersionString()
Gets the version string of Groovy used from classpath.- Returns:
- The version string of Groovy used by the project
-
getGroovyVersion
public Version getGroovyVersion()
Gets the version of Groovy used from the classpath.- Returns:
- The version of Groovy used by the project
-
groovyAtLeast
public static boolean groovyAtLeast(Version detectedVersion, Version compareToVersion)
Determines whether the detected Groovy version is the specified version or newer.- Parameters:
detectedVersion- the detected Groovy versioncompareToVersion- the version to compare the detected Groovy version to- Returns:
trueif the detected Groovy version is the specified version or newer,falseotherwise
-
groovyIs
public static boolean groovyIs(Version detectedVersion, Version compareToVersion)
Determines whether the detected Groovy version is the specified version.- Parameters:
detectedVersion- the detected Groovy versioncompareToVersion- the version to compare the detected Groovy version to- Returns:
trueif the detected Groovy version is the specified version,falseotherwise
-
groovyNewerThan
public static boolean groovyNewerThan(Version detectedVersion, Version compareToVersion)
Determines whether the detected Groovy version is newer than the specified version.- Parameters:
detectedVersion- the detected Groovy versioncompareToVersion- the version to compare the detected Groovy version to- Returns:
trueif the detected Groovy version is newer than the specified version,falseotherwise
-
groovyOlderThan
public static boolean groovyOlderThan(Version detectedVersion, Version compareToVersion)
Determines whether the detected Groovy version is older than the specified version.- Parameters:
detectedVersion- the detected Groovy versioncompareToVersion- the version to compare the detected Groovy version to- Returns:
trueif the detected Groovy version is older than the specified version,falseotherwise
-
isGroovyIndy
public boolean isGroovyIndy()
Gets whether the version of Groovy on the classpath supports invokedynamic.- Returns:
trueif the version of Groovy uses invokedynamic,falseif not or Groovy dependency cannot be found.
-
logGroovyVersion
public void logGroovyVersion(java.lang.String goal)
Logs the version of groovy used by this mojo.- Parameters:
goal- The goal to mention in the log statement showing Groovy version
-
getClass
public java.lang.Class<?> getClass(java.lang.String className) throws java.lang.ClassNotFoundExceptionGets a class for the given class name.- Parameters:
className- the class name to retrieve the class for- Returns:
- the class for the given class name
- Throws:
java.lang.ClassNotFoundException- when a class for the specified class name cannot be found
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Returns the classloader used for loading classes.- Returns:
- the classloader used for loading classes
-
createNewClassLoader
protected java.lang.ClassLoader createNewClassLoader(java.util.List<?> classpath, java.lang.ClassLoader classLoader) throws java.net.MalformedURLExceptionCreates a new ClassLoader with the specified classpath.- Parameters:
classpath- the classpath (a list of file path Strings) to include in the new loaderclassLoader- the ClassLoader to use as the parent for the new CLassLoader- Returns:
- the new ClassLoader
- Throws:
java.net.MalformedURLException- when a classpath element provides a malformed URL
-
getGroovyJar
protected java.lang.String getGroovyJar()
Returns the filename of the Groovy jar on the classpath.- Returns:
- the Groovy jar filename
-
getJarPath
protected java.lang.String getJarPath() throws java.lang.ClassNotFoundExceptionReturns the path of the Groovy jar on the classpath.- Returns:
- the path of the Groovy jar
- Throws:
java.lang.ClassNotFoundException- when Groovy couldn't be found on the classpath
-
-