Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@

import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineTimeOutException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.StreamConsumer;
import org.codehaus.plexus.util.cli.*;

import static org.scalatest.tools.maven.MojoUtils.*;

import java.io.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;

import static java.util.Collections.singletonList;

import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.net.URL;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;

import static java.util.Collections.singletonList;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.scalatest.tools.maven.MojoUtils.*;

/**
* Provides the base for all mojos.
Expand Down Expand Up @@ -270,7 +260,7 @@ private boolean runForkingOnce(String[] args) throws MojoFailureException {

final Commandline cli = new Commandline();
cli.setWorkingDirectory(project.getBasedir());
cli.setExecutable("java");
cli.setExecutable(getJvm());

// Set up environment
if (environmentVariables != null) {
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/scalatest/tools/maven/MojoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.List;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;

import static org.apache.commons.lang3.StringUtils.isEmpty;

/**
* Provides internal utilities for the Mojo's operations.
Expand Down Expand Up @@ -121,4 +122,12 @@ static String[] concat(List<String>...lists){
}
return c.toArray(new String[c.size()]);
}

static String getJvm() {
if (!isEmpty(System.getProperty( "java.home" ))) {
return System.getProperty( "java.home" ) + File.separator + "bin" + File.separator + "java";
} else {
return "java";
}
}
}
32 changes: 32 additions & 0 deletions src/test/scala/org/scalatest/tools/maven/MojoUtilsTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.scalatest.tools.maven

import org.junit.{After, Before, Test}

class MojoUtilsTest {
private var savedJavaHome: Option[String] = _

@Before
def save(): Unit = {
savedJavaHome = Option(System.getProperty("java.home"))
}

@After
def restore(): Unit = {
savedJavaHome match {
case None => System.clearProperty("java.home")
case Some(value) => System.setProperty("java.home", value)
}
}

@Test
def getJvmHappyPath(): Unit = {
System.setProperty("java.home", "/test/jvm")
assert(MojoUtils.getJvm == "/test/jvm/bin/java")
}

@Test
def getJvmWithoutJavaHome(): Unit = {
System.clearProperty("java.home")
assert(MojoUtils.getJvm == "java")
}
}