diff options
author | Paul Phillips <paulp@improving.org> | 2011-08-23 22:57:15 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-08-23 22:57:15 +0000 |
commit | 0e74720c491ce13e5e904e0bc39e9a60af26f37c (patch) | |
tree | 739584c007c30a6b1974a42674bb1e9b5aa4c721 /src/compiler/scala/tools/reflect/WrappedProperties.scala | |
parent | 3a1463cd833175bdaa7a31d96a41a0d926b0e9db (diff) | |
download | scala-0e74720c491ce13e5e904e0bc39e9a60af26f37c.tar.gz scala-0e74720c491ce13e5e904e0bc39e9a60af26f37c.tar.bz2 scala-0e74720c491ce13e5e904e0bc39e9a60af26f37c.zip |
Some 11th hour modifications with the dual purp...
Some 11th hour modifications with the dual purpose of a smooth console
life for sbt and so the repl can be used on google app engine. Although
this patch may look largish to be entering at RC4, there isn't a lot
going on. It's trying to make these dangerous things:
- property and environment variable accesses
- thread creation
- signal handler installation
happpen in a sufficiently uniform way that people who don't want them
and places who don't allow them are not left with an unfixable situation
where things blow up inside private methods. Also, the (ahem) lower than
usual elegance levels are due to it being intended for 2.9.x as well.
Review by harrah.
Diffstat (limited to 'src/compiler/scala/tools/reflect/WrappedProperties.scala')
-rw-r--r-- | src/compiler/scala/tools/reflect/WrappedProperties.scala | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/reflect/WrappedProperties.scala b/src/compiler/scala/tools/reflect/WrappedProperties.scala new file mode 100644 index 0000000000..2ca374cf01 --- /dev/null +++ b/src/compiler/scala/tools/reflect/WrappedProperties.scala @@ -0,0 +1,39 @@ +/* NSC -- new Scala compiler + * Copyright 2006-2011 LAMP/EPFL + * @author Paul Phillips + */ + +package scala.tools +package reflect + +import scala.util.PropertiesTrait +import java.security.AccessControlException + +/** For placing a wrapper function around property functions. + * Motivated by places like google app engine throwing exceptions + * on property lookups. + */ +trait WrappedProperties extends PropertiesTrait { + def wrap[T](body: => T): Option[T] + + protected def propCategory = "wrapped" + protected def pickJarBasedOn = this.getClass + + override def propIsSet(name: String) = wrap(super.propIsSet(name)) exists (x => x) + override def propOrElse(name: String, alt: String) = wrap(super.propOrElse(name, alt)) getOrElse alt + override def setProp(name: String, value: String) = wrap(super.setProp(name, value)) orNull + override def clearProp(name: String) = wrap(super.clearProp(name)) orNull + override def envOrElse(name: String, alt: String) = wrap(super.envOrElse(name, alt)) getOrElse alt + override def envOrNone(name: String) = wrap(super.envOrNone(name)).flatten + + def systemProperties: Iterator[(String, String)] = { + import scala.collection.JavaConverters._ + wrap(System.getProperties.asScala.iterator) getOrElse Iterator.empty + } +} + +object WrappedProperties { + object AccessControl extends WrappedProperties { + def wrap[T](body: => T) = try Some(body) catch { case _: AccessControlException => None } + } +} |