Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titletest.groovy
themeMidnight
languagegroovy
import java.util.zip.*


def printClassPath(classLoader, pattern) {
  println "$classLoader"


  classLoader.URLs.eachfindAll { url
->     def urlText = url.toString()it.toExternalForm().endsWith(".jar")
  }.each { url ->
 // for clarity, wedef only want to print out the jar file name once
    boolean urlPrinted = false
    if (urlText.endsWith('.jar')) {f = new File(url.toURI())
       try {
      boolean firstTime def f = new File(url.toURI())true
         new ZipFile(f).entries().eachfindAll { ZipEntry entry ->
          def matcher = entryit.name =~ pattern           if (matcher) {
  }.each { ZipEntry entry -> 
        if (!urlPrintedfirstTime) {
              println "  > $urlText$url"
          firstTime    urlPrinted = truefalse
            }
            println "    > ${entry.name}"  
          }
        }    
      } catch (Throwable e) {
        println "Error opening jar file ${f}, message: ${e.message}"
      }
    }


}     // if we have a parent, make a recursive call to search for the class there also
  if (classLoader.parent) {
     printClassPath(classLoader.parent, pattern)
  }
}

// call the method with the current classpath, ??
// look for classes matching 'http' ??
// (?i) switches on case insensitive regex matching
// the / .. / is a groovy string syntax suitable for regex handling
printClassPath this.class.classLoader, /(?i)http/


 

To try this out, paste the above code into 'test.groovy' and execute as follows: 

...