store CompilerDependencies in JetCoreEnvironment

This commit is contained in:
Stepan Koltsov
2012-05-01 22:59:42 +04:00
parent ba7a94e17d
commit b109ac5ad4
18 changed files with 48 additions and 50 deletions
@@ -127,7 +127,7 @@ public class K2JVMCompiler {
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, dependencies);
CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration(environment, dependencies, messageCollector);
CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration(environment, messageCollector);
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
CompilerMessageLocation.NO_LOCATION);
@@ -243,8 +243,8 @@ public class K2JVMCompiler {
configuration.getCompilerPlugins().addAll(plugins);
}
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
}
if (arguments.classpath != null) {
@@ -29,8 +29,9 @@ import java.util.List;
* @author abreslav
*/
public class CompileEnvironmentConfiguration {
@NotNull
private final JetCoreEnvironment environment;
private final CompilerDependencies compilerDependencies;
@NotNull
private final MessageCollector messageCollector;
private List<CompilerPlugin> compilerPlugins = Lists.newArrayList();
@@ -39,22 +40,16 @@ public class CompileEnvironmentConfiguration {
* NOTE: It's very important to call dispose for every object of this class or there will be memory leaks.
* @see Disposer
*/
public CompileEnvironmentConfiguration(@NotNull JetCoreEnvironment environment,
@NotNull CompilerDependencies compilerDependencies, @NotNull MessageCollector messageCollector) {
public CompileEnvironmentConfiguration(@NotNull JetCoreEnvironment environment, @NotNull MessageCollector messageCollector) {
this.messageCollector = messageCollector;
this.compilerDependencies = compilerDependencies;
this.environment = environment;
}
@NotNull
public JetCoreEnvironment getEnvironment() {
return environment;
}
@NotNull
public CompilerDependencies getCompilerDependencies() {
return compilerDependencies;
}
@NotNull
public MessageCollector getMessageCollector() {
return messageCollector;
@@ -162,7 +162,7 @@ public class CompileEnvironmentUtil {
scriptEnvironment.addSources(moduleScriptFile);
GenerationState generationState = KotlinToJVMBytecodeCompiler
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false);
if (generationState == null) {
return null;
}
@@ -47,8 +47,14 @@ import java.util.List;
public class JetCoreEnvironment extends JavaCoreEnvironment {
private final List<JetFile> sourceFiles = new ArrayList<JetFile>();
@NotNull
private final CompilerDependencies compilerDependencies;
public JetCoreEnvironment(Disposable parentDisposable, @NotNull CompilerDependencies compilerDependencies) {
super(parentDisposable);
this.compilerDependencies = compilerDependencies;
registerFileType(JetFileType.INSTANCE, "kt");
registerFileType(JetFileType.INSTANCE, "kts");
registerFileType(JetFileType.INSTANCE, "ktm");
@@ -152,4 +158,9 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
}
}
}
@NotNull
public CompilerDependencies getCompilerDependencies() {
return compilerDependencies;
}
}
@@ -83,7 +83,7 @@ public class KotlinToJVMBytecodeCompiler {
configuration.getEnvironment().addToClasspath(new File(classpathRoot));
}
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getCompilerDependencies());
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies());
GenerationState generationState = analyzeAndGenerate(configuration);
if (generationState == null) {
@@ -104,9 +104,9 @@ public class KotlinToJVMBytecodeCompiler {
for (Module moduleBuilder : modules) {
// TODO: this should be done only once for the environment
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
CompileEnvironmentUtil
.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
}
ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
if (moduleFactory == null) {
@@ -143,7 +143,7 @@ public class KotlinToJVMBytecodeCompiler {
}
}
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getCompilerDependencies());
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies());
GenerationState generationState = analyzeAndGenerate(configuration);
if (generationState == null) {
@@ -209,7 +209,7 @@ public class KotlinToJVMBytecodeCompiler {
@Nullable
public static GenerationState analyzeAndGenerate(CompileEnvironmentConfiguration configuration) {
return analyzeAndGenerate(configuration, configuration.getCompilerDependencies().getCompilerSpecialMode().isStubs());
return analyzeAndGenerate(configuration, configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode().isStubs());
}
@Nullable
@@ -244,7 +244,7 @@ public class KotlinToJVMBytecodeCompiler {
return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely,
JetControlFlowDataTraceFactory.EMPTY,
configuration.getCompilerDependencies());
configuration.getEnvironment().getCompilerDependencies());
}
}, environment.getSourceFiles()
);
@@ -267,7 +267,7 @@ public class KotlinToJVMBytecodeCompiler {
};
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
exhaust, environment.getSourceFiles(),
configuration.getCompilerDependencies().getCompilerSpecialMode());
configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode());
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
List<CompilerPlugin> plugins = configuration.getCompilerPlugins();