Class ClassWrangler


  • public class ClassWrangler
    extends Object
    Handles getting Groovy classes and version from the specified classpath.
    Since:
    1.2
    Author:
    Keegan Witt
    • Field Detail

      • groovyVersion

        protected String groovyVersion
        Cached Groovy version.
      • isIndy

        protected Boolean isIndy
        Cached whether Groovy supports invokedynamic (indy jar).
      • classLoader

        protected ClassLoader classLoader
        ClassLoader to use for class wrangling.
      • log

        protected org.apache.maven.plugin.logging.Log log
        Plugin log.
    • Constructor Detail

      • ClassWrangler

        public ClassWrangler​(ClassLoader classLoaderForLoading,
                             org.apache.maven.plugin.logging.Log pluginLog)
        Creates a new ClassWrangler using the specified ClassLoader.
        Parameters:
        classLoaderForLoading - the ClassLoader to use to load classes
        pluginLog - the Maven log to use for logging
      • ClassWrangler

        public ClassWrangler​(List classpath,
                             org.apache.maven.plugin.logging.Log pluginLog)
                      throws MalformedURLException
        Creates a new ClassWrangler using a new ClassLoader, loaded with the items from the specified classpath.
        Parameters:
        classpath - the classpath to load the new ClassLoader with
        pluginLog - the Maven log to use for logging
        Throws:
        MalformedURLException
    • Method Detail

      • getGroovyVersionString

        public 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
      • isGroovyIndy

        public boolean isGroovyIndy()
        Gets whether the version of Groovy on the classpath supports invokedynamic.
        Returns:
        true if the version of Groovy uses invokedynamic, false if not or Groovy dependency cannot be found.
      • getGroovyJar

        public String getGroovyJar()
        Returns the filename of the Groovy jar on the classpath.
        Returns:
        the Groovy jar filename
      • logGroovyVersion

        public void logGroovyVersion​(String goal)
        Logs the version of groovy used by this mojo.
        Parameters:
        goal - The goal to mention in the log statement showing Groovy version
      • createNewClassLoader

        public ClassLoader createNewClassLoader​(List classpath)
                                         throws MalformedURLException
        Creates a new ClassLoader with the specified classpath.
        Parameters:
        classpath - the classpath (a list of file path Strings) to include in the new loader
        Returns:
        the new ClassLoader
        Throws:
        MalformedURLException - when a classpath element provides a malformed URL
      • getClass

        public Class getClass​(String className)
                       throws ClassNotFoundException
        Gets 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:
        ClassNotFoundException - when a class for the specified class name cannot be found
      • getClassLoader

        public ClassLoader getClassLoader()
        Returns the classloader used for loading classes.
        Returns:
        the classloader used for loading classes