Moved CompilerDependencies.findRtJar() method to PathUtil.
This commit is contained in:
@@ -84,7 +84,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// will be ignored later
|
// will be ignored later
|
||||||
CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), jdkAnnotationsJar, runtimeJar);
|
CompilerDependencies dependencies = new CompilerDependencies(mode, PathUtil.findRtJar(), jdkAnnotationsJar, runtimeJar);
|
||||||
|
|
||||||
final List<String> argumentsSourceDirs = arguments.getSourceDirs();
|
final List<String> argumentsSourceDirs = arguments.getSourceDirs();
|
||||||
if (!arguments.script &&
|
if (!arguments.script &&
|
||||||
@@ -212,7 +212,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
|||||||
private static List<File> getClasspath(@NotNull K2JVMCompilerArguments arguments) {
|
private static List<File> getClasspath(@NotNull K2JVMCompilerArguments arguments) {
|
||||||
List<File> classpath = Lists.newArrayList();
|
List<File> classpath = Lists.newArrayList();
|
||||||
if (!arguments.noJdk) {
|
if (!arguments.noJdk) {
|
||||||
classpath.add(CompilerDependencies.findRtJar());
|
classpath.add(PathUtil.findRtJar());
|
||||||
}
|
}
|
||||||
if (!arguments.noStdlib) {
|
if (!arguments.noStdlib) {
|
||||||
classpath.add(PathUtil.getDefaultRuntimePath());
|
classpath.add(PathUtil.getDefaultRuntimePath());
|
||||||
|
|||||||
+1
-29
@@ -102,36 +102,8 @@ public class CompilerDependencies {
|
|||||||
public static CompilerDependencies compilerDependenciesForProduction(@NotNull CompilerSpecialMode compilerSpecialMode) {
|
public static CompilerDependencies compilerDependenciesForProduction(@NotNull CompilerSpecialMode compilerSpecialMode) {
|
||||||
return new CompilerDependencies(
|
return new CompilerDependencies(
|
||||||
compilerSpecialMode,
|
compilerSpecialMode,
|
||||||
compilerSpecialMode.includeJdk() ? findRtJar() : null,
|
compilerSpecialMode.includeJdk() ? PathUtil.findRtJar() : null,
|
||||||
compilerSpecialMode.includeJdkAnnotations() ? PathUtil.getJdkAnnotationsPath() : null,
|
compilerSpecialMode.includeJdkAnnotations() ? PathUtil.getJdkAnnotationsPath() : null,
|
||||||
compilerSpecialMode.includeKotlinRuntime() ? PathUtil.getDefaultRuntimePath() : null);
|
compilerSpecialMode.includeKotlinRuntime() ? PathUtil.getDefaultRuntimePath() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File findRtJar() {
|
|
||||||
String javaHome = System.getProperty("java.home");
|
|
||||||
if ("jre".equals(new File(javaHome).getName())) {
|
|
||||||
javaHome = new File(javaHome).getParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
File rtJar = findRtJar(javaHome);
|
|
||||||
|
|
||||||
if (rtJar == null || !rtJar.exists()) {
|
|
||||||
throw new IllegalArgumentException("No JDK rt.jar found under " + javaHome);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File findRtJar(String javaHome) {
|
|
||||||
File rtJar = new File(javaHome, "jre/lib/rt.jar");
|
|
||||||
if (rtJar.exists()) {
|
|
||||||
return rtJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
File classesJar = new File(new File(javaHome).getParentFile().getAbsolutePath(), "Classes/classes.jar");
|
|
||||||
if (classesJar.exists()) {
|
|
||||||
return classesJar;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
|||||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -57,7 +58,7 @@ public class CompileCompilerDependenciesTest {
|
|||||||
public static CompilerDependencies compilerDependenciesForTests(@NotNull CompilerSpecialMode compilerSpecialMode, boolean mockJdk) {
|
public static CompilerDependencies compilerDependenciesForTests(@NotNull CompilerSpecialMode compilerSpecialMode, boolean mockJdk) {
|
||||||
return new CompilerDependencies(
|
return new CompilerDependencies(
|
||||||
compilerSpecialMode,
|
compilerSpecialMode,
|
||||||
compilerSpecialMode.includeJdk() ? (mockJdk ? JetTestUtils.findMockJdkRtJar() : CompilerDependencies.findRtJar()) : null,
|
compilerSpecialMode.includeJdk() ? (mockJdk ? JetTestUtils.findMockJdkRtJar() : PathUtil.findRtJar()) : null,
|
||||||
compilerSpecialMode.includeJdkAnnotations() ? ForTestPackJdkAnnotations.jdkAnnotationsForTests() : null,
|
compilerSpecialMode.includeJdkAnnotations() ? ForTestPackJdkAnnotations.jdkAnnotationsForTests() : null,
|
||||||
compilerSpecialMode.includeKotlinRuntime() ? ForTestCompileRuntime.runtimeJarForTests() : null);
|
compilerSpecialMode.includeKotlinRuntime() ? ForTestCompileRuntime.runtimeJarForTests() : null);
|
||||||
}
|
}
|
||||||
@@ -65,7 +66,7 @@ public class CompileCompilerDependenciesTest {
|
|||||||
public static CompilerConfiguration compilerConfigurationForTests(@NotNull CompilerSpecialMode compilerSpecialMode, boolean mockJdk) {
|
public static CompilerConfiguration compilerConfigurationForTests(@NotNull CompilerSpecialMode compilerSpecialMode, boolean mockJdk) {
|
||||||
List<File> classpath = new ArrayList<File>();
|
List<File> classpath = new ArrayList<File>();
|
||||||
if (compilerSpecialMode.includeJdk()) {
|
if (compilerSpecialMode.includeJdk()) {
|
||||||
classpath.add(mockJdk ? JetTestUtils.findMockJdkRtJar() : CompilerDependencies.findRtJar());
|
classpath.add(mockJdk ? JetTestUtils.findMockJdkRtJar() : PathUtil.findRtJar());
|
||||||
}
|
}
|
||||||
if (compilerSpecialMode.includeKotlinRuntime()) {
|
if (compilerSpecialMode.includeKotlinRuntime()) {
|
||||||
classpath.add(ForTestCompileRuntime.runtimeJarForTests());
|
classpath.add(ForTestCompileRuntime.runtimeJarForTests());
|
||||||
|
|||||||
+4
-3
@@ -36,6 +36,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
|
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
|
||||||
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -115,7 +116,7 @@ public class ResolveDescriptorsFromExternalLibraries {
|
|||||||
System.out.println("Using file " + jar);
|
System.out.println("Using file " + jar);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
jar = CompilerDependencies.findRtJar();
|
jar = PathUtil.findRtJar();
|
||||||
System.out.println("Using rt.jar: " + jar);
|
System.out.println("Using rt.jar: " + jar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,8 +155,8 @@ public class ResolveDescriptorsFromExternalLibraries {
|
|||||||
else {
|
else {
|
||||||
CompilerDependencies compilerDependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.STDLIB, false);
|
CompilerDependencies compilerDependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.STDLIB, false);
|
||||||
jetCoreEnvironment = JetCoreEnvironment.createCoreEnvironmentForJVM(junk, compilerDependencies);
|
jetCoreEnvironment = JetCoreEnvironment.createCoreEnvironmentForJVM(junk, compilerDependencies);
|
||||||
if (!CompilerDependencies.findRtJar().equals(jar)) {
|
if (!PathUtil.findRtJar().equals(jar)) {
|
||||||
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + CompilerDependencies.findRtJar());
|
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + PathUtil.findRtJar());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,4 +119,32 @@ public class PathUtil {
|
|||||||
throw new IllegalStateException("Path " + file + " does not exist.");
|
throw new IllegalStateException("Path " + file + " does not exist.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File findRtJar() {
|
||||||
|
String javaHome = System.getProperty("java.home");
|
||||||
|
if ("jre".equals(new File(javaHome).getName())) {
|
||||||
|
javaHome = new File(javaHome).getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
File rtJar = findRtJar(javaHome);
|
||||||
|
|
||||||
|
if (rtJar == null || !rtJar.exists()) {
|
||||||
|
throw new IllegalArgumentException("No JDK rt.jar found under " + javaHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rtJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File findRtJar(String javaHome) {
|
||||||
|
File rtJar = new File(javaHome, "jre/lib/rt.jar");
|
||||||
|
if (rtJar.exists()) {
|
||||||
|
return rtJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
File classesJar = new File(new File(javaHome).getParentFile().getAbsolutePath(), "Classes/classes.jar");
|
||||||
|
if (classesJar.exists()) {
|
||||||
|
return classesJar;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user