diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 11 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Settings.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/AladdinReader.scala | 62 |
3 files changed, 73 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 4cf6055bb3..b8b0ee00ca 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -181,7 +181,16 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable error("unsupported charset '" + settings.encoding.value + "'") stdCharset } - new SourceReader(charset.newDecoder()) + try { + val clazz = Class.forName(settings.sourceReader.value) + val ccon = clazz.getConstructor(Array[Class](classOf[java.nio.charset.CharsetDecoder])) + ccon.newInstance(Array[AnyRef] (charset.newDecoder())).asInstanceOf[SourceReader]; + //new SourceReader(charset.newDecoder()) + } catch { + case e => + error("exception while trying to instantiate source reader \""+settings.sourceReader.value+"\" "); + new SourceReader(charset.newDecoder()) + } } lazy val classPath0 = new ClassPath(false && onlyPresentation) diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index 40355ea444..9ed8a42a69 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -123,7 +123,7 @@ class Settings(error: String => Unit) { val nouescape = new BooleanSetting("-nouescape", "disables handling of \\u unicode escapes") val showPhases = BooleanSetting("-showphases", "Print a synopsis of compiler phases") val showPlugins = BooleanSetting("-showplugins", "Print a synopsis of loaded plugins") - + val sourceReader = StringSetting ("-sourceReader", "classname", " for reading sources", "scala.tools.nsc.io.SourceReader") val inline = BooleanSetting("-Xinline", "Perform inlining when possible") /** non-standard options */ diff --git a/src/compiler/scala/tools/nsc/io/AladdinReader.scala b/src/compiler/scala/tools/nsc/io/AladdinReader.scala new file mode 100644 index 0000000000..e8dd056312 --- /dev/null +++ b/src/compiler/scala/tools/nsc/io/AladdinReader.scala @@ -0,0 +1,62 @@ +package scala.tools.nsc.io + +import java.io.{File, FileInputStream, InputStream, IOException} +import java.net.{ContentHandler, ContentHandlerFactory, URL, URLConnection} +import java.nio.charset.CharsetDecoder + +class AladdinReader(decoder: CharsetDecoder) extends SourceReader(decoder) { + + final val ALADDIN_URL = "http://scala-webapps.epfl.ch/bugtracking/bugs/json/" + + object AladdinHandler extends ContentHandler { + def getContent(con: URLConnection) = { + var state = 0 + val is = con.getInputStream + val src = scala.io.Source.fromInputStream(is) + while(state < 6 && src.hasNext) { + state = (state,src.next) match { + case (0,'\"') => 1 + case (1, 'c') => 2 + case (2, 'o') => 3 + case (3, 'd') => 4 + case (4, 'e') => 5 + case (5,'\"') => 6 + case _ => 0 + } + } + while(src.next != ':') {} + while(src.next != '\"') {} + val sb = new StringBuilder() + var c = ' ' + while(c != '\"' && src.hasNext) { /*Console.print("["+c+"]"); */sb.append(c); c = src.next;} + is.close + //Console.println("!!"+sb.toString+"!!") // DEBUG if you want to see what you are downloading + sb.toString.replace("\\u0022","\"").replace("\\uu005c","\\").toCharArray + } + } + + java.net.URLConnection.setContentHandlerFactory(new ContentHandlerFactory { def createContentHandler(s:String) = AladdinHandler }) + + private def wellformed(str: String): Boolean = try { + str.charAt(0) == '#' && { Integer.parseInt(str.substring(1)); true } + } catch { + case _ => false + } + + /** Reads the specified file. */ + @throws(classOf[java.net.MalformedURLException]) + override def read(file: File): Array[Char] = { + + val content = new String(super.read(file)).trim() + if(!wellformed(content)) + throw FatalError("content should just be a bug identifier, like \"#1023\"") + + var bugURL = ALADDIN_URL + new String(content).trim().substring(1) + try { + new java.net.URL(bugURL).getContent().asInstanceOf[Array[Char]] + } catch { + case e => throw FatalError("while getting content of URL, "+e.getClass()+" saying "+e.getMessage) + } + } + +} |