diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java index 4f8f6ef7506..061fde50f86 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java @@ -93,7 +93,7 @@ public class K2JVMCompiler extends CLICompiler 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 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(); } } diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java index a67cbbb8736..9c201dfe3af 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java @@ -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 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("")); @@ -110,16 +111,13 @@ public class ReplInterpreter { List 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]))); diff --git a/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java b/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java index f720cb232d4..05db2da5630 100644 --- a/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java +++ b/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java @@ -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 classpath = new ArrayList(); + 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; + } } diff --git a/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTest.java b/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTest.java index 11465c66033..a2b8b814b8b 100644 --- a/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTest.java +++ b/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTest.java @@ -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()) {