summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeather Miller <heather.miller@epfl.ch>2014-11-05 11:53:20 -0800
committerHeather Miller <heather.miller@epfl.ch>2014-11-05 11:53:20 -0800
commit9e56c7a6fe73bce5962a3b121615c6a5bc1023d2 (patch)
tree6524550bd2b270c8e1d06bf15b4af64d16947cf2 /src
parentbe3eb58d0c49139538e69b377834991510447b36 (diff)
downloadscala-9e56c7a6fe73bce5962a3b121615c6a5bc1023d2.tar.gz
scala-9e56c7a6fe73bce5962a3b121615c6a5bc1023d2.tar.bz2
scala-9e56c7a6fe73bce5962a3b121615c6a5bc1023d2.zip
SI-6502 Moving methods concerned with the state of Global from IMain to Global
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala35
-rw-r--r--src/repl/scala/tools/nsc/interpreter/IMain.scala34
2 files changed, 36 insertions, 33 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 1635b2c404..3fb1bd10f0 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -8,6 +8,7 @@ package tools
package nsc
import java.io.{ File, FileOutputStream, PrintWriter, IOException, FileNotFoundException }
+import java.net.URL
import java.nio.charset.{ Charset, CharsetDecoder, IllegalCharsetNameException, UnsupportedCharsetException }
import scala.compat.Platform.currentTime
import scala.collection.{ mutable, immutable }
@@ -841,6 +842,40 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
} reverse
}
+ // ------------ REPL utilities ---------------------------------
+
+ /** Extend classpath of `platform` and rescan updated packages. */
+ def extendCompilerClassPath(urls: URL*): Unit = {
+ val newClassPath = mergeUrlsIntoClassPath(platform, urls: _*)
+ platform.currentClassPath = Some(newClassPath)
+ // Reload all specified jars into this compiler instance
+ invalidateClassPathEntries(urls.map(_.getPath): _*)
+ }
+
+ /** Merge classpath of `platform` and `urls` into merged classpath */
+ def mergeUrlsIntoClassPath(platform: JavaPlatform, urls: URL*): MergedClassPath[AbstractFile] = {
+ // Collect our new jars/directories and add them to the existing set of classpaths
+ val prevEntries = platform.classPath match {
+ case mcp: MergedClassPath[AbstractFile] => mcp.entries
+ case cp: ClassPath[AbstractFile] => List(cp)
+ }
+ val allEntries = (prevEntries ++
+ urls.map(url => platform.classPath.context.newClassPath(
+ if (url.getProtocol == "file") {
+ val f = new File(url.getPath)
+ if (f.isDirectory) io.AbstractFile.getDirectory(f)
+ else io.AbstractFile.getFile(f)
+ } else {
+ io.AbstractFile.getURL(url)
+ }
+ )
+ )
+ ).distinct
+
+ // Combine all of our classpaths (old and new) into one merged classpath
+ new MergedClassPath(allEntries, platform.classPath.context)
+ }
+
// ------------ Invalidations ---------------------------------
/** Is given package class a system package class that cannot be invalidated?
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala
index 01b46541cd..b990e401ec 100644
--- a/src/repl/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala
@@ -252,39 +252,7 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
def addUrlsToClassPath(urls: URL*): Unit = {
new Run // force some initialization
urls.foreach(_runtimeClassLoader.addURL) // Add jars to runtime classloader
- extendCompilerClassPath(urls: _*) // Add jars to compile-time classpath
- }
-
- /** Extend classpath of global.platform and force `global` to rescan updated packages. */
- protected def extendCompilerClassPath(urls: URL*): Unit = {
- val newClassPath = mergeUrlsIntoClassPath(global.platform, urls: _*)
- global.platform.currentClassPath = Some(newClassPath)
- // Reload all specified jars into the current compiler instance (global)
- global.invalidateClassPathEntries(urls.map(_.getPath): _*)
- }
-
- /** Merge classpath of `platform` and `urls` into merged classpath */
- protected def mergeUrlsIntoClassPath(platform: JavaPlatform, urls: URL*): MergedClassPath[AbstractFile] = {
- // Collect our new jars/directories and add them to the existing set of classpaths
- val prevEntries = platform.classPath match {
- case mcp: MergedClassPath[AbstractFile] => mcp.entries
- case cp: ClassPath[AbstractFile] => List(cp)
- }
- val allEntries = (prevEntries ++
- urls.map(url => platform.classPath.context.newClassPath(
- if (url.getProtocol == "file") {
- val f = new File(url.getPath)
- if (f.isDirectory) io.AbstractFile.getDirectory(f)
- else io.AbstractFile.getFile(f)
- } else {
- io.AbstractFile.getURL(url)
- }
- )
- )
- ).distinct
-
- // Combine all of our classpaths (old and new) into one merged classpath
- new MergedClassPath(allEntries, platform.classPath.context)
+ global.extendCompilerClassPath(urls: _*) // Add jars to compile-time classpath
}
/** Parent classloader. Overridable. */