clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1539411 - in /clerezza/trunk: scala-scripting/script-engine/ scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/ shell/ shell/src/main/scala/org/apache/clerezza/shell/
Date Wed, 06 Nov 2013 18:03:01 GMT
Author: reto
Date: Wed Nov  6 18:03:01 2013
New Revision: 1539411

URL: http://svn.apache.org/r1539411
Log:
CLEREZZA-842: using the orginal bundle-classloader rather than the scalate one.

Modified:
    clerezza/trunk/scala-scripting/script-engine/pom.xml
    clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/BundleContextScalaCompiler.scala
    clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala
    clerezza/trunk/shell/pom.xml
    clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
    clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala

Modified: clerezza/trunk/scala-scripting/script-engine/pom.xml
URL: http://svn.apache.org/viewvc/clerezza/trunk/scala-scripting/script-engine/pom.xml?rev=1539411&r1=1539410&r2=1539411&view=diff
==============================================================================
--- clerezza/trunk/scala-scripting/script-engine/pom.xml (original)
+++ clerezza/trunk/scala-scripting/script-engine/pom.xml Wed Nov  6 18:03:01 2013
@@ -40,11 +40,11 @@
             <groupId>org.scala-lang</groupId>
             <artifactId>scala-actors</artifactId>
         </dependency>
-        <dependency>
+       <!-- <dependency>
             <groupId>org.fusesource.scalate</groupId>
             <artifactId>scalate-core_2.10</artifactId>
             <version>1.6.1</version>
-        </dependency>
+        </dependency> -->
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.scr.annotations</artifactId>
@@ -72,13 +72,13 @@
                     <instructions>
                         <Service-Component>OSGI-INF/serviceComponents.xml</Service-Component>
                         <Export-Package>org.apache.clerezza.scala.scripting,org.apache.clerezza.scala.scripting.util</Export-Package>
-                        <Import-Package>!com.sun.*,!javax.servlet,!javax.servlet.*,
+                        <!-- <Import-Package>!com.sun.*,!javax.servlet,!javax.servlet.*,
                             !org.fusesource.*,!org.mozilla.*,!scala.reflect.*,!javax.ws.rs,!javax.ws.rs.*,*
-                        </Import-Package>
-                        <Private-Package>org.fusesource.*</Private-Package>
+                        </Import-Package> -->
+                        <!-- <Private-Package>org.fusesource.*</Private-Package>
-->
                         <DynamicImport-Package>*</DynamicImport-Package>
                         <Bundle-SymbolicName>org.apache.clerezza.scala.scripting</Bundle-SymbolicName>
-                        <Embed-Dependency>scalate-core_2.10</Embed-Dependency>
+                    <!--    <Embed-Dependency>scalate-core_2.10</Embed-Dependency>
-->
                     </instructions>
                 </configuration>
             </plugin>

Modified: clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/BundleContextScalaCompiler.scala
URL: http://svn.apache.org/viewvc/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/BundleContextScalaCompiler.scala?rev=1539411&r1=1539410&r2=1539411&view=diff
==============================================================================
--- clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/BundleContextScalaCompiler.scala
(original)
+++ clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/BundleContextScalaCompiler.scala
Wed Nov  6 18:03:01 2013
@@ -19,6 +19,7 @@
 package org.apache.clerezza.scala.scripting
 
 import org.osgi.framework.BundleContext
+//import org.fusesource.scalate.util.Strings
 import org.osgi.framework.Bundle
 /*import java.io.File
 import scala.tools.nsc._;
@@ -29,8 +30,8 @@ import java.net._
 import scala.tools.nsc.io.AbstractFile
 import scala.tools.nsc.reporters.Reporter
 import scala.tools.util.PathResolver*/
-import org.fusesource.scalate._
-import osgi.{BundleHeaders, BundleClassPathBuilder, BundleClassLoader}
+import java.net.URL
+//import org.fusesource.scalate.osgi.BundleClassPathBuilder
 import scala.tools.nsc.Global
 import scala.tools.nsc.Settings
 import scala.tools.nsc.interpreter.ReplGlobal
