File tree Expand file tree Collapse file tree 3 files changed +41
-14
lines changed
main/java/org/scalatest/tools/maven
test/scala/org/scalatest/tools/maven Expand file tree Collapse file tree 3 files changed +41
-14
lines changed Original file line number Diff line number Diff line change @@ -319,19 +319,6 @@ public void consumeLine(final String line) {
319
319
}
320
320
}
321
321
322
- private String getJvm ()
323
- {
324
- // use the same JVM as the one used to run Maven (the "java.home" one)
325
- String jvmToUse = System .getProperty ( "java.home" ) + File .separator + "bin" + File .separator + "java" ;
326
-
327
- if (isEmpty (jvmToUse )) {
328
- jvmToUse = "java" ;
329
- }
330
-
331
- getLog ().debug ( "Using JVM: " + jvmToUse );
332
- return jvmToUse ;
333
- }
334
-
335
322
private String buildClassPathEnvironment () {
336
323
StringBuffer buf = new StringBuffer ();
337
324
boolean first = true ;
Original file line number Diff line number Diff line change 3
3
import java .util .List ;
4
4
import java .util .ArrayList ;
5
5
import java .io .File ;
6
- import java .io .IOException ;
6
+
7
+ import static org .apache .commons .lang3 .StringUtils .isEmpty ;
7
8
8
9
/**
9
10
* Provides internal utilities for the Mojo's operations.
@@ -121,4 +122,12 @@ static String[] concat(List<String>...lists){
121
122
}
122
123
return c .toArray (new String [c .size ()]);
123
124
}
125
+
126
+ static String getJvm () {
127
+ if (!isEmpty (System .getProperty ( "java.home" ))) {
128
+ return System .getProperty ( "java.home" ) + File .separator + "bin" + File .separator + "java" ;
129
+ } else {
130
+ return "java" ;
131
+ }
132
+ }
124
133
}
Original file line number Diff line number Diff line change
1
+ package org .scalatest .tools .maven
2
+
3
+ import org .junit .{Before , Test }
4
+
5
+ class MojoUtilsTest {
6
+ private var savedJavaHome : Option [String ] = _
7
+
8
+ @ Before
9
+ def save () = {
10
+ savedJavaHome = Option (System .getProperty(" java.home" ))
11
+ }
12
+
13
+ def restore () = {
14
+ savedJavaHome match {
15
+ case None => System .clearProperty(" java.home" )
16
+ case Some (value) => System .setProperty(" java.home" , value)
17
+ }
18
+ }
19
+
20
+ @ Test
21
+ def getJvmHappyPath () = {
22
+ System .setProperty(" java.home" , " /test/jvm" )
23
+ assert(MojoUtils .getJvm == " /test/jvm/bin/java" )
24
+ }
25
+
26
+ @ Test
27
+ def getJvmWithoutJavaHome () = {
28
+ System .clearProperty(" java.home" )
29
+ assert(MojoUtils .getJvm == " java" )
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments