test also looks for Java under JAVA_HOME
This commit is contained in:
@@ -88,6 +88,34 @@ public class CompileEnvironment {
|
|||||||
myEnvironment.addToClasspath(rtJarPath);
|
myEnvironment.addToClasspath(rtJarPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File findRtJar(boolean failOnError) {
|
||||||
|
String javaHome = System.getenv("JAVA_HOME");
|
||||||
|
File rtJar;
|
||||||
|
if (javaHome == null) {
|
||||||
|
rtJar = findActiveRtJar(failOnError);
|
||||||
|
|
||||||
|
if(rtJar == null && failOnError) {
|
||||||
|
throw new CompileEnvironmentException("JAVA_HOME environment variable needs to be defined");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rtJar = findRtJar(javaHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((rtJar == null || !rtJar.exists()) && failOnError) {
|
||||||
|
throw new CompileEnvironmentException("No rt.jar found under JAVA_HOME=" + javaHome);
|
||||||
|
}
|
||||||
|
return rtJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File findRtJar(String javaHome) {
|
||||||
|
File rtJar = new File(javaHome, "jre/lib/rt.jar");
|
||||||
|
if (rtJar.exists()) {
|
||||||
|
return rtJar;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static File findActiveRtJar(boolean failOnError) {
|
public static File findActiveRtJar(boolean failOnError) {
|
||||||
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
|
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
|
||||||
if (systemClassLoader instanceof URLClassLoader) {
|
if (systemClassLoader instanceof URLClassLoader) {
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import com.sampullara.cli.Argument;
|
|||||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||||
import org.jetbrains.jet.compiler.CompileEnvironmentException;
|
import org.jetbrains.jet.compiler.CompileEnvironmentException;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yole
|
* @author yole
|
||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
@@ -38,11 +36,8 @@ public class KotlinCompiler {
|
|||||||
|
|
||||||
CompileEnvironment environment = new CompileEnvironment();
|
CompileEnvironment environment = new CompileEnvironment();
|
||||||
|
|
||||||
File rtJar = initJdk();
|
|
||||||
if (rtJar == null) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
environment.setJavaRuntime(rtJar);
|
environment.setJavaRuntime(CompileEnvironment.findRtJar(true));
|
||||||
if (!environment.initializeKotlinRuntime()) {
|
if (!environment.initializeKotlinRuntime()) {
|
||||||
System.out.println("No runtime library found");
|
System.out.println("No runtime library found");
|
||||||
return;
|
return;
|
||||||
@@ -60,33 +55,4 @@ public class KotlinCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File initJdk() {
|
|
||||||
String javaHome = System.getenv("JAVA_HOME");
|
|
||||||
File rtJar;
|
|
||||||
if (javaHome == null) {
|
|
||||||
rtJar = CompileEnvironment.findActiveRtJar(false);
|
|
||||||
|
|
||||||
if(rtJar == null) {
|
|
||||||
System.out.println("JAVA_HOME environment variable needs to be defined");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
rtJar = findRtJar(javaHome);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rtJar == null || !rtJar.exists()) {
|
|
||||||
System.out.print("No rt.jar found under JAVA_HOME=" + javaHome);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return rtJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File findRtJar(String javaHome) {
|
|
||||||
File rtJar = new File(javaHome, "jre/lib/rt.jar");
|
|
||||||
if (rtJar.exists()) {
|
|
||||||
return rtJar;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class CompileEnvironmentTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testSmoke() {
|
public void testSmoke() {
|
||||||
final File activeRtJar = CompileEnvironment.findActiveRtJar(true);
|
final File activeRtJar = CompileEnvironment.findRtJar(true);
|
||||||
environment.setJavaRuntime(activeRtJar);
|
environment.setJavaRuntime(activeRtJar);
|
||||||
environment.initializeKotlinRuntime();
|
environment.initializeKotlinRuntime();
|
||||||
final String testDataDir = JetParsingTest.getTestDataDir() + "/compiler/smoke/";
|
final String testDataDir = JetParsingTest.getTestDataDir() + "/compiler/smoke/";
|
||||||
|
|||||||
Reference in New Issue
Block a user