@@ -43,8 +44,9 @@ import scala.runtime.ByteRef
 import scala.util.parsing.input.OffsetPosition
 import collection.mutable.ListBuffer
 import org.osgi.framework.Bundle
-import java.io.{PrintWriter, StringWriter, File}
+import java.io.{PrintWriter, StringWriter, File, IOException, InputStream}
 import org.slf4j.scala._
+import scala.collection.mutable.ListBuffer
 
 /*
  * unfortunately there seems to be no way to change the classpath, so this doesn't
@@ -69,11 +71,11 @@ class BundleContextScalaCompiler(bundleC
   def createClassPath[T](original: ClassPath[T]) = {
     
     var result = ListBuffer(original)
-    for (bundle <- bundleContext.getBundles; if bundle.getResource("/") != null) {
+    for (bundle <- bundleContext.getBundles/*; if bundle.getResource("/") != null*/) {
       try {
-        val files = BundleClassPathBuilder.fromBundle(bundle) 
+        val files = ListBuffer(BundleFS.create(bundle)); //BundleClassPathBuilder.fromBundle(bundle)

         files.foreach(file => {
-          //debug("Adding bundle " + file + " to the Scala compiler classpath")
+          //println("Adding bundle " + file + " to the Scala compiler classpath for "+bundle)
           result += original.context.newClassPath(file)
         })
       } catch {
@@ -110,6 +112,6 @@ class BundleContextScalaCompiler(bundleC
 	/*override def rootLoader: LazyType = {
 		new loaders.JavaPackageLoader(classPath)
 	}*/
-}
+        }
 
 

Modified: clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala
URL: http://svn.apache.org/viewvc/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala?rev=1539411&r1=1539410&r2=1539411&view=diff
==============================================================================
--- clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala
(original)
+++ clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala
Wed Nov  6 18:03:01 2013
@@ -46,143 +46,143 @@ import java.io.Reader
 import java.net._
 
 class CompileErrorsException(message: String, cause: Exception) extends Exception(message,
cause) {
-	def this(cause: Exception) = this(null, cause)
-        def this() = this(null)
+  def this(cause: Exception) = this(null, cause)
+  def this() = this(null)
 }
 
 class CompilePermission extends Permission("Compile Permssion") {
-	def getActions() = ""
-	def implies(p: Permission) = p.isInstanceOf[CompilePermission]
-	override def equals(o: Any): Boolean = o.isInstanceOf[CompilePermission]
-	override def hashCode = classOf[CompilePermission].hashCode
+  def getActions() = ""
+  def implies(p: Permission) = p.isInstanceOf[CompilePermission]
+  override def equals(o: Any): Boolean = o.isInstanceOf[CompilePermission]
+  override def hashCode = classOf[CompilePermission].hashCode
 }
 
 class CompilerService() extends BundleListener  {
 
-	protected var bundleContext : BundleContext = null;
-	//protected val sharedVirtualDirectory = new VirtualDirectory("(memory)", None)
-	protected var currentSharedCompilerOutputStream: OutputStream = null
-	protected val splipptingOutputStream = new OutputStream() {
-		def write(b: Int) {
-			if (currentSharedCompilerOutputStream == null) {
-				throw new IOException("no currentSharedCompilerOutputStream set")
-			}
-			currentSharedCompilerOutputStream.write(b)
-		}
-	}
-	protected val splittingPrintWriter = new PrintWriter(splipptingOutputStream, true)
-
-	protected var currentSharedCompiler: TrackingCompiler = null;
-	protected def sharedCompiler = {
-		if (currentSharedCompiler == null) {
-			synchronized {
-				if (currentSharedCompiler == null) {
-					currentSharedCompiler = TrackingCompiler(bundleContext, splittingPrintWriter, None)
-					//createCompiler(splittingPrintWriter, sharedVirtualDirectory)
-				}
-			}
-		}
-		currentSharedCompiler
-	}
-
-	def activate(componentContext: ComponentContext)= {
-		bundleContext = componentContext.getBundleContext
-		bundleContext.addBundleListener(this)
-	}
-
-	def deactivate(componentContext: ComponentContext) = {
-		currentSharedCompiler = null
-		bundleContext.removeBundleListener(this)
-	}
-
-	def bundleChanged(event: BundleEvent) = {
-		currentSharedCompiler = null
-	}
-
-	def createCompiler(out: PrintWriter, outputSirectory: AbstractFile) : TrackingCompiler =
{
-		TrackingCompiler(bundleContext, out, Some(outputSirectory))
-	}
-
-	def compile(sources: Array[Array[Char]]): Array[Class[_]] = {
-		compile(sources.toList).toArray
-	}
-
-	def compile(sources: List[Array[Char]]): List[Class[_]] = {
-		AccessController.checkPermission(new CompilePermission)
-		sharedCompiler.synchronized {
-			try {
-				AccessController.doPrivileged[List[Class[_]]](
-					new PrivilegedExceptionAction[List[Class[_]]] {
-						def run(): List[Class[_]] = {
-							val baos = new ByteArrayOutputStream
-							currentSharedCompilerOutputStream = baos
-							try {
-								sharedCompiler.compile(sources)
-							} catch {
-								case c: CompileErrorsException => {           
-                                                                    throw new CompileErrorsException(
-										new String(baos.toByteArray, "utf-8"), c)
-                                                                }
-								case e: Exception => throw e
-							} finally {
-								currentSharedCompilerOutputStream = null
-							}
-						}
-					})
-			} catch {
-				case e: PrivilegedActionException => throw e.getCause
-				case e: Exception => throw e
-			}
-		}
-	}
-
-	/**
-	 * compiles a set of sources with a dedicated compiler
-	 */
-	def compileIsolated(sources: List[Array[Char]]): List[Class[_]] = {
-		val virtualDirectory = new VirtualDirectory("(memory)", None)
-		compileIsolated(sources, virtualDirectory)
-	}
-
-	def compileIsolated(sources: List[Array[Char]], outputDirectory: AbstractFile): List[Class[_]]
= {
-		AccessController.checkPermission(new CompilePermission)
-		sharedCompiler.synchronized {
-                              AccessController.doPrivileged[List[Class[_]]](
-                                      new PrivilegedExceptionAction[List[Class[_]]] {
-                                              def run() = {
-                                                      val out = new ByteArrayOutputStream
-                                                      val printWriter = new PrintWriter(out)
-                                                      val compiler = createCompiler(printWriter,
outputDirectory)
-                                                      try {
-                                                              compiler.compile(sources)
-                                                      } catch {
-                                                              case c: CompileErrorsException
=> throw new CompileErrorsException(new String(out.toByteArray, "utf-8"), c)
-                                                              case e: Exception => throw
e
-                                                      }
-                                              }
-                                      })
-		}
-	}
-
-	def compileToDir(sources: List[Array[Char]], outputDirectory: AbstractFile): List[AbstractFile]
= {
-		AccessController.checkPermission(new CompilePermission)
-		sharedCompiler.synchronized {
-				AccessController.doPrivileged[List[AbstractFile]](
-					new PrivilegedExceptionAction[List[AbstractFile]] {
-						def run() = {
-							val out = new ByteArrayOutputStream
-							val printWriter = new PrintWriter(out)
-							val compiler = createCompiler(printWriter, outputDirectory)
-							try {
-								compiler.compileToDir(sources)
-							} catch {
-								case c: CompileErrorsException => throw new CompileErrorsException(new String(out.toByteArray,
"utf-8"), c)
-								case e: Exception => throw e
-							}
-						}
-					})
-		}
-	}
+  protected var bundleContext : BundleContext = null;
+  //protected val sharedVirtualDirectory = new VirtualDirectory("(memory)", None)
+  protected var currentSharedCompilerOutputStream: OutputStream = null
+  protected val splipptingOutputStream = new OutputStream() {
+    def write(b: Int) {
+      if (currentSharedCompilerOutputStream == null) {
+        throw new IOException("no currentSharedCompilerOutputStream set")
+      }
+      currentSharedCompilerOutputStream.write(b)
+    }
+  }
+  protected val splittingPrintWriter = new PrintWriter(splipptingOutputStream, true)
+
+  protected var currentSharedCompiler: TrackingCompiler = null;
+  protected def sharedCompiler = {
+    if (currentSharedCompiler == null) {
+      synchronized {
+        if (currentSharedCompiler == null) {
+          currentSharedCompiler = TrackingCompiler(bundleContext, splittingPrintWriter, None)
+          //createCompiler(splittingPrintWriter, sharedVirtualDirectory)
+        }
+      }
+    }
+    currentSharedCompiler
+  }
+
+  def activate(componentContext: ComponentContext)= {
+    bundleContext = componentContext.getBundleContext
+    bundleContext.addBundleListener(this)
+  }
+
+  def deactivate(componentContext: ComponentContext) = {
+    currentSharedCompiler = null
+    bundleContext.removeBundleListener(this)
+  }
+
+  def bundleChanged(event: BundleEvent) = {
+    currentSharedCompiler = null
+  }
+
+  def createCompiler(out: PrintWriter, outputSirectory: AbstractFile) : TrackingCompiler
= {
+    TrackingCompiler(bundleContext, out, Some(outputSirectory))
+  }
+
+  def compile(sources: Array[Array[Char]]): Array[Class[_]] = {
+    compile(sources.toList).toArray
+  }
+
+  def compile(sources: List[Array[Char]]): List[Class[_]] = {
+    AccessController.checkPermission(new CompilePermission)
+    sharedCompiler.synchronized {
+      try {
+        AccessController.doPrivileged[List[Class[_]]](
+          new PrivilegedExceptionAction[List[Class[_]]] {
+            def run(): List[Class[_]] = {
+              val baos = new ByteArrayOutputStream
+              currentSharedCompilerOutputStream = baos
+              try {
+                sharedCompiler.compile(sources)
+              } catch {
+                case c: CompileErrorsException => {  
+                    throw new CompileErrorsException(
+                      new String(baos.toByteArray, "utf-8"), c)
+                  }
+                case e: Exception => throw e
+              } finally {
+                currentSharedCompilerOutputStream = null
+              }
+            }
+          })
+      } catch {
+        case e: PrivilegedActionException => throw e.getCause
+        case e: Exception => throw e
+      }
+    }
+  }
+
+  /**
+   * compiles a set of sources with a dedicated compiler
+   */
+  def compileIsolated(sources: List[Array[Char]]): List[Class[_]] = {
+    val virtualDirectory = new VirtualDirectory("(memory)", None)
+    compileIsolated(sources, virtualDirectory)
+  }
+
+  def compileIsolated(sources: List[Array[Char]], outputDirectory: AbstractFile): List[Class[_]]
= {
+    AccessController.checkPermission(new CompilePermission)
+    sharedCompiler.synchronized {
+      AccessController.doPrivileged[List[Class[_]]](
+        new PrivilegedExceptionAction[List[Class[_]]] {
+          def run() = {
+            val out = new ByteArrayOutputStream
+            val printWriter = new PrintWriter(out)
+            val compiler = createCompiler(printWriter, outputDirectory)
+            try {
+              compiler.compile(sources)
+            } catch {
+              case c: CompileErrorsException => throw new CompileErrorsException(new String(out.toByteArray,
"utf-8"), c)
+              case e: Exception => throw e
+            }
+          }
+        })
+    }
+  }
+
+  def compileToDir(sources: List[Array[Char]], outputDirectory: AbstractFile): List[AbstractFile]
= {
+    AccessController.checkPermission(new CompilePermission)
+    sharedCompiler.synchronized {
+      AccessController.doPrivileged[List[AbstractFile]](
+        new PrivilegedExceptionAction[List[AbstractFile]] {
+          def run() = {
+            val out = new ByteArrayOutputStream
+            val printWriter = new PrintWriter(out)
+            val compiler = createCompiler(printWriter, outputDirectory)
+            try {
+              compiler.compileToDir(sources)
+            } catch {
+              case c: CompileErrorsException => throw new CompileErrorsException(new String(out.toByteArray,
"utf-8"), c)
+              case e: Exception => throw e
+            }
+          }
+        })
+    }
+  }
 
 	
 }

Modified: clerezza/trunk/shell/pom.xml
URL: http://svn.apache.org/viewvc/clerezza/trunk/shell/pom.xml?rev=1539411&r1=1539410&r2=1539411&view=diff
==============================================================================
--- clerezza/trunk/shell/pom.xml (original)
+++ clerezza/trunk/shell/pom.xml Wed Nov  6 18:03:01 2013
@@ -94,7 +94,8 @@
                         scala.tools.jline.console.history, 
                         scala.tools.jline.console.completer</Export-Package>
                         <Bundle-SymbolicName>org.apache.clerezza.shell</Bundle-SymbolicName>
-                        <Import-Package>org.apache.clerezza.platform.security;resolution:=optional,
*</Import-Package>
+                        <Import-Package>org.apache.clerezza.platform.security;resolution:=optional,

+                            org.osgi.*; version="[1,2)", *</Import-Package>
                         <Embed-Dependency>jline, scala-actors</Embed-Dependency>
                     </instructions>
                 </configuration>

Modified: clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
URL: http://svn.apache.org/viewvc/clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala?rev=1539411&r1=1539410&r2=1539411&view=diff
==============================================================================
--- clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala (original)
+++ clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala Wed Nov  6 18:03:01
2013
@@ -69,7 +69,7 @@ import scala.tools.jline.UnixTerminal
 import scala.tools.jline.console.history.History
 
 class Shell(factory: InterpreterFactory, val inStream: InputStream,
-  outStream: OutputStream, shellCommands: immutable.Set[ShellCommand], terminalOption: Option[Terminal]
= None) extends Logging {
+            outStream: OutputStream, shellCommands: immutable.Set[ShellCommand], terminalOption:
Option[Terminal] = None) extends Logging {
 
   private var bundleContext: BundleContext = null
 
@@ -101,11 +101,11 @@ class Shell(factory: InterpreterFactory,
     override lazy val standardCommands: List[LoopCommand] = {
       import LoopCommand._
       (for (shellCommand <- shellCommands) yield {
-        new LineCmd(shellCommand.command, "<unknown>", shellCommand.description, (line:
String) => {
-          val (continue, linesToRecord) = shellCommand.execute(line, Shell.this.outStream)
-          Result(continue, linesToRecord)
-        })
-      }).toList ::: List(
+          new LineCmd(shellCommand.command, "<unknown>", shellCommand.description,
(line: String) => {
+              val (continue, linesToRecord) = shellCommand.execute(line, Shell.this.outStream)
+              Result(continue, linesToRecord)
+            })
+        }).toList ::: List(
         cmd("help", "[command]", "print this summary or command-specific help", helpCommand),
         historyCommand,
         cmd("h?", "<string>", "search the history", searchHistory),
@@ -119,65 +119,65 @@ class Shell(factory: InterpreterFactory,
     }
 
     /** print a friendly help message */
-  override def helpCommand(line: String): Result = {
-    if (line == "") printAdditinalHelp();
+    override def helpCommand(line: String): Result = {
+      if (line == "") printAdditinalHelp();
       
-    super.helpCommand(line);
-  }
+      super.helpCommand(line);
+    }
 
     def printAdditinalHelp() = {
-			out println "This is a scala based console, it supports any Scala expression, as well
as the command described below."
-			out println "To access an OSGi service use $[interface]."
-			out println ""
-			out println "Initially the following variables are bound:"
-			for ((name, boundType, value) <- bindings) {
-				out println (name+": "+boundType+" = "+value)
-			}
-			out println ""
-			out println "This are the initial imports: "
-			for (v <- imports) {
-				out println ("import "+v)
-			}
-			out println ""
-		}
+      out println "This is a scala based console, it supports any Scala expression, as well
as the command described below."
+      out println "To access an OSGi service use $[interface]."
+      out println ""
+      out println "Initially the following variables are bound:"
+      for ((name, boundType, value) <- bindings) {
+        out println (name+": "+boundType+" = "+value)
+      }
+      out println ""
+      out println "This are the initial imports: "
+      for (v <- imports) {
+        out println ("import "+v)
+      }
+      out println ""
+    }
 
     override def process(settings: Settings): Boolean = {
       this.settings = settings
       createInterpreter()
 
       // sets in to some kind of reader depending on environmental cues
-     //ignore settings.noCompletion.value)
+      //ignore settings.noCompletion.value)
       {
-    	  val myIn = new StreamJLineReader(new JLineCompletion(intp), inStream, outStream, terminal)

-    	  in =  myIn
-    	  //are we postinit already?
-    	  addThunk(myIn.consoleReader.postInit)
+        val myIn = new StreamJLineReader(new JLineCompletion(intp), inStream, outStream,
terminal) 
+        in =  myIn
+        //are we postinit already?
+        addThunk(myIn.consoleReader.postInit)
       }
       loadFiles(settings)
-    // it is broken on startup; go ahead and exit
-    if (intp.reporter.hasErrors)
-      return false
-
-    // This is about the illusion of snappiness.  We call initialize()
-    // which spins off a separate thread, then print the prompt and try
-    // our best to look ready.  The interlocking lazy vals tend to
-    // inter-deadlock, so we break the cycle with a single asynchronous
-    // message to an actor.
-    if (isAsync) {
-      intp initialize initializedCallback()
-      createAsyncListener() // listens for signal to run postInitialization
-    }
-    else {
-      intp.initializeSynchronous()
-      postInitialization()
-    }
-    printWelcome()
-
-    try loop()
-    catch AbstractOrMissingHandler()
-    finally closeInterpreter()
+      // it is broken on startup; go ahead and exit
+      if (intp.reporter.hasErrors)
+        return false
+
+      // This is about the illusion of snappiness.  We call initialize()
+      // which spins off a separate thread, then print the prompt and try
+      // our best to look ready.  The interlocking lazy vals tend to
+      // inter-deadlock, so we break the cycle with a single asynchronous
+      // message to an actor.
+      if (isAsync) {
+        intp initialize initializedCallback()
+        createAsyncListener() // listens for signal to run postInitialization
+      }
+      else {
+        intp.initializeSynchronous()
+        postInitialization()
+      }
+      printWelcome()
+
+      try loop()
+      catch AbstractOrMissingHandler()
+      finally closeInterpreter()
 
-    true
+      true
     }
 
     override def printWelcome() {
@@ -187,7 +187,7 @@ class Shell(factory: InterpreterFactory,
 				|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)
+      stripMargin.format(versionString, javaVmName, javaVersion)
 
       echo(welcomeMsg)
     }

Modified: clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala
URL: http://svn.apache.org/viewvc/clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala?rev=1539411&r1=1539410&r2=1539411&view=diff
==============================================================================
--- clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala (original)
+++ clerezza/trunk/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala Wed Nov
 6 18:03:01 2013
@@ -25,7 +25,7 @@ import org.osgi.service.component.Compon
 import java.io.InputStream
 import java.io.OutputStream
 import java.security.AccessController
-import java.security.PrivilegedAction
+import java.security.PrivilegedExceptionAction
 import org.apache.clerezza.scala.scripting.InterpreterFactory
 import scala.tools.jline.Terminal
 
@@ -34,77 +34,78 @@ class ShellFactory()  {
 
 
 
-	private var interpreterFactory: InterpreterFactory = null
-	private var componentContext: ComponentContext = null
-	private var commands = Set[ShellCommand]()
-	private var customizers = Set[ShellCustomizer]()
-	
-	def activate(componentContext: ComponentContext)= {
-		this.componentContext = componentContext
-	}
-
-	def deactivate(componentContext: ComponentContext) = {
-		this.componentContext = componentContext
-	}
-
-	/* 
-	 * Using overloading instead of default, as default is not supported when calling from java
-	 */
-	def createShell(pIn: InputStream, pOut: OutputStream): Shell = {
-	  createShell(pIn, pOut, None)
-	}
-	def createShell(pIn: InputStream, pOut: OutputStream, terminalOption: Option[Terminal]):
Shell = {
+  private var interpreterFactory: InterpreterFactory = null
+  private var componentContext: ComponentContext = null
+  private var commands = Set[ShellCommand]()
+  private var customizers = Set[ShellCustomizer]()
+  
+  def activate(componentContext: ComponentContext)= {
+    this.componentContext = componentContext
+  }
+
+  def deactivate(componentContext: ComponentContext) = {
+    this.componentContext = componentContext
+  }
+
+  /* 
+   * Using overloading instead of default, as default is not supported when calling from
java
+   */
+  def createShell(pIn: InputStream, pOut: OutputStream): Shell = {
+    createShell(pIn, pOut, None)
+  }
+  def createShell(pIn: InputStream, pOut: OutputStream, terminalOption: Option[Terminal]):
Shell = {
     var security: SecurityManager = System.getSecurityManager
     if (security != null) {
       AccessController.checkPermission(new ShellPermission())
     }
-		AccessController.doPrivileged(new PrivilegedAction[Shell] {
-				override def run() = {
-					val shell = new Shell(interpreterFactory, pIn, pOut, commands, terminalOption)
-					//shell.bind("bundleContext", classOf[BundleContext].getName, componentContext.getBundleContext)
-					//shell.bind("componentContext", classOf[ComponentContext].getName, componentContext)
-					shell.bind("osgiDsl", classOf[OsgiDsl].getName, new OsgiDsl(componentContext, pOut))
-					shell.addImport("org.apache.clerezza.{scala => zzscala, _ }")
-					shell.addImport("osgiDsl._")
-					val environment = new Shell.Environment {
-						val componentContext: ComponentContext = ShellFactory.this.componentContext
-						val in: InputStream = pIn;
-						val out: OutputStream = pOut;
-					}
-					for (c <- customizers) {
-						for(b <- c.bindings(environment)) {
-							shell.bind(b._1, b._2, b._3)
-						}
-						for(i <- c.imports) {
-							shell.addImport(i)
-						}
-					}
-					shell
-				}
-			})
-	}
-
-	def bindInterpreterFactory(f: InterpreterFactory) = {
-		interpreterFactory = f
-	}
-
-	def unbindInterpreterFactory(f: InterpreterFactory) = {
-		interpreterFactory = null
-	}
-
-	def bindCommand(c: ShellCommand) = {
-		commands += c
-	}
-
-	def unbindCommand(c: ShellCommand) = {
-		commands -= c
-	}
-
-	def bindCustomizer(c: ShellCustomizer) = {
-		customizers += c
-	}
-
-	def unbindCustomizer(c: ShellCustomizer) = {
-		customizers -= c
-	}
+    AccessController.doPrivileged(new PrivilegedExceptionAction[Shell] {
+        override def run() = {
+          val shell = new Shell(interpreterFactory, pIn, pOut, commands, terminalOption)
+          //shell.bind("bundleContext", classOf[BundleContext].getName, componentContext.getBundleContext)
+          //shell.bind("componentContext", classOf[ComponentContext].getName, componentContext)
+          shell.bind("osgiDsl", classOf[OsgiDsl].getName, new OsgiDsl(componentContext, pOut))
+          shell.addImport("org.apache.clerezza.{scala => zzscala, _ }")
+          shell.addImport("osgiDsl._")
+          val environment = new Shell.Environment {
+            val componentContext: ComponentContext = ShellFactory.this.componentContext
+            val in: InputStream = pIn;
+            val out: OutputStream = pOut;
+          }
+          for (c <- customizers) {
+            for(b <- c.bindings(environment)) {
+              shell.bind(b._1, b._2, b._3)
+            }
+            for(i <- c.imports) {
+              shell.addImport(i)
+            }
+          }
+          shell
+        }
+      })
+
+  }
+
+  def bindInterpreterFactory(f: InterpreterFactory) = {
+    interpreterFactory = f
+  }
+
+  def unbindInterpreterFactory(f: InterpreterFactory) = {
+    interpreterFactory = null
+  }
+
+  def bindCommand(c: ShellCommand) = {
+    commands += c
+  }
+
+  def unbindCommand(c: ShellCommand) = {
+    commands -= c
+  }
+
+  def bindCustomizer(c: ShellCustomizer) = {
+    customizers += c
+  }
+
+  def unbindCustomizer(c: ShellCustomizer) = {
+    customizers -= c
+  }
 }
\ No newline at end of file



Mime
View raw message