From e0653db305c7567664fa500acccd2fd5ad7437c0 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 17 Apr 2011 21:28:03 +0000 Subject: Revised that last botched commit. No review. --- src/library/scala/util/Properties.scala | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/library/scala/util/Properties.scala b/src/library/scala/util/Properties.scala index 0674253ea6..f86df0ee96 100644 --- a/src/library/scala/util/Properties.scala +++ b/src/library/scala/util/Properties.scala @@ -59,23 +59,35 @@ private[scala] trait PropertiesTrait { def scalaPropOrEmpty(name: String): String = scalaPropOrElse(name, "") def scalaPropOrNone(name: String): Option[String] = Option(scalaProps.getProperty(name)) - /** The runtime scala version, if it has only three dotted segments. + /** The numeric portion of the runtime scala version, if this is a final + * release. If for instance the versionString says "version 2.9.0.final", + * this would return Some("2.9.0"). * - * @return Some(version) if this is not a development build, None if - * a development build or if the version cannot be read. + * @return Some(version) if this is a final release build, None if + * it is an RC, Beta, etc. or was built from source, or if the version + * cannot be read. */ - val releaseVersion = scalaPropOrNone("version.number") filter (_.split('.').size == 3) + val releaseVersion = scalaPropOrNone("version.number") flatMap { s => + val segments = s split '.' + if (segments.size == 4 && segments.last == "final") Some(segments take 3 mkString ".") else None + } - /** The development scala version. This is derived from the fourth dotted segment - * in the version string, which should only be present if built from source. - * At present it corresponds to the svn revision, but this is not guaranteed - * to remain the case. + /** The development scala version, if this is not a final release. + * The precise contents are not guaranteed, but it aims to provide a + * unique repository identifier (currently the svn revision) in the + * fourth dotted segment if the running version was built from source. * - * @return Some(version) if this is a development build, None if it has fewer - * than four segments or cannot be read. + * @return Some(version) if this is a non-final version, None if this + * is a final release or the version cannot be read. */ val developmentVersion = scalaPropOrNone("version.number") flatMap { s => - (s split '.' drop 3).headOption map (_ takeWhile (ch => ch != '-')) + val segments = s split '.' + if (segments.isEmpty || segments.last == "final") + None + else if (segments.last startsWith "r") + Some(s takeWhile (ch => ch != '-')) // Cutting e.g. 2.10.0.r24774-b20110417125606 to 2.10.0.r24774 + else + Some(s) } /** The version number of the jar this was loaded from plus "version " prefix, -- cgit v1.2.3