Author: reto
Date: Sun Mar 20 20:01:28 2011
New Revision: 1083553

URL: http://svn.apache.org/viewvc?rev=1083553&view=rev
Log:
CLEREZZA-465: renamed sourcebundle to bundledevtool to reflect its more generic 
nature

Added:
    incubator/clerezza/trunk/parent/bundledevtool/
      - copied from r1083437, incubator/clerezza/trunk/parent/sourcebundle/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/pom.xml
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/CLEREZZA-INF/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/CLEREZZA-INF/web-resources/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/CLEREZZA-INF/web-resources/styles/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/CLEREZZA-INF/web-resources/styles/hello-world/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/CLEREZZA-INF/web-resources/styles/hello-world/style.css
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Activator.scala
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorld.scala
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorldMessageRenderlet.scala
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Ontology.scala
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/BundleRoot.scala
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevDsl.scala
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevShellCustomizer.scala
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/UnavailableSkeletonException.scala
Removed:
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/sourcebundle/
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/sourcebundle/
    incubator/clerezza/trunk/parent/sourcebundle/
Modified:
    incubator/clerezza/trunk/parent/bundledevtool/pom.xml
    
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/OSGI-INF/serviceComponents.xml
    incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml
    incubator/clerezza/trunk/parent/pom.xml

Modified: incubator/clerezza/trunk/parent/bundledevtool/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/pom.xml?rev=1083553&r1=1083437&r2=1083553&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/bundledevtool/pom.xml (original)
+++ incubator/clerezza/trunk/parent/bundledevtool/pom.xml Sun Mar 20 20:01:28 
2011
@@ -5,10 +5,10 @@
                <artifactId>parent</artifactId>
                <version>0.2-incubating-SNAPSHOT</version>
        </parent>
-       <artifactId>sourcebundle</artifactId>
+       <artifactId>bundledevtool</artifactId>
        <version>0.1-incubating-SNAPSHOT</version>
        <packaging>bundle</packaging>
-       <name>Clerezza - Source-Bundle Service</name>
+       <name>Clerezza - Bundle Development Tools</name>
        <dependencies>
                <dependency>
                        <groupId>org.apache.clerezza.scala</groupId>
@@ -63,9 +63,9 @@
                                <configuration>
                                        <instructions>
                                                
<Service-Component>OSGI-INF/serviceComponents.xml</Service-Component>
-                                               
<Export-Package>org.apache.clerezza.sourcebundle</Export-Package>
+                                               
<Export-Package>org.apache.clerezza.bundledevtool</Export-Package>
                                                
<Private-Package>sbt,sbt.*</Private-Package>
-                                               
<Bundle-SymbolicName>org.apache.clerezza.sourcebundle</Bundle-SymbolicName>
+                                               
<Bundle-SymbolicName>org.apache.clerezza.bundledevtool</Bundle-SymbolicName>
                                        </instructions>
                                </configuration>
                        </plugin>

Modified: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/OSGI-INF/serviceComponents.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/OSGI-INF/serviceComponents.xml?rev=1083553&r1=1083437&r2=1083553&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/OSGI-INF/serviceComponents.xml
 (original)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/OSGI-INF/serviceComponents.xml
 Sun Mar 20 20:01:28 2011
@@ -1,10 +1,10 @@
 <?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.sourcebundle.BundleRoot">
-        <implementation class="org.apache.clerezza.sourcebundle.BundleRoot"/>
-        <property name="service.pid" 
value="org.apache.clerezza.sourcebundle.BundleRoot"/>
+        <implementation class="org.apache.clerezza.bundledevtool.BundleRoot"/>
+        <property name="service.pid" 
value="org.apache.clerezza.bundledevtool.BundleRoot"/>
                <service servicefactory="false">
-            <provide interface="org.apache.clerezza.sourcebundle.BundleRoot"/>
+            <provide interface="org.apache.clerezza.bundledevtool.BundleRoot"/>
         </service>
                <reference name="CompilerService"
                                
interface="org.apache.clerezza.scala.scripting.CompilerService"
@@ -16,8 +16,8 @@
                                bind="bindPackageAdmin" 
unbind="unbindPackageAdmin"/>
     </scr:component>
        <scr:component enabled="true"  
