Created
October 12, 2012 22:19
-
-
Save ericacm/3881937 to your computer and use it in GitHub Desktop.
classloaderJars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val isWindows = { | |
val osName = System.getProperty("os.name") | |
val isWin = osName.startsWith("Windows") | |
println("os.name=" + osName + " isWindows=" + isWin) | |
isWin | |
} | |
def currentJars: Array[String] = { | |
val classloader = ClassLoader.getSystemClassLoader | |
var jars = classloader.asInstanceOf[URLClassLoader].getURLs.map(_.getFile).map(URLDecoder.decode(_, "UTF-8")) | |
if (jars.length == 1 && jars(0).contains("surefirebooter")) { | |
jars = surefirebooterJars(jars(0)) | |
} | |
jars = jars.filter(j => !( | |
j.contains("/jre/lib/") || | |
j.contains("idea_rt.jar") || | |
j.contains("surefire/surefire-") || | |
j.contains("junit_rt.jar"))) | |
if (isWindows) jars = jars.map(_.tail) | |
jars | |
} | |
def surefirebooterJars(surefireJar: String): Array[String] = { | |
val is = new FileInputStream(surefireJar) | |
val jarStream = new JarInputStream(is) | |
val mf = jarStream.getManifest | |
val mainAttributes = mf.getMainAttributes | |
val classpath = mainAttributes.getValue("Class-Path") | |
classpath.replaceAll("file:", "").split(" ").toArray | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment