提交 71ba8e3a 编写于 作者: B baratynskiy 提交者: Mikhail Glukhikh

Add tools.jar for command line compiler if -Xuse-javac is specified

上级 09e4ea55
......@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.preloading;
import org.jetbrains.kotlin.preloading.instrumentation.Instrumenter;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
......@@ -74,6 +75,13 @@ public class Preloader {
ClassLoader parent = Preloader.class.getClassLoader();
List<File> instrumenters = options.instrumenters;
if (options.arguments.contains("-Xuse-javac")) {
File toolsJar = getJdkToolsJar();
if (toolsJar != null) {
instrumenters.add(toolsJar);
}
}
if (instrumenters.isEmpty()) return parent;
URL[] classpath = new URL[instrumenters.size()];
......@@ -84,11 +92,35 @@ public class Preloader {
return new URLClassLoader(classpath, parent);
}
private static File getJdkToolsJar() {
try {
String javaHomePath = System.getProperty("java.home");
if (javaHomePath == null || javaHomePath.isEmpty()) {
return null;
}
File javaHome = new File(javaHomePath);
File toolsJar = new File(javaHome, "lib/tools.jar");
if (toolsJar.exists()) {
return toolsJar.getCanonicalFile();
}
// We might be inside jre.
if (javaHome.getName().equals("jre")) {
toolsJar = new File(javaHome.getParent(), "lib/tools.jar");
if (toolsJar.exists()) {
return toolsJar.getCanonicalFile();
}
}
} catch (IOException ignored) {}
return null;
}
@SuppressWarnings("AssignmentToForLoopParameter")
private static Options parseOptions(String[] args) throws Exception {
List<File> classpath = Collections.emptyList();
boolean measure = false;
List<File> instrumenters = Collections.emptyList();
List<File> instrumenters = new ArrayList<>();
int estimate = DEFAULT_CLASS_NUMBER_ESTIMATE;
String mainClass = null;
List<String> arguments = new ArrayList<>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册