name="org.apache.clerezza.sourcebundle.DevShellCustomizer">
-        <implementation 
class="org.apache.clerezza.sourcebundle.DevShellCustomizer"/>
-        <property name="service.pid" 
value="org.apache.clerezza.sourcebundle.DevShellCustomizer"/>
+        <implementation 
class="org.apache.clerezza.bundledevtool.DevShellCustomizer"/>
+        <property name="service.pid" 
value="org.apache.clerezza.bundledevtool.DevShellCustomizer"/>
                <service servicefactory="false">
             <provide interface="org.apache.clerezza.shell.ShellCustomizer"/>
         </service>

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/pom.xml?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/pom.xml
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/pom.xml
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,97 @@
+<?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>parent</artifactId>
+               <version>0.2-incubating-SNAPSHOT</version>
+       </parent>
+       <artifactId>skeleton</artifactId>
+       <version>0.1-incubating-SNAPSHOT</version>
+       <packaging>bundle</packaging>
+       <name>Clerezza - Project Skeleton</name>
+       <dependencies>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.compendium</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.core</artifactId>
+               </dependency>
+        <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>platform.typerendering.core</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>platform.typerendering.scala</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>rdf.ontologies</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>rdf.utils</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>rdf.scala.utils</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>osgi.services</artifactId>
+               </dependency>
+        <dependency>
+                       <groupId>org.scala-lang</groupId>
+                       <artifactId>scala-library</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>javax.ws.rs</groupId>
+                       <artifactId>jsr311-api</artifactId>
+        </dependency>
+       </dependencies>
+       <build>
+               <sourceDirectory>src/main/scala</sourceDirectory>
+    <testSourceDirectory>src/test/scala</testSourceDirectory>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <configuration>
+                                       <instructions>
+                                               
<Bundle-activator>skeleton.Activator</Bundle-activator>
+                                               
<Export-Package>skeleton</Export-Package>
+                                               
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-eclipse-plugin</artifactId>
+                               <configuration>
+                                       <downloadSources>true</downloadSources>
+                                       
<downloadJavadocs>true</downloadJavadocs>
+                                       <buildcommands>
+                                               
<buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
+                                       </buildcommands>
+                                       <additionalProjectnatures>
+                                               
<projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
+                                       </additionalProjectnatures>
+                                       <classpathContainers>
+                                               
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER
+                                               </classpathContainer>
+                                               
<classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER
+                                               </classpathContainer>
+                                       </classpathContainers>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.scala-tools</groupId>
+                               <artifactId>maven-scala-plugin</artifactId>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
+
+

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/CLEREZZA-INF/web-resources/styles/hello-world/style.css
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/CLEREZZA-INF/web-resources/styles/hello-world/style.css?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/CLEREZZA-INF/web-resources/styles/hello-world/style.css
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/resources/CLEREZZA-INF/web-resources/styles/hello-world/style.css
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,4 @@
+.message {
+    color: green
+}
+

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Activator.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Activator.scala?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Activator.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Activator.scala
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,41 @@
+package skeleton
+
+import org.osgi.framework.{BundleActivator, BundleContext, ServiceRegistration}
+import scala.collection.JavaConversions.asJavaDictionary
+import org.apache.clerezza.platform.typerendering.{TypeRenderlet, 
RenderletManager}
+
+/**
+ * Activator for a bundle using Apache Clerezza.
+ */
+class Activator extends BundleActivator {
+
+       var helloWorldRegistration: ServiceRegistration = null
+       var renderletRegistration: ServiceRegistration = null
+       /**
+        * called when the bundle is started, this method initializes the 
provided service
+        */
+       def start(context: BundleContext) {
+               //import org.apache.clerezza.shell.OsgiDsl
+               //val osgiDsl = new OsgiDsl(context, System.out)
+               //import osgiDsl._
+               println("activating...")
+               val args = scala.collection.mutable.Map("javax.ws.rs" -> true)
+               helloWorldRegistration = 
context.registerService(classOf[Object].getName,
+                                                                               
                  new HelloWorld(), args)
+               val renderlet = new HelloWorldMessageRenderlet
+               val serviceReference = 
context.getServiceReference(classOf[RenderletManager].getName)
+               renderletRegistration = 
context.registerService(classOf[TypeRenderlet].getName,
+                                                                               
                  renderlet, null)
+               println("enjoy it!")
+       }
+
+       /**
+        * called when the bundle is stopped, this method unregisters the 
provided service
+        */
+       def stop(context: BundleContext) {
+               helloWorldRegistration.unregister()
+               renderletRegistration.unregister()
+               println("bye")
+       }
+
+}

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorld.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorld.scala?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorld.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorld.scala
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,22 @@
+package skeleton
+
+import javax.ws.rs._
+import org.apache.clerezza.rdf.core.BNode
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph
+import org.apache.clerezza.rdf.ontologies.{DC, RDF}
+import org.apache.clerezza.rdf.utils.GraphNode;
+
+/**
+ * The classical Hello World root resource
+ */
+@Path("hello-world")
+class HelloWorld {
+       @GET def get() = {
+               val resultMGraph = new SimpleMGraph();
+               val graphNode = new GraphNode(new BNode(), resultMGraph);
+               graphNode.addProperty(RDF.`type` , 
Ontology.HelloWordMessageType);
+               graphNode.addPropertyValue(DC.description,"Hello world");
+               graphNode;
+
+       }
+}

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorldMessageRenderlet.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorldMessageRenderlet.scala?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorldMessageRenderlet.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/HelloWorldMessageRenderlet.scala
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,34 @@
+package skeleton
+
+import javax.ws.rs.core.MediaType
+import org.apache.clerezza.platform.typerendering._
+import org.apache.clerezza.rdf.core.UriRef
+import org.apache.clerezza.rdf.utils.GraphNode
+import org.apache.clerezza.rdf.ontologies._
+import org.apache.clerezza.rdf.core._
+import org.apache.clerezza.rdf.utils._
+import org.apache.clerezza.rdf.scala.utils.Preamble._
+import org.apache.clerezza.platform.typerendering.scala._
+
+/**
+ * A Renderlet for HelloWorldMessage
+ */
+class HelloWorldMessageRenderlet extends SRenderlet {
+
+       val getRdfType = Ontology.HelloWordMessageType
+
+       override def getModePattern = "naked"
+
+       override def renderedPage(arguments: XmlResult.Arguments) = {
+               new XmlResult(arguments) {
+                       override def content = {
+                               
resultDocModifier.addStyleSheet("/styles/hello-world/style.css")
+                               <div xmlns="http://www.w3.org/1999/xhtml"; 
id="tx-content">
+                                       <h2>A Message</h2>
+                                       <div class="message">foo!</div>
+                               </div>
+                       }
+               }
+       }
+
+}

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Ontology.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Ontology.scala?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Ontology.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/resources/org/apache/clerezza/bundledevtool/skeletons/scala_with_activator/src/main/scala/Ontology.scala
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,12 @@
+package skeleton
+
+import org.apache.clerezza.rdf.core.UriRef
+
+object Ontology {
+
+       /**
+        * The uri for the RDF type of HelloWordMessage
+        */
+       val HelloWordMessageType = new 
UriRef("http://example.org/skeleton#HelloWordMessage";)
+
+}

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/BundleRoot.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/BundleRoot.scala?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/BundleRoot.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/BundleRoot.scala
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,303 @@
+/*
+ * 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.bundledevtool
+
+
+import scala.actors.DaemonActor
+import scala.io._
+import org.osgi.framework.Bundle
+import org.osgi.framework.BundleContext
+import sbt._
+import scala.actors.Actor
+import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles._
+import org.ops4j.pax.swissbox.tinybundles.core.TinyBundle
+import org.apache.clerezza.scala.scripting.CompilerService
+import org.osgi.framework.Constants
+import org.osgi.service.component.ComponentContext
+import org.slf4j.LoggerFactory
+import scala.collection.mutable
+import org.osgi.service.packageadmin.PackageAdmin
+import tools.nsc.io.{AbstractFile, VirtualDirectory}
+import java.io.{File, FileInputStream, ByteArrayInputStream}
+import org.apache.clerezza.utils.osgi.BundlePathNode
+import org.wymiwyg.commons.util.dirbrowser.PathNode
+
+/**
+ * Provides a service that allows to register directories containing a 
maven-style project
+ * structure to be registered as SourceBundle which is added as OSGi Bundle 
and regenerated
+ * whenever a file is changed.
+ *
+ * Currently only scala files are compiled.
+ */
+class BundleRoot {
+
+       private var compilerService: CompilerService = null
+       private var packageAdmin: PackageAdmin = null
+
+       private var bundleContext: BundleContext = null
+
+       private val skeletonsPath = 
"org/apache/clerezza/bundledevtool/skeletons"
+
+       val sourceBundles = mutable.ListBuffer[SourceBundle]()
+
+       protected def activate(c: ComponentContext) {
+               this.bundleContext = c.getBundleContext
+               sourceBundles.clear()
+               for (bundle <- bundleContext.getBundles) {
+                       val location = bundle.getLocation
+                       if 
(location.startsWith(BundleRoot.sourceBundleUriPrefix)) {
+                               val dir = new File(location.substring(
+                                               
BundleRoot.sourceBundleUriPrefix.length))
+                               val sourceBundle = new SourceBundle(dir, bundle)
+                               sourceBundle.start()
+                               sourceBundles += sourceBundle
+                       }
+               }
+       }
+
+       protected def deactivate(c: ComponentContext) {
+               for (sb <- sourceBundles) sb.stop()
+       }
+
+       /**
+        * adds a SourceBundle for the sources in the specified dir
+        */
+       def addSourceBundle(dir: File) = {
+               val sourceBundle = new SourceBundle(dir)
+               sourceBundle.start()
+               sourceBundles += sourceBundle
+               sourceBundle
+       }
+
+       @deprecated
+       def createSourceBundle(dir: File) = addSourceBundle(dir)
+
+       /**
+       * list of the available skletons
+       */
+       def availableSkeletons: Seq[Symbol] = {
+               val skeletonsNode = new BundlePathNode(bundleContext.getBundle, 
skeletonsPath)
+               for (name <- skeletonsNode.list) yield {
+                       Symbol(name.substring(1,name.length-1))
+               }
+       }
+
+       /**
+        * Creates and adds a new SourceBundle from a skeleton, no existing 
file is
+        * replaced
+        */
+       def createSourceBundle(skeleton: Symbol, dir: File) = {
+               dir.mkdirs
+               val skeletonsNode = new BundlePathNode(bundleContext.getBundle, 
skeletonsPath)
+               val skeletonNode = skeletonsNode.getSubPath(skeleton.name)
+               if (!skeletonNode.exists) {
+                       throw new UnavailableSkeletonException(skeleton, 
availableSkeletons)
+               }
+               def processFile(p: PathNode, f: File) {
+                       if (!f.exists) {
+                               val in = 
scala.io.Source.fromInputStream(p.getInputStream)
+                               val out = new java.io.PrintWriter(f)
+                               try { in.getLines().foreach(out.println(_)) }
+                               finally { out.close }
+                       }
+               }
+               def processDir(p: PathNode, f: File) {
+                       f.mkdir()
+                       for (subPathString <- p.list()) {
+                               val subPathNode: PathNode = 
p.getSubPath(subPathString)
+                               val subFile: File = new File(f, subPathString)
+                               if (subPathNode.isDirectory) {
+                                       processDir(subPathNode, subFile)
+                               } else {
+                                       processFile(subPathNode, subFile)
+                               }
+                       }
+               }
+
+               processDir(skeletonNode, dir)
+               addSourceBundle(dir)
+       }
+
+       def bindCompilerService(cs: CompilerService) {
+               compilerService = cs;
+       }
+
+       def unbindCompilerService(cs: CompilerService) {
+               compilerService = null;
+       }
+
+       def bindPackageAdmin(pa: PackageAdmin) {
+               packageAdmin = pa
+       }
+
+       def unbindPackageAdmin(pa: PackageAdmin) {
+               packageAdmin = null
+       }
+
+       class SourceBundle(dir: File, existingBundle: Bundle) extends 
DaemonActor {
+
+               def this(dir: File) {
+                       this(dir, null)
+               }
+
+               var stopped = false
+               var logger = LoggerFactory.getLogger(classOf[SourceBundle])
+
+               val sourcePath = Path.fromFile(dir)
+               var watchState = WatchState.empty
+               var bundle: Bundle = existingBundle
+
+               def getFilesAsCharArrays(file: File): List[Array[Char]] = {
+                       logger.debug("getting sources in "+file)
+                       var result: List[Array[Char]] = Nil
+                       if (file.isDirectory) {
+                               val children = file.listFiles
+                               import scala.collection.JavaConversions._
+                               for(child <- children) {
+                                       if (!child.getName.startsWith(".")) {
+                                               result = 
getFilesAsCharArrays(child) ::: result
+                                       }
+                               }
+                       } else {
+                               if (file.getName.endsWith(".scala")) {
+                                       val in = Source.fromFile(file, "utf-8")
+                                       val stream = in.toStream
+                                       result = stream.toArray :: result
+                               } 
+                       }
+                       result
+               }
+
+               private[this] def updateBundle() {
+                       logger.info("updating source bundle with root "+dir)
+
+                       val tinyBundle: TinyBundle = newBundle()
+
+                       def compileDir(sourceDir: File): Option[String] = {
+
+                               val charArrays = getFilesAsCharArrays(sourceDir)
+                               logger.debug("compiling "+charArrays.size+" 
files")
+
+                               val vdPathPrefix = "(memory)"
+                               val virtualDirectory = new 
VirtualDirectory(vdPathPrefix, None)
+                               //val wrappedDirectory = 
VirtualDirectoryWrapper.wrap(virtualDirectory, outputListener)
+
+                               val writtenClasses = 
compilerService.compileToDir(charArrays, virtualDirectory)
+                               logger.debug("virtualDirectory 
"+virtualDirectory.size)
+                               var potentialActivator: Option[String] = None
+                               for (writtenClass <- writtenClasses) {
+                                       val fullPath = writtenClass.path
+                                       val path = 
fullPath.substring(vdPathPrefix.length+1)
+                                       if (path.endsWith("Activator.class")) {
+                                               potentialActivator = 
Some(path.substring(0, path.lastIndexOf('.')).replace('/', '.'))
+                                       }
+                                       tinyBundle.add(path, new 
ByteArrayInputStream(writtenClass.toByteArray))
+                               }
+                   potentialActivator
+                       }
+
+                       def copyResource(resourcesDir: File) {
+                               def copyResource(resourcesDir: File, prefix: 
String) {
+                                       val children = resourcesDir.listFiles
+                                       import 
scala.collection.JavaConversions._
+                                       for(child <- children) {
+                                               val childName = child.getName
+                                               if (!childName.startsWith(".")) 
{
+                                                       if (child.isDirectory) {
+                                                               
copyResource(child, prefix+childName+"/")
+                                                       } else {
+                                                               
tinyBundle.add(prefix+childName, new FileInputStream(child))
+                                                       }
+                                               }
+                                       }
+                               }
+                               copyResource(resourcesDir, "")
+                       }
+
+                       val symName = 
dir.getPath.substring(1).replace(File.separatorChar, '.')
+
+                       tinyBundle.set("Bundle-SymbolicName", symName)
+
+                       val scalaSourceDir = new File(dir, "src/main/scala")
+
+                       val potentialActivator = if (scalaSourceDir.exists) {
+                               compileDir(scalaSourceDir)
+                       } else {
+                               logger.debug("No source dir "+scalaSourceDir)
+                               None
+                       }
+                       val resourcesDir = new File(dir, "src/main/resources")
+                       if (resourcesDir.exists) {
+                               copyResource(resourcesDir)
+                       } else {
+                               logger.debug("No resources dir "+resourcesDir)
+                       }
+                       val serviceComponentsFile = new File(resourcesDir, 
"OSGI-INF/serviceComponents.xml")
+                       if (serviceComponentsFile.exists) {
+                               tinyBundle.set("Service-Component", 
"OSGI-INF/serviceComponents.xml")
+                               tinyBundle.set(Constants.EXPORT_PACKAGE, 
"!OSGI-INF, *" )
+                       }
+                       potentialActivator match {
+                               case Some(s) =>  
tinyBundle.set("Bundle-Activator", s)
+                               case _ => ;
+                       }
+                       tinyBundle.set(Constants.IMPORT_PACKAGE, "*" );
+                       val in = tinyBundle.build(
+                                       withBnd()
+                               )
+
+
+                       if (bundle == null) {
+                               bundle = 
bundleContext.installBundle(BundleRoot.sourceBundleUriPrefix+dir.toString, in)
+                               bundle.start()
+                       } else {
+                               bundle.update(in)
+                       }
+
+               }
+
+               def act() {
+                       while (!stopped) {
+                               logger.debug("wathcing "+dir)
+                               val (triggered, newWatchState) =
+                                       
SourceModificationWatch.watch(sourcePath**(-HiddenFileFilter), 1, 
watchState)(stopped)
+                               if (!stopped) {
+                                       try {
+                                               updateBundle()
+                                       } catch {
+                                               case e => 
logger.warn("Exception compiling", e)
+                                       }
+                                       watchState = newWatchState
+                               }
+                       }
+               }
+
+               def stop() {
+                       stopped = true
+               }
+       }
+}
+
+
+object BundleRoot {
+
+       val sourceBundleUriPrefix = "bundledevtool:"
+
+}

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevDsl.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevDsl.scala?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevDsl.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevDsl.scala
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,60 @@
+/*
+ * 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.bundledevtool
+
+import java.io.File
+import java.io.OutputStream
+import java.io.OutputStreamWriter
+import java.io.PrintWriter
+import org.osgi.framework.BundleContext
+import org.apache.clerezza.osgi.services.ServicesDsl
+
+class DevDsl(outputStream: OutputStream, bundleContext: BundleContext) {
+
+       object Dev {
+               private val serviceDsl = new ServicesDsl(bundleContext)
+               import serviceDsl._
+               private lazy val out = new PrintWriter(new 
OutputStreamWriter(outputStream, "utf-8"), true)
+               
+               def create(skeleton: Symbol) = new Object() {
+                       def in(location: String): Unit = try {
+                               $[BundleRoot].createSourceBundle(skeleton, new 
File(location))
+                       } catch {
+                               case u: UnavailableSkeletonException => {
+                                       out println "FAILURE: no skeleton 
"+skeleton+" is available"
+                                       out println "The following skeletons 
are available"
+                                       for (a <- u.available) {
+                                               out println "  - "+a
+                                       }
+                               }
+                       }
+               }
+
+               def load(location: String) {
+                       val dir = new File(location)
+                       if (!dir.isDirectory) {
+                               out println "No directory "+location+" found"
+                       } else {
+                               $[BundleRoot].addSourceBundle(dir)
+                       }
+               }
+       }
+
+}

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevShellCustomizer.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevShellCustomizer.scala?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevShellCustomizer.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/DevShellCustomizer.scala
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,30 @@
+/*
+ * 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.bundledevtool
+
+import org.apache.clerezza.shell.Shell
+import org.apache.clerezza.shell.ShellCustomizer
+
+class DevShellCustomizer extends ShellCustomizer {
+       def bindings(e: Shell.Environment): List[(String, String, Any)] = {
+               List(("devDsl", classOf[DevDsl].getName, new DevDsl(e.out,
+                                               
e.componentContext.getBundleContext)))
+       }
+       def imports: List[String] = List("devDsl._")
+}

Added: 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/UnavailableSkeletonException.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/UnavailableSkeletonException.scala?rev=1083553&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/UnavailableSkeletonException.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/bundledevtool/src/main/scala/org/apache/clerezza/bundledevtool/UnavailableSkeletonException.scala
 Sun Mar 20 20:01:28 2011
@@ -0,0 +1,25 @@
+/*
+ * 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.bundledevtool
+
+class UnavailableSkeletonException(val requested: Symbol, val available: 
Seq[Symbol])
+       extends RuntimeException("The Skeleton "+requested.name+" is not 
avialble") {
+
+}

Modified: 
incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml?rev=1083553&r1=1083552&r2=1083553&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml 
(original)
+++ 
incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml 
Sun Mar 20 20:01:28 2011
@@ -327,7 +327,7 @@
                </dependency>
                <dependency>
                        <groupId>org.apache.clerezza</groupId>
-                       <artifactId>sourcebundle</artifactId>
+                       <artifactId>bundledevtool</artifactId>
                        <scope>runtime</scope>
                </dependency>
                <dependency>

Modified: incubator/clerezza/trunk/parent/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/pom.xml?rev=1083553&r1=1083552&r2=1083553&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/pom.xml (original)
+++ incubator/clerezza/trunk/parent/pom.xml Sun Mar 20 20:01:28 2011
@@ -107,7 +107,7 @@
                                <module>rdf.web.proxy</module>
                                <module>shell</module>
                                <module>shell.felixshellcommand</module>
-                               <module>sourcebundle</module>
+                               <module>bundledevtool</module>
                                <module>sshshell</module>
                                <module>templating</module>
                                <module>templating.seedsnipe</module>
@@ -1179,7 +1179,7 @@
                        </dependency>
                        <dependency>
                                <groupId>org.apache.clerezza</groupId>
-                               <artifactId>sourcebundle</artifactId>
+                               <artifactId>bundledevtool</artifactId>
                                <version>0.1-incubating-SNAPSHOT</version>
                        </dependency>
                        <dependency>


Reply via email to