Author: reto
Date: Tue Nov 30 20:01:32 2010
New Revision: 1040745
URL: http://svn.apache.org/viewvc?rev=1040745&view=rev
Log:
CLEREZZA-353: added scala based shell with support for executing felix commands
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/pom.xml
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/resources/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/resources/OSGI-INF/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/resources/OSGI-INF/serviceComponents.xml
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/apache/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/apache/clerezza/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/pom.xml
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/resources/OSGI-INF/serviceComponents.xml
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/OsgiDsl.scala
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala
incubator/clerezza/trunk/org.apache.clerezza.parent/pom.xml
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/pom.xml?rev=1040745&view=auto
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/pom.xml
(added)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/pom.xml
Tue Nov 30 20:01:32 2010
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.parent</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.shell.felixshellcommand</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <name>Clerezza - Integartion of felix shell commands into clerezza
shell</name>
+ <description>
+ Allows felix shell command to be executed in Clerezza Shell
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.shell</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+
<artifactId>org.apache.clerezza.web.fileserver</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.shell</artifactId>
+ <version>1.4.2</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <sourceDirectory>src/main/scala</sourceDirectory>
+ <testSourceDirectory>src/test/scala</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <!--
<scalaVersion>${scala.version}</scalaVersion> -->
+ <!-- <args>
+ <arg>-target:jvm-1.5</arg>
+ </args> -->
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+
<Service-Component>OSGI-INF/serviceComponents.xml</Service-Component>
+
<Export-Package>org.apache.clerezza.shell.felixshellcommand</Export-Package>
+
<Bundle-SymbolicName>org.apache.clerezza.shell.felixshellcommand</Bundle-SymbolicName>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/resources/OSGI-INF/serviceComponents.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/resources/OSGI-INF/serviceComponents.xml?rev=1040745&view=auto
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/resources/OSGI-INF/serviceComponents.xml
(added)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/resources/OSGI-INF/serviceComponents.xml
Tue Nov 30 20:01:32 2010
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+ <scr:component enabled="true" immediate="true"
name="org.apache.clerezza.shell.felixshellcommand.FelixShellCommand">
+ <implementation
class="org.apache.clerezza.shell.felixshellcommand.FelixShellCommand"/>
+ <service servicefactory="false">
+ <provide interface="org.apache.clerezza.shell.ShellCommand"/>
+ </service>
+ <property name="service.pid"
value="org.apache.clerezza.shell.felixshellcommand.FelixShellCommand"/>
+ <reference name="felixShell"
+ interface="org.apache.felix.shell.ShellService"
+ cardinality="1..1"
+ bind="bindFelixShell"
unbind="unbindFelixShell"/>
+ </scr:component>
+</components>
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala?rev=1040745&view=auto
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala
(added)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell.felixshellcommand/src/main/scala/org/apache/clerezza/shell/felixshellcommand/FelixShellCommand.scala
Tue Nov 30 20:01:32 2010
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2010 reto.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package org.apache.clerezza.shell.felixshellcommand
+
+import java.io.OutputStream
+import java.io.PrintStream
+import java.io.Writer
+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
+ }
+
+
+}
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/pom.xml?rev=1040745&r1=1040744&r2=1040745&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/pom.xml
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/pom.xml
Tue Nov 30 20:01:32 2010
@@ -51,7 +51,6 @@
<instructions>
<Service-Component>OSGI-INF/serviceComponents.xml</Service-Component>
<Export-Package>org.apache.clerezza.shell</Export-Package>
-
<Private-Package>org.apache.clerezza.shell</Private-Package>
<Bundle-SymbolicName>org.apache.clerezza.shell</Bundle-SymbolicName>
</instructions>
</configuration>
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/resources/OSGI-INF/serviceComponents.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/resources/OSGI-INF/serviceComponents.xml?rev=1040745&r1=1040744&r2=1040745&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/resources/OSGI-INF/serviceComponents.xml
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/resources/OSGI-INF/serviceComponents.xml
Tue Nov 30 20:01:32 2010
@@ -18,5 +18,9 @@
interface="org.apache.clerezza.scala.scripting.InterpreterFactory"
cardinality="1..1"
bind="bindInterpreterFactory"
unbind="unbindInterpreterFactory"/>
+ <reference name="commands"
+
interface="org.apache.clerezza.shell.ShellCommand"
+ cardinality="0..n"
+ bind="bindCommand" unbind="unbindCommand"/>
</scr:component>
</components>
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala?rev=1040745&r1=1040744&r2=1040745&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ConsoleShell.scala
Tue Nov 30 20:01:32 2010
@@ -38,6 +38,7 @@ class ConsoleShell() {
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
@@ -48,7 +49,8 @@ class ConsoleShell() {
bundle.stop()
stoppedBundle = Some(bundle)
}
- val shell = factory.createShell
+ interruptibleIn = new InterruptibleInputStream(System.in)
+ val shell = factory.createShell(interruptibleIn, System.out)
shell.start()
shellOption = Some(shell)
}
@@ -64,6 +66,7 @@ class ConsoleShell() {
case Some(shell) => shell.stop()
case _ =>
}
+ interruptibleIn.terminate()
}
def bindShellFactory(f: ShellFactory) = {
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala?rev=1040745&view=auto
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala
(added)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/InterruptibleInputStream.scala
Tue Nov 30 20:01:32 2010
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.shell
+
+import java.io.InputStream
+import scala.actors.Actor
+import scala.actors.Actor._
+
+class InterruptibleInputStream(base: InputStream) extends InputStream {
+ private case object Stop
+ private case object Read
+
+ private var lastReader: Actor = null
+
+ val readerActor = new Actor() {
+ def act() {
+ loop {
+ react {
+ case Stop => exit()
+ case Read => {
+ val ch = base.read()
+ lastReader ! ch
+ }
+ }
+ }
+ }
+ }
+ readerActor.start()
+
+ def read() = {
+ lastReader = self
+ readerActor ! Read
+ self.receive {
+ case x: Int => x
+ }
+ }
+
+ def terminate() {
+ readerActor ! Stop
+ if (lastReader != null) {
+ lastReader ! -1
+ }
+ }
+
+}
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/OsgiDsl.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/OsgiDsl.scala?rev=1040745&r1=1040744&r2=1040745&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/OsgiDsl.scala
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/OsgiDsl.scala
Tue Nov 30 20:01:32 2010
@@ -28,6 +28,20 @@ class OsgiDsl(context: ComponentContext)
for (b <- bundleContext.getBundles) { println(b.getBundleId+" -
"+b.getSymbolicName+" "+b.getLocation)}
}
+ def install(uri: String) = {
+ bundleContext.installBundle(uri)
+ }
+
+ def start(uri: String) = {
+ val b = install(uri)
+ b.start()
+ b
+ }
+
+ def shutdown {
+ bundleContext.getBundle(0).stop()
+ }
+
def $[T](implicit m: Manifest[T]): T = {
getService(m.erasure.asInstanceOf[Class[T]])
}
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/Shell.scala?rev=1040745&r1=1040744&r2=1040745&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
Tue Nov 30 20:01:32 2010
@@ -26,7 +26,7 @@ import org.osgi.framework.BundleEvent
import org.osgi.framework.BundleListener
import org.osgi.service.component.ComponentContext;
import org.osgi.framework.Bundle
-import java.io.{File, PrintWriter, Reader, StringWriter, BufferedReader,
InputStreamReader, InputStream, Writer}
+import java.io.{File, PrintWriter, Reader, StringWriter, BufferedReader,
InputStreamReader, InputStream, Writer, OutputStream}
import java.lang.reflect.InvocationTargetException
import java.net._
import java.security.PrivilegedActionException
@@ -39,6 +39,7 @@ import javax.script.{ScriptEngineFactory
SimpleBindings, ScriptException}
//import scala.collection.immutable.Map
import scala.actors.DaemonActor
+import scala.collection.immutable
import scala.tools.nsc._;
import scala.tools.nsc.interpreter._;
import scala.tools.nsc.io.{AbstractFile, PlainFile, VirtualDirectory}
@@ -56,7 +57,7 @@ import org.apache.clerezza.scala.scripti
import java.io.File
import jline.{ ConsoleReader, ArgumentCompletor, History => JHistory }
-class Shell(factory: InterpreterFactory, val inStream: InputStream, out:
Writer) {
+class Shell(factory: InterpreterFactory, val inStream: InputStream, out:
OutputStream, shellCommands: immutable.Set[ShellCommand]) {
private var bundleContext: BundleContext = null
@@ -65,15 +66,12 @@ class Shell(factory: InterpreterFactory,
private var imports = Set[String]()
- val interpreterLoop = new InterpreterLoop(new BufferedReader(new
InputStreamReader(System.in)), new PrintWriter(System.out, true)) {
+ val interpreterLoop = new InterpreterLoop(new BufferedReader(new
InputStreamReader(System.in)), new PrintWriter(out, true)) {
override def createInterpreter() {
- println("creating interpreter")
interpreter = factory.createInterpreter(out)
- println("binding bindings")
for (binding <- bindings) {
interpreter.bind(binding._1, binding._2,
binding._3)
}
- println("adding imports")
for (v <- imports) {
interpreter.interpret("import "+v)
}
@@ -83,19 +81,42 @@ class Shell(factory: InterpreterFactory,
override val standardCommands: List[Command] = {
import CommandImplicits._
+ (for (shellCommand <- shellCommands) yield {
+ LineArg(shellCommand.command,
shellCommand.description, (line: String)=> {
+ val (continue,
linesToRecord) = shellCommand.execute(line, Shell.this.out)
+ Result(continue,
linesToRecord)
+ })
+ }).toList :::
List(
- NoArgs("help", "print this help message", printHelp),
- VarArgs("history", "show the history (optional arg:
lines to show)", printHistory),
- LineArg("h?", "search the history", searchHistory),
- OneArg("load", "load and interpret a Scala file",
load),
- NoArgs("power", "enable power user mode", power),
- NoArgs("quit", "exit the interpreter", () =>
Result(false, None)),
- NoArgs("replay", "reset execution and replay all
previous commands", replay),
- LineArg("sh", "fork a shell and run a command",
runShellCmd),
- LineArg("felix", "execute a felix shell command",
runShellCmd),
- NoArgs("silent", "disable/enable automatic printing
of results", verbosity)
+ NoArgs("help", "print this help message",
printHelp),
+ VarArgs("history", "show the history (optional
arg: lines to show)", printHistory),
+ LineArg("h?", "search the history",
searchHistory),
+ OneArg("load", "load and interpret a Scala
file", load),
+ NoArgs("power", "enable power user mode",
power),
+ NoArgs("quit", "terminate the console shell
(use shutdown to shut down clerezza)", () => Result(false, None)),
+ NoArgs("replay", "reset execution and replay
all previous commands", replay),
+ LineArg("sh", "fork a shell and run a command",
runShellCmd),
+ NoArgs("silent", "disable/enable automatic
printing of results", verbosity)
)
- }
+ }
+
+ override def printHelp() = {
+ 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 ""
+ super.printHelp()
+ }
+
override def main(settings: Settings) {
this.settings = settings
@@ -104,23 +125,23 @@ class Shell(factory: InterpreterFactory,
// sets in to some kind of reader depending on
environmental cues
in = new InteractiveReader() {
- override lazy val history =
Some(History(consoleReader))
- override lazy val completion = Option(interpreter)
map (x => new Completion(x))
+ override lazy val history =
Some(History(consoleReader))
+ override lazy val completion =
Option(interpreter) map (x => new Completion(x))
- val consoleReader = {
- val r = new jline.ConsoleReader(inStream, out)
- r setHistory (History().jhistory)
- r setBellEnabled false
- completion foreach { c =>
- r addCompletor c.jline
- r setAutoprintThreshhold 250
- }
+ val consoleReader = {
+ val r = new
jline.ConsoleReader(inStream, out)
+ r setHistory (History().jhistory)
+ r setBellEnabled false
+ completion foreach { c =>
+ r addCompletor c.jline
+ r setAutoprintThreshhold 250
+ }
- r
- }
+ r
+ }
- def readOneLine(prompt: String) = consoleReader
readLine prompt
- val interactive = true
+ def readOneLine(prompt: String) = consoleReader
readLine prompt
+ val interactive = true
}
loadFiles(settings)
@@ -140,11 +161,21 @@ class Shell(factory: InterpreterFactory,
}
finally closeInterpreter()
}
+
+ override def printWelcome() {
+ 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.
+ |Hint: To execute a Felix-Shell command prepend
":f "
+ |Type :help for more information.""" .
+ stripMargin.format(versionString, javaVmName,
javaVersion)
+
+ plushln(welcomeMsg)
+ }
}
val console: Actor = actor {
- //cala.tools.nsc.MainGenericRunner.main(Array[String]());
- //scalaConsole();
-
println("starting console")
try {
interpreterLoop.main(Array[String]())
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala?rev=1040745&view=auto
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
(added)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
Tue Nov 30 20:01:32 2010
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2010 reto.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package org.apache.clerezza.shell
+
+import java.io.OutputStream
+import java.io.Writer
+
+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])
+}
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala?rev=1040745&r1=1040744&r2=1040745&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala
Tue Nov 30 20:01:32 2010
@@ -23,16 +23,18 @@ package org.apache.clerezza.shell;
import org.osgi.service.component.ComponentContext;
-import java.io.OutputStreamWriter
+import java.io.InputStream
+import java.io.OutputStream
import org.apache.clerezza.scala.scripting.InterpreterFactory
-import org.osgi.framework.BundleContext
+
class ShellFactory() {
- var factory: InterpreterFactory = null
+ var interpreterFactory: InterpreterFactory = null
var componentContext: ComponentContext = null
+ var commands = Set[ShellCommand]()
def activate(componentContext: ComponentContext)= {
this.componentContext = componentContext
@@ -42,21 +44,29 @@ class ShellFactory() {
this.componentContext = componentContext
}
- def createShell() = {
- val shell = new Shell(factory, System.in, new
OutputStreamWriter(System.out))
+ def createShell(in: InputStream, out: OutputStream) = {
+ val shell = new Shell(interpreterFactory, in, out, commands)
//shell.bind("bundleContext", classOf[BundleContext].getName,
componentContext.getBundleContext)
//shell.bind("componentContext",
classOf[ComponentContext].getName, componentContext)
shell.bind("osgiDsl", classOf[OsgiDsl].getName, new
OsgiDsl(componentContext))
- shell.addImport("org.apache.clerezza._")
+ shell.addImport("org.apache.clerezza.{scala => zzscala, _ }")
shell.addImport("osgiDsl._")
shell
}
def bindInterpreterFactory(f: InterpreterFactory) = {
- factory = f
+ interpreterFactory = f
}
def unbindInterpreterFactory(f: InterpreterFactory) = {
- factory = null
+ interpreterFactory = null
+ }
+
+ def bindCommand(c: ShellCommand) = {
+ commands += c
+ }
+
+ def unbindCommand(c: ShellCommand) = {
+ commands -= c
}
}
\ No newline at end of file
Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/pom.xml?rev=1040745&r1=1040744&r2=1040745&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/pom.xml (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/pom.xml Tue Nov 30
20:01:32 2010
@@ -102,6 +102,8 @@
<module>org.apache.clerezza.rdf.simple.storage</module>
<module>org.apache.clerezza.rdf.utils</module>
<module>org.apache.clerezza.rdf.web</module>
+ <module>org.apache.clerezza.shell</module>
+ <module>org.apache.clerezza.shell.felixshellcommand</module>
<module>org.apache.clerezza.templating</module>
<module>org.apache.clerezza.templating.seedsnipe</module>
<module>org.apache.clerezza.tools.offline</module>
@@ -1123,6 +1125,16 @@
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
+
<artifactId>org.apache.clerezza.shell</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+
<artifactId>org.apache.clerezza.shell.felixshellcommand</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
<artifactId>org.apache.clerezza.utils</artifactId>
<version>0.1-incubating-SNAPSHOT</version>
</dependency>