Moved CompilerDependencies.findRtJar() method to PathUtil.

This commit is contained in:
Evgeny Gerashchenko
2012-07-04 15:27:10 +04:00
parent 701ddc6376
commit c833ca251f
5 changed files with 38 additions and 36 deletions
@@ -84,7 +84,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
}
// 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();
if (!arguments.script &&
@@ -212,7 +212,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
private static List<File> getClasspath(@NotNull K2JVMCompilerArguments arguments) {
List<File> classpath = Lists.newArrayList();
if (!arguments.noJdk) {
classpath.add(CompilerDependencies.findRtJar());
classpath.add(PathUtil.findRtJar());
}
if (!arguments.noStdlib) {
classpath.add(PathUtil.getDefaultRuntimePath());
@@ -102,36 +102,8 @@ public class CompilerDependencies {
public static CompilerDependencies compilerDependenciesForProduction(@NotNull CompilerSpecialMode compilerSpecialMode) {
return new CompilerDependencies(
compilerSpecialMode,
compilerSpecialMode.includeJdk() ? findRtJar() : null,
compilerSpecialMode.includeJdk() ? PathUtil.findRtJar() : null,
compilerSpecialMode.includeJdkAnnotations() ? PathUtil.getJdkAnnotationsPath() : 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.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.utils.PathUtil;
import org.junit.Test;
import java.io.File;
@@ -57,7 +58,7 @@ public class CompileCompilerDependenciesTest {
public static CompilerDependencies compilerDependenciesForTests(@NotNull CompilerSpecialMode compilerSpecialMode, boolean mockJdk) {
return new CompilerDependencies(
compilerSpecialMode,
compilerSpecialMode.includeJdk() ? (mockJdk ? JetTestUtils.findMockJdkRtJar() : CompilerDependencies.findRtJar()) : null,
compilerSpecialMode.includeJdk() ? (mockJdk ? JetTestUtils.findMockJdkRtJar() : PathUtil.findRtJar()) : null,
compilerSpecialMode.includeJdkAnnotations() ? ForTestPackJdkAnnotations.jdkAnnotationsForTests() : null,
compilerSpecialMode.includeKotlinRuntime() ? ForTestCompileRuntime.runtimeJarForTests() : null);
}
@@ -65,7 +66,7 @@ public class CompileCompilerDependenciesTest {
public static CompilerConfiguration compilerConfigurationForTests(@NotNull CompilerSpecialMode compilerSpecialMode, boolean mockJdk) {
List<File> classpath = new ArrayList<File>();
if (compilerSpecialMode.includeJdk()) {
classpath.add(mockJdk ? JetTestUtils.findMockJdkRtJar() : CompilerDependencies.findRtJar());
classpath.add(mockJdk ? JetTestUtils.findMockJdkRtJar() : PathUtil.findRtJar());
}
if (compilerSpecialMode.includeKotlinRuntime()) {
classpath.add(ForTestCompileRuntime.runtimeJarForTests());
@@ -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.CompilerSpecialMode;
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
import org.jetbrains.jet.utils.PathUtil;
import java.io.File;
import java.io.FileInputStream;
@@ -115,7 +116,7 @@ public class ResolveDescriptorsFromExternalLibraries {
System.out.println("Using file " + jar);
}
else {
jar = CompilerDependencies.findRtJar();
jar = PathUtil.findRtJar();
System.out.println("Using rt.jar: " + jar);
}
@@ -154,8 +155,8 @@ public class ResolveDescriptorsFromExternalLibraries {
else {
CompilerDependencies compilerDependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.STDLIB, false);
jetCoreEnvironment = JetCoreEnvironment.createCoreEnvironmentForJVM(junk, compilerDependencies);
if (!CompilerDependencies.findRtJar().equals(jar)) {
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + CompilerDependencies.findRtJar());
if (!PathUtil.findRtJar().equals(jar)) {
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + PathUtil.findRtJar());
}
}
@@ -119,4 +119,32 @@ public class PathUtil {
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;
}
}