You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2013/12/04 16:21:19 UTC
[2/9] CLEREZZA-435: repaced tabs with spaces in scala files
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/ScriptEngineFactory.scala
----------------------------------------------------------------------
diff --git a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/ScriptEngineFactory.scala b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/ScriptEngineFactory.scala
index f5f1e0b..5f66c77 100644
--- a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/ScriptEngineFactory.scala
+++ b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/ScriptEngineFactory.scala
@@ -34,8 +34,8 @@ import java.security.AccessController
import java.security.PrivilegedAction
import javax.script.ScriptContext
import javax.script.{ScriptEngineFactory => JavaxEngineFactory, Compilable,
- CompiledScript, ScriptEngine, AbstractScriptEngine, Bindings,
- SimpleBindings, ScriptException}
+ CompiledScript, ScriptEngine, AbstractScriptEngine, Bindings,
+ SimpleBindings, ScriptException}
//import scala.collection.immutable.Map
import scala.actors.DaemonActor
import scala.tools.nsc._;
@@ -50,266 +50,266 @@ import scala.actors.Actor._
class ScriptEngineFactory() extends JavaxEngineFactory with BundleListener {
- def bundleChanged(event: BundleEvent) = {
- MyScriptEngine.interpreterAction ! ScriptEngineFactory.RefreshInterpreter
- //_interpreter = null
- }
+ def bundleChanged(event: BundleEvent) = {
+ MyScriptEngine.interpreterAction ! ScriptEngineFactory.RefreshInterpreter
+ //_interpreter = null
+ }
- private var factory: InterpreterFactory = null
- private var compilerService: CompilerService = null
- var _interpreter : IMain = null;
- private var bundleContext: BundleContext = null
- def interpreter = {
- if (_interpreter == null) {
- this.synchronized {
- if (_interpreter == null) {
- _interpreter = factory.createInterpreter(new PrintWriter(System.out))
- }
- }
- }
- _interpreter
- }
+ private var factory: InterpreterFactory = null
+ private var compilerService: CompilerService = null
+ var _interpreter : IMain = null;
+ private var bundleContext: BundleContext = null
+ def interpreter = {
+ if (_interpreter == null) {
+ this.synchronized {
+ if (_interpreter == null) {
+ _interpreter = factory.createInterpreter(new PrintWriter(System.out))
+ }
+ }
+ }
+ _interpreter
+ }
- //methods from ScriptEngineFactory
- override def getEngineName() = "Scala Scripting Engine for OSGi"
- override def getEngineVersion() = "0.3/scala 2.9.2"
- override def getExtensions() = java.util.Collections.singletonList("scala")
- override def getMimeTypes() = java.util.Collections.singletonList("application/x-scala")
- override def getNames() = java.util.Collections.singletonList("scala")
- override def getLanguageName() = "Scala"
- override def getLanguageVersion ="2.8.1"
- override def getParameter(key : String) = {
- key match {
- case ScriptEngine.ENGINE => getEngineName
- case ScriptEngine.ENGINE_VERSION => getEngineVersion
- case ScriptEngine.NAME => getNames.get(0)
- case ScriptEngine.LANGUAGE => getLanguageName
- case ScriptEngine.LANGUAGE_VERSION => getLanguageVersion
- case _ => null
- }
- }
- override def getMethodCallSyntax(obj : String,
- m : String,
- args : String*) = {
- obj+"."+m+"("+args.mkString(",")+")"
- }
- override def getOutputStatement(toDisplay : String) = "println(\""+toDisplay+"\")"
- override def getProgram(statements : String*) = statements.mkString("\n")
- override def getScriptEngine : ScriptEngine = MyScriptEngine
+ //methods from ScriptEngineFactory
+ override def getEngineName() = "Scala Scripting Engine for OSGi"
+ override def getEngineVersion() = "0.3/scala 2.9.2"
+ override def getExtensions() = java.util.Collections.singletonList("scala")
+ override def getMimeTypes() = java.util.Collections.singletonList("application/x-scala")
+ override def getNames() = java.util.Collections.singletonList("scala")
+ override def getLanguageName() = "Scala"
+ override def getLanguageVersion ="2.8.1"
+ override def getParameter(key : String) = {
+ key match {
+ case ScriptEngine.ENGINE => getEngineName
+ case ScriptEngine.ENGINE_VERSION => getEngineVersion
+ case ScriptEngine.NAME => getNames.get(0)
+ case ScriptEngine.LANGUAGE => getLanguageName
+ case ScriptEngine.LANGUAGE_VERSION => getLanguageVersion
+ case _ => null
+ }
+ }
+ override def getMethodCallSyntax(obj : String,
+ m : String,
+ args : String*) = {
+ obj+"."+m+"("+args.mkString(",")+")"
+ }
+ override def getOutputStatement(toDisplay : String) = "println(\""+toDisplay+"\")"
+ override def getProgram(statements : String*) = statements.mkString("\n")
+ override def getScriptEngine : ScriptEngine = MyScriptEngine
- def activate(componentContext: ComponentContext)= {
- bundleContext = componentContext.getBundleContext
- bundleContext.addBundleListener(this)
- }
+ def activate(componentContext: ComponentContext)= {
+ bundleContext = componentContext.getBundleContext
+ bundleContext.addBundleListener(this)
+ }
- def deactivate(componentContext: ComponentContext) = {
- bundleContext = componentContext.getBundleContext
- bundleContext.removeBundleListener(this)
- }
+ def deactivate(componentContext: ComponentContext) = {
+ bundleContext = componentContext.getBundleContext
+ bundleContext.removeBundleListener(this)
+ }
- def bindInterpreterFactory(f: InterpreterFactory) = {
- factory = f
- }
+ def bindInterpreterFactory(f: InterpreterFactory) = {
+ factory = f
+ }
- def unbindInterpreterFactory(f: InterpreterFactory) = {
- factory = null
- _interpreter = null
- }
+ def unbindInterpreterFactory(f: InterpreterFactory) = {
+ factory = null
+ _interpreter = null
+ }
- def bindCompilerService(s: CompilerService) = {
- compilerService = s
- }
+ def bindCompilerService(s: CompilerService) = {
+ compilerService = s
+ }
- def unbindCompilerService(s: CompilerService) = {
- compilerService = null
- }
- /** Inner object as it accesse interpreter
- */
- object MyScriptEngine extends AbstractScriptEngine() with Compilable {
- override def eval(script : Reader, context : ScriptContext) : Object = {
- val scriptStringWriter = new StringWriter()
- var ch = script.read
- while (ch != -1) {
- scriptStringWriter.write(ch)
- ch = script.read
- }
- eval(scriptStringWriter.toString, context)
- }
+ def unbindCompilerService(s: CompilerService) = {
+ compilerService = null
+ }
+ /** Inner object as it accesse interpreter
+ */
+ object MyScriptEngine extends AbstractScriptEngine() with Compilable {
+ override def eval(script : Reader, context : ScriptContext) : Object = {
+ val scriptStringWriter = new StringWriter()
+ var ch = script.read
+ while (ch != -1) {
+ scriptStringWriter.write(ch)
+ ch = script.read
+ }
+ eval(scriptStringWriter.toString, context)
+ }
- val interpreterAction = new DaemonActor {
- def act() {
- //not using loop { react {, as this method doesn't seem to guarantee
- //asynchronous execution
- //also using react with a final invocation of act() different exception from interprter.bind have been seen
- while(true) {
- receive {
- case (script : String, context : ScriptContext) => {
- //not yet threadsafe, but the test isn't failing
- //should pass jobs to actor that guarantees they are executed sequentially
- //and binding to not inferfere
- try {
- val jTypeMap : java.util.Map[String, java.lang.reflect.Type] =
- new java.util.HashMap[String, java.lang.reflect.Type]()
- val valueMap = new java.util.HashMap[String, Any]()
- import _root_.scala.collection.JavaConversions._
- for (scope <- context.getScopes;
- if (context.getBindings(scope.intValue) != null);
- entry <- context.getBindings(scope.intValue)) {
- interpreter.bind(entry._1,
- getAccessibleClass(entry._2.getClass).getName, entry._2)
- }
- interpreter.interpret("val zzScriptResult = {"+script+"}")
- println("visible stuff:")
- System.out.println("stuff stuff stuff");
- println("interpreter.valueOfTerm(\"zzScriptResult\"): "+interpreter.valueOfTerm("zzScriptResult"))
- interpreter.visibleTermNames.foreach(println)
- if (interpreter.reporter.hasErrors) {
- throw new ScriptException("some error","script-file",1)
- }
- sender ! interpreter.valueOfTerm("zzScriptResult")
- } catch {
- case e: Exception => sender ! ScriptEngineFactory.ActorException(e)
- }
- }
- case ScriptEngineFactory.RefreshInterpreter => {
- _interpreter = null;
- }
- }
- }
- }
- }
- interpreterAction.start()
+ val interpreterAction = new DaemonActor {
+ def act() {
+ //not using loop { react {, as this method doesn't seem to guarantee
+ //asynchronous execution
+ //also using react with a final invocation of act() different exception from interprter.bind have been seen
+ while(true) {
+ receive {
+ case (script : String, context : ScriptContext) => {
+ //not yet threadsafe, but the test isn't failing
+ //should pass jobs to actor that guarantees they are executed sequentially
+ //and binding to not inferfere
+ try {
+ val jTypeMap : java.util.Map[String, java.lang.reflect.Type] =
+ new java.util.HashMap[String, java.lang.reflect.Type]()
+ val valueMap = new java.util.HashMap[String, Any]()
+ import _root_.scala.collection.JavaConversions._
+ for (scope <- context.getScopes;
+ if (context.getBindings(scope.intValue) != null);
+ entry <- context.getBindings(scope.intValue)) {
+ interpreter.bind(entry._1,
+ getAccessibleClass(entry._2.getClass).getName, entry._2)
+ }
+ interpreter.interpret("val zzScriptResult = {"+script+"}")
+ println("visible stuff:")
+ System.out.println("stuff stuff stuff");
+ println("interpreter.valueOfTerm(\"zzScriptResult\"): "+interpreter.valueOfTerm("zzScriptResult"))
+ interpreter.visibleTermNames.foreach(println)
+ if (interpreter.reporter.hasErrors) {
+ throw new ScriptException("some error","script-file",1)
+ }
+ sender ! interpreter.valueOfTerm("zzScriptResult")
+ } catch {
+ case e: Exception => sender ! ScriptEngineFactory.ActorException(e)
+ }
+ }
+ case ScriptEngineFactory.RefreshInterpreter => {
+ _interpreter = null;
+ }
+ }
+ }
+ }
+ }
+ interpreterAction.start()
- override def eval(script : String, context : ScriptContext) : Object = {
- /*val timeout = 180*1000
- interpreterAction !? (timeout, (script, context)) match {
- case Some(x : Object) => x
- case x => throw new RuntimeException("Timeout executing script")
- }*/
- interpreterAction !? ((script, context)) match {
- case ScriptEngineFactory.ActorException(e) => throw e
- case x : Object => x match {
- case Some(y:Object) => y
- case None => null
- }
- }
- }
-
- override def getFactory() = ScriptEngineFactory.this
- override def createBindings() : Bindings = new SimpleBindings
+ override def eval(script : String, context : ScriptContext) : Object = {
+ /*val timeout = 180*1000
+ interpreterAction !? (timeout, (script, context)) match {
+ case Some(x : Object) => x
+ case x => throw new RuntimeException("Timeout executing script")
+ }*/
+ interpreterAction !? ((script, context)) match {
+ case ScriptEngineFactory.ActorException(e) => throw e
+ case x : Object => x match {
+ case Some(y:Object) => y
+ case None => null
+ }
+ }
+ }
+
+ override def getFactory() = ScriptEngineFactory.this
+ override def createBindings() : Bindings = new SimpleBindings
- override def compile(script: Reader): CompiledScript = {
- val scriptStringWriter = new StringWriter()
- var ch = script.read
- while (ch != -1) {
- scriptStringWriter.write(ch)
- ch = script.read
- }
- compile(scriptStringWriter.toString)
- }
+ override def compile(script: Reader): CompiledScript = {
+ val scriptStringWriter = new StringWriter()
+ var ch = script.read
+ while (ch != -1) {
+ scriptStringWriter.write(ch)
+ ch = script.read
+ }
+ compile(scriptStringWriter.toString)
+ }
-
- var classCounter = 0
+
+ var classCounter = 0
- val virtualDirectory = new VirtualDirectory("(memory)", None)
- var msgWriter = new StringWriter
+ val virtualDirectory = new VirtualDirectory("(memory)", None)
+ var msgWriter = new StringWriter
-
- override def compile(script: String): CompiledScript = {
- try {
- AccessController.doPrivileged(new PrivilegedAction[CompiledScript]() {
- override def run() = {
- val objectName = "CompiledScript"+classCounter
- classCounter += 1
- val classCode = "class " + objectName + """ {
- | def run($: Map[String, Object]) = {
- |""".stripMargin + script +"""
- | }
- |}""".stripMargin
- val sources: List[Array[Char]] = List(classCode.toCharArray)
- val clazz = try {
- compilerService.compile(sources)(0)
- } catch {
- case e: CompileErrorsException => throw new ScriptException(e.getMessage, "script", -1);
- case e: Exception => throw e
- }
- val scriptObject = clazz.newInstance()
+
+ override def compile(script: String): CompiledScript = {
+ try {
+ AccessController.doPrivileged(new PrivilegedAction[CompiledScript]() {
+ override def run() = {
+ val objectName = "CompiledScript"+classCounter
+ classCounter += 1
+ val classCode = "class " + objectName + """ {
+ | def run($: Map[String, Object]) = {
+ |""".stripMargin + script +"""
+ | }
+ |}""".stripMargin
+ val sources: List[Array[Char]] = List(classCode.toCharArray)
+ val clazz = try {
+ compilerService.compile(sources)(0)
+ } catch {
+ case e: CompileErrorsException => throw new ScriptException(e.getMessage, "script", -1);
+ case e: Exception => throw e
+ }
+ val scriptObject = clazz.newInstance()
- new CompiledScript() {
- override def eval(context: ScriptContext) = {
+ new CompiledScript() {
+ override def eval(context: ScriptContext) = {
- var map = Map[String, Object]()
- import _root_.scala.collection.JavaConversions._
- for ( scope <- context.getScopes;
- if (context.getBindings(scope.intValue) != null);
- entry <- context.getBindings(scope.intValue)) {
- map = map + (entry._1 -> entry._2)
- }
- val runMethod = clazz.getMethod("run", classOf[Map[String, Object]])
- try {
- runMethod.invoke(scriptObject, map)
- } catch {
- case e: InvocationTargetException => {
- throw e.getCause
- }
- }
- }
- override def getEngine = MyScriptEngine.this
- }
- }
- })
- } catch {
- case e: PrivilegedActionException => throw e.getCause
- }
- }
+ var map = Map[String, Object]()
+ import _root_.scala.collection.JavaConversions._
+ for ( scope <- context.getScopes;
+ if (context.getBindings(scope.intValue) != null);
+ entry <- context.getBindings(scope.intValue)) {
+ map = map + (entry._1 -> entry._2)
+ }
+ val runMethod = clazz.getMethod("run", classOf[Map[String, Object]])
+ try {
+ runMethod.invoke(scriptObject, map)
+ } catch {
+ case e: InvocationTargetException => {
+ throw e.getCause
+ }
+ }
+ }
+ override def getEngine = MyScriptEngine.this
+ }
+ }
+ })
+ } catch {
+ case e: PrivilegedActionException => throw e.getCause
+ }
+ }
-
+
-
+
- /**
- * returns an accessible class or interface that is implemented by class,
- * is doesn't look for superinterfaces of implement interfaces
- */
- private def getAccessibleClass(clazz : Class[_]) : Class[_] = {
- if(isAccessible(clazz)) {
- return clazz
- } else {
- val foo : Class[_] = clazz.getInterfaces()(0)
- for (implementedInterface <- clazz.getInterfaces()) {
- if (isAccessible(implementedInterface)) return implementedInterface
- }
- }
- return getAccessibleSuperClass(clazz)
- }
+ /**
+ * returns an accessible class or interface that is implemented by class,
+ * is doesn't look for superinterfaces of implement interfaces
+ */
+ private def getAccessibleClass(clazz : Class[_]) : Class[_] = {
+ if(isAccessible(clazz)) {
+ return clazz
+ } else {
+ val foo : Class[_] = clazz.getInterfaces()(0)
+ for (implementedInterface <- clazz.getInterfaces()) {
+ if (isAccessible(implementedInterface)) return implementedInterface
+ }
+ }
+ return getAccessibleSuperClass(clazz)
+ }
- private def getAccessibleSuperClass(clazz : Class[_]) : Class[_] = {
- val superClass = clazz.getSuperclass
- if (superClass == null) {
- throw new RuntimeException("No upper class to be checked for accessibility for "+clazz)
- }
- if (isAccessible(superClass)) {
- superClass
- } else {
- getAccessibleSuperClass(superClass)
- }
- }
+ private def getAccessibleSuperClass(clazz : Class[_]) : Class[_] = {
+ val superClass = clazz.getSuperclass
+ if (superClass == null) {
+ throw new RuntimeException("No upper class to be checked for accessibility for "+clazz)
+ }
+ if (isAccessible(superClass)) {
+ superClass
+ } else {
+ getAccessibleSuperClass(superClass)
+ }
+ }
- private def isAccessible(clazz : Class[_]) = {
- try {
- Class.forName(clazz.getName)
- true
- } catch {
- case e: Exception => false
- }
- }
- }
+ private def isAccessible(clazz : Class[_]) = {
+ try {
+ Class.forName(clazz.getName)
+ true
+ } catch {
+ case e: Exception => false
+ }
+ }
+ }
}
object ScriptEngineFactory {
- case class ActorException(e: Throwable);
- case object RefreshInterpreter;
+ case class ActorException(e: Throwable);
+ case object RefreshInterpreter;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala
----------------------------------------------------------------------
diff --git a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala
index c20e264..11cf3f1 100644
--- a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala
+++ b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala
@@ -39,90 +39,90 @@ import java.net._
/** a compiler that keeps track of classes added to the directory
*/
class TrackingCompiler private (bundleContext : BundleContext,
- settings: Settings, reporter: Reporter, classLoaderBuilder: () => ClassLoader,
- writtenClasses: mutable.ListBuffer[AbstractFile])
- extends BundleContextScalaCompiler(bundleContext : BundleContext,
- settings: Settings, reporter: Reporter) {
+ settings: Settings, reporter: Reporter, classLoaderBuilder: () => ClassLoader,
+ writtenClasses: mutable.ListBuffer[AbstractFile])
+ extends BundleContextScalaCompiler(bundleContext : BundleContext,
+ settings: Settings, reporter: Reporter) {
- /**
- * compiles a list of classes to settings.outputDirs returning a
- * the generated AbstractFiles
- */
- @throws(classOf[CompileErrorsException])
- def compileToDir(sources: List[Array[Char]]): List[AbstractFile] = {
- writtenClasses.clear()
- var i = 0
- val sourceFiles: List[SourceFile] = for(chars <- sources) yield {
- i = i +1;
- new BatchSourceFile("<script"+i+">", chars)
- }
- (new Run).compileSources(sourceFiles)
- if (reporter.hasErrors) {
- reporter.reset
- throw new CompileErrorsException;
- }
- writtenClasses.toList
- }
+ /**
+ * compiles a list of classes to settings.outputDirs returning a
+ * the generated AbstractFiles
+ */
+ @throws(classOf[CompileErrorsException])
+ def compileToDir(sources: List[Array[Char]]): List[AbstractFile] = {
+ writtenClasses.clear()
+ var i = 0
+ val sourceFiles: List[SourceFile] = for(chars <- sources) yield {
+ i = i +1;
+ new BatchSourceFile("<script"+i+">", chars)
+ }
+ (new Run).compileSources(sourceFiles)
+ if (reporter.hasErrors) {
+ reporter.reset
+ throw new CompileErrorsException;
+ }
+ writtenClasses.toList
+ }
- /**
- * compiles a list of class sources returning a list of compiled classes
- */
- @throws(classOf[CompileErrorsException])
- def compile(sources: List[Array[Char]]): List[Class[_]] = {
- val classFiles = compileToDir(sources)
- val classLoader = classLoaderBuilder()
- val result: List[Class[_]] = for (classFile <- classFiles;
- if (!classFile.name.contains('$'))) yield {
- val path = classFile.path
- val relevantPath = path.substring(path.indexOf('/')+1,path.lastIndexOf('.'))
- val fqn = relevantPath.replace("/",".")
- classLoader.loadClass(fqn)
- }
- return result
- }
-
+ /**
+ * compiles a list of class sources returning a list of compiled classes
+ */
+ @throws(classOf[CompileErrorsException])
+ def compile(sources: List[Array[Char]]): List[Class[_]] = {
+ val classFiles = compileToDir(sources)
+ val classLoader = classLoaderBuilder()
+ val result: List[Class[_]] = for (classFile <- classFiles;
+ if (!classFile.name.contains('$'))) yield {
+ val path = classFile.path
+ val relevantPath = path.substring(path.indexOf('/')+1,path.lastIndexOf('.'))
+ val fqn = relevantPath.replace("/",".")
+ classLoader.loadClass(fqn)
+ }
+ return result
+ }
+
}
object TrackingCompiler {
- private class TrackingCompilerSplittingDirectory extends SplittingDirectory
+ private class TrackingCompilerSplittingDirectory extends SplittingDirectory
- private def createClassLoader(dir: AbstractFile) = new AbstractFileClassLoader(dir, this.getClass.getClassLoader())
+ private def createClassLoader(dir: AbstractFile) = new AbstractFileClassLoader(dir, this.getClass.getClassLoader())
- def apply(bundleContext : BundleContext, out: PrintWriter, outputDirectoryOption: Option[AbstractFile]) = {
- val (outputDirectory, classLoaderBuilder): (AbstractFile, () => ClassLoader) = outputDirectoryOption match {
- case Some(d) => (d, () => createClassLoader(d))
- case None => {
- val d = new TrackingCompilerSplittingDirectory
- d.currentTarget = new VirtualDirectory("(memory)", None)
- def createClassLoaderAndReset() = {
- val r = createClassLoader(d.currentTarget)
- //println("created class loader with "+(for (c <- d.currentTarget) yield c).mkString("-"))
- d.currentTarget = new VirtualDirectory("(memory)", None)
- r
- }
- (d, createClassLoaderAndReset _)
- }
- }
+ def apply(bundleContext : BundleContext, out: PrintWriter, outputDirectoryOption: Option[AbstractFile]) = {
+ val (outputDirectory, classLoaderBuilder): (AbstractFile, () => ClassLoader) = outputDirectoryOption match {
+ case Some(d) => (d, () => createClassLoader(d))
+ case None => {
+ val d = new TrackingCompilerSplittingDirectory
+ d.currentTarget = new VirtualDirectory("(memory)", None)
+ def createClassLoaderAndReset() = {
+ val r = createClassLoader(d.currentTarget)
+ //println("created class loader with "+(for (c <- d.currentTarget) yield c).mkString("-"))
+ d.currentTarget = new VirtualDirectory("(memory)", None)
+ r
+ }
+ (d, createClassLoaderAndReset _)
+ }
+ }
- val writtenClasses: mutable.ListBuffer[AbstractFile] = mutable.ListBuffer[AbstractFile]()
- val settings = {
- def outputListener(abtractFile: AbstractFile) {
- writtenClasses += abtractFile
- }
- val settings = new Settings
- settings.outputDirs setSingleOutput VirtualDirectoryWrapper.wrap(outputDirectory, outputListener)
- settings
- }
- new TrackingCompiler(bundleContext,
- settings,
- new ConsoleReporter(settings, null, out) {
- override def printMessage(msg: String) {
- out write msg
- out.flush()
- }
- }, classLoaderBuilder, writtenClasses)
- }
+ val writtenClasses: mutable.ListBuffer[AbstractFile] = mutable.ListBuffer[AbstractFile]()
+ val settings = {
+ def outputListener(abtractFile: AbstractFile) {
+ writtenClasses += abtractFile
+ }
+ val settings = new Settings
+ settings.outputDirs setSingleOutput VirtualDirectoryWrapper.wrap(outputDirectory, outputListener)
+ settings
+ }
+ new TrackingCompiler(bundleContext,
+ settings,
+ new ConsoleReporter(settings, null, out) {
+ override def printMessage(msg: String) {
+ out write msg
+ out.flush()
+ }
+ }, classLoaderBuilder, writtenClasses)
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/FileWrapper.scala
----------------------------------------------------------------------
diff --git a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/FileWrapper.scala b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/FileWrapper.scala
index 5fb27d3..2cd55fe 100644
--- a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/FileWrapper.scala
+++ b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/FileWrapper.scala
@@ -30,18 +30,18 @@ import scala.tools.nsc.io.AbstractFile
class FileWrapper(val wrapped: AbstractFile, val childWrapper: (AbstractFile) => AbstractFile) extends AbstractFile with GenericFileWrapperTrait {
- /** overriding this here rather than in the trait as this is a var in VirtualDirectory
- */
- def lastModified = {
- wrapped.lastModified
- }
+ /** overriding this here rather than in the trait as this is a var in VirtualDirectory
+ */
+ def lastModified = {
+ wrapped.lastModified
+ }
- override protected def unsupported(msg: String) = {
- println("unsupported!")
- try {
- super.unsupported(msg)
- } catch {
- case e: Exception => e.printStackTrace(); throw e
- }
- }
+ override protected def unsupported(msg: String) = {
+ println("unsupported!")
+ try {
+ super.unsupported(msg)
+ } catch {
+ case e: Exception => e.printStackTrace(); throw e
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/GenericFileWrapperTrait.scala
----------------------------------------------------------------------
diff --git a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/GenericFileWrapperTrait.scala b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/GenericFileWrapperTrait.scala
index 4e55feb..d443eaa 100644
--- a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/GenericFileWrapperTrait.scala
+++ b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/GenericFileWrapperTrait.scala
@@ -29,63 +29,63 @@ package org.apache.clerezza.scala.scripting.util
import scala.tools.nsc.io.AbstractFile
trait GenericFileWrapperTrait extends AbstractFile with Wrapper[AbstractFile] {
- override def lookupNameUnchecked(name: String,directory: Boolean) = {
- childWrapper(wrapped.lookupNameUnchecked(name, directory))
- }
- override def lookupName(name: String,directory: Boolean) = {
- wrapped.lookupName(name, directory)
- }
- override def iterator = {
- //TODO wrap
- wrapped.iterator
- }
- override def output = {
- wrapped.output
- }
- override def input = {
- wrapped.input
- }
-
- override def isDirectory = {
- wrapped.isDirectory
- }
- override def delete = {
- wrapped.delete
- }
- override def create = {
- wrapped.create
- }
- override def file = {
- wrapped.file
- }
- override def container = {
- childWrapper(wrapped.container)
- }
- override def absolute = {
- childWrapper(wrapped.absolute)
- }
- override def path = {
- wrapped.path
- }
- override def name = {
- wrapped.name
- }
+ override def lookupNameUnchecked(name: String,directory: Boolean) = {
+ childWrapper(wrapped.lookupNameUnchecked(name, directory))
+ }
+ override def lookupName(name: String,directory: Boolean) = {
+ wrapped.lookupName(name, directory)
+ }
+ override def iterator = {
+ //TODO wrap
+ wrapped.iterator
+ }
+ override def output = {
+ wrapped.output
+ }
+ override def input = {
+ wrapped.input
+ }
+
+ override def isDirectory = {
+ wrapped.isDirectory
+ }
+ override def delete = {
+ wrapped.delete
+ }
+ override def create = {
+ wrapped.create
+ }
+ override def file = {
+ wrapped.file
+ }
+ override def container = {
+ childWrapper(wrapped.container)
+ }
+ override def absolute = {
+ childWrapper(wrapped.absolute)
+ }
+ override def path = {
+ wrapped.path
+ }
+ override def name = {
+ wrapped.name
+ }
- override def sizeOption = {
- wrapped.sizeOption
- }
+ override def sizeOption = {
+ wrapped.sizeOption
+ }
- override def lookupPath(path: String, directory: Boolean): AbstractFile = {
- childWrapper(wrapped.lookupPath(path, directory))
- }
- override def lookupPathUnchecked(path: String, directory: Boolean): AbstractFile = {
- childWrapper(wrapped.lookupPathUnchecked(path, directory))
- }
- override def fileNamed(name: String): AbstractFile = {
- childWrapper(wrapped.fileNamed(name))
- }
+ override def lookupPath(path: String, directory: Boolean): AbstractFile = {
+ childWrapper(wrapped.lookupPath(path, directory))
+ }
+ override def lookupPathUnchecked(path: String, directory: Boolean): AbstractFile = {
+ childWrapper(wrapped.lookupPathUnchecked(path, directory))
+ }
+ override def fileNamed(name: String): AbstractFile = {
+ childWrapper(wrapped.fileNamed(name))
+ }
- override def subdirectoryNamed(name: String): AbstractFile = {
- childWrapper(wrapped.subdirectoryNamed(name))
- }
+ override def subdirectoryNamed(name: String): AbstractFile = {
+ childWrapper(wrapped.subdirectoryNamed(name))
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/SplittingDirectory.scala
----------------------------------------------------------------------
diff --git a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/SplittingDirectory.scala b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/SplittingDirectory.scala
index d28c29c..2d318c0 100644
--- a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/SplittingDirectory.scala
+++ b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/SplittingDirectory.scala
@@ -30,52 +30,52 @@ import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.io.VirtualDirectory
class SplittingDirectory()
- extends VirtualDirectory(null, None) with GenericFileWrapperTrait {
+ extends VirtualDirectory(null, None) with GenericFileWrapperTrait {
- var currentTarget: VirtualDirectory = null
+ var currentTarget: VirtualDirectory = null
- protected def wrapped: VirtualDirectory = {
- if (currentTarget == null) {
- throw new RuntimeException("No current Target set, SplittingDirectory not usable")
- }
- currentTarget
- }
+ protected def wrapped: VirtualDirectory = {
+ if (currentTarget == null) {
+ throw new RuntimeException("No current Target set, SplittingDirectory not usable")
+ }
+ currentTarget
+ }
- private def wrap(f: AbstractFile): AbstractFile = {
- f match {
- case d: VirtualDirectory => new VirtualDirectoryWrapper(d, wrap) {
- override def output = d.output
- }
- case o => new FileWrapper(o, wrap)
- }
- }
- val childWrapper: (AbstractFile) => AbstractFile = wrap
+ private def wrap(f: AbstractFile): AbstractFile = {
+ f match {
+ case d: VirtualDirectory => new VirtualDirectoryWrapper(d, wrap) {
+ override def output = d.output
+ }
+ case o => new FileWrapper(o, wrap)
+ }
+ }
+ val childWrapper: (AbstractFile) => AbstractFile = wrap
- //lastModified = wrapped.lastModified
+ //lastModified = wrapped.lastModified
- override def output = {
- wrapped.asInstanceOf[VirtualDirectory].output
- }
- override def input = {
- wrapped.asInstanceOf[VirtualDirectory].input
- }
- override def file = {
- wrapped.asInstanceOf[VirtualDirectory].file
- }
- override def container = {
- wrapped.asInstanceOf[VirtualDirectory].container
- }
- override def absolute = {
- wrapped.asInstanceOf[VirtualDirectory].absolute
- }
- override val name = "(splitting)"
-
- override def lookupPath(path: String, directory: Boolean): AbstractFile = {
- childWrapper(wrapped.lookupPath(path, directory))
- }
- override def lookupPathUnchecked(path: String, directory: Boolean): AbstractFile = {
- childWrapper(wrapped.lookupPathUnchecked(path, directory))
- }
+ override def output = {
+ wrapped.asInstanceOf[VirtualDirectory].output
+ }
+ override def input = {
+ wrapped.asInstanceOf[VirtualDirectory].input
+ }
+ override def file = {
+ wrapped.asInstanceOf[VirtualDirectory].file
+ }
+ override def container = {
+ wrapped.asInstanceOf[VirtualDirectory].container
+ }
+ override def absolute = {
+ wrapped.asInstanceOf[VirtualDirectory].absolute
+ }
+ override val name = "(splitting)"
+
+ override def lookupPath(path: String, directory: Boolean): AbstractFile = {
+ childWrapper(wrapped.lookupPath(path, directory))
+ }
+ override def lookupPathUnchecked(path: String, directory: Boolean): AbstractFile = {
+ childWrapper(wrapped.lookupPathUnchecked(path, directory))
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/VirtualDirectoryWrapper.scala
----------------------------------------------------------------------
diff --git a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/VirtualDirectoryWrapper.scala b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/VirtualDirectoryWrapper.scala
index 7b43344..b56de63 100644
--- a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/VirtualDirectoryWrapper.scala
+++ b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/VirtualDirectoryWrapper.scala
@@ -30,67 +30,67 @@ import scala.reflect.io.AbstractFile
import scala.reflect.io.VirtualDirectory
class VirtualDirectoryWrapper(val wrapped: AbstractFile,
- val childWrapper: (AbstractFile) => AbstractFile) extends VirtualDirectory(null, None)
- with GenericFileWrapperTrait {
- lastModified =wrapped.lastModified
+ val childWrapper: (AbstractFile) => AbstractFile) extends VirtualDirectory(null, None)
+ with GenericFileWrapperTrait {
+ lastModified =wrapped.lastModified
- override def output = {
- wrapped.asInstanceOf[VirtualDirectory].output
- }
- override def input = {
- wrapped.asInstanceOf[VirtualDirectory].input
- }
- override def file = {
- wrapped.asInstanceOf[VirtualDirectory].file
- }
- override def container = {
- wrapped.asInstanceOf[VirtualDirectory].container
- }
- override def absolute = {
- wrapped.asInstanceOf[VirtualDirectory].absolute
- }
- override val name = {
- wrapped.name
- }
- override def lookupPath(path: String, directory: Boolean): AbstractFile = {
- childWrapper(wrapped.lookupPath(path, directory))
- }
- override def lookupPathUnchecked(path: String, directory: Boolean): AbstractFile = {
- childWrapper(wrapped.lookupPathUnchecked(path, directory))
- }
+ override def output = {
+ wrapped.asInstanceOf[VirtualDirectory].output
+ }
+ override def input = {
+ wrapped.asInstanceOf[VirtualDirectory].input
+ }
+ override def file = {
+ wrapped.asInstanceOf[VirtualDirectory].file
+ }
+ override def container = {
+ wrapped.asInstanceOf[VirtualDirectory].container
+ }
+ override def absolute = {
+ wrapped.asInstanceOf[VirtualDirectory].absolute
+ }
+ override val name = {
+ wrapped.name
+ }
+ override def lookupPath(path: String, directory: Boolean): AbstractFile = {
+ childWrapper(wrapped.lookupPath(path, directory))
+ }
+ override def lookupPathUnchecked(path: String, directory: Boolean): AbstractFile = {
+ childWrapper(wrapped.lookupPathUnchecked(path, directory))
+ }
}
object VirtualDirectoryWrapper {
- trait VirtualDirectoryFlavour extends VirtualDirectoryWrapper {
- abstract override def output = {
- println("unexpected call to output "+name)
- super.output
- }
- }
+ trait VirtualDirectoryFlavour extends VirtualDirectoryWrapper {
+ abstract override def output = {
+ println("unexpected call to output "+name)
+ super.output
+ }
+ }
- def wrap(f: AbstractFile, outputListenerParam: (AbstractFile) => Unit): AbstractFile = {
- def innerWrap(f: AbstractFile) = wrap(f, outputListenerParam)
- f match {
- case d: VirtualDirectory => new VirtualDirectoryWrapper(d,
- innerWrap)
- with LoggingFileWrapper with VirtualDirectoryFlavour {
- override def output = d.output
- val outputListener = outputListenerParam
- }
- case o => new FileWrapper(o, innerWrap) with LoggingFileWrapper {
- val outputListener = outputListenerParam
- }
- }
- }
+ def wrap(f: AbstractFile, outputListenerParam: (AbstractFile) => Unit): AbstractFile = {
+ def innerWrap(f: AbstractFile) = wrap(f, outputListenerParam)
+ f match {
+ case d: VirtualDirectory => new VirtualDirectoryWrapper(d,
+ innerWrap)
+ with LoggingFileWrapper with VirtualDirectoryFlavour {
+ override def output = d.output
+ val outputListener = outputListenerParam
+ }
+ case o => new FileWrapper(o, innerWrap) with LoggingFileWrapper {
+ val outputListener = outputListenerParam
+ }
+ }
+ }
- trait LoggingFileWrapper extends GenericFileWrapperTrait {
+ trait LoggingFileWrapper extends GenericFileWrapperTrait {
- val outputListener: (AbstractFile) => Unit
+ val outputListener: (AbstractFile) => Unit
- abstract override def output = {
- outputListener(this)
- super.output
- }
- }
+ abstract override def output = {
+ outputListener(this)
+ super.output
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/Wrapper.scala
----------------------------------------------------------------------
diff --git a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/Wrapper.scala b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/Wrapper.scala
index 473fe6d..97d3dfd 100644
--- a/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/Wrapper.scala
+++ b/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/util/Wrapper.scala
@@ -27,6 +27,6 @@
package org.apache.clerezza.scala.scripting.util
trait Wrapper[T] {
- protected def wrapped: T
- protected def childWrapper: (T) => T
+ protected def wrapped: T
+ protected def childWrapper: (T) => T
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala
----------------------------------------------------------------------
diff --git a/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala b/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala
index 74dabb2..3832804 100644
--- a/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala
+++ b/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala
@@ -49,177 +49,177 @@ import scala.math.random
class CompilerServiceTest {
-
- @Inject
- private var bundleContext: BundleContext = null;
-
- private var webServerExist = false;
-
- private var service: CompilerService = null;
-
- @Before
- def getService() : Unit = {
- /*webServerExist = waitForWebserver();*/
- service = waitFor(classOf[CompilerService], 300000);
- }
-
- private def waitFor[T](aClass: Class[T], timeout: Long): T = {
- System.out.println("waiting for a " + aClass);
- val tracker = new ServiceTracker(bundleContext,
- aClass.getName(), null);
- tracker.open();
- val service = tracker.waitForService(timeout);
- return service.asInstanceOf[T];
- }
+
+ @Inject
+ private var bundleContext: BundleContext = null;
+
+ private var webServerExist = false;
+
+ private var service: CompilerService = null;
+
+ @Before
+ def getService() : Unit = {
+ /*webServerExist = waitForWebserver();*/
+ service = waitFor(classOf[CompilerService], 300000);
+ }
+
+ private def waitFor[T](aClass: Class[T], timeout: Long): T = {
+ System.out.println("waiting for a " + aClass);
+ val tracker = new ServiceTracker(bundleContext,
+ aClass.getName(), null);
+ tracker.open();
+ val service = tracker.waitForService(timeout);
+ return service.asInstanceOf[T];
+ }
//disabled, interpretation not currently working
-// @Test
-// def checkEngine(): Unit = {
-// Assert.assertNotNull(service);
-// //do it once
-// val testClassClass1 = {
-// val s = """
-// package foo {
-// class TestClass() {
-// println("constructing TestClass");
-// }
-// object TestClass {
-// println("constructing TestClass Object");
-// val msg = "Hello"
-// }
-// }
-// """
-// val compileResult = priv(service.compile(List(s.toCharArray)))
-// println("finished compiling")
-// Assert.assertEquals(1, compileResult.size)
-// val testClassClass: Class[_] = compileResult(0)
-// //Assert.assertEquals("foo.TestClass", testClassClass.getName)
-// testClassClass
-// }
-// //compile different class with same name
-// {
-// val s = """
-// package foo {
-// class TestClass() {
-// println("constructing a different TestClass");
-// }
-// object TestClass {
-// println("constructing TestClass Object");
-// val msg = "Hello2"
-// }
-// }
-// """
-// //and another class
-// val s2 = """
-// package foo {
-// class TestClass2() {
-// println("constructing TestClass2");
-// }
-// object TestClass2 {
-// println("constructing TestClass2 Object");
-// val msg = "Hello2b"
-// }
-// }
-// """
-// val compileResult = priv(service.compile(List(s.toCharArray, s2.toCharArray)))
-// Assert.assertEquals(2, compileResult.size)
-// val nameMsg = for (cr <- compileResult) yield
-// (cr.getName, {
-// val method = cr.getMethod("msg")
-// method.invoke(null)
-// })
-// val nameMsgMap = Map(nameMsg: _*)
-// Assert.assertTrue(nameMsgMap.contains("foo.TestClass"))
-// Assert.assertTrue(nameMsgMap.contains("foo.TestClass2"))
+// @Test
+// def checkEngine(): Unit = {
+// Assert.assertNotNull(service);
+// //do it once
+// val testClassClass1 = {
+// val s = """
+// package foo {
+// class TestClass() {
+// println("constructing TestClass");
+// }
+// object TestClass {
+// println("constructing TestClass Object");
+// val msg = "Hello"
+// }
+// }
+// """
+// val compileResult = priv(service.compile(List(s.toCharArray)))
+// println("finished compiling")
+// Assert.assertEquals(1, compileResult.size)
+// val testClassClass: Class[_] = compileResult(0)
+// //Assert.assertEquals("foo.TestClass", testClassClass.getName)
+// testClassClass
+// }
+// //compile different class with same name
+// {
+// val s = """
+// package foo {
+// class TestClass() {
+// println("constructing a different TestClass");
+// }
+// object TestClass {
+// println("constructing TestClass Object");
+// val msg = "Hello2"
+// }
+// }
+// """
+// //and another class
+// val s2 = """
+// package foo {
+// class TestClass2() {
+// println("constructing TestClass2");
+// }
+// object TestClass2 {
+// println("constructing TestClass2 Object");
+// val msg = "Hello2b"
+// }
+// }
+// """
+// val compileResult = priv(service.compile(List(s.toCharArray, s2.toCharArray)))
+// Assert.assertEquals(2, compileResult.size)
+// val nameMsg = for (cr <- compileResult) yield
+// (cr.getName, {
+// val method = cr.getMethod("msg")
+// method.invoke(null)
+// })
+// val nameMsgMap = Map(nameMsg: _*)
+// Assert.assertTrue(nameMsgMap.contains("foo.TestClass"))
+// Assert.assertTrue(nameMsgMap.contains("foo.TestClass2"))
//
-// Assert.assertEquals("Hello2", nameMsgMap("foo.TestClass"))
-// Assert.assertEquals("Hello2b", nameMsgMap("foo.TestClass2"))
-// }
-// val methodFrom1Again = testClassClass1.getMethod("msg")
-// Assert.assertEquals("Hello", methodFrom1Again.invoke(null))
-// }
-
- @Test
- def testConcurrency : Unit = {
- val startTime = System.currentTimeMillis
- import scala.actors.Actor._
- val actorsCount = 5
- val iterationsCount = 9
- val testRunner = self
- for (i <- 1 to actorsCount) {
- object ValueVerifier extends Actor {
- def act() {
- try {
- for (i <- 1 to iterationsCount) {
- val uniqueToken = (for (i <-1 to 12) yield ((random*('z'-'a'+1))+'a').asInstanceOf[Char]).mkString
- val objectName = "MyClass"
- val message = "Hello from "+uniqueToken
-
- val source = """
+// Assert.assertEquals("Hello2", nameMsgMap("foo.TestClass"))
+// Assert.assertEquals("Hello2b", nameMsgMap("foo.TestClass2"))
+// }
+// val methodFrom1Again = testClassClass1.getMethod("msg")
+// Assert.assertEquals("Hello", methodFrom1Again.invoke(null))
+// }
+
+ @Test
+ def testConcurrency : Unit = {
+ val startTime = System.currentTimeMillis
+ import scala.actors.Actor._
+ val actorsCount = 5
+ val iterationsCount = 9
+ val testRunner = self
+ for (i <- 1 to actorsCount) {
+ object ValueVerifier extends Actor {
+ def act() {
+ try {
+ for (i <- 1 to iterationsCount) {
+ val uniqueToken = (for (i <-1 to 12) yield ((random*('z'-'a'+1))+'a').asInstanceOf[Char]).mkString
+ val objectName = "MyClass"
+ val message = "Hello from "+uniqueToken
+
+ val source = """
object """+objectName+""" {
- println("constructing TestClass Object");
- val msg = """"+message+""""
+ println("constructing TestClass Object");
+ val msg = """"+message+""""
}"""
- //println("compiling: "+source)
- val sources = List(source.toCharArray)
- val compiled = priv(service.compile(sources))
- val clazz = compiled(0)
- val className = clazz.getName
- testRunner ! (objectName, className)
- val method = clazz.getMethod("msg")
- val receivedMessage = method.invoke(null)
- testRunner ! (message, receivedMessage)
- }
- } catch {
- case t: Throwable => testRunner ! t
- }
- }
- }
- ValueVerifier.start()
- }
- for (i <- 1 to (actorsCount*iterationsCount*2)) {
- self.receive {
- case (expected, got) => {
- Assert.assertEquals(expected, got)
- }
- case t : Throwable => throw t
- }
- }
- val duration = System.currentTimeMillis - startTime
- println("running the tests took "+duration)
-
- }
-
- def priv[T](action: => T): T = {
- try {
- AccessController.doPrivileged(
- new PrivilegedExceptionAction[T]() {
- def run = action
- })
- } catch {
- case e: PrivilegedActionException => throw e.getCause
- case e: Throwable => throw e
- }
- }
+ //println("compiling: "+source)
+ val sources = List(source.toCharArray)
+ val compiled = priv(service.compile(sources))
+ val clazz = compiled(0)
+ val className = clazz.getName
+ testRunner ! (objectName, className)
+ val method = clazz.getMethod("msg")
+ val receivedMessage = method.invoke(null)
+ testRunner ! (message, receivedMessage)
+ }
+ } catch {
+ case t: Throwable => testRunner ! t
+ }
+ }
+ }
+ ValueVerifier.start()
+ }
+ for (i <- 1 to (actorsCount*iterationsCount*2)) {
+ self.receive {
+ case (expected, got) => {
+ Assert.assertEquals(expected, got)
+ }
+ case t : Throwable => throw t
+ }
+ }
+ val duration = System.currentTimeMillis - startTime
+ println("running the tests took "+duration)
+
+ }
+
+ def priv[T](action: => T): T = {
+ try {
+ AccessController.doPrivileged(
+ new PrivilegedExceptionAction[T]() {
+ def run = action
+ })
+ } catch {
+ case e: PrivilegedActionException => throw e.getCause
+ case e: Throwable => throw e
+ }
+ }
}
object CompilerServiceTest {
- protected val testHttpPort = 8976;
-
- @Configuration
- def configuration() : Array[Option] = {
- return options(
- mavenConfiguration(),
- dsProfile(),
- configProfile(),
- //webProfile(),
- junitBundles(),
- frameworks(
- felix()),
- systemProperty("org.osgi.service.http.port").value(
- Integer.toString(testHttpPort)));
- }
+ protected val testHttpPort = 8976;
+
+ @Configuration
+ def configuration() : Array[Option] = {
+ return options(
+ mavenConfiguration(),
+ dsProfile(),
+ configProfile(),
+ //webProfile(),
+ junitBundles(),
+ frameworks(
+ felix()),
+ systemProperty("org.osgi.service.http.port").value(
+ Integer.toString(testHttpPort)));
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/ScriptEngineFactoryTest.scala
----------------------------------------------------------------------
diff --git a/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/ScriptEngineFactoryTest.scala b/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/ScriptEngineFactoryTest.scala
index 9a17897..8fa62fb 100644
--- a/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/ScriptEngineFactoryTest.scala
+++ b/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/ScriptEngineFactoryTest.scala
@@ -44,169 +44,169 @@ import scala.math.random
*/
@RunWith(classOf[JUnit4TestRunner])
class ScriptEngineFactoryTest {
-
+
-
- @Inject
- private var bundleContext: BundleContext = null;
-
- private var webServerExist = false;
+
+ @Inject
+ private var bundleContext: BundleContext = null;
+
+ private var webServerExist = false;
- private var factory: ScriptEngineFactory = null;
+ private var factory: ScriptEngineFactory = null;
- @Before
- def getService() : Unit = {
- /*webServerExist = waitForWebserver();*/
- factory = waitFor(classOf[ScriptEngineFactory], 300000);
- }
+ @Before
+ def getService() : Unit = {
+ /*webServerExist = waitForWebserver();*/
+ factory = waitFor(classOf[ScriptEngineFactory], 300000);
+ }
- private def waitFor[T](aClass: Class[T], timeout: Long): T = {
- System.out.println("waiting for a " + aClass);
- val tracker = new ServiceTracker(bundleContext,
- aClass.getName(), null);
- tracker.open();
- val service = tracker.waitForService(timeout);
- return service.asInstanceOf[T];
- }
+ private def waitFor[T](aClass: Class[T], timeout: Long): T = {
+ System.out.println("waiting for a " + aClass);
+ val tracker = new ServiceTracker(bundleContext,
+ aClass.getName(), null);
+ tracker.open();
+ val service = tracker.waitForService(timeout);
+ return service.asInstanceOf[T];
+ }
-//disabled, interpretation not currently working
-// @Test
-// def checkEngine(): Unit = {
-// Assert.assertNotNull(factory)
-// Assert.assertEquals("Scala Scripting Engine for OSGi", factory.getEngineName);
-// val s = "hello"
-// val engine = factory.getScriptEngine
-// Assert.assertEquals(s, engine.eval("\""+s+"\""))
-// val bindings = engine.createBindings
-// bindings.put("s",s)
-// Assert.assertEquals(s, engine.eval("s", bindings))
-// }
+//disabled, interpretation not currently working
+// @Test
+// def checkEngine(): Unit = {
+// Assert.assertNotNull(factory)
+// Assert.assertEquals("Scala Scripting Engine for OSGi", factory.getEngineName);
+// val s = "hello"
+// val engine = factory.getScriptEngine
+// Assert.assertEquals(s, engine.eval("\""+s+"\""))
+// val bindings = engine.createBindings
+// bindings.put("s",s)
+// Assert.assertEquals(s, engine.eval("s", bindings))
+// }
//
-// @Test
-// def testConcurrency : Unit = {
-// val startTime = System.currentTimeMillis
-// import scala.actors.Actor._
-// val actorsCount = 5
-// val iterationsCount = 9
-// val testRunner = self
-// for (i <- 1 to actorsCount) {
-// object ValueVerifier extends Actor {
-// def act() {
-// try {
-// for (i <- 1 to iterationsCount) {
-// val s = "r: "+random.toString
-// val engine = factory.getScriptEngine
-// val bindings = engine.createBindings
-// bindings.put("s",s)
-// val script = """
+// @Test
+// def testConcurrency : Unit = {
+// val startTime = System.currentTimeMillis
+// import scala.actors.Actor._
+// val actorsCount = 5
+// val iterationsCount = 9
+// val testRunner = self
+// for (i <- 1 to actorsCount) {
+// object ValueVerifier extends Actor {
+// def act() {
+// try {
+// for (i <- 1 to iterationsCount) {
+// val s = "r: "+random.toString
+// val engine = factory.getScriptEngine
+// val bindings = engine.createBindings
+// bindings.put("s",s)
+// val script = """
//import scala.math.random
//Thread.sleep((random*10).toInt)
//s"""
-// testRunner ! (s, engine.eval(script, bindings))
-// }
-// } catch {
-// case t => testRunner ! t
-// }
-// }
-// }
-// ValueVerifier.start()
-// }
-// for (i <- 1 to (actorsCount*iterationsCount)) {
-// self.receive {
-// case (expected, got) => {
-// Assert.assertEquals(expected, got)
-// }
-// case t : Throwable => throw t
-// }
-// }
-// val duration = System.currentTimeMillis - startTime
-// println("running the tests took "+duration)
+// testRunner ! (s, engine.eval(script, bindings))
+// }
+// } catch {
+// case t => testRunner ! t
+// }
+// }
+// }
+// ValueVerifier.start()
+// }
+// for (i <- 1 to (actorsCount*iterationsCount)) {
+// self.receive {
+// case (expected, got) => {
+// Assert.assertEquals(expected, got)
+// }
+// case t : Throwable => throw t
+// }
+// }
+// val duration = System.currentTimeMillis - startTime
+// println("running the tests took "+duration)
//
-// }
+// }
//
-// @Test
-// def classFromNewlyAddedBundle(): Unit = {
-// val s = "hello"
-// val engine = factory.getScriptEngine
-// val bindings = engine.createBindings
-// bindings.put("s",s)
-// Assert.assertEquals(s, engine.eval("s", bindings))
-// bundleContext.installBundle("http://repo2.maven.org/maven2/org/wymiwyg/wrhapi/0.8.2/wrhapi-0.8.2.jar");
-// Thread.sleep(100)
-// val script = """
-// |import org.wymiwyg.wrhapi._
-// |val h : Handler = null
-// |s""".stripMargin
-// Assert.assertEquals(s, engine.eval(script, bindings))
-// }
+// @Test
+// def classFromNewlyAddedBundle(): Unit = {
+// val s = "hello"
+// val engine = factory.getScriptEngine
+// val bindings = engine.createBindings
+// bindings.put("s",s)
+// Assert.assertEquals(s, engine.eval("s", bindings))
+// bundleContext.installBundle("http://repo2.maven.org/maven2/org/wymiwyg/wrhapi/0.8.2/wrhapi-0.8.2.jar");
+// Thread.sleep(100)
+// val script = """
+// |import org.wymiwyg.wrhapi._
+// |val h : Handler = null
+// |s""".stripMargin
+// Assert.assertEquals(s, engine.eval(script, bindings))
+// }
- @Test
- def compiledScript(): Unit = {
- val string = "hello"
- val script = "\""+string+"\""
- val engine = factory.getScriptEngine.asInstanceOf[Compilable]
- val compiledScript = engine.compile(script)
- Assert.assertEquals(string, compiledScript.eval())
- }
-
- @Test(expected=classOf[ScriptException])
- def compileErrorScript(): Unit = {
- val script = "this is not real scala !"
- val engine = factory.getScriptEngine.asInstanceOf[Compilable]
- val compiledScript = engine.compile(script)
- }
-
- @Test(expected=classOf[ScriptException])
- def compileUnfinishedScript(): Unit = {
- val script = "if (true) {"
- val engine = factory.getScriptEngine.asInstanceOf[Compilable]
- val compiledScript = engine.compile(script)
- }
+ @Test
+ def compiledScript(): Unit = {
+ val string = "hello"
+ val script = "\""+string+"\""
+ val engine = factory.getScriptEngine.asInstanceOf[Compilable]
+ val compiledScript = engine.compile(script)
+ Assert.assertEquals(string, compiledScript.eval())
+ }
+
+ @Test(expected=classOf[ScriptException])
+ def compileErrorScript(): Unit = {
+ val script = "this is not real scala !"
+ val engine = factory.getScriptEngine.asInstanceOf[Compilable]
+ val compiledScript = engine.compile(script)
+ }
+
+ @Test(expected=classOf[ScriptException])
+ def compileUnfinishedScript(): Unit = {
+ val script = "if (true) {"
+ val engine = factory.getScriptEngine.asInstanceOf[Compilable]
+ val compiledScript = engine.compile(script)
+ }
-
- def compileNormalAfterErrorScript(): Unit = {
- val script = "this is not real scala !"
- val engine = factory.getScriptEngine.asInstanceOf[Compilable]
- try {
- val compiledScript = engine.compile(script)
- } catch {
- case e: Throwable => Assert.assertEquals(classOf[ScriptException], e.getClass)
- }
- val string = "hello"
- val script2 = "\""+string+"\""
- val compiledScript2 = engine.compile(script2)
- Assert.assertEquals(string, compiledScript2.eval())
- }
- //This seems hard to realize before https://lampsvn.epfl.ch/trac/scala/ticket/3513 is fixed
- /*@Test
- def checkException(): Unit = {
- val s = """val s="hello"
- illegal.do"""
- val engine = factory.getScriptEngine
- try {
- Assert.assertEquals("should have exception",engine.eval(s))
- } catch {
- case e : ScriptException => Assert.assertEquals(2, e.getLineNumber)
- }
- }*/
+
+ def compileNormalAfterErrorScript(): Unit = {
+ val script = "this is not real scala !"
+ val engine = factory.getScriptEngine.asInstanceOf[Compilable]
+ try {
+ val compiledScript = engine.compile(script)
+ } catch {
+ case e: Throwable => Assert.assertEquals(classOf[ScriptException], e.getClass)
+ }
+ val string = "hello"
+ val script2 = "\""+string+"\""
+ val compiledScript2 = engine.compile(script2)
+ Assert.assertEquals(string, compiledScript2.eval())
+ }
+ //This seems hard to realize before https://lampsvn.epfl.ch/trac/scala/ticket/3513 is fixed
+ /*@Test
+ def checkException(): Unit = {
+ val s = """val s="hello"
+ illegal.do"""
+ val engine = factory.getScriptEngine
+ try {
+ Assert.assertEquals("should have exception",engine.eval(s))
+ } catch {
+ case e : ScriptException => Assert.assertEquals(2, e.getLineNumber)
+ }
+ }*/
}
object ScriptEngineFactoryTest {
- protected val testHttpPort = 8976;
+ protected val testHttpPort = 8976;
- @Configuration
- def configuration() : Array[Option] = {
- return options(
- mavenConfiguration(),
- //using old ds because of issues with 1.0.8
- dsProfile(),
- configProfile(),
- webProfile(),
- junitBundles(),
- frameworks(
- felix()),
- systemProperty("org.osgi.service.http.port").value(
- Integer.toString(testHttpPort)));
- }
+ @Configuration
+ def configuration() : Array[Option] = {
+ return options(
+ mavenConfiguration(),
+ //using old ds because of issues with 1.0.8
+ dsProfile(),
+ configProfile(),
+ webProfile(),
+ junitBundles(),
+ frameworks(
+ felix()),
+ systemProperty("org.osgi.service.http.port").value(
+ Integer.toString(testHttpPort)));
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala
----------------------------------------------------------------------
diff --git a/shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala b/shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala
index db6ae4b..591c105 100644
--- a/shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala
+++ b/shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala
@@ -24,27 +24,27 @@ import org.apache.clerezza.shell.ShellCommand
import org.apache.felix.shell.ShellService
class FelixShellCommand extends ShellCommand {
- private var felixShell: ShellService = null
-
- def command: String = "felix"
- def description: String = "execute a felix shell command"
- /**
- * Extecutes the command an return (keepRunning,Option[lineToRecord])
- */
- def execute(line: String, out: OutputStream): (Boolean, Option[String]) = {
- val printStream = new PrintStream(out)
- felixShell.executeCommand(line, printStream, printStream)
- printStream.flush()
- (true, None)
- }
-
- def bindFelixShell(felixShell: ShellService) {
- this.felixShell = felixShell
- }
-
- def unbindFelixShell(felixShell: ShellService) {
- this.felixShell = null
- }
+ private var felixShell: ShellService = null
+
+ def command: String = "felix"
+ def description: String = "execute a felix shell command"
+ /**
+ * Extecutes the command an return (keepRunning,Option[lineToRecord])
+ */
+ def execute(line: String, out: OutputStream): (Boolean, Option[String]) = {
+ val printStream = new PrintStream(out)
+ felixShell.executeCommand(line, printStream, printStream)
+ printStream.flush()
+ (true, None)
+ }
+
+ def bindFelixShell(felixShell: ShellService) {
+ this.felixShell = felixShell
+ }
+
+ def unbindFelixShell(felixShell: ShellService) {
+ this.felixShell = null
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala
----------------------------------------------------------------------
diff --git a/shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala b/shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala
index 835d9e1..cd3c13d 100644
--- a/shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala
+++ b/shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala
@@ -37,57 +37,57 @@ class ConsoleShell() {
- var factory: ShellFactory = null
- var bundleContext: BundleContext = null
- var stoppedBundle: Option[Bundle] = None
- var shellOption: Option[Shell] = None
- var interruptibleIn: InterruptibleInputStream = null
+ var factory: ShellFactory = null
+ var bundleContext: BundleContext = null
+ var stoppedBundle: Option[Bundle] = None
+ var shellOption: Option[Shell] = None
+ var interruptibleIn: InterruptibleInputStream = null
- def activate(componentContext: ComponentContext)= {
- bundleContext = componentContext.getBundleContext
- if (("true" != bundleContext.getProperty("clerezza.shell.disable")) &&
- (System.console != null)) {
- for (bundle <- bundleContext.getBundles;
- if (bundle.getSymbolicName == "org.apache.felix.shell.tui");
- if (bundle.getState == Bundle.ACTIVE)) {
- println("stopping "+bundle);
- bundle.stop()
- stoppedBundle = Some(bundle)
- }
- //this call sets the console terminal to the right settings
- //and it must not be invoked when there is no console input, or the system will stop
- val terminalOption = Some(scala.tools.jline.TerminalFactory.create())
- val in = Channels.newInputStream(
- (new FileInputStream(FileDescriptor.in)).getChannel());
- interruptibleIn = new InterruptibleInputStream(in)
- val shell = factory.createShell(interruptibleIn, System.out, terminalOption)
- shell.start()
- shellOption = Some(shell)
- }
- }
+ def activate(componentContext: ComponentContext)= {
+ bundleContext = componentContext.getBundleContext
+ if (("true" != bundleContext.getProperty("clerezza.shell.disable")) &&
+ (System.console != null)) {
+ for (bundle <- bundleContext.getBundles;
+ if (bundle.getSymbolicName == "org.apache.felix.shell.tui");
+ if (bundle.getState == Bundle.ACTIVE)) {
+ println("stopping "+bundle);
+ bundle.stop()
+ stoppedBundle = Some(bundle)
+ }
+ //this call sets the console terminal to the right settings
+ //and it must not be invoked when there is no console input, or the system will stop
+ val terminalOption = Some(scala.tools.jline.TerminalFactory.create())
+ val in = Channels.newInputStream(
+ (new FileInputStream(FileDescriptor.in)).getChannel());
+ interruptibleIn = new InterruptibleInputStream(in)
+ val shell = factory.createShell(interruptibleIn, System.out, terminalOption)
+ shell.start()
+ shellOption = Some(shell)
+ }
+ }
- def deactivate(componentContext: ComponentContext) = {
- bundleContext = componentContext.getBundleContext
- stoppedBundle match {
- case Some(bundle) => bundle.start()
- case _ =>
- }
- shellOption match {
- case Some(shell) => shell.stop()
- case _ =>
- }
- if (interruptibleIn != null) {
- interruptibleIn.terminate()
- }
- }
+ def deactivate(componentContext: ComponentContext) = {
+ bundleContext = componentContext.getBundleContext
+ stoppedBundle match {
+ case Some(bundle) => bundle.start()
+ case _ =>
+ }
+ shellOption match {
+ case Some(shell) => shell.stop()
+ case _ =>
+ }
+ if (interruptibleIn != null) {
+ interruptibleIn.terminate()
+ }
+ }
- def bindShellFactory(f: ShellFactory) = {
- factory = f
- }
+ def bindShellFactory(f: ShellFactory) = {
+ factory = f
+ }
- def unbindShellFactory(f: ShellFactory) = {
- factory = null
- }
-
+ def unbindShellFactory(f: ShellFactory) = {
+ factory = null
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala
----------------------------------------------------------------------
diff --git a/shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala b/shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala
index fcd0e0f..d4db45b 100644
--- a/shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala
+++ b/shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala
@@ -24,47 +24,47 @@ import scala.actors.Actor
import scala.actors.Actor._
class InterruptibleInputStream(base: InputStream) extends InputStream {
- private case object Stop
- private case object Read
+ private case object Stop
+ private case object Read
- private var readingThread: Thread = null
+ private var readingThread: Thread = null
- val readerActor = new Actor() {
- def act() {
- loop {
- react {
- case Stop => exit()
- case Read => {
- readingThread = Thread.currentThread
- val ch = try {
- base.read()
- } catch {
- case e: ClosedByInterruptException => {
- -1
- }
- }
- readingThread = null
- sender ! ch
- }
- }
- }
- }
- }
- readerActor.start()
+ val readerActor = new Actor() {
+ def act() {
+ loop {
+ react {
+ case Stop => exit()
+ case Read => {
+ readingThread = Thread.currentThread
+ val ch = try {
+ base.read()
+ } catch {
+ case e: ClosedByInterruptException => {
+ -1
+ }
+ }
+ readingThread = null
+ sender ! ch
+ }
+ }
+ }
+ }
+ }
+ readerActor.start()
- def read() = {
- readerActor ! Read
- self.receive {
- case x: Int => x
- }
- }
+ def read() = {
+ readerActor ! Read
+ self.receive {
+ case x: Int => x
+ }
+ }
- def terminate() {
- readerActor ! Stop
- val currentReadingThread = readingThread
- if (currentReadingThread != null) {
- currentReadingThread.interrupt()
- }
- }
+ def terminate() {
+ readerActor ! Stop
+ val currentReadingThread = readingThread
+ if (currentReadingThread != null) {
+ currentReadingThread.interrupt()
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
----------------------------------------------------------------------
diff --git a/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala b/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
index fce3200..412819d 100644
--- a/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
+++ b/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
@@ -184,9 +184,9 @@ class Shell(factory: InterpreterFactory, val inStream: InputStream,
import Properties._
val welcomeMsg =
"""|Welcome to the Apache Clerezza Console
- |Console is based on Scala %s (%s, Java %s).
- |Type in expressions to have them evaluated.
- |Type :help for more information.""".
+ |Console is based on Scala %s (%s, Java %s).
+ |Type in expressions to have them evaluated.
+ |Type :help for more information.""".
stripMargin.format(versionString, javaVmName, javaVersion)
echo(welcomeMsg)
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
----------------------------------------------------------------------
diff --git a/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala b/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
index b83a269..d6dcd29 100644
--- a/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
+++ b/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
@@ -21,10 +21,10 @@ package org.apache.clerezza.shell
import java.io.OutputStream
trait ShellCommand {
- def command: String
- def description: String
- /**
- * Extecutes the command an return (keepRunning,Option[lineToRecord])
- */
- def execute(line: String, out: OutputStream): (Boolean, Option[String])
+ def command: String
+ def description: String
+ /**
+ * Extecutes the command an return (keepRunning,Option[lineToRecord])
+ */
+ def execute(line: String, out: OutputStream): (Boolean, Option[String])
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala
----------------------------------------------------------------------
diff --git a/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala b/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala
index 80d02d8..d5487e6 100644
--- a/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala
+++ b/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala
@@ -29,14 +29,14 @@ import org.osgi.service.component.ComponentContext
*/
trait ShellCustomizer {
- /**
- * A list of bindings that will be available in the shell
- * The tuple consist of: bindingName, typeName, value
- */
- def bindings(e: Shell.Environment): List[(String, String, Any)]
+ /**
+ * A list of bindings that will be available in the shell
+ * The tuple consist of: bindingName, typeName, value
+ */
+ def bindings(e: Shell.Environment): List[(String, String, Any)]
- /**
- * A list of imports that will be available in the shell
- */
- def imports: List[String]
+ /**
+ * A list of imports that will be available in the shell
+ */
+ def imports: List[String]
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/shell/src/main/scala/org/apache/clerezza/shell/ShellPermission.scala
----------------------------------------------------------------------
diff --git a/shell/src/main/scala/org/apache/clerezza/shell/ShellPermission.scala b/shell/src/main/scala/org/apache/clerezza/shell/ShellPermission.scala
index 018ca19..d0a2cb1 100644
--- a/shell/src/main/scala/org/apache/clerezza/shell/ShellPermission.scala
+++ b/shell/src/main/scala/org/apache/clerezza/shell/ShellPermission.scala
@@ -22,18 +22,18 @@ package org.apache.clerezza.shell
import java.security.Permission
class ShellPermission(t: String, a: String) extends Permission(t) {
- def this() = this(null,null)
+ def this() = this(null,null)
- def getActions = ""
+ def getActions = ""
- def implies(p: Permission) = {
- p match {
- case sp: ShellPermission => true
- case _ => false
- }
- }
+ def implies(p: Permission) = {
+ p match {
+ case sp: ShellPermission => true
+ case _ => false
+ }
+ }
- override def hashCode = 67823
+ override def hashCode = 67823
- override def equals(other: Any) = other.isInstanceOf[ShellPermission]
+ override def equals(other: Any) = other.isInstanceOf[ShellPermission]
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/site/src/main/scala/Activator.scala
----------------------------------------------------------------------
diff --git a/site/src/main/scala/Activator.scala b/site/src/main/scala/Activator.scala
index 41260dc..7b9224b 100644
--- a/site/src/main/scala/Activator.scala
+++ b/site/src/main/scala/Activator.scala
@@ -16,76 +16,76 @@ import java.io.{FileOutputStream, FileInputStream, File}
*/
class Activator extends BundleActivator {
- var renderletRegistration,
- titledContentRenderletRegistration,
- globalMenuRenderletRegistration: ServiceRegistration[TypeRenderlet] = null
- var graphListenerOption: Option[GraphListener] = null
+ var renderletRegistration,
+ titledContentRenderletRegistration,
+ globalMenuRenderletRegistration: ServiceRegistration[TypeRenderlet] = null
+ var graphListenerOption: Option[GraphListener] = null
- /**
- * called when the bundle is started, this method initializes the provided service
- */
- def start(context: BundleContext) {
- val servicesDsl = new ServicesDsl(context)
- import servicesDsl._
+ /**
+ * called when the bundle is started, this method initializes the provided service
+ */
+ def start(context: BundleContext) {
+ val servicesDsl = new ServicesDsl(context)
+ import servicesDsl._
- val renderlet = new HeadedPageRenderlet
- renderletRegistration = context.registerService(classOf[TypeRenderlet],
- renderlet, null)
- titledContentRenderletRegistration = context.registerService(classOf[TypeRenderlet],
- new TitledContentRenderlet, null)
- globalMenuRenderletRegistration = context.registerService(classOf[TypeRenderlet],
- new GlobalMenuRenderlet, null)
- context.installBundle("mvn:org.apache.clerezza/rdf.stable.serializer").start();
- context.installBundle("mvn:org.apache.clerezza/tools.offline").start();
- val path = {
- val bl = context.getBundle.getLocation
- bl.substring(bl.indexOf(':')+1)
- }
- val graphFile = new File(new File(path), "graph.nt");
- doWith {
- (tcManager: TcManager, parser: Parser) => {
- val contentGraph = tcManager.getMGraph(Constants.CONTENT_GRAPH_URI)
- val fileGraph = parser.parse(new FileInputStream(graphFile), SupportedFormat.N_TRIPLE)
- if (contentGraph.size > fileGraph.size) {
- println("content graph if bigger than the graph from file, not replacing with the content from file and not " +
- "writing any data to the file, you should manually either write the content graph to the file or clear " +
- "the content graph. Restart this bundle after resolving the issue.")
- graphListenerOption = None
- } else {
- contentGraph.clear
- contentGraph.addAll(fileGraph)
- println("the content graph has been replaced with "+graphFile)
- object graphListener extends GraphListener {
- val serializer = $[Serializer]
- override def graphChanged(events: java.util.List[GraphEvent]) {
- serializer.serialize(new FileOutputStream(graphFile), contentGraph,SupportedFormat.N_TRIPLE)
- }
- }
- contentGraph.addGraphListener(graphListener, new FilterTriple(null, null, null), 2000)
- graphListenerOption = Some(graphListener)
- println("A GraphListener has been added that writes changes to the content graph to graph.nt")
- }
- }
- }
- }
+ val renderlet = new HeadedPageRenderlet
+ renderletRegistration = context.registerService(classOf[TypeRenderlet],
+ renderlet, null)
+ titledContentRenderletRegistration = context.registerService(classOf[TypeRenderlet],
+ new TitledContentRenderlet, null)
+ globalMenuRenderletRegistration = context.registerService(classOf[TypeRenderlet],
+ new GlobalMenuRenderlet, null)
+ context.installBundle("mvn:org.apache.clerezza/rdf.stable.serializer").start();
+ context.installBundle("mvn:org.apache.clerezza/tools.offline").start();
+ val path = {
+ val bl = context.getBundle.getLocation
+ bl.substring(bl.indexOf(':')+1)
+ }
+ val graphFile = new File(new File(path), "graph.nt");
+ doWith {
+ (tcManager: TcManager, parser: Parser) => {
+ val contentGraph = tcManager.getMGraph(Constants.CONTENT_GRAPH_URI)
+ val fileGraph = parser.parse(new FileInputStream(graphFile), SupportedFormat.N_TRIPLE)
+ if (contentGraph.size > fileGraph.size) {
+ println("content graph if bigger than the graph from file, not replacing with the content from file and not " +
+ "writing any data to the file, you should manually either write the content graph to the file or clear " +
+ "the content graph. Restart this bundle after resolving the issue.")
+ graphListenerOption = None
+ } else {
+ contentGraph.clear
+ contentGraph.addAll(fileGraph)
+ println("the content graph has been replaced with "+graphFile)
+ object graphListener extends GraphListener {
+ val serializer = $[Serializer]
+ override def graphChanged(events: java.util.List[GraphEvent]) {
+ serializer.serialize(new FileOutputStream(graphFile), contentGraph,SupportedFormat.N_TRIPLE)
+ }
+ }
+ contentGraph.addGraphListener(graphListener, new FilterTriple(null, null, null), 2000)
+ graphListenerOption = Some(graphListener)
+ println("A GraphListener has been added that writes changes to the content graph to graph.nt")
+ }
+ }
+ }
+ }
- /**
- * called when the bundle is stopped, this method unregisters the provided service
- */
- def stop(context: BundleContext) {
- renderletRegistration.unregister()
- titledContentRenderletRegistration.unregister()
- globalMenuRenderletRegistration.unregister()
- val servicesDsl = new ServicesDsl(context)
- import servicesDsl._
- val tcManager = $[TcManager]
- val contentGraph = tcManager.getMGraph(Constants.CONTENT_GRAPH_URI)
- graphListenerOption match {
- case Some(l) => contentGraph.removeGraphListener(l)
- case None => ;
- }
- println("bye")
- }
+ /**
+ * called when the bundle is stopped, this method unregisters the provided service
+ */
+ def stop(context: BundleContext) {
+ renderletRegistration.unregister()
+ titledContentRenderletRegistration.unregister()
+ globalMenuRenderletRegistration.unregister()
+ val servicesDsl = new ServicesDsl(context)
+ import servicesDsl._
+ val tcManager = $[TcManager]
+ val contentGraph = tcManager.getMGraph(Constants.CONTENT_GRAPH_URI)
+ graphListenerOption match {
+ case Some(l) => contentGraph.removeGraphListener(l)
+ case None => ;
+ }
+ println("bye")
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/site/src/main/scala/GlobalMenuRenderlet.scala
----------------------------------------------------------------------
diff --git a/site/src/main/scala/GlobalMenuRenderlet.scala b/site/src/main/scala/GlobalMenuRenderlet.scala
index 6c5493c..7f6e26b 100644
--- a/site/src/main/scala/GlobalMenuRenderlet.scala
+++ b/site/src/main/scala/GlobalMenuRenderlet.scala
@@ -16,20 +16,20 @@ import org.apache.clerezza.rdf.ontologies.DC
*/
class GlobalMenuRenderlet extends SRenderlet {
- val getRdfType = RDFS.Resource
+ val getRdfType = RDFS.Resource
- override def getModePattern = "menu"
+ override def getModePattern = "menu"
- override def renderedPage(arguments: XmlResult.Arguments) = {
- new XmlResult(arguments) {
- def menuLink(href: String, label: String) =
- if ((res*).endsWith(href) || (res*).endsWith(href+"index")) {
- <a href={href} class="active">{label}</a>
- } else {
- <a href={href}>{label}</a>
- }
- override def content = {
- def menu(s: Any) = new UriRef("http://clerezza.org/2009/11/global-menu#"+s)
+ override def renderedPage(arguments: XmlResult.Arguments) = {
+ new XmlResult(arguments) {
+ def menuLink(href: String, label: String) =
+ if ((res*).endsWith(href) || (res*).endsWith(href+"index")) {
+ <a href={href} class="active">{label}</a>
+ } else {
+ <a href={href}>{label}</a>
+ }
+ override def content = {
+ def menu(s: Any) = new UriRef("http://clerezza.org/2009/11/global-menu#"+s)
def rdfs(s: Any) = new UriRef("http://www.w3.org/2000/01/rdf-schema#"+s)
def platform(s: Any) = new UriRef("http://clerezza.org/2009/08/platform#"+s)
def dct(s: Any) = new UriRef("http://purl.org/dc/terms/"+s)
@@ -38,38 +38,38 @@ resultDocModifier.addScriptReference("/style/scripts/login.js");
<div class="column nav">
- <ul>
-
+ <ul>
+
- {for (menuItem <- res/menu("globalMenu")!!) yield
- <li class="top-nav-entry"><div class="title">
- {
- if ((menuItem/menu("path")).length > 0) {
- <a href={menuItem/menu("path")*}>{(menuItem/rdfs("label")*)}</a>
- } else {
- <a href="#" onclick="return false">{(menuItem/rdfs("label")*)}</a>
- }
- }
- </div>
- {
- ifx ((menuItem/menu("children")).length > 0) {
- <div>
- <ul class="nav-entries">
- {
- for (childMenuItem <- menuItem/menu("children")!!) yield {
- <li><a href={childMenuItem/menu("path")*}>{childMenuItem/rdfs("label")*}</a><span>{childMenuItem/dct("description")*}</span></li>
- }
- }
- </ul>
- </div>
- }
- }
- </li>
- }
- </ul>
+ {for (menuItem <- res/menu("globalMenu")!!) yield
+ <li class="top-nav-entry"><div class="title">
+ {
+ if ((menuItem/menu("path")).length > 0) {
+ <a href={menuItem/menu("path")*}>{(menuItem/rdfs("label")*)}</a>
+ } else {
+ <a href="#" onclick="return false">{(menuItem/rdfs("label")*)}</a>
+ }
+ }
+ </div>
+ {
+ ifx ((menuItem/menu("children")).length > 0) {
+ <div>
+ <ul class="nav-entries">
+ {
+ for (childMenuItem <- menuItem/menu("children")!!) yield {
+ <li><a href={childMenuItem/menu("path")*}>{childMenuItem/rdfs("label")*}</a><span>{childMenuItem/dct("description")*}</span></li>
+ }
+ }
+ </ul>
+ </div>
+ }
+ }
+ </li>
+ }
+ </ul>
</div>
- }
- }
- }
+ }
+ }
+ }
}