Skip to content

Commit

Permalink
No 'scala-reflect*.jar' warning for Scala 2.10 compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfatin committed Jan 22, 2013
1 parent 7a87421 commit bb3463d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
26 changes: 18 additions & 8 deletions jps-plugin/src/org/jetbrains/jps/incremental/scala/package.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jetbrains.jps.incremental

import _root_.java.io._
import _root_.java.net.URL
import _root_.java.util.Properties

/**
Expand Down Expand Up @@ -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.