Permalink
Browse files

No 'scala-reflect*.jar' warning for Scala 2.10 compiler

  • Loading branch information...
1 parent 7a87421 commit bb3463dc80199863338ab2113b5277fafacb04f8 @pavelfatin pavelfatin committed Jan 22, 2013
@@ -71,9 +71,19 @@ object CompilerData {
case right => right
}
- compiler.map { compilerJar =>
+ compiler.flatMap { compilerJar =>
val extraJars = files.filterNot(file => file == libraryJar || file == compilerJar)
- CompilerJars(libraryJar, compilerJar, extraJars)
+
+ val reflectJarError = {
+ readProperty(compilerJar, "compiler.properties", "version.number").flatMap {
+ case version if version.startsWith("2.10") => // TODO implement a better version comparison
+ find(extraJars, "scala-reflect", ".jar").left.toOption
+ .map(_ + " in Scala compiler library in " + module.getName)
+ case _ => None
+ }
+ }
+
+ reflectJarError.toLeft(CompilerJars(libraryJar, compilerJar, extraJars))
}
}
}
@@ -1,5 +1,7 @@
package org.jetbrains.jps.incremental
+import _root_.java.io._
+import _root_.java.net.URL
import _root_.java.util.Properties
/**
@@ -31,14 +33,22 @@ package object scala {
}
def readProperty(classLoader: ClassLoader, resource: String, name: String): Option[String] = {
- Option(classLoader.getResourceAsStream(resource)).flatMap { stream =>
- try {
- val properties = new Properties()
- properties.load(stream)
- Option(properties.getProperty(name))
- } finally {
- stream.close()
- }
+ Option(classLoader.getResourceAsStream(resource))
+ .flatMap(it => using(new BufferedInputStream(it))(readProperty(_, name)))
+ }
+
+ def readProperty(file: File, resource: String, name: String): Option[String] = {
+ try {
+ val url = new URL("jar:%s!/%s".format(file.toURI.toString, resource))
+ Option(url.openStream).flatMap(it => using(new BufferedInputStream(it))(readProperty(_, name)))
+ } catch {
+ case _: IOException => None
}
}
+
+ private def readProperty(input: InputStream, name: String): Option[String] = {
+ val properties = new Properties()
+ properties.load(input)
+ Option(properties.getProperty(name))
+ }
}

0 comments on commit bb3463d

Please sign in to comment.