diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2017-02-17 09:51:07 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2017-02-17 19:40:33 +1000 |
commit | 09c7edc8a83caaa03127574d38c70a2e5e3b294d (patch) | |
tree | e4ed4adea5afc0a8ca7fc28250438901a7cf55aa /test | |
parent | 502e3c6296e5e997549b7e496e0bbfa62c522110 (diff) | |
download | scala-09c7edc8a83caaa03127574d38c70a2e5e3b294d.tar.gz scala-09c7edc8a83caaa03127574d38c70a2e5e3b294d.tar.bz2 scala-09c7edc8a83caaa03127574d38c70a2e5e3b294d.zip |
Faster and simpler Java 9 classpath implementation
- Take advantage of the `/packages` index provided by the
jrt file system to avoid (expensive) Files.exist for
non-existent entries across the full list of modules.
- Extends ClassPath directly which leads to a simpler
implemnentation that using the base class.
- Add a unit test that shows we can read classes and packages
from the Java standard library.
Fixes scala/scala-dev#306
With this change bootstrap time under Java 9 was comparable to
Java 8. Before, it was about 40% slower.
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/tools/nsc/classpath/JrtClassPathTest.scala | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/classpath/JrtClassPathTest.scala b/test/junit/scala/tools/nsc/classpath/JrtClassPathTest.scala new file mode 100644 index 0000000000..2c3c5134da --- /dev/null +++ b/test/junit/scala/tools/nsc/classpath/JrtClassPathTest.scala @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014 Contributor. All rights reserved. + */ +package scala.tools.nsc.classpath + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.tools.nsc.Settings +import scala.tools.nsc.backend.jvm.AsmUtils +import scala.tools.nsc.util.ClassPath +import scala.tools.util.PathResolver + +@RunWith(classOf[JUnit4]) +class JrtClassPathTest { + + @Test def lookupJavaClasses(): Unit = { + val specVersion = scala.util.Properties.javaSpecVersion + // Run the test using the JDK8 or 9 provider for rt.jar depending on the platform the test is running on. + val cp: ClassPath = + if (specVersion == "" || specVersion == "1.8") { + val settings = new Settings() + val resolver = new PathResolver(settings) + val elements = new ClassPathFactory(settings).classesInPath(resolver.Calculated.javaBootClassPath) + AggregateClassPath(elements) + } + else JrtClassPath().get + + assertEquals(Nil, cp.classes("")) + assertTrue(cp.packages("java").toString, cp.packages("java").exists(_.name == "java.lang")) + assertTrue(cp.classes("java.lang").exists(_.name == "Object")) + val jl_Object = cp.classes("java.lang").find(_.name == "Object").get + assertEquals("java/lang/Object", AsmUtils.classFromBytes(jl_Object.file.toByteArray).name) + assertTrue(cp.list("java.lang").packages.exists(_.name == "java.lang.annotation")) + assertTrue(cp.list("java.lang").classesAndSources.exists(_.name == "Object")) + assertTrue(cp.findClass("java.lang.Object").isDefined) + assertTrue(cp.findClassFile("java.lang.Object").isDefined) + } +} |