Skip to content

Instantly share code, notes, and snippets.

@erikerlandson
Last active April 8, 2022 23:20
Show Gist options
  • Save erikerlandson/5f0519664059b00e98cb4a5d2e6dfd50 to your computer and use it in GitHub Desktop.
Save erikerlandson/5f0519664059b00e98cb4a5d2e6dfd50 to your computer and use it in GitHub Desktop.
import java.lang.{ClassLoader, Package}
def allDefinedPackages(loader: ClassLoader): Vector[Package] =
if (loader == null)
Vector.empty[Package]
else
allDefinedPackages(loader.getParent()) ++ loader.getDefinedPackages()
def allClassPathURLs(loader: ClassLoader): Vector[java.net.URL] =
loader match
case null => Vector.empty[java.net.URL]
case u: java.net.URLClassLoader => allClassPathURLs(loader.getParent) ++ u.getURLs()
case _ => allClassPathURLs(loader.getParent)
Welcome to Scala 3.1.1 (11.0.14, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> coulomb.infra.allClassPathURLs(getClass.getClassLoader)
val res0: Vector[java.net.URL] = Vector(file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/compiler-interface-1.6.0.jar, file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/util-interface-1.6.2.jar, file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/test-interface-1.0.jar, file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jna-5.8.0.jar, file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jna-platform-5.8.0.jar, file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jline-terminal-3.19.0.jar, file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jline-2.14.7-sbt-a1b0ffbb8f64bb820f4f84a0c07a0c0964507493.jar, file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jline-terminal-jna-3.19.0.jar, file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jline-terminal-jansi-3.19.0.jar, file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jansi-2.1.0.jar, file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala ... large output truncated, print value to show all
scala> print(res0.mkString("\n"))
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/compiler-interface-1.6.0.jar
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/util-interface-1.6.2.jar
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/test-interface-1.0.jar
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jna-5.8.0.jar
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jna-platform-5.8.0.jar
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jline-terminal-3.19.0.jar
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jline-2.14.7-sbt-a1b0ffbb8f64bb820f4f84a0c07a0c0964507493.jar
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jline-terminal-jna-3.19.0.jar
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jline-terminal-jansi-3.19.0.jar
file:/home/eje/.sbt/boot/scala-2.12.15/org.scala-sbt/sbt/1.6.2/jansi-2.1.0.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.1/scala3-library_3-3.1.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.6/scala-library-2.13.6.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.1/scala3-library_3-3.1.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.6/scala-library-2.13.6.jar
file:/home/eje/git/coulomb/all/target/scala-3.1.1/classes
file:/home/eje/git/coulomb/core/.jvm/target/scala-3.1.1/classes/
file:/home/eje/git/coulomb/units/.jvm/target/scala-3.1.1/classes/
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.1.1/scala3-library_3-3.1.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/algebra_3/2.7.0/algebra_3-2.7.0.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-staging_3/3.1.1/scala3-staging_3-3.1.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.6/scala-library-2.13.6.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-kernel_3/2.7.0/cats-kernel_3-2.7.0.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.1.1/scala3-compiler_3-3.1.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-interfaces/3.1.1/scala3-interfaces-3.1.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/tasty-core_3/3.1.1/tasty-core_3-3.1.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-asm/9.1.0-scala-1/scala-asm-9.1.0-scala-1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/compiler-interface/1.3.5/compiler-interface-1.3.5.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-reader/3.19.0/jline-reader-3.19.0.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-terminal/3.19.0/jline-terminal-3.19.0.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-terminal-jna/3.19.0/jline-terminal-jna-3.19.0.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.7.0/protobuf-java-3.7.0.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/util-interface/1.3.0/util-interface-1.3.0.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scaladoc_3/3.1.1/scaladoc_3-3.1.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-tasty-inspector_3/3.1.1/scala3-tasty-inspector_3-3.1.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark/0.42.12/flexmark-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-html-parser/0.42.12/flexmark-html-parser-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-anchorlink/0.42.12/flexmark-ext-anchorlink-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-autolink/0.42.12/flexmark-ext-autolink-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-emoji/0.42.12/flexmark-ext-emoji-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-gfm-strikethrough/0.42.12/flexmark-ext-gfm-strikethrough-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-gfm-tables/0.42.12/flexmark-ext-gfm-tables-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-gfm-tasklist/0.42.12/flexmark-ext-gfm-tasklist-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-wikilink/0.42.12/flexmark-ext-wikilink-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-yaml-front-matter/0.42.12/flexmark-ext-yaml-front-matter-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/nl/big-o/liqp/0.6.7/liqp-0.6.7.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jsoup/jsoup/1.13.1/jsoup-1.13.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.9.8/jackson-dataformat-yaml-2.9.8.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util/0.42.12/flexmark-util-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-formatter/0.42.12/flexmark-formatter-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/nibor/autolink/autolink/0.6.0/autolink-0.6.0.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-jira-converter/0.42.12/flexmark-jira-converter-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/antlr/antlr/3.5.1/antlr-3.5.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.2.3/jackson-annotations-2.2.3.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.9.8/jackson-core-2.9.8.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.2.3/jackson-databind-2.2.3.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/yaml/snakeyaml/1.23/snakeyaml-1.23.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-tables/0.42.12/flexmark-ext-tables-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-ins/0.42.12/flexmark-ext-ins-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-superscript/0.42.12/flexmark-ext-superscript-0.42.12.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/antlr/antlr-runtime/3.5.1/antlr-runtime-3.5.1.jar
file:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/antlr/ST4/4.0.7/ST4-4.0.7.jar~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment