diff options
author | Heather Miller <heather.miller@epfl.ch> | 2014-10-24 14:18:38 -0700 |
---|---|---|
committer | Heather Miller <heather.miller@epfl.ch> | 2014-11-05 10:56:53 -0800 |
commit | be3eb58d0c49139538e69b377834991510447b36 (patch) | |
tree | 2741238fbfeded4fe1cdc600f86fdd536f63768b /src/repl/scala | |
parent | d045ddeba0bec4deef8cd5825d4b8c022c726ca8 (diff) | |
download | scala-be3eb58d0c49139538e69b377834991510447b36.tar.gz scala-be3eb58d0c49139538e69b377834991510447b36.tar.bz2 scala-be3eb58d0c49139538e69b377834991510447b36.zip |
Addresses review comments
Diffstat (limited to 'src/repl/scala')
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/ILoop.scala | 35 |
1 files changed, 8 insertions, 27 deletions
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 = { |