@@ -3,18 +3,15 @@ package dotc
3
3
package config
4
4
5
5
import 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 }
8
8
import ClassPath .split
9
9
import PartialFunction .condOpt
10
10
import scala .language .postfixOps
11
11
import core .Contexts ._
12
12
import Settings ._
13
13
import dotty .tools .io .File
14
14
15
- // Loosely based on the draft specification at:
16
- // https://wiki.scala-lang.org/display/SW/Classpath
17
-
18
15
object PathResolver {
19
16
20
17
// Imports property/environment functions which suppress
@@ -24,10 +21,11 @@ object PathResolver {
24
21
def firstNonEmpty (xs : String * ): String = xs find (_ != " " ) getOrElse " "
25
22
26
23
/** Map all classpath elements to absolute paths and reconstruct the classpath.
27
- */
24
+ */
28
25
def makeAbsolute (cp : String ): String = ClassPath .map(cp, x => Path (x).toAbsolute.path)
29
26
30
- /** pretty print class path */
27
+ /** pretty print class path
28
+ */
31
29
def ppcp (s : String ): String = split(s) match {
32
30
case Nil => " "
33
31
case Seq (x) => x
@@ -53,7 +51,8 @@ object PathResolver {
53
51
def scalaHome : String = propOrEmpty(" scala.home" )
54
52
def scalaExtDirs : String = propOrEmpty(" scala.ext.dirs" )
55
53
56
- /** The java classpath and whether to use it. */
54
+ /** The java classpath and whether to use it.
55
+ */
57
56
def javaUserClassPath : String = propOrElse(" java.class.path" , " " )
58
57
def useJavaClassPath : Boolean = propOrFalse(" scala.usejavacp" )
59
58
@@ -77,14 +76,14 @@ object PathResolver {
77
76
def javaExtDirs : String = Environment .javaExtDirs
78
77
def useJavaClassPath : Boolean = Environment .useJavaClassPath
79
78
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
85
84
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
88
87
89
88
def scalaLibDirFound : Option [Directory ] =
90
89
if (scalaLibAsJar.isFile) Some (scalaLibDir)
@@ -134,9 +133,9 @@ object PathResolver {
134
133
new PathResolver ()(ctx.fresh.setSettings(settings)).result
135
134
}
136
135
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.
140
139
*/
141
140
def main (args : Array [String ]): Unit = {
142
141
if (args.isEmpty) {
@@ -159,19 +158,19 @@ object PathResolver {
159
158
}
160
159
}
161
160
}
162
- import PathResolver .{ Defaults , ppcp }
161
+
162
+ import PathResolver .{Defaults , ppcp }
163
163
164
164
class PathResolver (implicit ctx : Context ) {
165
165
import ctx .base .settings
166
166
167
167
private val classPathFactory = new ClassPathFactory
168
168
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
+ }
175
174
176
175
private def commandLineFor (s : String ): Option [String ] = condOpt(s) {
177
176
case " javabootclasspath" => settings.javabootclasspath.value
@@ -199,23 +198,13 @@ class PathResolver(implicit ctx: Context) {
199
198
* [scaladoc] ../scala-trunk/src/reflect/scala/reflect/macros/Reifiers.scala:89: error: object api is not a member of package reflect
200
199
* [scaladoc] case class ReificationException(val pos: reflect.api.PositionApi, val msg: String) extends Throwable(msg)
201
200
* [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
+ */
206
204
def sourcePath : String = cmdLineOrElse(" sourcepath" , Defaults .scalaSourcePath)
207
205
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
- */
216
206
def userClassPath : String = {
217
- if (! settings.classpath.isDefault)
218
- settings.classpath.value
207
+ if (! settings.classpath.isDefault) settings.classpath.value
219
208
else sys.env.getOrElse(" CLASSPATH" , " ." )
220
209
}
221
210
0 commit comments