Class ClassWrangler


  • public class ClassWrangler
    extends java.lang.Object
    Handles getting Groovy classes and version from the specified classpath.
    Since:
    1.2
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ClassLoader classLoader
      ClassLoader to use for class wrangling.
      private java.lang.String groovyVersion
      Cached Groovy version.
      private java.lang.Boolean isIndy
      Cached whether Groovy supports invokedynamic (indy jar).
      private org.apache.maven.plugin.logging.Log log
      Plugin 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.ClassLoader createNewClassLoader​(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.ClassLoader getClassLoader()
      Returns the classloader used for loading classes.
      protected java.lang.String getGroovyJar()
      Returns the filename of the Groovy jar on the classpath.
      Version getGroovyVersion()
      Gets the version of Groovy used from the classpath.
      java.lang.String getGroovyVersionString()
      Gets the version string of Groovy used from classpath.
      protected java.lang.String getJarPath()
      Returns the path of the Groovy jar on the classpath.
      static boolean groovyAtLeast​(Version detectedVersion, Version compareToVersion)
      Determines whether the detected Groovy version is the specified version or newer.
      static boolean groovyIs​(Version detectedVersion, Version compareToVersion)
      Determines whether the detected Groovy version is the specified version.
      static boolean groovyNewerThan​(Version detectedVersion, Version compareToVersion)
      Determines whether the detected Groovy version is newer than the specified version.
      static boolean groovyOlderThan​(Version detectedVersion, Version compareToVersion)
      Determines whether the detected Groovy version is older than the specified version.
      boolean isGroovyIndy()
      Gets whether the version of Groovy on the classpath supports invokedynamic.
      void logGroovyVersion​(java.lang.String goal)
      Logs the version of groovy used by this mojo.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.MalformedURLException
        Creates 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 with
        parentClassLoader - the parent for the new ClassLoader used to use to load classes
        pluginLog - 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 version
        compareToVersion - the version to compare the detected Groovy version to
        Returns:
        true if the detected Groovy version is the specified version or newer, false otherwise
      • groovyIs

        public static boolean groovyIs​(Version detectedVersion,
                                       Version compareToVersion)
        Determines whether the detected Groovy version is the specified version.
        Parameters:
        detectedVersion - the detected Groovy version
        compareToVersion - the version to compare the detected Groovy version to
        Returns:
        true if the detected Groovy version is the specified version, false otherwise
      • 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 version
        compareToVersion - the version to compare the detected Groovy version to
        Returns:
        true if the detected Groovy version is newer than the specified version, false otherwise
      • 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 version
        compareToVersion - the version to compare the detected Groovy version to
        Returns:
        true if the detected Groovy version is older than the specified version, false otherwise
      • 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.
      • 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.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:
        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.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
        classLoader - 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.ClassNotFoundException
        Returns 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