Got rid of actual using compiler dependencies in some classes (using only mode). Affected classes: K2JVMCompiler, KotlinToJVMBytecodeCompiler, TestlibTest.
Got rid of actual using compiler dependencies in KotlinToJVMBytecodeCompiler. Got rid of actual using compiler dependencies in TestlibTest.
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.jet.cli.jvm;
|
package org.jetbrains.jet.cli.jvm;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import jet.modules.Module;
|
import jet.modules.Module;
|
||||||
@@ -31,6 +30,7 @@ import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
|
|||||||
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||||
import org.jetbrains.jet.cli.jvm.repl.ReplFromTerminal;
|
import org.jetbrains.jet.cli.jvm.repl.ReplFromTerminal;
|
||||||
import org.jetbrains.jet.codegen.CompilationException;
|
import org.jetbrains.jet.codegen.CompilationException;
|
||||||
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
import org.jetbrains.jet.utils.PathUtil;
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
@@ -83,6 +83,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
|||||||
runtimeJar = null;
|
runtimeJar = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// will be ignored later
|
||||||
CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), jdkAnnotationsJar, runtimeJar);
|
CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), jdkAnnotationsJar, runtimeJar);
|
||||||
|
|
||||||
final List<String> argumentsSourceDirs = arguments.getSourceDirs();
|
final List<String> argumentsSourceDirs = arguments.getSourceDirs();
|
||||||
@@ -196,26 +197,26 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
|||||||
protected void configureEnvironment(@NotNull K2JVMCompileEnvironmentConfiguration configuration, @NotNull K2JVMCompilerArguments arguments) {
|
protected void configureEnvironment(@NotNull K2JVMCompileEnvironmentConfiguration configuration, @NotNull K2JVMCompilerArguments arguments) {
|
||||||
super.configureEnvironment(configuration, arguments);
|
super.configureEnvironment(configuration, arguments);
|
||||||
|
|
||||||
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
|
configuration.getEnvironment().configure(createCompilerConfiguration(arguments));
|
||||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(),
|
}
|
||||||
configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arguments.classpath != null) {
|
@NotNull
|
||||||
List<File> classpath = getClasspath(arguments);
|
private static CompilerConfiguration createCompilerConfiguration(@NotNull K2JVMCompilerArguments arguments) {
|
||||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, File.class));
|
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||||
}
|
configuration.putUserData(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(arguments).toArray(new File[0]));
|
||||||
|
configuration.putUserData(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, getAnnotationsPath(arguments).toArray(new File[0]));
|
||||||
if (arguments.annotations != null) {
|
return configuration;
|
||||||
for (String root : Splitter.on(File.pathSeparatorChar).split(arguments.annotations)) {
|
|
||||||
configuration.getEnvironment().addExternalAnnotationsRoot(PathUtil.jarFileOrDirectoryToVirtualFile(new File(root)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<File> getClasspath(@NotNull K2JVMCompilerArguments arguments) {
|
private static List<File> getClasspath(@NotNull K2JVMCompilerArguments arguments) {
|
||||||
List<File> classpath = Lists.newArrayList();
|
List<File> classpath = Lists.newArrayList();
|
||||||
|
if (!arguments.noJdk) {
|
||||||
|
classpath.add(CompilerDependencies.findRtJar());
|
||||||
|
}
|
||||||
|
if (!arguments.noStdlib) {
|
||||||
|
classpath.add(PathUtil.getDefaultRuntimePath());
|
||||||
|
}
|
||||||
if (arguments.classpath != null) {
|
if (arguments.classpath != null) {
|
||||||
for (String element : Splitter.on(File.pathSeparatorChar).split(arguments.classpath)) {
|
for (String element : Splitter.on(File.pathSeparatorChar).split(arguments.classpath)) {
|
||||||
classpath.add(new File(element));
|
classpath.add(new File(element));
|
||||||
@@ -223,4 +224,18 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
|||||||
}
|
}
|
||||||
return classpath;
|
return classpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static List<File> getAnnotationsPath(@NotNull K2JVMCompilerArguments arguments) {
|
||||||
|
List<File> annotationsPath = Lists.newArrayList();
|
||||||
|
if (!arguments.noJdkAnnotations) {
|
||||||
|
annotationsPath.add(PathUtil.getJdkAnnotationsPath());
|
||||||
|
}
|
||||||
|
if (arguments.annotations != null) {
|
||||||
|
for (String element : Splitter.on(File.pathSeparatorChar).split(arguments.classpath)) {
|
||||||
|
annotationsPath.add(new File(element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return annotationsPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import com.intellij.psi.PsiFile;
|
|||||||
import com.intellij.psi.PsiManager;
|
import com.intellij.psi.PsiManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.asJava.JavaElementFinder;
|
import org.jetbrains.jet.asJava.JavaElementFinder;
|
||||||
|
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||||
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
import org.jetbrains.jet.lang.parsing.JetParser;
|
import org.jetbrains.jet.lang.parsing.JetParser;
|
||||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
@@ -37,6 +39,7 @@ import org.jetbrains.jet.lang.resolve.java.extAnnotations.CoreAnnotationsProvide
|
|||||||
import org.jetbrains.jet.lang.resolve.java.extAnnotations.ExternalAnnotationsProvider;
|
import org.jetbrains.jet.lang.resolve.java.extAnnotations.ExternalAnnotationsProvider;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -189,4 +192,16 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
|||||||
public CompilerDependencies getCompilerDependencies() {
|
public CompilerDependencies getCompilerDependencies() {
|
||||||
return compilerDependencies;
|
return compilerDependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void configure(@NotNull CompilerConfiguration compilerConfiguration) {
|
||||||
|
File[] classpath = compilerConfiguration.getUserData(JVMConfigurationKeys.CLASSPATH_KEY);
|
||||||
|
File[] annotationsPath = compilerConfiguration.getUserData(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY);
|
||||||
|
assert classpath != null && annotationsPath != null;
|
||||||
|
for (File path : classpath) {
|
||||||
|
addToClasspath(path);
|
||||||
|
}
|
||||||
|
for (File path : annotationsPath) {
|
||||||
|
addExternalAnnotationsRoot(PathUtil.jarFileOrDirectoryToVirtualFile(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -19,6 +19,7 @@ package org.jetbrains.jet.cli.jvm.compiler;
|
|||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.testFramework.LightVirtualFile;
|
import com.intellij.testFramework.LightVirtualFile;
|
||||||
import com.intellij.util.LocalTimeCounter;
|
import com.intellij.util.LocalTimeCounter;
|
||||||
@@ -36,6 +37,7 @@ import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
|||||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
@@ -100,11 +102,6 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
boolean jarRuntime) {
|
boolean jarRuntime) {
|
||||||
|
|
||||||
for (Module moduleBuilder : modules) {
|
for (Module moduleBuilder : modules) {
|
||||||
// TODO: this should be done only once for the environment
|
|
||||||
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
|
|
||||||
CompileEnvironmentUtil
|
|
||||||
.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
|
||||||
}
|
|
||||||
ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
|
ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
|
||||||
if (moduleFactory == null) {
|
if (moduleFactory == null) {
|
||||||
return false;
|
return false;
|
||||||
@@ -210,7 +207,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
try {
|
try {
|
||||||
GeneratedClassLoader classLoader = new GeneratedClassLoader(factory, new URLClassLoader(new URL[]{
|
GeneratedClassLoader classLoader = new GeneratedClassLoader(factory, new URLClassLoader(new URL[]{
|
||||||
// TODO: add all classpath
|
// TODO: add all classpath
|
||||||
configuration.getEnvironment().getCompilerDependencies().getRuntimeJar().toURI().toURL()
|
PathUtil.getDefaultRuntimePath().toURI().toURL()
|
||||||
},
|
},
|
||||||
AllModules.class.getClassLoader()));
|
AllModules.class.getClassLoader()));
|
||||||
Class<?> scriptClass = classLoader.loadClass(ScriptCodegen.SCRIPT_DEFAULT_CLASS_NAME.getFqName().getFqName());
|
Class<?> scriptClass = classLoader.loadClass(ScriptCodegen.SCRIPT_DEFAULT_CLASS_NAME.getFqName().getFqName());
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class TestlibTest extends CodegenTestCase {
|
|||||||
|
|
||||||
myEnvironment.addToClasspath(junitJar);
|
myEnvironment.addToClasspath(junitJar);
|
||||||
|
|
||||||
myEnvironment.addToClasspath(myEnvironment.getCompilerDependencies().getRuntimeJar());
|
myEnvironment.addToClasspath(ForTestCompileRuntime.runtimeJarForTests());
|
||||||
|
|
||||||
CoreLocalFileSystem localFileSystem = myEnvironment.getLocalFileSystem();
|
CoreLocalFileSystem localFileSystem = myEnvironment.getLocalFileSystem();
|
||||||
myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/stdlib/test"));
|
myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/stdlib/test"));
|
||||||
|
|||||||
Reference in New Issue
Block a user