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 2010/11/09 00:03:51 UTC
svn commit: r1032781 - in
/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell:
./ src/main/scala/org/apache/clerezza/shell/
Author: reto
Date: Mon Nov 8 23:03:50 2010
New Revision: 1032781
URL: http://svn.apache.org/viewvc?rev=1032781&view=rev
Log:
CLEREZZA-353: started osgi console dsl with support to access services using $[interfaceName]
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/maven-eclipse.xml
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/OsgiDsl.scala
Modified:
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
Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/maven-eclipse.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/maven-eclipse.xml?rev=1032781&view=auto
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/maven-eclipse.xml (added)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/maven-eclipse.xml Mon Nov 8 23:03:50 2010
@@ -0,0 +1,8 @@
+<project default="copy-resources">
+ <target name="init"/>
+ <target name="copy-resources" depends="init">
+ <copy todir="target/classes/META-INF" filtering="false">
+ <fileset dir="." includes="NOTICE.txt|LICENSE.*" excludes="**/*.java"/>
+ </copy>
+ </target>
+</project>
\ No newline at end of file
Added: 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=1032781&view=auto
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/OsgiDsl.scala (added)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.shell/src/main/scala/org/apache/clerezza/shell/OsgiDsl.scala Mon Nov 8 23:03:50 2010
@@ -0,0 +1,41 @@
+/*
+ * 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 org.osgi.service.component.ComponentContext
+
+class OsgiDsl(context: ComponentContext) {
+
+ val bundleContext = context.getBundleContext
+
+ def ps = {
+ for (b <- bundleContext.getBundles) { println(b.getBundleId+" - "+b.getSymbolicName+" "+b.getLocation)}
+ }
+
+ def $[T](implicit m: Manifest[T]): T = {
+ getService(m.erasure.asInstanceOf[Class[T]])
+ }
+
+ private def getService[T](clazz : Class[T]) : T= {
+ val serviceReference = bundleContext.getServiceReference(clazz.getName)
+ if (serviceReference != null) {
+ bundleContext.getService(serviceReference).asInstanceOf[T]
+ } else null.asInstanceOf[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=1032781&r1=1032780&r2=1032781&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 Mon Nov 8 23:03:50 2010
@@ -62,21 +62,41 @@ class Shell(factory: InterpreterFactory,
private var bundleContext: BundleContext = null
private var bindings = Set[(String, String, Any)]()
+ private var imports = Set[String]()
val interpreterLoop = new InterpreterLoop(new BufferedReader(new InputStreamReader(System.in)), new PrintWriter(System.out, true)) {
override def createInterpreter() {
+ println("creating interpreter")
interpreter = factory.createInterpreter(out)
- interpreter.interpret("import org.apache.clerezza._")
- interpreter.interpret("val a = 33")
- interpreter.interpret("println(\"enjoy!\")")
+ println("binding bindings")
for (binding <- bindings) {
interpreter.bind(binding._1, binding._2, binding._3)
}
+ println("adding imports")
+ for (v <- imports) {
+ interpreter.interpret("import "+v)
+ }
}
override val prompt = "zz>"
+ override val standardCommands: List[Command] = {
+ import CommandImplicits._
+ 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)
+ )
+ }
+
override def main(settings: Settings) {
this.settings = settings
createInterpreter()
@@ -146,6 +166,10 @@ class Shell(factory: InterpreterFactory,
bindings += ((name, boundType, value))
}
+ def addImport(importValue: String) {
+ imports += importValue
+ }
+
}
\ No newline at end of file
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=1032781&r1=1032780&r2=1032781&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 Mon Nov 8 23:03:50 2010
@@ -32,19 +32,23 @@ class ShellFactory() {
var factory: InterpreterFactory = null
- var bundleContext: BundleContext = null
+ var componentContext: ComponentContext = null
def activate(componentContext: ComponentContext)= {
- bundleContext = componentContext.getBundleContext
+ this.componentContext = componentContext
}
def deactivate(componentContext: ComponentContext) = {
- bundleContext = componentContext.getBundleContext
+ this.componentContext = componentContext
}
def createShell() = {
val shell = new Shell(factory, System.in, new OutputStreamWriter(System.out))
- shell.bind("bundleContext", classOf[BundleContext].getName, bundleContext)
+ //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("osgiDsl._")
shell
}