Skip to content

Commit

Permalink
[FLINK-2767] [scala shell] Add Scala 2.11 support to Scala shell.
Browse files Browse the repository at this point in the history
Update Scala 2.11 version and jline dependency.

This closes apache#1197
  • Loading branch information
chiwanpark authored and fhueske committed Oct 7, 2015
1 parent a437a2b commit 8d62033
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 68 deletions.
29 changes: 6 additions & 23 deletions flink-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,33 +125,16 @@ under the License.
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala-shell</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

<!-- See main pom.xml for explanation of profiles -->
<profiles>
<profile>
<id>scala-2.10</id>
<activation>

<property>
<!-- this is the default scala profile -->
<name>!scala-2.11</name>
</property>
</activation>

<properties>
<scala.version>2.10.4</scala.version>
<scala.binary.version>2.10</scala.binary.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala-shell</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>include-yarn</id>
<activation>
Expand Down
13 changes: 7 additions & 6 deletions flink-staging/flink-scala-shell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ under the License.
<version>${scala.version}</version>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>jline</artifactId>
<version>2.10.4</version>
</dependency>

<!-- tests -->
<dependency>
<groupId>org.apache.flink</groupId>
Expand Down Expand Up @@ -180,6 +174,7 @@ under the License.
<configuration>
<sources>
<source>src/main/scala</source>
<source>src/main/scala-${scala.binary.version}</source>
</sources>
</configuration>
</execution>
Expand Down Expand Up @@ -274,6 +269,12 @@ under the License.
<artifactId>quasiquotes_${scala.binary.version}</artifactId>
<version>${scala.macros.version}</version>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>jline</artifactId>
<version>2.10.4</version>
</dependency>
</dependencies>
</profile>
</profiles>
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
*
* https://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.flink.api.scala

import java.io.BufferedReader

import _root_.scala.tools.nsc.interpreter._

class ILoopCompat(
in0: Option[BufferedReader],
out0: JPrintWriter)
extends ILoop(in0, out0) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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
*
* https://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.flink.api.scala

import java.io.BufferedReader

import _root_.scala.tools.nsc.interpreter._

class ILoopCompat(
in0: Option[BufferedReader],
out0: JPrintWriter)
extends ILoop(in0, out0) {

protected def addThunk(f: => Unit): Unit = f
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@ package org.apache.flink.api.scala

import java.io.{BufferedReader, File, FileOutputStream}

import scala.tools.nsc.interpreter._

import org.apache.flink.api.java.{JarHelper, ScalaShellRemoteEnvironment}
import org.apache.flink.util.AbstractID

import scala.tools.nsc.interpreter._


class FlinkILoop(
val host: String,
val port: Int,
val externalJars: Option[Array[String]],
in0: Option[BufferedReader],
out0: JPrintWriter)
extends ILoop(in0, out0) {



extends ILoopCompat(in0, out0) {

def this(host:String,
port:Int,
externalJars : Option[Array[String]],
Expand All @@ -51,6 +49,7 @@ class FlinkILoop(
def this(host: String, port: Int, in0: BufferedReader, out: JPrintWriter){
this(host: String, port: Int, None, in0: BufferedReader, out: JPrintWriter)
}

// remote environment
private val remoteEnv: ScalaShellRemoteEnvironment = {
// allow creation of environments
Expand All @@ -71,17 +70,6 @@ class FlinkILoop(
scalaEnv
}

addThunk {
intp.beQuietDuring {
// automatically imports the flink scala api
intp.addImports("org.apache.flink.api.scala._")
intp.addImports("org.apache.flink.api.common.functions._")
// with this we can access this object in the scala shell
intp.bindValue("env", this.scalaEnv)
}
}


/**
* creates a temporary directory to store compiled console files
*/
Expand All @@ -107,6 +95,24 @@ class FlinkILoop(
new File(tmpDirBase, "scala_shell_commands.jar")
}

private val packageImports = Seq[String](
"org.apache.flink.api.scala._",
"org.apache.flink.api.common.functions._"
)

override def createInterpreter(): Unit = {
super.createInterpreter()

addThunk {
intp.beQuietDuring {
// import dependencies
intp.interpret("import " + packageImports.mkString(", "))

// set execution environment
intp.bind("env", this.scalaEnv)
}
}
}

/**
* Packages the compiled classes of the current shell session into a Jar file for execution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

package org.apache.flink.api.scala


import scala.tools.nsc.Settings

import org.apache.flink.configuration.Configuration
import org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster

import scala.tools.nsc.Settings


object FlinkShell {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.io._
import java.util.concurrent.TimeUnit

import org.apache.flink.runtime.StreamingMode
import org.apache.flink.test.util.{ForkableFlinkMiniCluster, TestBaseUtils, TestEnvironment}
import org.apache.flink.test.util.{TestEnvironment, ForkableFlinkMiniCluster, TestBaseUtils}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfterAll, FunSuite, Matchers}
Expand Down
18 changes: 1 addition & 17 deletions flink-staging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ under the License.
<module>flink-ml</module>
<module>flink-language-binding</module>
<module>flink-gelly-scala</module>
<module>flink-scala-shell</module>
</modules>

<!-- See main pom.xml for explanation of profiles -->
Expand All @@ -71,22 +72,5 @@ under the License.
<module>flink-tez</module>
</modules>
</profile>
<profile>
<id>scala-2.10</id>
<activation>

<property>
<!-- this is the default scala profile -->
<name>!scala-2.11</name>
</property>
</activation>
<properties>
<scala.version>2.10.4</scala.version>
<scala.binary.version>2.10</scala.binary.version>
</properties>
<modules>
<module>flink-scala-shell</module>
</modules>
</profile>
</profiles>
</project>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ under the License.
</property>
</activation>
<properties>
<scala.version>2.11.4</scala.version>
<scala.version>2.11.7</scala.version>
<scala.binary.version>2.11</scala.binary.version>
</properties>
</profile>
Expand Down

0 comments on commit 8d62033

Please sign in to comment.