From 8aa7f6b634c15138af1bdef711599aedb150f056 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 6 Aug 2020 12:10:07 +0200 Subject: [PATCH] fix classpath handling in staging [test-only] --- .../dotc/util/ClasspathFromClassloader.scala | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/util/ClasspathFromClassloader.scala b/compiler/src/dotty/tools/dotc/util/ClasspathFromClassloader.scala index de7edd804d85..6dc3b74fe7ac 100644 --- a/compiler/src/dotty/tools/dotc/util/ClasspathFromClassloader.scala +++ b/compiler/src/dotty/tools/dotc/util/ClasspathFromClassloader.scala @@ -27,21 +27,26 @@ object ClasspathFromClassloader { classpathBuff ++= cl.getURLs.iterator.map(url => Paths.get(url.toURI).toAbsolutePath.toString) case _ => - // HACK: We can't just collect the classpath from arbitrary parent - // classloaders since the current classloader might intentionally - // filter loading classes from its parent (for example - // BootFilteredLoader in the sbt launcher does this and we really - // don't want to include the scala-library that sbt depends on - // here), but we do need to look at the parent of the REPL - // classloader, so we special case it. We can't do this using a type - // test since the REPL classloader class itself is normally loaded - // with a different classloader. - if (cl.getClass.getName == classOf[AbstractFileClassLoader].getName) + if cl.getClass.getName == classOf[AbstractFileClassLoader].getName then + // HACK: We can't just collect the classpath from arbitrary parent + // classloaders since the current classloader might intentionally + // filter loading classes from its parent (for example + // BootFilteredLoader in the sbt launcher does this and we really + // don't want to include the scala-library that sbt depends on + // here), but we do need to look at the parent of the REPL + // classloader, so we special case it. We can't do this using a type + // test since the REPL classloader class itself is normally loaded + // with a different classloader. collectClassLoaderPaths(cl.getParent) + else if cl eq ClassLoader.getSystemClassLoader then + // HACK: For Java 9+, if the classloader is an AppClassLoader then use the classpath from the system + // property `java.class.path`. + // See: https://java-browser.yawk.at/java/10/java.base/jdk/internal/loader/ClassLoaders.java#163 + classpathBuff += System.getProperty("java.class.path") } } } collectClassLoaderPaths(cl) classpathBuff.result().mkString(java.io.File.pathSeparator) } -} +} \ No newline at end of file