toree-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lbust...@apache.org
Subject [1/2] incubator-toree git commit: Converted magics to plugins
Date Tue, 29 Mar 2016 18:03:08 GMT
Repository: incubator-toree
Updated Branches:
  refs/heads/master 429c74c67 -> 9c8824fff


http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/main/scala/org/apache/toree/magic/builtin/AddDeps.scala
----------------------------------------------------------------------
diff --git a/kernel/src/main/scala/org/apache/toree/magic/builtin/AddDeps.scala b/kernel/src/main/scala/org/apache/toree/magic/builtin/AddDeps.scala
index c6771be..be36c8f 100644
--- a/kernel/src/main/scala/org/apache/toree/magic/builtin/AddDeps.scala
+++ b/kernel/src/main/scala/org/apache/toree/magic/builtin/AddDeps.scala
@@ -23,15 +23,15 @@ import java.net.URL
 import org.apache.toree.magic._
 import org.apache.toree.magic.dependencies._
 import org.apache.toree.utils.ArgumentParsingSupport
-
 import scala.util.Try
+import org.apache.toree.plugins.annotations.Event
 
 class AddDeps extends LineMagic with IncludeInterpreter
   with IncludeOutputStream with IncludeSparkContext with ArgumentParsingSupport
   with IncludeDependencyDownloader with IncludeKernel
 {
 
-  private lazy val printStream = new PrintStream(outputStream)
+  private def printStream = new PrintStream(outputStream)
 
   private val _transitive = parser.accepts(
     "transitive", "Retrieve dependencies recursively"
@@ -59,6 +59,7 @@ class AddDeps extends LineMagic with IncludeInterpreter
    * @param code The single line of code
    * @return The output of the magic
    */
+  @Event(name = "adddeps")
   override def execute(code: String): Unit = {
     val nonOptionArgs = parseArgs(code)
     dependencyDownloader.setPrintStream(printStream)

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/main/scala/org/apache/toree/magic/builtin/AddJar.scala
----------------------------------------------------------------------
diff --git a/kernel/src/main/scala/org/apache/toree/magic/builtin/AddJar.scala b/kernel/src/main/scala/org/apache/toree/magic/builtin/AddJar.scala
index 65abccc..125ee0a 100644
--- a/kernel/src/main/scala/org/apache/toree/magic/builtin/AddJar.scala
+++ b/kernel/src/main/scala/org/apache/toree/magic/builtin/AddJar.scala
@@ -26,6 +26,7 @@ import org.apache.toree.magic.builtin.AddJar._
 import org.apache.toree.magic.dependencies._
 import org.apache.toree.utils.{ArgumentParsingSupport, DownloadSupport, LogLike}
 import com.typesafe.config.Config
+import org.apache.toree.plugins.annotations.Event
 
 object AddJar {
 
@@ -47,7 +48,7 @@ object AddJar {
 class AddJar
   extends LineMagic with IncludeInterpreter with IncludeSparkContext
   with IncludeOutputStream with DownloadSupport with ArgumentParsingSupport
-  with IncludeKernel with IncludeMagicLoader with IncludeConfig with LogLike
+  with IncludeKernel with IncludePluginManager with IncludeConfig with LogLike
 {
   // Option to mark re-downloading of jars
   private val _force =
@@ -58,7 +59,7 @@ class AddJar
     parser.accepts("magic", "loads jar as a magic extension")
 
   // Lazy because the outputStream is not provided at construction
-  private lazy val printStream = new PrintStream(outputStream)
+  private def printStream = new PrintStream(outputStream)
 
   /**
    * Retrieves file name from URL.
@@ -82,6 +83,7 @@ class AddJar
    *
    * @param code The line containing the location of the jar
    */
+  @Event(name = "addjar")
   override def execute(code: String): Unit = {
     val nonOptionArgs = parseArgs(code.trim)
 
@@ -103,12 +105,14 @@ class AddJar
 
     // Ensure the URL actually contains a jar or zip file
     if (!jarName.endsWith(".jar") && !jarName.endsWith(".zip")) {
-        throw new IllegalArgumentException(s"The jar file $jarName must end in .jar or .zip.")
+        throw new IllegalArgumentException(
+          s"The jar file $jarName must end in .jar or .zip."
+        )
     }
 
     val downloadLocation = getJarDir(config) + "/" + jarName
 
-    logger.debug( "Downloading jar to %s".format(downloadLocation) )
+    logger.debug("Downloading jar to %s".format(downloadLocation))
 
     val fileDownloadLocation = new File(downloadLocation)
 
@@ -128,18 +132,12 @@ class AddJar
       printStream.println(s"Using cached version of $jarName")
     }
 
-
-    if (_magic)
-    {
-
-      magicLoader.addJar(fileDownloadLocation.toURI.toURL)
-
-    }
-    else
-    {
+    if (_magic) {
+      val plugins = pluginManager.loadPlugins(fileDownloadLocation)
+      pluginManager.initializePlugins(plugins)
+    } else {
       interpreter.addJars(fileDownloadLocation.toURI.toURL)
       sparkContext.addJar(fileDownloadLocation.getCanonicalPath)
-
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/main/scala/org/apache/toree/magic/builtin/Html.scala
----------------------------------------------------------------------
diff --git a/kernel/src/main/scala/org/apache/toree/magic/builtin/Html.scala b/kernel/src/main/scala/org/apache/toree/magic/builtin/Html.scala
index 8060a46..7975ce7 100644
--- a/kernel/src/main/scala/org/apache/toree/magic/builtin/Html.scala
+++ b/kernel/src/main/scala/org/apache/toree/magic/builtin/Html.scala
@@ -24,13 +24,15 @@ import org.apache.toree.magic._
 import org.apache.toree.magic.dependencies.IncludeOutputStream
 import org.apache.toree.utils.ArgumentParsingSupport
 import com.google.common.base.Strings
+import org.apache.toree.plugins.annotations.Event
 
 class Html extends CellMagic with ArgumentParsingSupport
   with IncludeOutputStream {
 
   // Lazy because the outputStream is not provided at construction
-  private lazy val printStream = new PrintStream(outputStream)
-
+  private def printStream = new PrintStream(outputStream)
+  
+  @Event(name = "html")
   override def execute(code: String): CellMagicOutput = {
     def printHelpAndReturn: CellMagicOutput = {
       printHelp(printStream, """%%Html <string_code>""")

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/main/scala/org/apache/toree/magic/builtin/JavaScript.scala
----------------------------------------------------------------------
diff --git a/kernel/src/main/scala/org/apache/toree/magic/builtin/JavaScript.scala b/kernel/src/main/scala/org/apache/toree/magic/builtin/JavaScript.scala
index a3bd585..f6b7dbf 100644
--- a/kernel/src/main/scala/org/apache/toree/magic/builtin/JavaScript.scala
+++ b/kernel/src/main/scala/org/apache/toree/magic/builtin/JavaScript.scala
@@ -25,13 +25,15 @@ import org.apache.toree.magic._
 import org.apache.toree.magic.dependencies.IncludeOutputStream
 import org.apache.toree.utils.ArgumentParsingSupport
 import org.slf4j.LoggerFactory
+import org.apache.toree.plugins.annotations.Event
 
 class JavaScript extends CellMagic with ArgumentParsingSupport
   with IncludeOutputStream {
 
   // Lazy because the outputStream is not provided at construction
-  private lazy val printStream = new PrintStream(outputStream)
-
+  private def printStream = new PrintStream(outputStream)
+  
+  @Event(name = "javascript")
   override def execute(code: String): CellMagicOutput = {
     def printHelpAndReturn: CellMagicOutput = {
       printHelp(printStream, """%JavaScript <string_code>""")

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/main/scala/org/apache/toree/magic/builtin/LSMagic.scala
----------------------------------------------------------------------
diff --git a/kernel/src/main/scala/org/apache/toree/magic/builtin/LSMagic.scala b/kernel/src/main/scala/org/apache/toree/magic/builtin/LSMagic.scala
index 260db25..48e5ad4 100644
--- a/kernel/src/main/scala/org/apache/toree/magic/builtin/LSMagic.scala
+++ b/kernel/src/main/scala/org/apache/toree/magic/builtin/LSMagic.scala
@@ -21,16 +21,18 @@ import java.io.PrintStream
 
 import org.apache.toree.magic._
 import org.apache.toree.magic.dependencies.IncludeOutputStream
+import org.apache.toree.plugins.annotations.Event
 
 class LSMagic extends LineMagic with IncludeOutputStream {
 
-  private lazy val printStream = new PrintStream(outputStream)
+  private def printStream = new PrintStream(outputStream)
 
   /**
    * Lists all available magics.
    * @param code The single line of code
    * @return The output of the magic
    */
+  @Event(name = "lsmagic")
   override def execute(code: String): Unit = {
     val classes = new BuiltinLoader().loadClasses().toList
     val lineMagics = magicNames("%", classOf[LineMagic], classes)

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/main/scala/org/apache/toree/magic/builtin/RDD.scala
----------------------------------------------------------------------
diff --git a/kernel/src/main/scala/org/apache/toree/magic/builtin/RDD.scala b/kernel/src/main/scala/org/apache/toree/magic/builtin/RDD.scala
index 32244d0..b165ac8 100644
--- a/kernel/src/main/scala/org/apache/toree/magic/builtin/RDD.scala
+++ b/kernel/src/main/scala/org/apache/toree/magic/builtin/RDD.scala
@@ -24,6 +24,7 @@ import org.apache.toree.magic.dependencies.{IncludeKernelInterpreter, IncludeInt
 import org.apache.toree.utils.LogLike
 import org.apache.toree.utils.json.RddToJson
 import org.apache.spark.sql.SchemaRDD
+import org.apache.toree.plugins.annotations.Event
 
 /**
  * Temporary magic to show an RDD as JSON
@@ -57,6 +58,7 @@ class RDD extends CellMagic with IncludeKernelInterpreter with LogLike {
     }
   }
 
+  @Event(name = "rdd")
   override def execute(code: String): CellMagicOutput =
     convertToJson(code)
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/main/scala/org/apache/toree/magic/builtin/ShowTypes.scala
----------------------------------------------------------------------
diff --git a/kernel/src/main/scala/org/apache/toree/magic/builtin/ShowTypes.scala b/kernel/src/main/scala/org/apache/toree/magic/builtin/ShowTypes.scala
index 62cfb3a..fb9e4c9 100644
--- a/kernel/src/main/scala/org/apache/toree/magic/builtin/ShowTypes.scala
+++ b/kernel/src/main/scala/org/apache/toree/magic/builtin/ShowTypes.scala
@@ -20,11 +20,13 @@ import org.apache.toree.magic.LineMagic
 import org.apache.toree.magic.dependencies.IncludeOutputStream
 import java.io.PrintStream
 import org.apache.toree.kernel.api.KernelOptions
+import org.apache.toree.plugins.annotations.Event
 
 
 class ShowTypes extends LineMagic with IncludeOutputStream {
-  private lazy val printStream = new PrintStream(outputStream)
+  private def printStream = new PrintStream(outputStream)
 
+  @Event(name = "showtypes")
   override def execute(code: String): Unit = {
     code match {
       case "on" =>

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/main/scala/org/apache/toree/magic/builtin/Truncation.scala
----------------------------------------------------------------------
diff --git a/kernel/src/main/scala/org/apache/toree/magic/builtin/Truncation.scala b/kernel/src/main/scala/org/apache/toree/magic/builtin/Truncation.scala
index 0443199..1a07827 100644
--- a/kernel/src/main/scala/org/apache/toree/magic/builtin/Truncation.scala
+++ b/kernel/src/main/scala/org/apache/toree/magic/builtin/Truncation.scala
@@ -20,11 +20,13 @@ import org.apache.toree.magic.LineMagic
 import org.apache.toree.magic.dependencies.IncludeOutputStream
 import java.io.PrintStream
 import org.apache.toree.kernel.api.KernelOptions
+import org.apache.toree.plugins.annotations.Event
 
 
 class Truncation extends LineMagic with IncludeOutputStream {
-  private lazy val printStream = new PrintStream(outputStream)
+  private def printStream = new PrintStream(outputStream)
 
+  @Event(name = "truncation")
   override def execute(code: String): Unit = {
     code match {
       case "on" =>

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/test/scala/org/apache/toree/kernel/api/KernelSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/org/apache/toree/kernel/api/KernelSpec.scala b/kernel/src/test/scala/org/apache/toree/kernel/api/KernelSpec.scala
index 0118cec..f8ae1eb 100644
--- a/kernel/src/test/scala/org/apache/toree/kernel/api/KernelSpec.scala
+++ b/kernel/src/test/scala/org/apache/toree/kernel/api/KernelSpec.scala
@@ -19,19 +19,18 @@ package org.apache.toree.kernel.api
 
 import java.io.{InputStream, PrintStream}
 
+import com.typesafe.config.Config
+import org.apache.spark.{SparkConf, SparkContext}
 import org.apache.toree.boot.layer.InterpreterManager
 import org.apache.toree.comm.CommManager
+import org.apache.toree.global.ExecuteRequestState
 import org.apache.toree.interpreter._
 import org.apache.toree.kernel.protocol.v5._
 import org.apache.toree.kernel.protocol.v5.kernel.ActorLoader
-import org.apache.toree.magic.MagicLoader
-import com.typesafe.config.Config
-import org.apache.spark.{SparkConf, SparkContext}
+import org.apache.toree.plugins.PluginManager
 import org.mockito.Mockito._
-import org.mockito.Matchers._
 import org.scalatest.mock.MockitoSugar
 import org.scalatest.{BeforeAndAfter, FunSpec, Matchers}
-import org.apache.toree.global.ExecuteRequestState
 
 class KernelSpec extends FunSpec with Matchers with MockitoSugar
   with BeforeAndAfter
@@ -50,7 +49,7 @@ class KernelSpec extends FunSpec with Matchers with MockitoSugar
   private var mockInterpreter: Interpreter = _
   private var mockInterpreterManager: InterpreterManager = _
   private var mockCommManager: CommManager = _
-  private var mockMagicLoader: MagicLoader = _
+  private var mockPluginManager: PluginManager = _
   private var kernel: Kernel = _
   private var spyKernel: Kernel = _
 
@@ -60,6 +59,7 @@ class KernelSpec extends FunSpec with Matchers with MockitoSugar
     mockInterpreterManager = mock[InterpreterManager]
     mockSparkContext = mock[SparkContext]
     mockSparkConf = mock[SparkConf]
+    mockPluginManager = mock[PluginManager]
     when(mockInterpreterManager.defaultInterpreter)
       .thenReturn(Some(mockInterpreter))
     when(mockInterpreterManager.interpreters)
@@ -74,11 +74,10 @@ class KernelSpec extends FunSpec with Matchers with MockitoSugar
 
     mockCommManager = mock[CommManager]
     mockActorLoader = mock[ActorLoader]
-    mockMagicLoader = mock[MagicLoader]
 
     kernel = new Kernel(
       mockConfig, mockActorLoader, mockInterpreterManager, mockCommManager,
-      mockMagicLoader
+      mockPluginManager
     )
 
     spyKernel = spy(kernel)

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/magic/MagicParserSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/magic/MagicParserSpec.scala b/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/magic/MagicParserSpec.scala
index 705161e..86d320c 100644
--- a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/magic/MagicParserSpec.scala
+++ b/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/magic/MagicParserSpec.scala
@@ -17,7 +17,7 @@
 
 package org.apache.toree.kernel.protocol.v5.magic
 
-import org.apache.toree.magic.MagicLoader
+import org.apache.toree.magic.{CellMagic, Magic, MagicManager}
 import org.scalatest.mock.MockitoSugar
 import org.scalatest.{FunSpec, Matchers}
 import org.mockito.Mockito._
@@ -32,14 +32,14 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
           |foo
           |bean
         """.stripMargin
-      val parser = spy(new MagicParser(mock[MagicLoader]))
+      val parser = spy(new MagicParser(mock[MagicManager]))
       parser.parse(codeBlob)
       verify(parser).parseCell(codeBlob.trim)
     }
 
     it("should call parseLines if the code is not a cell magic") {
       val codeBlob = """%magic foo bean"""
-      val parser = spy(new MagicParser(mock[MagicLoader]))
+      val parser = spy(new MagicParser(mock[MagicManager]))
       parser.parse(codeBlob)
       verify(parser).parseLines(codeBlob.trim)
     }
@@ -47,8 +47,10 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
 
   describe("#parseCell") {
     it("should substitute the magic code for kernel code when magic is valid") {
-      val magicLoader = mock[MagicLoader]
-      doReturn(true).when(magicLoader).hasCellMagic(anyString())
+      val magicManager = mock[MagicManager]
+      val mockMagic = mock[Magic]
+      doReturn(mockMagic).when(magicManager).findMagic(anyString())
+      doReturn(true).when(magicManager).isCellMagic(mockMagic)
 
       val magicName = "magic"
       val args = "foo\nbean\nbar"
@@ -56,7 +58,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
         s"""%%$magicName
            |$args
          """.stripMargin
-      val parser = spy(new MagicParser(magicLoader))
+      val parser = spy(new MagicParser(magicManager))
       val result = parser.parseCell(codeBlob)
 
       verify(parser).substitute(magicName, args)
@@ -64,8 +66,10 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
     }
 
     it("should return an error if the magic invocation is invalid") {
-      val magicLoader = mock[MagicLoader]
-      doReturn(false).when(magicLoader).hasCellMagic(anyString())
+      val magicManager = mock[MagicManager]
+      val mockMagic = mock[Magic]
+      doReturn(mockMagic).when(magicManager).findMagic(anyString())
+      doReturn(false).when(magicManager).isCellMagic(mockMagic)
 
       val magicName = "magic"
       val args = "foo\nbean\nbar"
@@ -73,7 +77,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
         s"""%%$magicName
            |$args
          """.stripMargin
-      val parser = spy(new MagicParser(magicLoader))
+      val parser = spy(new MagicParser(magicManager))
       val result = parser.parseCell(codeBlob)
 
       verify(parser, times(0)).substitute(anyString(), anyString())
@@ -81,14 +85,16 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
     }
 
     it("should return original code if code contains no magic invocations") {
-      val magicLoader = mock[MagicLoader]
-      doReturn(false).when(magicLoader).hasCellMagic(anyString())
+      val magicManager = mock[MagicManager]
+      val mockMagic = mock[Magic]
+      doReturn(mockMagic).when(magicManager).findMagic(anyString())
+      doReturn(false).when(magicManager).isCellMagic(mockMagic)
 
       val codeBlob =
         s"""val x = 3
            |println(x + 2)
          """.stripMargin
-      val parser = spy(new MagicParser(magicLoader))
+      val parser = spy(new MagicParser(magicManager))
       val result = parser.parseCell(codeBlob)
 
       verify(parser, times(0)).substitute(anyString(), anyString())
@@ -100,14 +106,16 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
   describe("#parseLines") {
     it("should call substituteLine for each line of code " +
       "when there are no invalid magic invocations") {
-      val magicLoader = mock[MagicLoader]
-      doReturn(true).when(magicLoader).hasLineMagic(anyString())
+      val magicManager = mock[MagicManager]
+      val mockMagic = mock[Magic]
+      doReturn(mockMagic).when(magicManager).findMagic(anyString())
+      doReturn(true).when(magicManager).isLineMagic(mockMagic)
 
       val codeBlob =
         s"""val x = 3
            |%lineMagic
          """.stripMargin
-      val parser = spy(new MagicParser(magicLoader))
+      val parser = spy(new MagicParser(magicManager))
       val result = parser.parseLines(codeBlob)
 
       verify(parser, times(2)).substituteLine(anyString())
@@ -115,14 +123,16 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
     }
 
     it("should return an error when there are invalid magic invocations") {
-      val magicLoader = mock[MagicLoader]
-      doReturn(false).when(magicLoader).hasLineMagic(anyString())
+      val magicManager = mock[MagicManager]
+      val mockMagic = mock[Magic]
+      doReturn(mockMagic).when(magicManager).findMagic(anyString())
+      doReturn(false).when(magicManager).isLineMagic(mockMagic)
 
       val codeBlob =
         s"""val x = 3
            |%lineMagic
          """.stripMargin
-      val parser = spy(new MagicParser(magicLoader))
+      val parser = spy(new MagicParser(magicManager))
       val result = parser.parseLines(codeBlob)
 
       verify(parser, times(0)).substituteLine(anyString())
@@ -130,14 +140,16 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
     }
 
     it("should return original code when there are no magic invocations") {
-      val magicLoader = mock[MagicLoader]
-      doReturn(false).when(magicLoader).hasLineMagic(anyString())
+      val magicManager = mock[MagicManager]
+      val mockMagic = mock[Magic]
+      doReturn(mockMagic).when(magicManager).findMagic(anyString())
+      doReturn(false).when(magicManager).isLineMagic(mockMagic)
 
       val codeBlob =
         s"""val x = 3
            |val y = x + 2
          """.stripMargin
-      val parser = spy(new MagicParser(magicLoader))
+      val parser = spy(new MagicParser(magicManager))
       val result = parser.parseLines(codeBlob.trim)
 
       result.isLeft should be(true)
@@ -150,7 +162,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
       val magicName = "foobar"
       val magicArgs = "baz\nbean"
       val codeBlob = s"""%%$magicName\n$magicArgs"""
-      val parser = new MagicParser(mock[MagicLoader])
+      val parser = new MagicParser(mock[MagicManager])
       parser.parseMagic(codeBlob) should be(Some((magicName, magicArgs)))
     }
 
@@ -158,7 +170,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
       val magicName = "foobar"
       val magicArgs = "baz\nbean"
       val codeBlob = s"""%$magicName $magicArgs"""
-      val parser = new MagicParser(mock[MagicLoader])
+      val parser = new MagicParser(mock[MagicManager])
       parser.parseMagic(codeBlob) should be(Some((magicName, magicArgs)))
     }
 
@@ -166,7 +178,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
       val magicName = "foobar"
       val magicArgs = "baz\nbean"
       val codeBlob = s"""$magicName\n$magicArgs"""
-      val parser = new MagicParser(mock[MagicLoader])
+      val parser = new MagicParser(mock[MagicManager])
       parser.parseMagic(codeBlob) should be(None)
     }
   }
@@ -176,7 +188,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
       val magicName = "magic"
       val args = "-v foo bar"
       val codeLine = s"""%$magicName $args"""
-      val parser = spy(new MagicParser(mock[MagicLoader]))
+      val parser = spy(new MagicParser(mock[MagicManager]))
       doReturn(true).when(parser).isValidLineMagic(anyString())
       parser.substituteLine(codeLine)
       verify(parser).substitute(magicName, args)
@@ -185,7 +197,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
     it("should return original line of code when it's not a valid +" +
       "magic invocation") {
       val codeLine = """val x = 3"""
-      val parser = spy(new MagicParser(mock[MagicLoader]))
+      val parser = spy(new MagicParser(mock[MagicManager]))
       doReturn(false).when(parser).isValidLineMagic(anyString())
       parser.substituteLine(codeLine) should be(codeLine)
     }
@@ -196,7 +208,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
     it("should replace a magic invocation with an equivalent kernel call") {
       val magicName = "magic"
       val args = "foo bean"
-      val parser = new MagicParser(mock[MagicLoader])
+      val parser = new MagicParser(mock[MagicManager])
 
       val equivalent =
         s"""${parser.kernelObjectName}.$magicName(\"\"\"$args\"\"\")"""
@@ -213,7 +225,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
           |%$magicOne bar baz
           |%$magicTwo quo bean
         """.stripMargin
-      val parser = spy(new MagicParser(mock[MagicLoader]))
+      val parser = spy(new MagicParser(mock[MagicManager]))
       doReturn(false).when(parser).isValidLineMagic(anyString())
 
       parser.parseOutInvalidMagics(codeBlob) should be(List(magicOne, magicTwo))
@@ -227,7 +239,7 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
           |%$magicOne bar baz
           |%$magicTwo quo bean
         """.stripMargin
-      val parser = spy(new MagicParser(mock[MagicLoader]))
+      val parser = spy(new MagicParser(mock[MagicManager]))
       doReturn(true).when(parser).isValidLineMagic(anyString())
 
       parser.parseOutInvalidMagics(codeBlob) should be(Nil)
@@ -236,18 +248,22 @@ class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
 
   describe("#isValidLineMagic") {
     it("should return true if the line magic invocation is valid") {
-      val magicLoader = mock[MagicLoader]
-      doReturn(true).when(magicLoader).hasLineMagic(anyString())
+      val magicManager = mock[MagicManager]
+      val mockMagic = mock[Magic]
+      doReturn(mockMagic).when(magicManager).findMagic(anyString())
+      doReturn(true).when(magicManager).isLineMagic(mockMagic)
 
-      val parser = new MagicParser(magicLoader)
+      val parser = new MagicParser(magicManager)
       parser.isValidLineMagic("%foobar baz") should be(true)
     }
 
     it("should return false if the line magic invocation is not valid") {
-      val magicLoader = mock[MagicLoader]
-      doReturn(false).when(magicLoader).hasLineMagic(anyString())
+      val magicManager = mock[MagicManager]
+      val mockMagic = mock[Magic]
+      doReturn(mockMagic).when(magicManager).findMagic(anyString())
+      doReturn(false).when(magicManager).isLineMagic(mockMagic)
 
-      val parser = new MagicParser(magicLoader)
+      val parser = new MagicParser(magicManager)
       parser.isValidLineMagic("%foobar baz") should be(false)
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/relay/ExecuteRequestRelaySpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/relay/ExecuteRequestRelaySpec.scala b/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/relay/ExecuteRequestRelaySpec.scala
index eccc5fc..0661191 100644
--- a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/relay/ExecuteRequestRelaySpec.scala
+++ b/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/relay/ExecuteRequestRelaySpec.scala
@@ -26,9 +26,9 @@ import org.apache.toree.kernel.protocol.v5._
 import org.apache.toree.kernel.protocol.v5.content._
 import org.apache.toree.kernel.protocol.v5.kernel.ActorLoader
 import org.apache.toree.kernel.protocol.v5.magic.{MagicParser, PostProcessor}
-import org.apache.toree.magic.MagicLoader
-import org.apache.toree.magic.dependencies.DependencyMap
 import com.typesafe.config.ConfigFactory
+import org.apache.toree.plugins.PluginManager
+import org.apache.toree.plugins.dependencies.DependencyManager
 import org.mockito.Mockito._
 import org.scalatest.mock.MockitoSugar
 import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
@@ -66,10 +66,10 @@ class ExecuteRequestRelaySpec extends TestKit(
         val executeRequest =
           ExecuteRequest("%myMagic", false, true, UserExpressions(), true)
 
-        val mockMagicLoader = mock[MagicLoader]
         val mockPostProcessor = mock[PostProcessor]
-        val mockDependencyMap = mock[DependencyMap]
-        doReturn(mockDependencyMap).when(mockMagicLoader).dependencyMap
+        val mockPluginManager = mock[PluginManager]
+        val mockDependencyManager = mock[DependencyManager]
+        doReturn(mockDependencyManager).when(mockPluginManager).dependencyManager
 
         val mockMagicParser = mock[MagicParser]
         doReturn(Left(executeRequest.code))
@@ -77,7 +77,7 @@ class ExecuteRequestRelaySpec extends TestKit(
 
         val executeRequestRelay = system.actorOf(Props(
           classOf[ExecuteRequestRelay], mockActorLoader,
-          mockMagicLoader, mockMagicParser, mockPostProcessor
+          mockPluginManager, mockMagicParser, mockPostProcessor
         ))
 
         // Send the message to the ExecuteRequestRelay
@@ -103,10 +103,10 @@ class ExecuteRequestRelaySpec extends TestKit(
         val executeRequest =
           ExecuteRequest("%myMagic", false, true, UserExpressions(), true)
 
-        val mockMagicLoader = mock[MagicLoader]
         val mockPostProcessor = mock[PostProcessor]
-        val mockDependencyMap = mock[DependencyMap]
-        doReturn(mockDependencyMap).when(mockMagicLoader).dependencyMap
+        val mockPluginManager = mock[PluginManager]
+        val mockDependencyManager = mock[DependencyManager]
+        doReturn(mockDependencyManager).when(mockPluginManager).dependencyManager
 
         val mockMagicParser = mock[MagicParser]
         doReturn(Left(executeRequest.code))
@@ -114,7 +114,7 @@ class ExecuteRequestRelaySpec extends TestKit(
 
         val executeRequestRelay = system.actorOf(Props(
           classOf[ExecuteRequestRelay], mockActorLoader,
-          mockMagicLoader, mockMagicParser, mockPostProcessor
+          mockPluginManager, mockMagicParser, mockPostProcessor
         ))
 
         // Send the message to the ExecuteRequestRelay
@@ -144,13 +144,12 @@ class ExecuteRequestRelaySpec extends TestKit(
         val executeRequest =
           ExecuteRequest("notAMagic", false, true, UserExpressions(), true)
 
-        val mockMagicLoader = mock[MagicLoader]
         val mockPostProcessor = mock[PostProcessor]
         doReturn(Data(MIMEType.PlainText -> expected))
           .when(mockPostProcessor).process(expected)
-
-        val mockDependencyMap = mock[DependencyMap]
-        doReturn(mockDependencyMap).when(mockMagicLoader).dependencyMap
+        val mockPluginManager = mock[PluginManager]
+        val mockDependencyManager = mock[DependencyManager]
+        doReturn(mockDependencyManager).when(mockPluginManager).dependencyManager
 
         val mockMagicParser = mock[MagicParser]
         doReturn(Left(executeRequest.code))
@@ -158,7 +157,7 @@ class ExecuteRequestRelaySpec extends TestKit(
 
         val executeRequestRelay = system.actorOf(Props(
           classOf[ExecuteRequestRelay], mockActorLoader,
-          mockMagicLoader, mockMagicParser, mockPostProcessor
+          mockPluginManager, mockMagicParser, mockPostProcessor
         ))
 
         // Send the message to the ExecuteRequestRelay

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/test/scala/org/apache/toree/magic/builtin/AddJarSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/org/apache/toree/magic/builtin/AddJarSpec.scala b/kernel/src/test/scala/org/apache/toree/magic/builtin/AddJarSpec.scala
index 255853d..169fb60 100644
--- a/kernel/src/test/scala/org/apache/toree/magic/builtin/AddJarSpec.scala
+++ b/kernel/src/test/scala/org/apache/toree/magic/builtin/AddJarSpec.scala
@@ -25,12 +25,11 @@ import org.apache.toree.interpreter.Interpreter
 import org.apache.toree.magic.dependencies.{IncludeConfig, IncludeOutputStream, IncludeInterpreter, IncludeSparkContext}
 import com.typesafe.config.ConfigFactory
 import org.apache.spark.SparkContext
+import org.apache.toree.plugins.PluginManager
 import org.scalatest.{Matchers, FunSpec}
 import org.scalatest.mock.MockitoSugar
-
 import org.mockito.Mockito._
 import org.mockito.Matchers._
-import org.apache.toree.magic.MagicLoader
 
 class AddJarSpec extends FunSpec with Matchers with MockitoSugar {
   describe("AddJar"){
@@ -40,7 +39,7 @@ class AddJarSpec extends FunSpec with Matchers with MockitoSugar {
         val mockSparkContext = mock[SparkContext]
         val mockInterpreter = mock[Interpreter]
         val mockOutputStream = mock[OutputStream]
-        val mockMagicLoader = mock[MagicLoader]
+        val mockPluginManager = mock[PluginManager]
         val testConfig = ConfigFactory.load()
 
         val addJarMagic = new AddJar
@@ -52,7 +51,7 @@ class AddJarSpec extends FunSpec with Matchers with MockitoSugar {
           override val sparkContext: SparkContext = mockSparkContext
           override val interpreter: Interpreter = mockInterpreter
           override val outputStream: OutputStream = mockOutputStream
-          override lazy val magicLoader: MagicLoader = mockMagicLoader
+          override lazy val pluginManager: PluginManager = mockPluginManager
           override val config = testConfig
           override def downloadFile(fileUrl: URL, destinationUrl: URL): URL =
             new URL("file://someFile") // Cannot mock URL
@@ -62,7 +61,7 @@ class AddJarSpec extends FunSpec with Matchers with MockitoSugar {
 
         verify(mockSparkContext).addJar(anyString())
         verify(mockInterpreter).addJars(any[URL])
-        verify(mockMagicLoader, times(0)).addJar(any())
+        verify(mockPluginManager, times(0)).loadPlugins(any())
       }
 
       it("should raise exception if jar file does not end in .jar or .zip") {
@@ -191,7 +190,7 @@ class AddJarSpec extends FunSpec with Matchers with MockitoSugar {
         val mockSparkContext = mock[SparkContext]
         val mockInterpreter = mock[Interpreter]
         val mockOutputStream = mock[OutputStream]
-        val mockMagicLoader = mock[MagicLoader]
+        val mockPluginManager = mock[PluginManager]
         val testConfig = ConfigFactory.load()
 
         val addJarMagic = new AddJar
@@ -203,7 +202,7 @@ class AddJarSpec extends FunSpec with Matchers with MockitoSugar {
           override val sparkContext: SparkContext = mockSparkContext
           override val interpreter: Interpreter = mockInterpreter
           override val outputStream: OutputStream = mockOutputStream
-          override lazy val magicLoader: MagicLoader = mockMagicLoader
+          override lazy val pluginManager: PluginManager = mockPluginManager
           override val config = testConfig
           override def downloadFile(fileUrl: URL, destinationUrl: URL): URL =
             new URL("file://someFile") // Cannot mock URL
@@ -212,7 +211,7 @@ class AddJarSpec extends FunSpec with Matchers with MockitoSugar {
         addJarMagic.execute(
           """--magic http://www.example.com/someJar.jar""")
 
-        verify(mockMagicLoader).addJar(any())
+        verify(mockPluginManager).loadPlugins(any())
         verify(mockSparkContext, times(0)).addJar(anyString())
         verify(mockInterpreter, times(0)).addJars(any[URL])
       }

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/test/scala/system/KernelCommSpecForSystem.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/system/KernelCommSpecForSystem.scala b/kernel/src/test/scala/system/KernelCommSpecForSystem.scala
index 6cc50f5..9ebe146 100644
--- a/kernel/src/test/scala/system/KernelCommSpecForSystem.scala
+++ b/kernel/src/test/scala/system/KernelCommSpecForSystem.scala
@@ -17,17 +17,18 @@
 
 package system
 
-import akka.testkit.{TestProbe}
+import akka.testkit.TestProbe
 import org.apache.toree.communication.ZMQMessage
-import org.apache.toree.kernel.protocol.v5.kernel.{ActorLoader, Utilities}
-import Utilities._
 import org.apache.toree.kernel.protocol.v5
-import org.apache.toree.kernel.protocol.v5.{KernelMessage, SocketType, KMBuilder}
 import org.apache.toree.kernel.protocol.v5.content._
+import org.apache.toree.kernel.protocol.v5.kernel.ActorLoader
+import org.apache.toree.kernel.protocol.v5.kernel.Utilities._
+import org.apache.toree.kernel.protocol.v5.{KMBuilder, KernelMessage, SocketType}
 import org.scalatest._
 import play.api.libs.json.Json
+import test.utils.NoArgSparkKernelTestKit
+
 import scala.concurrent.duration._
-import test.utils.{NoArgSparkKernelTestKit}
 
 
 /**
@@ -44,7 +45,7 @@ class KernelCommSpecForSystem
 {
   private val MaxFishTime = 5.seconds
 
-  import org.apache.toree.boot.layer.SparkKernelDeployer._
+  import test.utils.SparkKernelDeployer._
 
   private def waitForExecuteReply(
     shell: TestProbe, headerId: v5.UUID, maxTime: Duration = MaxFishTime

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/test/scala/system/SuiteForSystem.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/system/SuiteForSystem.scala b/kernel/src/test/scala/system/SuiteForSystem.scala
index 19f256a..4556e5a 100644
--- a/kernel/src/test/scala/system/SuiteForSystem.scala
+++ b/kernel/src/test/scala/system/SuiteForSystem.scala
@@ -17,8 +17,8 @@
 
 package system
 
-import org.apache.toree.boot.layer.SparkKernelDeployer
 import org.scalatest.{BeforeAndAfterAll, Suites}
+import test.utils.SparkKernelDeployer
 
 class SuiteForSystem extends Suites(
   new KernelCommSpecForSystem,
@@ -29,4 +29,10 @@ class SuiteForSystem extends Suites(
     println("Initializing kernel for system tests")
     SparkKernelDeployer.noArgKernelBootstrap
   }
+
+  override protected def afterAll(): Unit = {
+    println("Shutting down kernel for system tests")
+    SparkKernelDeployer.noArgKernelBootstrap.shutdown()
+    println("Finished shutting down kernel!")
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/test/scala/system/TruncationTests.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/system/TruncationTests.scala b/kernel/src/test/scala/system/TruncationTests.scala
index 2fe107f..118a609 100644
--- a/kernel/src/test/scala/system/TruncationTests.scala
+++ b/kernel/src/test/scala/system/TruncationTests.scala
@@ -28,7 +28,6 @@ import org.scalatest._
 import play.api.libs.json.Json
 import scala.concurrent.duration._
 import test.utils.NoArgSparkKernelTestKit
-import org.apache.toree.boot.layer.SparkKernelDeployer
 
 
 /**
@@ -44,8 +43,7 @@ class TruncationTests
   with FunSpecLike with Matchers
 {
   private val MaxFishTime =   30.seconds
-
-  import SparkKernelDeployer._
+  import test.utils.SparkKernelDeployer._
 
   private def waitForExecuteReply(
     shell: TestProbe, headerId: v5.UUID, maxTime: Duration = MaxFishTime
@@ -194,10 +192,7 @@ class TruncationTests
     str
   }
 
-
-
-
-  describe("Test Truncation") {
+  describe( "Test Truncation") {
     it("should show or not show types based on %showtypes") {
       withNoArgSparkKernel { (actorLoader, heartbeat, shell, ioPub) =>
 
@@ -216,7 +211,6 @@ class TruncationTests
     }
     it("should truncate or not truncate based on %truncate") {
       withNoArgSparkKernel { (actorLoader, heartbeat, shell, ioPub) =>
-
         executeCode("for ( a <-  1 to 300 ) yield a",actorLoader,ioPub) should endWith("...")
 
         executeCode(
@@ -224,18 +218,11 @@ class TruncationTests
             |for ( a <-  1 to 300 ) yield a
           """.stripMargin,actorLoader,ioPub) should endWith("300)")
 
-
-
         executeCode(
           """%Truncation on
             |for ( a <-  1 to 300 ) yield a
           """.stripMargin,actorLoader,ioPub) should endWith("...")
-
-
-
       }
     }
-    }
-
-
   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/test/scala/test/utils/NoArgSparkKernelTestKit.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/test/utils/NoArgSparkKernelTestKit.scala b/kernel/src/test/scala/test/utils/NoArgSparkKernelTestKit.scala
index 3052cfe..3a06a21 100644
--- a/kernel/src/test/scala/test/utils/NoArgSparkKernelTestKit.scala
+++ b/kernel/src/test/scala/test/utils/NoArgSparkKernelTestKit.scala
@@ -18,7 +18,6 @@
 package test.utils
 
 import akka.testkit.TestKit
-import org.apache.toree.boot.layer.SparkKernelDeployer
 
 class NoArgSparkKernelTestKit
   extends TestKit(SparkKernelDeployer.getNoArgSparkKernelActorSystem)

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/kernel/src/test/scala/test/utils/SparkKernelDeployer.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/test/utils/SparkKernelDeployer.scala b/kernel/src/test/scala/test/utils/SparkKernelDeployer.scala
index b157eaa..62548c7 100644
--- a/kernel/src/test/scala/test/utils/SparkKernelDeployer.scala
+++ b/kernel/src/test/scala/test/utils/SparkKernelDeployer.scala
@@ -15,27 +15,19 @@
  *  limitations under the License
  */
 
-package org.apache.toree.boot.layer
+package test.utils
 
-import java.io.OutputStream
-
-import akka.actor.{Actor, Props, ActorRef, ActorSystem}
+import akka.actor.{Actor, ActorRef, ActorSystem, Props}
 import akka.testkit.TestProbe
+import com.typesafe.config.Config
+import org.apache.toree.boot.layer.{StandardBareInitialization, StandardComponentInitialization, StandardHandlerInitialization, StandardHookInitialization}
 import org.apache.toree.boot.{CommandLineOptions, KernelBootstrap}
-import org.apache.toree.kernel.api.KernelLike
-import org.apache.toree.kernel.interpreter.scala.{StandardTaskManagerProducer, StandardSparkIMainProducer, StandardSettingsProducer, ScalaInterpreter}
-import org.apache.toree.kernel.protocol.v5.{KMBuilder, SocketType}
+import org.apache.toree.kernel.protocol.v5.SocketType
 import org.apache.toree.kernel.protocol.v5.kernel.ActorLoader
 import org.apache.toree.kernel.protocol.v5.kernel.socket._
 import org.apache.toree.utils.LogLike
-import com.typesafe.config.Config
 import org.scalatest.mock.MockitoSugar
 import play.api.libs.json.Json
-import scala.collection.JavaConverters._
-import test.utils.SparkContextProvider
-import org.apache.spark.{SparkContext, SparkConf}
-import org.apache.toree.kernel.protocol.v5.stream.KernelOutputStream
-import org.apache.toree.global
 
 /**
  * Represents an object that can deploy a singleton Spark Kernel for tests,
@@ -172,7 +164,6 @@ object SparkKernelDeployer extends LogLike with MockitoSugar {
    * KernelBootstrap through an actor loader and socket test probes.
    *
    * @param testCode The test code to execute
-   *
    * @return The results from the test code
    */
   def withNoArgSparkKernel(

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/plugins/src/main/scala/org/apache/toree/plugins/Plugin.scala
----------------------------------------------------------------------
diff --git a/plugins/src/main/scala/org/apache/toree/plugins/Plugin.scala b/plugins/src/main/scala/org/apache/toree/plugins/Plugin.scala
index 66cd4a8..42f0eb8 100644
--- a/plugins/src/main/scala/org/apache/toree/plugins/Plugin.scala
+++ b/plugins/src/main/scala/org/apache/toree/plugins/Plugin.scala
@@ -36,11 +36,17 @@ object Plugin {
  */
 trait Plugin {
   /** Plugin manager containing the plugin */
-  @Internal private var _pluginManager: PluginManager = null
+  @Internal private var _internalPluginManager: PluginManager = null
 
-  /** Represents the name of the plugin. */
+  /** Represents the fully qualified name of the plugin. */
   final val name: String = getClass.getName
 
+  /**
+   * Represents the simple name of the plugin. In the case of a anonymous class
+   * it will just be the name of the anonymous class.
+   */
+  final val simpleName: String = getClass.getSimpleName
+
   /** Represents the priority of the plugin. */
   final val priority: Long = {
     Option(getClass.getAnnotation(classOf[annotations.Priority]))
@@ -49,13 +55,19 @@ trait Plugin {
   }
 
   /** Sets the plugin manager pointer for this plugin. */
-  @Internal private[plugins] final def pluginManager_=(_pluginManager: PluginManager) = {
-    require(this._pluginManager == null, "Plugin manager cannot be reassigned!")
-    this._pluginManager = _pluginManager
+  @Internal private[plugins] final def internalPluginManager_=(
+    _pluginManager: PluginManager
+  ) = {
+    require(
+      this._internalPluginManager == null,
+      "Plugin manager cannot be reassigned!"
+    )
+    this._internalPluginManager = _pluginManager
   }
 
   /** Returns the plugin manager pointer for this plugin. */
-  @Internal private[plugins] final def pluginManager = _pluginManager
+  @Internal private[plugins] final def internalPluginManager =
+    _internalPluginManager
 
   /** Represents all @init methods in the plugin. */
   @Internal private[plugins] final lazy val initMethods: Seq[PluginMethod] = {
@@ -109,7 +121,7 @@ trait Plugin {
    * @tparam T The dependency's type
    */
   protected def register[T <: AnyRef](name: String, value: T)(implicit typeTag: TypeTag[T]): Unit = {
-    assert(_pluginManager != null, "Internal plugin manager reference invalid!")
-    _pluginManager.dependencyManager.add(name, value)
+    assert(_internalPluginManager != null, "Internal plugin manager reference invalid!")
+    _internalPluginManager.dependencyManager.add(name, value)
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/plugins/src/main/scala/org/apache/toree/plugins/PluginManager.scala
----------------------------------------------------------------------
diff --git a/plugins/src/main/scala/org/apache/toree/plugins/PluginManager.scala b/plugins/src/main/scala/org/apache/toree/plugins/PluginManager.scala
index 4b7338f..4b611a1 100644
--- a/plugins/src/main/scala/org/apache/toree/plugins/PluginManager.scala
+++ b/plugins/src/main/scala/org/apache/toree/plugins/PluginManager.scala
@@ -91,6 +91,8 @@ class PluginManager(
    * @return The collection of loaded plugins
    */
   def loadPlugins(paths: File*): Seq[Plugin] = {
+    require(paths.nonEmpty, "Plugin paths cannot be empty!")
+
     // Search for plugins in our new paths, then add loaded plugins to list
     // NOTE: Iterator returned from plugin searcher, so avoid building a
     //       large collection by performing all tasks together
@@ -136,7 +138,7 @@ class PluginManager(
       // Attempt to cast as plugin type to add to active plugins
       tryInstance.transform({
         case p: Plugin  =>
-          p.pluginManager_=(this)
+          p.internalPluginManager_=(this)
           activePlugins.put(p.name, p)
           Success(p)
         case x          =>

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/plugins/src/main/scala/org/apache/toree/plugins/PluginMethod.scala
----------------------------------------------------------------------
diff --git a/plugins/src/main/scala/org/apache/toree/plugins/PluginMethod.scala b/plugins/src/main/scala/org/apache/toree/plugins/PluginMethod.scala
index cb87b65..50aafe3 100644
--- a/plugins/src/main/scala/org/apache/toree/plugins/PluginMethod.scala
+++ b/plugins/src/main/scala/org/apache/toree/plugins/PluginMethod.scala
@@ -81,9 +81,6 @@ case class PluginMethod(
    *                          (as needed)
    * @return The result from invoking the plugin
    */
-  @throws[DepNameNotFoundException]
-  @throws[DepClassNotFoundException]
-  @throws[DepUnexpectedClassException]
   def invoke(dependencyManager: DependencyManager): PluginMethodResult = Try({
     // Get dependency info (if has specific name or just use class)
     val depInfo = method.getParameterAnnotations

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/plugins/src/main/scala/org/apache/toree/plugins/PluginSearcher.scala
----------------------------------------------------------------------
diff --git a/plugins/src/main/scala/org/apache/toree/plugins/PluginSearcher.scala b/plugins/src/main/scala/org/apache/toree/plugins/PluginSearcher.scala
index e6c9141..4686a50 100644
--- a/plugins/src/main/scala/org/apache/toree/plugins/PluginSearcher.scala
+++ b/plugins/src/main/scala/org/apache/toree/plugins/PluginSearcher.scala
@@ -48,7 +48,7 @@ class PluginSearcher {
    *
    * @return The new class finder
    */
-  protected def newClassFinder(): ClassFinder = ClassFinder()
+  protected def newClassFinder(): ClassFinder = ClassFinder(classpath)
 
   /**
    * Creates a new class finder for the given paths.
@@ -83,24 +83,28 @@ class PluginSearcher {
     classes: Map[String, ClassInfo]
   ): Iterator[ClassInfo] = {
     @tailrec def classMatches(
-      ancestorClassInfo: ClassInfo,
       classesToCheck: Seq[ClassInfo]
     ): Boolean = {
       if (classesToCheck.isEmpty) false
-      else if (classesToCheck.exists(_.name == ancestorClassInfo.name)) true
-      else if (classesToCheck.exists(_.superClassName == ancestorClassInfo.name)) true
-      else if (classesToCheck.exists(_ implements ancestorClassInfo.name)) true
+      else if (classesToCheck.exists(_.name == ancestor)) true
+      else if (classesToCheck.exists(_.superClassName == ancestor)) true
+      else if (classesToCheck.exists(_ implements ancestor)) true
       else {
         val superClasses = classesToCheck.map(_.superClassName).flatMap(classes.get)
         val interfaces = classesToCheck.flatMap(_.interfaces).flatMap(classes.get)
-        classMatches(ancestorClassInfo, superClasses ++ interfaces)
+        classMatches(superClasses ++ interfaces)
       }
     }
 
-    classes.get(ancestor).map(ci => {
-      classes.values.toIterator
-        .filter(_.isConcrete)
-        .filter(c => classMatches(ci, Seq(c)))
-    }).getOrElse(Iterator.empty)
+    classes.values.toIterator
+      .filter(_.isConcrete)
+      .filter(c => classMatches(Seq(c)))
   }
+
+  private def classpath = System.getProperty("java.class.path")
+    .split(File.pathSeparator)
+    .map(s => if (s.trim.length == 0) "." else s)
+    .map(new File(_))
+    .filter(_.getAbsolutePath.toLowerCase.contains("toree"))
+    .toList
 }

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/plugins/src/test/scala/integration/PluginManagerSpecForIntegration.scala
----------------------------------------------------------------------
diff --git a/plugins/src/test/scala/integration/PluginManagerSpecForIntegration.scala b/plugins/src/test/scala/integration/PluginManagerSpecForIntegration.scala
index b2e9d00..c97e61a 100644
--- a/plugins/src/test/scala/integration/PluginManagerSpecForIntegration.scala
+++ b/plugins/src/test/scala/integration/PluginManagerSpecForIntegration.scala
@@ -26,6 +26,15 @@ class PluginManagerSpecForIntegration extends FunSpec with Matchers
   private val pluginManager = new PluginManager
 
   describe("PluginManager") {
+    it("should be able to load and initialize internal plugins") {
+      val plugins = pluginManager.initialize()
+      plugins.map(_.name) should contain allOf (
+        classOf[NonCircularPlugin].getName,
+        classOf[RegisterPluginA].getName,
+        classOf[ConsumePluginA].getName
+      )
+    }
+
     it("should be able to initialize plugins with dependencies provided by other plugins") {
       val cpa = pluginManager.loadPlugin("", classOf[ConsumePluginA]).get
       val rpa = pluginManager.loadPlugin("", classOf[RegisterPluginA]).get

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/plugins/src/test/scala/org/apache/toree/plugins/PluginManagerSpec.scala
----------------------------------------------------------------------
diff --git a/plugins/src/test/scala/org/apache/toree/plugins/PluginManagerSpec.scala b/plugins/src/test/scala/org/apache/toree/plugins/PluginManagerSpec.scala
index 09e0f10..86097c8 100644
--- a/plugins/src/test/scala/org/apache/toree/plugins/PluginManagerSpec.scala
+++ b/plugins/src/test/scala/org/apache/toree/plugins/PluginManagerSpec.scala
@@ -116,7 +116,7 @@ class PluginManagerSpec extends FunSpec with Matchers
       it("should set the internal plugin manager of the new plugin") {
         val p = pluginManager.loadPlugin("name", classOf[TestPlugin])
 
-        p.get.pluginManager should be (pluginManager)
+        p.get.internalPluginManager should be (pluginManager)
       }
 
       it("should add the new plugin to the list of active plugins") {
@@ -146,6 +146,12 @@ class PluginManagerSpec extends FunSpec with Matchers
     }
 
     describe("#loadPlugins") {
+      it("should throw an IllegalArgumentException if provided no paths") {
+        intercept[IllegalArgumentException] {
+          pluginManager.loadPlugins()
+        }
+      }
+
       it("should load nothing if the plugin searcher returns empty handed") {
         val expected = Nil
 

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/plugins/src/test/scala/org/apache/toree/plugins/PluginSpec.scala
----------------------------------------------------------------------
diff --git a/plugins/src/test/scala/org/apache/toree/plugins/PluginSpec.scala b/plugins/src/test/scala/org/apache/toree/plugins/PluginSpec.scala
index fd5e1f0..5ea58a7 100644
--- a/plugins/src/test/scala/org/apache/toree/plugins/PluginSpec.scala
+++ b/plugins/src/test/scala/org/apache/toree/plugins/PluginSpec.scala
@@ -30,12 +30,12 @@ class PluginSpec extends FunSpec with Matchers with OneInstancePerTest with Mock
   private val mockPluginManager = mock[PluginManager]
   private val testPlugin = {
     val plugin = new TestPlugin
-    plugin.pluginManager_=(mockPluginManager)
+    plugin.internalPluginManager_=(mockPluginManager)
     plugin
   }
   private val extendedTestPlugin = {
     val extendedPlugin = new ExtendedTestPlugin
-    extendedPlugin.pluginManager_=(mockPluginManager)
+    extendedPlugin.internalPluginManager_=(mockPluginManager)
     extendedPlugin
   }
   private val registerPlugin = new RegisterPlugin
@@ -53,6 +53,26 @@ class PluginSpec extends FunSpec with Matchers with OneInstancePerTest with Mock
       }
     }
 
+    describe("#simpleName") {
+      it("should be the simple name of the class implementing the plugin") {
+        val expected = classOf[TestPlugin].getSimpleName
+
+        val actual = testPlugin.simpleName
+
+        actual should be (expected)
+      }
+
+      it("should be the simple name of an anonymous class implementing the plugin") {
+        val anonymousPlugin = new TestPlugin {}
+        val anonymousClass = anonymousPlugin.getClass
+        val expected = anonymousClass.getSimpleName
+
+        val actual = anonymousPlugin.simpleName
+
+        actual should be(expected)
+      }
+    }
+
     describe("#priority") {
       it("should return the priority set by the plugin's annotation") {
         val expected = 999
@@ -236,7 +256,7 @@ class PluginSpec extends FunSpec with Matchers with OneInstancePerTest with Mock
       }
 
       it("should create a new name for the dependency if not specified") {
-        registerPlugin.pluginManager_=(mockPluginManager)
+        registerPlugin.internalPluginManager_=(mockPluginManager)
 
         val value = new AnyRef
         val mockDependencyManager = mock[DependencyManager]
@@ -247,7 +267,7 @@ class PluginSpec extends FunSpec with Matchers with OneInstancePerTest with Mock
       }
 
       it("should add the dependency using the provided name") {
-        registerPlugin.pluginManager_=(mockPluginManager)
+        registerPlugin.internalPluginManager_=(mockPluginManager)
 
         val name = "some name"
         val value = new AnyRef

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/project/Build.scala
----------------------------------------------------------------------
diff --git a/project/Build.scala b/project/Build.scala
index baf8baf..8984570 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -100,7 +100,8 @@ trait SubProjects extends Settings with TestTasks {
     settings = fullSettings ++ Seq(
         test in assembly := {}
       )
-  )) dependsOn(
+  // Enable forking to load correct classes with plugin loader during tests
+  ), doFork = true) dependsOn(
     macros % "test->test;compile->compile",
     protocol % "test->test;compile->compile",
     communication % "test->test;compile->compile",
@@ -227,7 +228,8 @@ trait SubProjects extends Settings with TestTasks {
     id = "toree-plugins",
     base = file("plugins"),
     settings = fullSettings
-  )) dependsOn(
+  // Enable forking to load correct classes with plugin loader during tests
+  ), doFork = true) dependsOn(
     macros % "test->test;compile->compile"
   )
 
@@ -251,7 +253,7 @@ trait SubProjects extends Settings with TestTasks {
  * scratch:test - runs temporary tests
  */
 trait TestTasks {
-  def addTestTasksToProject(project: Project): Project =
+  def addTestTasksToProject(project: Project, doFork: Boolean = false): Project =
     project
       .configs( UnitTest )
       .configs( IntegrationTest )
@@ -266,6 +268,12 @@ trait TestTasks {
         testOptions in IntegrationTest := Seq(Tests.Filter(intFilter)),
         testOptions in SystemTest := Seq(Tests.Filter(sysFilter)),
         testOptions in ScratchTest := Seq(Tests.Filter(scratchFilter))
+      ).settings(
+        fork in Test := doFork,
+        fork in UnitTest := doFork,
+        fork in IntegrationTest := doFork,
+        fork in SystemTest := doFork,
+        fork in ScratchTest := doFork
       )
 
   def scratchFilter(name: String): Boolean =

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/project/Common.scala
----------------------------------------------------------------------
diff --git a/project/Common.scala b/project/Common.scala
index dd1c8aa..872db2e 100644
--- a/project/Common.scala
+++ b/project/Common.scala
@@ -115,7 +115,8 @@ object Common {
       //"-Xlint", // Scala 2.11.x only
       "-Xfatal-warnings",
       "-Ywarn-all",
-      "-language:reflectiveCalls"
+      "-language:reflectiveCalls",
+      "-target:jvm-1.6"
     ),
 
     // Java-based options for compilation (all tasks)
@@ -126,7 +127,19 @@ object Common {
     javacOptions in (Compile, compile) ++= Seq(
       "-Xlint:all",   // Enable all Java-based warnings
       "-Xlint:-path", // Suppress path warnings since we get tons of them
-      "-Werror"       // Treat warnings as errors
+      "-Xlint:-options",
+      "-Xlint:-processing",
+      "-Werror",       // Treat warnings as errors
+      "-source", "1.6",
+      "-target", "1.6"
+    ),
+
+    // Options provided to forked JVMs through sbt, based on our .jvmopts file
+    javaOptions ++= Seq(
+      "-Xms1024M", "-Xmx4096M", "-Xss2m", "-XX:MaxPermSize=1024M",
+      "-XX:ReservedCodeCacheSize=256M", "-XX:+TieredCompilation",
+      "-XX:+CMSPermGenSweepingEnabled", "-XX:+CMSClassUnloadingEnabled",
+      "-XX:+UseConcMarkSweepGC", "-XX:+HeapDumpOnOutOfMemoryError"
     ),
 
     // Add additional test option to show time taken per test
@@ -143,20 +156,10 @@ object Common {
 
     credentials += Credentials("Sonatype Nexus Repository Manager", repoHost, repoUsername, repoPassword),
 
-    // Change destination of local delivery (building ivy.xml) to have *-ivy.xml
-    deliverLocalConfiguration := {
-      val newDestinationPath = crossTarget.value / s"${name.value}-ivy.xml"
-      val dlc = deliverLocalConfiguration.value
-      new DeliverConfiguration(
-        newDestinationPath.absolutePath, dlc.status,
-        dlc.configurations, dlc.logging)
-    },
-
     // Add rebuild ivy xml to the following tasks
     compile <<= (compile in Compile) dependsOn (rebuildIvyXml dependsOn deliverLocal)
   ) ++ rebuildIvyXmlSettings // Include our rebuild ivy xml settings
 
-
   buildLibraryDependencies ++= Seq( "org.apache.spark" %% "spark-core" % sparkVersion  % "provided" excludeAll( // Apache v2
 
     // Exclude netty (org.jboss.netty is for 3.2.2.Final only)
@@ -187,7 +190,7 @@ object Common {
   lazy val rebuildIvyXmlSettings = Seq(
     rebuildIvyXml := {
       val s: TaskStreams = streams.value
-      val inputFile = (crossTarget.value / s"${name.value}-ivy.xml").getAbsoluteFile
+      val inputFile = (crossTarget.value / s"ivy-${version.value}.xml").getAbsoluteFile
       val outputFile =
         ((resourceDirectory in Compile).value / s"${name.value}-ivy.xml").getAbsoluteFile
       s.log.info(s"Copying ${inputFile.getPath} to ${outputFile.getPath}")

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/project/plugins.sbt
----------------------------------------------------------------------
diff --git a/project/plugins.sbt b/project/plugins.sbt
index f0ef85b..081776e 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -50,4 +50,4 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "0.8.1")
 addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.5.3")
 
 // Provides alternative resolving/downloading over sbt
-addSbtPlugin("com.github.alexarchambault" % "coursier-sbt-plugin" % "1.0.0-M9")
+addSbtPlugin("com.github.alexarchambault" % "coursier-sbt-plugin" % "1.0.0-M10")

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/pyspark-interpreter/src/main/scala/org/apache/toree/magic/builtin/PySpark.scala
----------------------------------------------------------------------
diff --git a/pyspark-interpreter/src/main/scala/org/apache/toree/magic/builtin/PySpark.scala b/pyspark-interpreter/src/main/scala/org/apache/toree/magic/builtin/PySpark.scala
index 7510656..015320d 100644
--- a/pyspark-interpreter/src/main/scala/org/apache/toree/magic/builtin/PySpark.scala
+++ b/pyspark-interpreter/src/main/scala/org/apache/toree/magic/builtin/PySpark.scala
@@ -21,11 +21,13 @@ import org.apache.toree.kernel.interpreter.pyspark.{PySparkInterpreter, PySparkE
 import org.apache.toree.kernel.protocol.v5.MIMEType
 import org.apache.toree.magic.{CellMagicOutput, CellMagic}
 import org.apache.toree.magic.dependencies.IncludeKernel
+import org.apache.toree.plugins.annotations.Event
 
 /**
  * Represents the magic interface to use the PySpark interpreter.
  */
 class PySpark extends CellMagic with IncludeKernel {
+  @Event(name = "pyspark")
   override def execute(code: String): CellMagicOutput = {
     val pySpark = kernel.interpreter("PySpark")
 

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/resources/compile/log4j.properties
----------------------------------------------------------------------
diff --git a/resources/compile/log4j.properties b/resources/compile/log4j.properties
index c760493..82fcf92 100644
--- a/resources/compile/log4j.properties
+++ b/resources/compile/log4j.properties
@@ -26,6 +26,7 @@ log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} [%p] %c{1.
 # Override log levels of external packages that clutter our output
 log4j.logger.org.eclipse.jetty=WARN
 log4j.logger.org.apache=WARN
+log4j.logger.org.apache.toree=INFO
 log4j.logger.org.spark-project=WARN
 log4j.logger.io.netty=WARN
 log4j.logger.akka=WARN

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/scala-interpreter/src/main/scala/org/apache/toree/magic/builtin/Scala.scala
----------------------------------------------------------------------
diff --git a/scala-interpreter/src/main/scala/org/apache/toree/magic/builtin/Scala.scala b/scala-interpreter/src/main/scala/org/apache/toree/magic/builtin/Scala.scala
index 7d18405..ceeda00 100644
--- a/scala-interpreter/src/main/scala/org/apache/toree/magic/builtin/Scala.scala
+++ b/scala-interpreter/src/main/scala/org/apache/toree/magic/builtin/Scala.scala
@@ -21,11 +21,13 @@ import org.apache.toree.kernel.interpreter.scala.{ScalaException, ScalaInterpret
 import org.apache.toree.kernel.protocol.v5.MIMEType
 import org.apache.toree.magic.dependencies.IncludeKernel
 import org.apache.toree.magic.{CellMagic, CellMagicOutput}
-
+import org.apache.toree.plugins.annotations.Event
 /**
  * Represents the magic interface to use the Scala interpreter.
  */
 class Scala extends CellMagic with IncludeKernel {
+
+  @Event(name = "scala")
   override def execute(code: String): CellMagicOutput = {
     val scala = kernel.interpreter("Scala")
 

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/sparkr-interpreter/src/main/scala/org/apache/toree/magic/builtin/SparkR.scala
----------------------------------------------------------------------
diff --git a/sparkr-interpreter/src/main/scala/org/apache/toree/magic/builtin/SparkR.scala b/sparkr-interpreter/src/main/scala/org/apache/toree/magic/builtin/SparkR.scala
index 9f12973..facf3ac 100644
--- a/sparkr-interpreter/src/main/scala/org/apache/toree/magic/builtin/SparkR.scala
+++ b/sparkr-interpreter/src/main/scala/org/apache/toree/magic/builtin/SparkR.scala
@@ -21,11 +21,14 @@ import org.apache.toree.kernel.interpreter.sparkr.{SparkRInterpreter, SparkRExce
 import org.apache.toree.kernel.protocol.v5.MIMEType
 import org.apache.toree.magic.{CellMagicOutput, CellMagic}
 import org.apache.toree.magic.dependencies.IncludeKernel
+import org.apache.toree.plugins.annotations.Event
 
 /**
  * Represents the magic interface to use the SparkR interpreter.
  */
 class SparkR extends CellMagic with IncludeKernel {
+
+  @Event(name = "sparkr")
   override def execute(code: String): CellMagicOutput = {
     val sparkR = kernel.interpreter("SparkR")
 

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/9c8824ff/sql-interpreter/src/main/scala/org/apache/toree/magic/builtin/Sql.scala
----------------------------------------------------------------------
diff --git a/sql-interpreter/src/main/scala/org/apache/toree/magic/builtin/Sql.scala b/sql-interpreter/src/main/scala/org/apache/toree/magic/builtin/Sql.scala
index 955bdd5..4144cf4 100644
--- a/sql-interpreter/src/main/scala/org/apache/toree/magic/builtin/Sql.scala
+++ b/sql-interpreter/src/main/scala/org/apache/toree/magic/builtin/Sql.scala
@@ -21,11 +21,14 @@ import org.apache.toree.kernel.interpreter.sql.{SqlInterpreter, SqlException}
 import org.apache.toree.kernel.protocol.v5.MIMEType
 import org.apache.toree.magic.{CellMagicOutput, CellMagic}
 import org.apache.toree.magic.dependencies.IncludeKernel
+import org.apache.toree.plugins.annotations.Event
 
 /**
  * Represents the magic interface to use the SQL interpreter.
  */
 class Sql extends CellMagic with IncludeKernel {
+
+  @Event(name = "sql")
   override def execute(code: String): CellMagicOutput = {
     val sparkR = kernel.interpreter("SQL")
 


Mime
View raw message