Author: dspicar
Date: Wed Jan 18 11:09:13 2012
New Revision: 1232832

URL: http://svn.apache.org/viewvc?rev=1232832&view=rev
Log:
CLEREZZA-617: cleaned up issue code, adapted compile interface for compiling 
with and without bundlecontext in a scala friendly way.

Modified:
    
incubator/clerezza/issues/CLEREZZA-617/platform.typerendering.scalaserverpages/src/main/java/org/apache/clerezza/platform/typerendering/scalaserverpages/SspTypeRenderlet.java
    
incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala
    
incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala

Modified: 
incubator/clerezza/issues/CLEREZZA-617/platform.typerendering.scalaserverpages/src/main/java/org/apache/clerezza/platform/typerendering/scalaserverpages/SspTypeRenderlet.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-617/platform.typerendering.scalaserverpages/src/main/java/org/apache/clerezza/platform/typerendering/scalaserverpages/SspTypeRenderlet.java?rev=1232832&r1=1232831&r2=1232832&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-617/platform.typerendering.scalaserverpages/src/main/java/org/apache/clerezza/platform/typerendering/scalaserverpages/SspTypeRenderlet.java
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-617/platform.typerendering.scalaserverpages/src/main/java/org/apache/clerezza/platform/typerendering/scalaserverpages/SspTypeRenderlet.java
 Wed Jan 18 11:09:13 2012
@@ -18,7 +18,6 @@
  */
 package org.apache.clerezza.platform.typerendering.scalaserverpages;
 
-import java.util.logging.Level;
 import org.apache.clerezza.platform.typerendering.CallbackRenderer;
 import org.apache.clerezza.platform.typerendering.TypeRenderlet;
 import org.apache.clerezza.rdf.core.UriRef;

Modified: 
incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala?rev=1232832&r1=1232831&r2=1232832&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/CompilerService.scala
 Wed Jan 18 11:09:13 2012
@@ -21,12 +21,8 @@ package org.apache.clerezza.scala.script
 
 import java.security.AccessController
 import java.security.Permission
-import java.security.PrivilegedAction
 import java.security.PrivilegedActionException
 import java.security.PrivilegedExceptionAction
-import org.apache.clerezza.scala.scripting.util.FileWrapper
-import org.apache.clerezza.scala.scripting.util.GenericFileWrapperTrait
-import org.apache.clerezza.scala.scripting.util.VirtualDirectoryWrapper
 import org.osgi.framework.BundleContext
 import org.osgi.framework.BundleEvent
 import org.osgi.framework.BundleListener
@@ -35,14 +31,11 @@ import scala.tools.nsc._;
 import scala.tools.nsc.interpreter._;
 import scala.tools.nsc.io.AbstractFile
 import scala.tools.nsc.io.VirtualDirectory
-import scala.tools.nsc.reporters.ConsoleReporter
 import scala.tools.nsc.util._
 import java.io.ByteArrayOutputStream
-import java.io.File
 import java.io.IOException
 import java.io.OutputStream
 import java.io.PrintWriter
-import java.io.Reader
 import java.net._
 
 class CompileErrorsException(message: String) extends Exception(message) {
@@ -106,38 +99,19 @@ class CompilerService() extends BundleLi
                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"))
-                                                               case e => throw 
e
-                                                       } finally {
-                                                               
currentSharedCompilerOutputStream = null
-                                                       }
-                                               }
-                                       })
-                       } catch {
-                               case e: PrivilegedActionException => throw 
e.getCause
-                               case e => throw e
-                       }
-               }
-       }
-       
+       /**
+        * Compiles an array of class sources returning an array of compiled 
classes.
+        * Uses the ClassLoader of the supplied BundleContext's bundle.'
+        */
        def compile(sources: Array[Array[Char]], registratorContext: 
BundleContext): Array[Class[_]] = {
                compile(sources.toList, registratorContext).toArray
        }
        
