summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-04-23 00:58:12 -0700
committerSom Snytt <som.snytt@gmail.com>2013-05-23 01:20:24 -0700
commit63bd52781faa1192de1c87028d6ac637d535a50e (patch)
tree84a0fc87f76344a1c68164763e7f4e2c25ec7acd
parent649d5bb3a59326ea8fb7790f6abc948951c73905 (diff)
downloadscala-63bd52781faa1192de1c87028d6ac637d535a50e.tar.gz
scala-63bd52781faa1192de1c87028d6ac637d535a50e.tar.bz2
scala-63bd52781faa1192de1c87028d6ac637d535a50e.zip
SI-7410 REPL uses improved tools.jar locator
The logic in partest for snooping around for tools.jar is moved to PathResolver, and ILoop uses it from there. If JAVA_HOME is toolless, check out java.home. The use case was that Ubuntu installs with `java` at version 6 and `javac` at version 7; it's easy to wind up with JAVA_HOME pointing at the version 6 JRE, as I discovered. It's confusing when that happens. In future, partest might run under 7 and fork tests under 6, but those permutations are downstream.
-rw-r--r--src/compiler/scala/tools/reflect/WrappedProperties.scala1
-rw-r--r--src/compiler/scala/tools/util/PathResolver.scala46
-rw-r--r--src/library/scala/util/Properties.scala2
-rw-r--r--src/partest/scala/tools/partest/nest/PathSettings.scala31
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala10
5 files changed, 51 insertions, 39 deletions
diff --git a/src/compiler/scala/tools/reflect/WrappedProperties.scala b/src/compiler/scala/tools/reflect/WrappedProperties.scala
index c34edb8ba0..20567719be 100644
--- a/src/compiler/scala/tools/reflect/WrappedProperties.scala
+++ b/src/compiler/scala/tools/reflect/WrappedProperties.scala
@@ -25,6 +25,7 @@ trait WrappedProperties extends PropertiesTrait {
override def clearProp(name: String) = wrap(super.clearProp(name)).orNull
override def envOrElse(name: String, alt: String) = wrap(super.envOrElse(name, alt)) getOrElse alt
override def envOrNone(name: String) = wrap(super.envOrNone(name)).flatten
+ override def envOrSome(name: String, alt: Option[String]) = wrap(super.envOrNone(name)).flatten orElse alt
def systemProperties: Iterator[(String, String)] = {
import scala.collection.JavaConverters._
diff --git a/src/compiler/scala/tools/util/PathResolver.scala b/src/compiler/scala/tools/util/PathResolver.scala
index 863cbc5c1a..fdc0f5a889 100644
--- a/src/compiler/scala/tools/util/PathResolver.scala
+++ b/src/compiler/scala/tools/util/PathResolver.scala
@@ -39,7 +39,7 @@ object PathResolver {
/** Environment variables which java pays attention to so it
* seems we do as well.
*/
- def sourcePathEnv = envOrElse("SOURCEPATH", "")
+ def sourcePathEnv = envOrElse("SOURCEPATH", "")
def javaBootClassPath = propOrElse("sun.boot.class.path", searchForBootClasspath)
def javaExtDirs = propOrEmpty("java.ext.dirs")
@@ -119,6 +119,50 @@ object PathResolver {
)
}
+ /** Locations discovered by supplemental heuristics.
+ */
+ object SupplementalLocations {
+
+ /** The platform-specific support jar.
+ *
+ * Usually this is `tools.jar` in the jdk/lib directory of the platform distribution.
+ *
+ * The file location is determined by probing the lib directory under JDK_HOME or JAVA_HOME,
+ * if one of those environment variables is set, then the lib directory under java.home,
+ * and finally the lib directory under the parent of java.home. Or, as a last resort,
+ * search deeply under those locations (except for the parent of java.home, on the notion
+ * that if this is not a canonical installation, then that search would have little
+ * chance of succeeding).
+ */
+ def platformTools: Option[File] = {
+ val jarName = "tools.jar"
+ def jarPath(path: Path) = (path / "lib" / jarName).toFile
+ def jarAt(path: Path) = {
+ val f = jarPath(path)
+ if (f.isFile) Some(f) else None
+ }
+ val jdkDir = {
+ val d = Directory(jdkHome)
+ if (d.isDirectory) Some(d) else None
+ }
+ def deeply(dir: Directory) = dir.deepFiles find (_.name == jarName)
+
+ val home = envOrSome("JDK_HOME", envOrNone("JAVA_HOME")) map (p => Path(p))
+ val install = Some(Path(javaHome))
+
+ (home flatMap jarAt) orElse (install flatMap jarAt) orElse (install map (_.parent) flatMap jarAt) orElse
+ (jdkDir flatMap deeply)
+ }
+ private def vals = List(
+ s"platformTools = $platformTools"
+ )
+ override def toString = vals mkString (
+ f"object SupplementalLocations {%n ",
+ f"%n ",
+ f"%n}"
+ )
+ }
+
def fromPathString(path: String, context: JavaContext = DefaultJavaContext): JavaClassPath = { // called from scalap
val s = new Settings()
s.classpath.value = path
diff --git a/src/library/scala/util/Properties.scala b/src/library/scala/util/Properties.scala
index d2d473bf98..73469a955d 100644
--- a/src/library/scala/util/Properties.scala
+++ b/src/library/scala/util/Properties.scala
@@ -60,6 +60,8 @@ private[scala] trait PropertiesTrait {
def envOrElse(name: String, alt: String) = Option(System getenv name) getOrElse alt
def envOrNone(name: String) = Option(System getenv name)
+ def envOrSome(name: String, alt: Option[String]) = envOrNone(name) orElse alt
+
// for values based on propFilename
def scalaPropOrElse(name: String, alt: String): String = scalaProps.getProperty(name, alt)
def scalaPropOrEmpty(name: String): String = scalaPropOrElse(name, "")
diff --git a/src/partest/scala/tools/partest/nest/PathSettings.scala b/src/partest/scala/tools/partest/nest/PathSettings.scala
index 8e454d8de8..030c515947 100644
--- a/src/partest/scala/tools/partest/nest/PathSettings.scala
+++ b/src/partest/scala/tools/partest/nest/PathSettings.scala
@@ -5,10 +5,8 @@
package scala.tools.partest
package nest
-import scala.tools.nsc.Properties.{ setProp, propOrEmpty, propOrNone, propOrElse }
import scala.tools.nsc.util.ClassPath
import scala.tools.nsc.io.{ Path, File, Directory }
-import scala.util.Properties.{ envOrElse, envOrNone, javaHome, jdkHome }
import Path._
object PathSettings {
@@ -80,34 +78,9 @@ object PathSettings {
lazy val diffUtils: File =
findJar(buildPackLibDir.files, "diffutils") getOrElse sys.error(s"No diffutils.jar found in '$buildPackLibDir'.")
- /** The platform-specific support jar.
- * Usually this is tools.jar in the jdk/lib directory of the platform distribution.
- * The file location is determined by probing the lib directory under JDK_HOME or JAVA_HOME,
- * if one of those environment variables is set, then the lib directory under java.home,
- * and finally the lib directory under the parent of java.home. Or, as a last resort,
- * search deeply under those locations (except for the parent of java.home, on the notion
- * that if this is not a canonical installation, then that search would have little
- * chance of succeeding).
+ /** The platform-specific support jar, `tools.jar`.
*/
- lazy val platformTools: Option[File] = {
- val jarName = "tools.jar"
- def jarPath(path: Path) = (path / "lib" / jarName).toFile
- def jarAt(path: Path) = {
- val f = jarPath(path)
- if (f.isFile) Some(f) else None
- }
- val jdkDir = {
- val d = Directory(jdkHome)
- if (d.isDirectory) Some(d) else None
- }
- def deeply(dir: Directory) = dir.deepFiles find (_.name == jarName)
-
- val home = envOrNone("JDK_HOME") orElse envOrNone("JAVA_HOME") map (p => Path(p))
- val install = Some(Path(javaHome))
-
- (home flatMap jarAt) orElse (install flatMap jarAt) orElse (install map (_.parent) flatMap jarAt) orElse
- (jdkDir flatMap deeply)
- }
+ lazy val platformTools: Option[File] = PathResolver.SupplementalLocations.platformTools
}
class PathSettings() {
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
index f4e06f6bfc..9f841f2c44 100644
--- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
@@ -255,16 +255,8 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
}
- private def findToolsJar() = {
- val jdkPath = Directory(jdkHome)
- val jar = jdkPath / "lib" / "tools.jar" toFile
+ private def findToolsJar() = PathResolver.SupplementalLocations.platformTools
- if (jar isFile)
- Some(jar)
- else if (jdkPath.isDirectory)
- jdkPath.deepFiles find (_.name == "tools.jar")
- else None
- }
private def addToolsJarToLoader() = {
val cl = findToolsJar() match {
case Some(tools) => ScalaClassLoader.fromURLs(Seq(tools.toURL), intp.classLoader)