@@ -3,18 +3,15 @@ package dotc
33package config
44
55import WrappedProperties .AccessControl
6- import io .{ ClassPath , Directory , Path }
7- import classpath .{AggregateClassPath , ClassPathFactory , JrtClassPath }
6+ import io .{ClassPath , Directory , Path }
7+ import classpath .{AggregateClassPath , ClassPathFactory , JrtClassPath }
88import ClassPath .split
99import PartialFunction .condOpt
1010import scala .language .postfixOps
1111import core .Contexts ._
1212import Settings ._
1313import dotty .tools .io .File
1414
15- // Loosely based on the draft specification at:
16- // https://wiki.scala-lang.org/display/SW/Classpath
17-
1815object PathResolver {
1916
2017 // Imports property/environment functions which suppress
@@ -24,10 +21,11 @@ object PathResolver {
2421 def firstNonEmpty (xs : String * ): String = xs find (_ != " " ) getOrElse " "
2522
2623 /** Map all classpath elements to absolute paths and reconstruct the classpath.
27- */
24+ */
2825 def makeAbsolute (cp : String ): String = ClassPath .map(cp, x => Path (x).toAbsolute.path)
2926
30- /** pretty print class path */
27+ /** pretty print class path
28+ */
3129 def ppcp (s : String ): String = split(s) match {
3230 case Nil => " "
3331 case Seq (x) => x
@@ -53,7 +51,8 @@ object PathResolver {
5351 def scalaHome : String = propOrEmpty(" scala.home" )
5452 def scalaExtDirs : String = propOrEmpty(" scala.ext.dirs" )
5553
56- /** The java classpath and whether to use it. */
54+ /** The java classpath and whether to use it.
55+ */
5756 def javaUserClassPath : String = propOrElse(" java.class.path" , " " )
5857 def useJavaClassPath : Boolean = propOrFalse(" scala.usejavacp" )
5958
@@ -77,14 +76,14 @@ object PathResolver {
7776 def javaExtDirs : String = Environment .javaExtDirs
7877 def useJavaClassPath : Boolean = Environment .useJavaClassPath
7978
80- def scalaHome : String = Environment .scalaHome
81- def scalaHomeDir : Directory = Directory (scalaHome)
82- def scalaHomeExists : Boolean = scalaHomeDir.isDirectory
83- def scalaLibDir : Directory = (scalaHomeDir / " lib" ).toDirectory
84- def scalaClassesDir : Directory = (scalaHomeDir / " classes" ).toDirectory
79+ def scalaHome : String = Environment .scalaHome
80+ def scalaHomeDir : Directory = Directory (scalaHome)
81+ def scalaHomeExists : Boolean = scalaHomeDir.isDirectory
82+ def scalaLibDir : Directory = (scalaHomeDir / " lib" ).toDirectory
83+ def scalaClassesDir : Directory = (scalaHomeDir / " classes" ).toDirectory
8584
86- def scalaLibAsJar : File = (scalaLibDir / " scala-library.jar" ).toFile
87- def scalaLibAsDir : Directory = (scalaClassesDir / " library" ).toDirectory
85+ def scalaLibAsJar : File = (scalaLibDir / " scala-library.jar" ).toFile
86+ def scalaLibAsDir : Directory = (scalaClassesDir / " library" ).toDirectory
8887
8988 def scalaLibDirFound : Option [Directory ] =
9089 if (scalaLibAsJar.isFile) Some (scalaLibDir)
@@ -134,9 +133,9 @@ object PathResolver {
134133 new PathResolver ()(ctx.fresh.setSettings(settings)).result
135134 }
136135
137- /** With no arguments, show the interesting values in Environment and Defaults.
138- * If there are arguments , show those in Calculated as if those options had been
139- * given to a scala runner.
136+ /** Show values in Environment and Defaults when no argument is provided .
137+ * Otherwise , show values in Calculated as if those options had been given
138+ * to a scala runner.
140139 */
141140 def main (args : Array [String ]): Unit = {
142141 if (args.isEmpty) {
@@ -159,19 +158,19 @@ object PathResolver {
159158 }
160159 }
161160}
162- import PathResolver .{ Defaults , ppcp }
161+
162+ import PathResolver .{Defaults , ppcp }
163163
164164class PathResolver (implicit ctx : Context ) {
165165 import ctx .base .settings
166166
167167 private val classPathFactory = new ClassPathFactory
168168
169- private def cmdLineOrElse (name : String , alt : String ) = {
170- (commandLineFor(name) match {
171- case Some (" " ) => None
172- case x => x
173- }) getOrElse alt
174- }
169+ private def cmdLineOrElse (name : String , alt : String ) =
170+ commandLineFor(name) match {
171+ case Some (" " ) | None => alt
172+ case Some (x) => x
173+ }
175174
176175 private def commandLineFor (s : String ): Option [String ] = condOpt(s) {
177176 case " javabootclasspath" => settings.javabootclasspath.value
@@ -199,23 +198,13 @@ class PathResolver(implicit ctx: Context) {
199198 * [scaladoc] ../scala-trunk/src/reflect/scala/reflect/macros/Reifiers.scala:89: error: object api is not a member of package reflect
200199 * [scaladoc] case class ReificationException(val pos: reflect.api.PositionApi, val msg: String) extends Throwable(msg)
201200 * [scaladoc] ^
202- * because the bootstrapping will look at the sourcepath and create package "reflect" in "<root>"
203- * and then when typing relative names, instead of picking <root>.scala.relect, typedIdentifier will pick up the
204- * <root>.reflect package created by the bootstrapping. Thus, no bootstrapping for scaladoc!
205- * TODO: we should refactor this as a separate -bootstrap option to have a clean implementation, no? */
201+ * Because bootstrapping looks at the sourcepath and creates the package "reflect" in "<root>" it will cause the
202+ * typedIdentifier to pick <root>.reflect instead of the <root>.scala.reflect package. Thus, no bootstrapping for scaladoc!
203+ */
206204 def sourcePath : String = cmdLineOrElse(" sourcepath" , Defaults .scalaSourcePath)
207205
208- /** Against my better judgment, giving in to martin here and allowing
209- * CLASSPATH to be used automatically. So for the user-specified part
210- * of the classpath:
211- *
212- * - If -classpath or -cp is given, it is that
213- * - Otherwise, if CLASSPATH is set, it is that
214- * - If neither of those, then "." is used.
215- */
216206 def userClassPath : String = {
217- if (! settings.classpath.isDefault)
218- settings.classpath.value
207+ if (! settings.classpath.isDefault) settings.classpath.value
219208 else sys.env.getOrElse(" CLASSPATH" , " ." )
220209 }
221210
0 commit comments