Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit 96c3c00

Browse files
committed
SI-7786 Partest finds javac
Since partest is probably running with a JDK, use JDK_HOME/bin/javac for compilation, if it exists; otherwise, fall back to whatever is on the command line. Javac can still be specified explicitly.
1 parent 53a5130 commit 96c3c00

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main/scala/scala/tools/partest/PartestDefaults.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package partest
33

44
import scala.concurrent.duration.Duration
55
import scala.tools.nsc.Properties.{ propOrNone => prop }
6+
import scala.util.Properties.jdkHome
67
import java.lang.Runtime.{ getRuntime => runtime }
78

89
object PartestDefaults {
910
def sourcePath = prop("partest.srcdir") getOrElse "files"
10-
def javaCmd = prop("partest.javacmd") getOrElse "java"
11-
def javacCmd = prop("partest.javac_cmd") getOrElse "javac"
11+
def javaCmd = prop("partest.javacmd") orElse jdkexec("java") getOrElse "java"
12+
def javacCmd = prop("partest.javac_cmd") orElse jdkexec("javac") getOrElse "javac"
1213
def javaOpts = prop("partest.java_opts") getOrElse "" // opts when running java during tests
1314
def scalacOpts = prop("partest.scalac_opts") getOrElse ""
1415

@@ -18,4 +19,13 @@ object PartestDefaults {
1819
def waitTime = Duration(prop("partest.timeout") getOrElse "4 hours")
1920

2021
//def timeout = "1200000" // per-test timeout
22+
23+
// probe for the named executable
24+
private def jdkexec(name: String): Option[String] = {
25+
import scala.reflect.io.Path, Path._
26+
Some(Path(jdkHome) / "bin") filter (_.isDirectory) flatMap { p =>
27+
val candidates = (p walkFilter { e => (e.name == name || e.name.startsWith(s"$name.")) && e.jfile.canExecute }).toList
28+
(candidates find (_.name == name) orElse candidates.headOption) map (_.path)
29+
}
30+
}
2131
}

0 commit comments

Comments
 (0)