Got rid of actual using CompilerDependencies in REPL interpreter classes.
This commit is contained in:
@@ -93,7 +93,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
||||
arguments.freeArgs.isEmpty() &&
|
||||
(argumentsSourceDirs == null || argumentsSourceDirs.size() == 0)) {
|
||||
|
||||
ReplFromTerminal.run(rootDisposable, dependencies, getClasspath(arguments));
|
||||
ReplFromTerminal.run(rootDisposable, dependencies, createCompilerConfiguration(arguments));
|
||||
return ExitCode.OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import jline.console.ConsoleReader;
|
||||
import jline.console.history.FileHistory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -44,12 +44,12 @@ public class ReplFromTerminal {
|
||||
public ReplFromTerminal(
|
||||
@NotNull final Disposable disposable,
|
||||
@NotNull final CompilerDependencies compilerDependencies,
|
||||
@NotNull final List<File> extraClasspath) {
|
||||
@NotNull final CompilerConfiguration compilerConfiguration) {
|
||||
new Thread("initialize-repl") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
replInterpreter = new ReplInterpreter(disposable, compilerDependencies, extraClasspath);
|
||||
replInterpreter = new ReplInterpreter(disposable, compilerDependencies, compilerConfiguration);
|
||||
} catch (Throwable e) {
|
||||
replInitializationFailed = e;
|
||||
}
|
||||
@@ -195,8 +195,9 @@ public class ReplFromTerminal {
|
||||
return Arrays.asList(command.split(" "));
|
||||
}
|
||||
|
||||
public static void run(@NotNull Disposable disposable, @NotNull CompilerDependencies compilerDependencies, @NotNull List<File> extraClasspath) {
|
||||
new ReplFromTerminal(disposable, compilerDependencies, extraClasspath).doRun();
|
||||
public static void run(@NotNull Disposable disposable, @NotNull CompilerDependencies compilerDependencies,
|
||||
@NotNull CompilerConfiguration compilerConfiguration) {
|
||||
new ReplFromTerminal(disposable, compilerDependencies, compilerConfiguration).doRun();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,10 +33,12 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollectorToString;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderFactories;
|
||||
import org.jetbrains.jet.codegen.CompilationErrorHandler;
|
||||
import org.jetbrains.jet.codegen.GenerationState;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorImpl;
|
||||
@@ -65,6 +67,7 @@ import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Collections;
|
||||
@@ -91,12 +94,10 @@ public class ReplInterpreter {
|
||||
@NotNull
|
||||
private final ModuleDescriptor module;
|
||||
|
||||
public ReplInterpreter(@NotNull Disposable disposable, @NotNull CompilerDependencies compilerDependencies, @NotNull List<File> extraClasspath) {
|
||||
// TODO: add extraClasspath to jetCoreEnvironment
|
||||
public ReplInterpreter(@NotNull Disposable disposable, @NotNull CompilerDependencies compilerDependencies,
|
||||
@NotNull CompilerConfiguration configuration) {
|
||||
jetCoreEnvironment = new JetCoreEnvironment(disposable, compilerDependencies);
|
||||
for (File pathElement : extraClasspath) {
|
||||
jetCoreEnvironment.addToClasspath(pathElement);
|
||||
}
|
||||
jetCoreEnvironment.configure(configuration);
|
||||
Project project = jetCoreEnvironment.getProject();
|
||||
trace = new BindingTraceContext();
|
||||
module = new ModuleDescriptor(Name.special("<repl>"));
|
||||
@@ -110,16 +111,13 @@ public class ReplInterpreter {
|
||||
|
||||
List<URL> classpath = Lists.newArrayList();
|
||||
|
||||
try {
|
||||
if (compilerDependencies.getRuntimeJar() != null) {
|
||||
classpath.add(compilerDependencies.getRuntimeJar().toURI().toURL());
|
||||
for (File file : configuration.getUserData(JVMConfigurationKeys.CLASSPATH_KEY)) {
|
||||
try {
|
||||
classpath.add(file.toURI().toURL());
|
||||
}
|
||||
|
||||
for (File extra : extraClasspath) {
|
||||
classpath.add(extra.toURI().toURL());
|
||||
catch (MalformedURLException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
|
||||
classLoader = new ReplClassLoader(new URLClassLoader(classpath.toArray(new URL[0])));
|
||||
|
||||
@@ -17,13 +17,19 @@
|
||||
package org.jetbrains.jet;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileBuiltins;
|
||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestPackJdkAnnotations;
|
||||
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.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
@@ -55,4 +61,23 @@ public class CompileCompilerDependenciesTest {
|
||||
compilerSpecialMode.includeJdkAnnotations() ? ForTestPackJdkAnnotations.jdkAnnotationsForTests() : null,
|
||||
compilerSpecialMode.includeKotlinRuntime() ? ForTestCompileRuntime.runtimeJarForTests() : null);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
if (compilerSpecialMode.includeKotlinRuntime()) {
|
||||
classpath.add(ForTestCompileRuntime.runtimeJarForTests());
|
||||
}
|
||||
File[] annotationsPath = new File[0];
|
||||
if (compilerSpecialMode.includeJdkAnnotations()) {
|
||||
annotationsPath = new File[]{ForTestPackJdkAnnotations.jdkAnnotationsForTests()};
|
||||
}
|
||||
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
configuration.putUserData(JVMConfigurationKeys.CLASSPATH_KEY, classpath.toArray(new File[classpath.size()]));
|
||||
configuration.putUserData(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, annotationsPath);
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,12 @@ package org.jetbrains.jet.repl;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.CompileCompilerDependenciesTest;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.repl.ReplInterpreter;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import org.junit.After;
|
||||
@@ -29,7 +32,6 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
@@ -53,7 +55,12 @@ public class ReplInterpreterTest {
|
||||
|
||||
private void testFile(@NotNull String relativePath) {
|
||||
CompilerDependencies compilerDependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.JDK_HEADERS, false);
|
||||
ReplInterpreter repl = new ReplInterpreter(disposable, compilerDependencies, Collections.singletonList(new File("out/production/runtime")));
|
||||
CompilerConfiguration configuration =
|
||||
CompileCompilerDependenciesTest.compilerConfigurationForTests(CompilerSpecialMode.JDK_HEADERS, false);
|
||||
File[] classpath = configuration.getUserData(JVMConfigurationKeys.CLASSPATH_KEY);
|
||||
assert classpath != null;
|
||||
configuration.putUserData(JVMConfigurationKeys.CLASSPATH_KEY, ArrayUtil.append(classpath, new File("out/production/runtime")));
|
||||
ReplInterpreter repl = new ReplInterpreter(disposable, compilerDependencies, configuration);
|
||||
|
||||
ReplSessionTestFile file = ReplSessionTestFile.load(new File("compiler/testData/repl/" + relativePath));
|
||||
for (ReplSessionTestFile.OneLine t : file.getLines()) {
|
||||
|
||||
Reference in New Issue
Block a user