-       def compile(sources: List[Array[Char]], registratorContext: 
BundleContext): List[Class[_]] = {
+       /**
+        * Compiles a list of class sources returning a list of compiled 
classes.
+        * Uses the ClassLoader of the supplied BundleContext's bundle.'
+        */
+       def compile(sources: List[Array[Char]], registratorContext: 
BundleContext = null): List[Class[_]] = {
                AccessController.checkPermission(new CompilePermission)
                sharedCompiler.synchronized {
                        try {
@@ -147,7 +121,11 @@ class CompilerService() extends BundleLi
                                                        val baos = new 
ByteArrayOutputStream
                                                        
currentSharedCompilerOutputStream = baos
                                                        try {
-                                                               
sharedCompiler.compile(sources, registratorContext)
+                                                               var context: 
Option[BundleContext] = None;
+                                                               
if(registratorContext != null) {
+                                                                 context = 
Some(registratorContext)
+                                                               }
+                                                               
sharedCompiler.compile(sources, context)
                                                        } catch {
                                                                case c: 
CompileErrorsException => throw new CompileErrorsException(
                                                                                
new String(baos.toByteArray, "utf-8"))

Modified: 
incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala?rev=1232832&r1=1232831&r2=1232832&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-617/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/scripting/TrackingCompiler.scala
 Wed Jan 18 11:09:13 2012
@@ -20,11 +20,8 @@
 package org.apache.clerezza.scala.scripting
 
 
-import org.apache.clerezza.scala.scripting.util.FileWrapper
-import org.apache.clerezza.scala.scripting.util.GenericFileWrapperTrait
 import org.apache.clerezza.scala.scripting.util.SplittingDirectory
 import org.apache.clerezza.scala.scripting.util.VirtualDirectoryWrapper
-import org.apache.felix.framework.BundleImpl
 import org.osgi.framework.Bundle
 import org.osgi.framework.BundleContext
 import scala.collection.mutable
@@ -35,12 +32,10 @@ import scala.tools.nsc.io.VirtualDirecto
 import scala.tools.nsc.reporters.ConsoleReporter
 import scala.tools.nsc.reporters.Reporter
 import scala.tools.nsc.util._
-import java.io.ByteArrayOutputStream
 import java.io.PrintWriter
 import java.lang.reflect.Field
 import java.net._
 
-
 /** a compiler that keeps track of classes added to the directory
  */
 class TrackingCompiler private (bundleContext : BundleContext,
@@ -70,12 +65,17 @@ class TrackingCompiler private (bundleCo
        }
 
        /**
-        * compiles a list of class sources returning a list of compiled classes
+        * Compiles a list of class sources returning a list of compiled 
classes.
+        * Uses the ClassLoader of the supplied BundleContext's bundle, if 
supplied.
         */
        @throws(classOf[CompileErrorsException])
-       def compile(sources: List[Array[Char]]): List[Class[_]] = {
+       def compile(sources: List[Array[Char]], registratorContext: 
Option[BundleContext] = None): List[Class[_]] = {
                val classFiles = compileToDir(sources)
-               val classLoader = 
classLoaderBuilder(this.getClass.getClassLoader)
+               val classLoader = registratorContext match {
+                 case Some(x) => 
classLoaderBuilder(getBundleClassLoader(x.getBundle))
+                 case None => classLoaderBuilder(this.getClass.getClassLoader)
+               }
+               //println("ClassLoader: " + classLoader + " Parent: " + 
classLoader.getParent)
                val result: List[Class[_]] = for (classFile <- classFiles;
                                                                                
  if (!classFile.name.contains('$'))) yield {
                        val path = classFile.path
@@ -87,26 +87,10 @@ class TrackingCompiler private (bundleCo
        }
        
        /**
-        * compiles a list of class sources returning a list of compiled classes
+        * Return the a bundle's classloader.
+        *
+        * Hack to get the classloader from a bundle reference, is felix 
dependend
         */
-       @throws(classOf[CompileErrorsException])
-       def compile(sources: List[Array[Char]], registratorContext: 
BundleContext): List[Class[_]] = {
-               val classFiles = compileToDir(sources)
-               val classLoader = 
classLoaderBuilder(getBundleClassLoader(registratorContext.getBundle))
-               //val classLoader = 
classLoaderBuilder(this.getClass.getClassLoader)
-               //println("ClassLoader: " + classLoader + " Parent: " + 
classLoader.getParent + " PParent: " + classLoader.getParent.getParent)
-               println("ClassLoader: " + classLoader + " Parent: " + 
classLoader.getParent)
-               val result: List[Class[_]] = for (classFile <- classFiles;
-                                                                               
  if (!classFile.name.contains('$'))) yield {
-                       val path = classFile.path
-                       println("pop: " + classFile.path)
-                       val relevantPath = 
path.substring(path.indexOf('/')+1,path.lastIndexOf('.'))
-                       val fqn = relevantPath.replace("/",".")
-                       classLoader.loadClass(fqn)
-               }
-               return result
-       }
-       
     def getBundleClassLoader(bundle: Bundle): ClassLoader = {
          val modulesField: Field = 
bundle.getClass.getClassLoader.loadClass("org.apache.felix.framework.BundleImpl").getDeclaredField("m_modules")
          modulesField.setAccessible(true);
@@ -135,12 +119,10 @@ object TrackingCompiler {
 
        private class TrackingCompilerSplittingDirectory extends 
SplittingDirectory
 
-       //private def createClassLoader(dir: AbstractFile) = new 
AbstractFileClassLoader(dir, this.getClass.getClassLoader())
        private def createClassLoader(dir: AbstractFile, cl: ClassLoader) = new 
AbstractFileClassLoader(dir, cl)
 
        def apply(bundleContext : BundleContext, out: PrintWriter, 
outputDirectoryOption: Option[AbstractFile]) = {
                val (outputDirectory, classLoaderBuilder): (AbstractFile, 
(ClassLoader) => ClassLoader) = outputDirectoryOption match {
-                       //case Some(d) => (d, (_: ClassLoader) => 
createClassLoader(d, this.getClass.getClassLoader()))
                        case Some(d) => (d, (c: ClassLoader) => 
createClassLoader(d, c))
                        case None => {
                                        val d = new 
TrackingCompilerSplittingDirectory


Reply via email to