Skip to content

Commit 673f7ac

Browse files
committed
Added support for -java-home as well
1 parent 80a13e8 commit 673f7ac

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

extras/java8-tests/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
These tests are bundled with spark and run if you have java 8 installed as system default or your `JAVA_HOME` points to a java 8(or higher) installation. `JAVA_HOME` is preferred to system default jdk installation. Since these tests require jdk 8 or higher, they defined to be optional to run in the build system.
44

5-
For sbt users, it automatically detects the presence of java 8 based on either `JAVA_HOME` environment variable or default installed jdk and run these tests.
5+
* For sbt users, it automatically detects the presence of java 8 based on either `JAVA_HOME` environment variable or default installed jdk and run these tests. It takes highest precednce, if java home is passed as follows.
66

7-
For maven users,
7+
`$ sbt/sbt -java-home "/path/to/jdk1.8.0"`
88

9-
This automatic detection is not possible and thus user has to ensure that either `JAVA_HOME` environment variable or default installed jdk points to jdk 8.
9+
* For maven users,
1010

11-
`$ mvn install -Pjava8-tests`
11+
This automatic detection is not possible and thus user has to ensure that either `JAVA_HOME` environment variable or default installed jdk points to jdk 8.
1212

13-
Above command can only be run from project root directory since this module depends on both core and test-jars of core and streaming. These jars are installed first time the above command is run as java8-tests profile enables local publishing of test-jar artifacts as well. Once these artifacts are published then these tests can be run from this module's directory as well.
13+
`$ mvn install -Pjava8-tests`
14+
15+
Above command can only be run from project root directory since this module depends on both core and test-jars of core and streaming. These jars are installed first time the above command is run as java8-tests profile enables local publishing of test-jar artifacts as well. Once these artifacts are published then these tests can be run from this module's directory as well.

extras/java8-tests/src/test/java/org/apache/spark/Java8APISuite.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ public void tearDown() {
6060
System.clearProperty("spark.driver.port");
6161
}
6262

63+
@Test
64+
public void foreachWithAnonymousClass() {
65+
foreachCalls = 0;
66+
JavaRDD<String> rdd = sc.parallelize(Arrays.asList("Hello", "World"));
67+
rdd.foreach(new VoidFunction<String>() {
68+
@Override
69+
public void call(String s) {
70+
foreachCalls++;
71+
}
72+
});
73+
Assert.assertEquals(2, foreachCalls);
74+
}
75+
6376
@Test
6477
public void foreach() {
6578
foreachCalls = 0;

project/SparkBuild.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ object SparkBuild extends Build {
9898
lazy val java8Tests = Project("java8-tests", file("extras/java8-tests"), settings = java8TestsSettings).
9999
dependsOn(core) dependsOn(streaming % "compile->compile;test->test")
100100

101-
val javaHomeEnv = Properties.envOrNone("JAVA_HOME").map(file)
102-
103101
// Conditionally include the yarn sub-project
104102
lazy val yarnAlpha = Project("yarn-alpha", file("yarn/alpha"), settings = yarnAlphaSettings) dependsOn(core)
105103
lazy val yarn = Project("yarn", file("yarn/stable"), settings = yarnSettings) dependsOn(core)
@@ -143,7 +141,7 @@ object SparkBuild extends Build {
143141
javacOptions := Seq("-target", JAVAC_JVM_VERSION, "-source", JAVAC_JVM_VERSION),
144142
unmanagedJars in Compile <<= baseDirectory map { base => (base / "lib" ** "*.jar").classpath },
145143
retrieveManaged := true,
146-
if (javaHomeEnv.isDefined) javaHome := javaHomeEnv else javaHome <<= javaHome in Compile,
144+
javaHome := Properties.envOrNone("JAVA_HOME").map(file),
147145
// This is to add convenience of enabling sbt -Dsbt.offline=true for making the build offline.
148146
offline := "true".equalsIgnoreCase(sys.props("sbt.offline")),
149147
retrievePattern := "[type]s/[artifact](-[revision])(-[classifier]).[ext]",

sbt/sbt-launch-lib.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ process_args () {
137137

138138
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
139139
-sbt-version) require_arg version "$1" "$2" && sbt_version="$2" && shift 2 ;;
140-
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
140+
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && export JAVA_HOME=$2 && shift 2 ;;
141141

142142
-D*) addJava "$1" && shift ;;
143143
-J*) addJava "${1:2}" && shift ;;

0 commit comments

Comments
 (0)