summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala2
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala35
2 files changed, 9 insertions, 28 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 658aa66fd9..1635b2c404 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -845,7 +845,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
/** Is given package class a system package class that cannot be invalidated?
*/
- private def isSystemPackageClass(pkg: Symbol) =
+ private def isSystemPackageClass(pkg: Symbol) =
pkg == RootClass || (pkg.hasTransOwner(definitions.ScalaPackageClass) && !pkg.hasTransOwner(this.rootMirror.staticPackage("scala.tools").moduleClass.asClass))
/** Invalidates packages that contain classes defined in a classpath entry, and
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
index 209e3f96bd..fd2b2dbb5e 100644
--- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
@@ -634,15 +634,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
super.defineClass(null, arr, 0, arr.length)
}
- def readFully(is: InputStream): Array[Byte] = {
- val dis = new java.io.DataInputStream(is)
- val len = dis.available()
- val arr = Array.ofDim[Byte](len)
- dis.readFully(arr)
- dis.close()
- arr
- }
-
val f = File(arg).normalize
if (f.isDirectory) {
@@ -658,29 +649,19 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
val entries = flatten(jarFile)
val cloader = new InfoClassLoader
- var exists = false
-
- while (entries.hasNext) {
- val entry = entries.next()
- // skip directories and manifests
- if (!entry.isDirectory && entry.name.endsWith(".class")) {
- // for each entry get InputStream
- val is = entry.input
- // read InputStream into Array[Byte]
- val arr = readFully(is)
- val clazz = cloader.classOf(arr)
- if ((intp.classLoader tryToLoadClass clazz.getName).isDefined) exists = true
- }
- }
- if (f.exists && !exists) {
+ def classNameOf(classFile: AbstractFile): String = cloader.classOf(classFile.toByteArray).getName
+ def alreadyDefined(clsName: String) = intp.classLoader.tryToLoadClass(clsName).isDefined
+ val exists = entries.filter(_.hasExtension("class")).map(classNameOf).exists(alreadyDefined)
+
+ if (!f.exists) echo(s"The path '$f' doesn't seem to exist.")
+ else if (exists) echo(s"The path '$f' cannot be loaded, because existing classpath entries conflict.") // TODO tell me which one
+ else {
addedClasspath = ClassPath.join(addedClasspath, f.path)
intp.addUrlsToClassPath(f.toURI.toURL)
echo("Added '%s' to classpath.".format(f.path, intp.global.classPath.asClasspathString))
repldbg("Added '%s'. Your new classpath is:\n\"%s\"".format(f.path, intp.global.classPath.asClasspathString))
- } else if (exists) {
- echo("The path '" + f + "' cannot be loaded, because existing classpath entries conflict.")
- } else echo("The path '" + f + "' doesn't seem to exist.")
+ }
}
def powerCmd(): Result = {