Created
April 17, 2011 00:25
-
-
Save ymasory/923640 to your computer and use it in GitHub Desktop.
detect Scala version at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getRunningScalaVersion(): String = { | |
try { | |
//OLD WAY | |
//val stream = getClass.getResourceAsStream("/library.properties") | |
//val iter = scala.io.Source.fromInputStream(stream).getLines | |
//val line = (iter find {l => l.startsWith("version.number")}).get | |
//val Version = """version\.number=(\d\.\d\.\d).*""".r | |
//stainsby's way | |
val props = new java.util.Properties | |
props.load(getClass.getResourceAsStream("/library.properties")) | |
val line = props.getProperty("version.number") | |
val Version = """(\d\.\d\.\d).*""".r | |
val Version(versionStr) = line | |
versionStr | |
} | |
catch { | |
case e => { | |
e.printStackTrace() | |
"2.8.0" //or some other default version, or re-raise | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment