Skip to content

Commit

Permalink
ass compile on 2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
pan3793 committed Aug 20, 2023
1 parent 21c39c4 commit 55a9098
Show file tree
Hide file tree
Showing 50 changed files with 112 additions and 78 deletions.
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ ThisBuild / version := Properties.envOrElse("VERSION", "0.0.0-dev") +
(if ((ThisBuild / isSnapshot ).value) "-SNAPSHOT" else "")
ThisBuild / isSnapshot := Properties.envOrElse("IS_SNAPSHOT","true").toBoolean
ThisBuild / organization := "org.apache.toree.kernel"
ThisBuild / crossScalaVersions := Seq("2.13.10")
ThisBuild / scalaVersion := (ThisBuild / crossScalaVersions ).value.head
ThisBuild / crossScalaVersions := Seq("2.13.8", "2.12.15")
//ThisBuild / crossScalaVersions := Seq("2.12.15", "2.13.8")
ThisBuild / scalaVersion := (ThisBuild / crossScalaVersions).value.head
ThisBuild / Dependencies.sparkVersion := {
val envVar = "APACHE_SPARK_VERSION"
val defaultVersion = "3.3.2"
Expand All @@ -40,7 +41,7 @@ ThisBuild / Dependencies.sparkVersion := {

// Compiler settings
ThisBuild / scalacOptions ++= Seq(
"-deprecation",
// "-deprecation",
"-unchecked",
"-feature",
// "-Xfatal-warnings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.apache.toree.kernel.protocol.v5.content.ExecuteRequest
import org.apache.toree.utils.LogLike
import play.api.libs.json.{JsPath, Json, JsonValidationError, Reads}

import scala.collection.mutable
import scala.concurrent.duration._

object Utilities extends LogLike {
Expand Down Expand Up @@ -78,15 +79,15 @@ object Utilities extends LogLike {
}

implicit def KernelMessageToZMQMessage(kernelMessage : KernelMessage) : ZMQMessage = {
var frames: Seq[ByteString] = Seq()
kernelMessage.ids.map((id : Array[Byte]) => frames = frames :+ ByteString.apply(id) )
frames = frames :+ "<IDS|MSG>"
frames = frames :+ kernelMessage.signature
frames = frames :+ Json.toJson(kernelMessage.header).toString()
frames = frames :+ Json.toJson(kernelMessage.parentHeader).toString()
frames = frames :+ Json.toJson(kernelMessage.metadata).toString
frames = frames :+ kernelMessage.contentString
ZMQMessage(frames : _*)
val frames: mutable.ListBuffer[ByteString] = scala.collection.mutable.ListBuffer()
kernelMessage.ids.map((id: Array[Byte]) => frames += ByteString.apply(id))
frames += "<IDS|MSG>"
frames += kernelMessage.signature
frames += Json.toJson(kernelMessage.header).toString()
frames += Json.toJson(kernelMessage.parentHeader).toString()
frames += Json.toJson(kernelMessage.metadata).toString
frames += kernelMessage.contentString
ZMQMessage(frames.toSeq : _*)
}

def parseAndHandle[T](json: String, reads: Reads[T], handler: T => Unit) : Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ object Credentials {
p
}

private def findKey(keys: collection.Seq[String]) = keys
private def findKey(keys: collection.Seq[String]): String = keys
.iterator
.map(props.getProperty)
.filter(_ != null)
.to(LazyList)
.toStream
.headOption
.getOrElse {
throw new NoSuchElementException(s"${keys.head} key in $file")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class InternalClassLoader(

// TODO: Provides an exposed reference to the super loadClass to be stubbed
// out in tests.
private[magic] def parentLoadClass(name: String, resolve: Boolean) =
private[magic] def parentLoadClass(name: String, resolve: Boolean): Class[_] =
super.loadClass(name, resolve)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MultiClassLoader(
private val classLoaders: collection.Seq[ClassLoader]
) extends URLClassLoader(
classLoaders.flatMap({
case urlClassLoader: URLClassLoader => urlClassLoader.getURLs.to(collection.Seq)
case urlClassLoader: URLClassLoader => urlClassLoader.getURLs.toSeq
case _ => Nil
}).distinct.toArray,
/* Create a parent chain based on a each classloader's parent */ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class CommInfoRequestHandler(
extends BaseHandler(actorLoader) with MessageLogSupport
{

def buildCommMap(targetName: String) = {
def buildCommMap(targetName: String): Map[UUID, Map[UUID, UUID]] = {
commStorage.getCommIdsFromTarget(targetName) match {
case Some(commVector) => {
commVector.map(x => Map(x -> Map("target_name" -> targetName))).flatten.toMap
commVector.flatMap(x => Map(x -> Map("target_name" -> targetName))).toMap
}
case _ => {
Map()
Expand All @@ -54,13 +54,14 @@ class CommInfoRequestHandler(
override def process(kernelMessage: KernelMessage): Future[_] = Future {
logKernelMessageAction("Initiating CommInfo request for", kernelMessage)
import scala.language.existentials
val commMap = (Json.parse(kernelMessage.contentString) \ "target_name").asOpt[String] match {
val commMap: Map[String, Map[String, String]] =
(Json.parse(kernelMessage.contentString) \ "target_name").asOpt[String] match {
case Some(targetName) => {
buildCommMap(targetName)
}
case None => {
//target_name is missing from the kernel message so return all comms over every target
commStorage.getTargets().map(buildCommMap(_))
// target_name is missing from the kernel message so return all comms over every target
commStorage.getTargets().map(buildCommMap).reduce(_ ++ _)
}
}
val commInfoReply = CommInfoReply(commMap.asInstanceOf[Map[String, Map[String, String]]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.apache.toree.utils.LogLike
import play.api.libs.json.JsonValidationError
import play.api.libs.json.{JsPath, Json, Reads}

import scala.collection.mutable
import scala.concurrent.duration._

object Utilities extends LogLike {
Expand Down Expand Up @@ -77,15 +78,15 @@ object Utilities extends LogLike {
}

implicit def KernelMessageToZMQMessage(kernelMessage : KernelMessage) : ZMQMessage = {
var frames: Seq[ByteString] = Seq()
kernelMessage.ids.map((id : Array[Byte]) => frames = frames :+ ByteString.apply(id) )
frames = frames :+ "<IDS|MSG>"
frames = frames :+ kernelMessage.signature
frames = frames :+ Json.toJson(kernelMessage.header).toString()
frames = frames :+ Json.toJson(kernelMessage.parentHeader).toString()
frames = frames :+ Json.toJson(kernelMessage.metadata).toString
frames = frames :+ kernelMessage.contentString
ZMQMessage(frames : _*)
val frames: mutable.ListBuffer[ByteString] = mutable.ListBuffer()
kernelMessage.ids.map((id: Array[Byte]) => frames += ByteString.apply(id))
frames += "<IDS|MSG>"
frames += kernelMessage.signature
frames += Json.toJson(kernelMessage.header).toString()
frames += Json.toJson(kernelMessage.parentHeader).toString()
frames += Json.toJson(kernelMessage.metadata).toString
frames += kernelMessage.contentString
ZMQMessage(frames.toSeq : _*)
}

def parseAndHandle[T, U](json: String, reads: Reads[T],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class AddDeps extends LineMagic with IncludeInterpreter
} else {
(x, "*")
}
}: (String, String)).to(collection.Set)
}: (String, String)).toSet

val repositoriesWithCreds = dependencyDownloader.resolveRepositoriesAndCredentials(repository, credentials)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SocketConfigSpec extends AnyFunSpec with Matchers {
val CompleteRequestResults = socketConfigJson.validate[SocketConfig]

CompleteRequestResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: SocketConfig) => valid
) should be (socketConfig)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class KernelOuputStreamSpec
val message = kernelOutputRelayProbe
.receiveOne(MaxAkkaTestTimeout).asInstanceOf[KernelMessage]

message.ids(0).deep should equal (MessageType.Outgoing.Stream.toString.getBytes.deep)
message.ids.head.toIndexedSeq should equal (MessageType.Outgoing.Stream.toString.getBytes.toIndexedSeq)
}

it("should set the message type in the header of the kernel message to an execute_result") {
Expand Down
5 changes: 2 additions & 3 deletions kernel/src/test/scala/test/utils/DummyInterpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

package test.utils

import java.net.URL

import org.apache.toree.interpreter.Results.Result
import org.apache.toree.interpreter.{ExecuteFailure, ExecuteOutput, Interpreter, LanguageInfo}
import org.apache.toree.kernel.api.KernelLike

import scala.tools.nsc.interpreter.{InputStream, OutputStream}
import java.io.{InputStream, OutputStream}
import java.net.URL

class DummyInterpreter(kernel: KernelLike) extends Interpreter {
/**
Expand Down
4 changes: 3 additions & 1 deletion macros/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
*/
resolvers += Resolver.sonatypeRepo("releases")

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
if (scalaBinaryVersion.value == "2.12") {
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class PluginSearcher {
s"Failed to load class info from classpath: ${classFinder.classpath.mkString(",")}",
_: Throwable
))
val stream = tryStream.getOrElse(LazyList.empty)
ClassFinder.classInfoMap(stream.iterator)
val stream = tryStream.getOrElse(Stream.empty)
ClassFinder.classInfoMap(stream.toIterator)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.toree.plugins.dependencies

import java.net.URL
import java.lang.{ClassLoader => JClassLoader}

import scala.reflect.internal.util.ScalaClassLoader

object ClassLoaderHelper {

def URLClassLoader(urls: Seq[URL], parent: JClassLoader): ScalaClassLoader.URLClassLoader = {
new scala.reflect.internal.util.ScalaClassLoader.URLClassLoader(urls, parent)
}
}
8 changes: 4 additions & 4 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import scala.util.Properties
object Dependencies {

// Libraries

val akkaActor = "com.typesafe.akka" %% "akka-actor" % "2.7.0" // Apache v2
val akkaSlf4j = "com.typesafe.akka" %% "akka-slf4j" % "2.7.0" // Apache v2
val akkaTestkit = "com.typesafe.akka" %% "akka-testkit" % "2.7.0" // Apache v2
val akkaVersion = "2.6.21" // The latest version under Apache v2
val akkaActor = "com.typesafe.akka" %% "akka-actor" % akkaVersion // Apache v2
val akkaSlf4j = "com.typesafe.akka" %% "akka-slf4j" % akkaVersion // Apache v2
val akkaTestkit = "com.typesafe.akka" %% "akka-testkit" % akkaVersion // Apache v2

val clapper = "org.clapper" %% "classutil" % "1.5.1" // BSD 3-clause license, used for detecting plugins

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ package object v5 {
Map.empty
} else {
// triple quotes due https://github.com/scala/bug/issues/6476
kv.toMap.view.mapValues(v => Json.parse(s""""$v"""")).toMap
kv.toMap.mapValues(v => Json.parse(s""""$v"""")).toMap
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class HeaderSpec extends AnyFunSpec with Matchers {
val headerResults = headerJson.validate[Header]

headerResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: Header) => valid
) should be (header)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ClearOutputSpec extends AnyFunSpec with Matchers {
val CompleteRequestResults = clearOutputJson.validate[ClearOutput]

CompleteRequestResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: ClearOutput) => valid
) should be (clearOutput)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CommCloseSpec extends AnyFunSpec with Matchers {
val CompleteRequestResults = commCloseJson.validate[CommClose]

CompleteRequestResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: CommClose) => valid
) should be (commClose)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CommMsgSpec extends AnyFunSpec with Matchers {
val CompleteRequestResults = commMsgJson.validate[CommMsg]

CompleteRequestResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: CommMsg) => valid
) should be (commMsg)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CommOpenSpec extends AnyFunSpec with Matchers {
val CompleteRequestResults = commOpenJson.validate[CommOpen]

CompleteRequestResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: CommOpen) => valid
) should be (commOpen)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CompleteReplyErrorSpec extends AnyFunSpec with Matchers {
val CompleteReplyOkResults = completeReplyErrorJson.validate[CompleteReplyError]

CompleteReplyOkResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: CompleteReplyError) => valid
) should be (completeReplyError)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CompleteReplyOkSpec extends AnyFunSpec with Matchers {
val CompleteReplyOkResults = completeReplyOkJson.validate[CompleteReplyOk]

CompleteReplyOkResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: CompleteReplyOk) => valid
) should be (completeReplyOk)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CompleteReplySpec extends AnyFunSpec with Matchers {
val CompleteReplyResults = completeReplyJson.validate[CompleteReply]

CompleteReplyResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: CompleteReply) => valid
) should be (completeReply)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CompleteRequestSpec extends AnyFunSpec with Matchers {
val CompleteRequestResults = completeRequestJson.validate[CompleteRequest]

CompleteRequestResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: CompleteRequest) => valid
) should be (completeRequest)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ConnectReplySpec extends AnyFunSpec with Matchers {
val ConnectReplyResults = connectReplyJson.validate[ConnectReply]

ConnectReplyResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: ConnectReply) => valid
) should be (connectReply)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ConnectRequestSpec extends AnyFunSpec with Matchers {
val ConnectRequestResults = connectRequestJson.validate[ConnectRequest]

ConnectRequestResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: ConnectRequest) => valid
) should be (connectRequest)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DisplayDataSpec extends AnyFunSpec with Matchers {
val displayDataResults = displayDataJson.validate[DisplayData]

displayDataResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: DisplayData) => valid
) should be (displayData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ErrorContentSpec extends AnyFunSpec with Matchers {
val CompleteRequestResults = errorJson.validate[ErrorContent]

CompleteRequestResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: ErrorContent) => valid
) should be (error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ExecuteInputSpec extends AnyFunSpec with Matchers {
val executeInputResults = executeInputJson.validate[ExecuteInput]

executeInputResults.fold(
(invalid: Seq[(JsPath, Seq[JsonValidationError])]) => println("Failed!"),
(invalid: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) => println("Failed!"),
(valid: ExecuteInput) => valid
) should be (executeInput)
}
Expand Down
Loading

0 comments on commit 55a9098

Please sign in to comment.