Add tools.jar for command line compiler if -Xuse-javac is specified
This commit is contained in:
committed by
Mikhail Glukhikh
parent
09e4ea55c7
commit
71ba8e3ad0
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.preloading;
|
|||||||
import org.jetbrains.kotlin.preloading.instrumentation.Instrumenter;
|
import org.jetbrains.kotlin.preloading.instrumentation.Instrumenter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@@ -74,6 +75,13 @@ public class Preloader {
|
|||||||
ClassLoader parent = Preloader.class.getClassLoader();
|
ClassLoader parent = Preloader.class.getClassLoader();
|
||||||
|
|
||||||
List<File> instrumenters = options.instrumenters;
|
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;
|
if (instrumenters.isEmpty()) return parent;
|
||||||
|
|
||||||
URL[] classpath = new URL[instrumenters.size()];
|
URL[] classpath = new URL[instrumenters.size()];
|
||||||
@@ -84,11 +92,35 @@ public class Preloader {
|
|||||||
return new URLClassLoader(classpath, parent);
|
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")
|
@SuppressWarnings("AssignmentToForLoopParameter")
|
||||||
private static Options parseOptions(String[] args) throws Exception {
|
private static Options parseOptions(String[] args) throws Exception {
|
||||||
List<File> classpath = Collections.emptyList();
|
List<File> classpath = Collections.emptyList();
|
||||||
boolean measure = false;
|
boolean measure = false;
|
||||||
List<File> instrumenters = Collections.emptyList();
|
List<File> instrumenters = new ArrayList<>();
|
||||||
int estimate = DEFAULT_CLASS_NUMBER_ESTIMATE;
|
int estimate = DEFAULT_CLASS_NUMBER_ESTIMATE;
|
||||||
String mainClass = null;
|
String mainClass = null;
|
||||||
List<String> arguments = new ArrayList<>();
|
List<String> arguments = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user