@@ -129,6 +129,47 @@ object PathResolver {
129
129
)
130
130
}
131
131
132
+ /** Locations discovered by supplemental heuristics.
133
+ */
134
+ object SupplementalLocations {
135
+
136
+ /** The platform-specific support jar.
137
+ *
138
+ * Usually this is `tools.jar` in the jdk/lib directory of the platform distribution.
139
+ *
140
+ * The file location is determined by probing the lib directory under JDK_HOME or JAVA_HOME,
141
+ * if one of those environment variables is set, then the lib directory under java.home,
142
+ * and finally the lib directory under the parent of java.home. Or, as a last resort,
143
+ * search deeply under those locations (except for the parent of java.home, on the notion
144
+ * that if this is not a canonical installation, then that search would have little
145
+ * chance of succeeding).
146
+ */
147
+ def platformTools : Option [File ] = {
148
+ val jarName = " tools.jar"
149
+ def jarPath (path : Path ) = (path / " lib" / jarName).toFile
150
+ def jarAt (path : Path ) = {
151
+ val f = jarPath(path)
152
+ if (f.isFile) Some (f) else None
153
+ }
154
+ val jdkDir = {
155
+ val d = Directory (jdkHome)
156
+ if (d.isDirectory) Some (d) else None
157
+ }
158
+ def deeply (dir : Directory ) = dir.deepFiles find (_.name == jarName)
159
+
160
+ val home = envOrSome(" JDK_HOME" , envOrNone(" JAVA_HOME" )) map (p => Path (p))
161
+ val install = Some (Path (javaHome))
162
+
163
+ (home flatMap jarAt) orElse (install flatMap jarAt) orElse (install map (_.parent) flatMap jarAt) orElse
164
+ (jdkDir flatMap deeply)
165
+ }
166
+
167
+ override def toString = s """
168
+ |object SupplementalLocations {
169
+ | platformTools = $platformTools
170
+ |} """ .trim.stripMargin
171
+ }
172
+
132
173
def fromPathString (path : String )(using Context ): ClassPath = {
133
174
val settings = ctx.settings.classpath.update(path)
134
175
inContext(ctx.fresh.setSettings(settings)) {
0 commit comments