Rename CompileEnvironmentConfiguration. Drop ArgsUtil class. Add CompilerSpecialMode.JS.
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.cli.common;
|
||||
|
||||
import com.sampullara.cli.Args;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ArgsUtil {
|
||||
|
||||
private ArgsUtil() {
|
||||
}
|
||||
|
||||
public static void printUsage(@NotNull PrintStream target, @NotNull CompilerArguments exampleInstance) {
|
||||
// We should say something like
|
||||
// Args.usage(target, K2JVMCompilerArguments.class);
|
||||
// but currently cli-parser we are using does not support that
|
||||
// a corresponding patch has been sent to the authors
|
||||
// For now, we are using this:
|
||||
PrintStream oldErr = System.err;
|
||||
System.setErr(target);
|
||||
try {
|
||||
// TODO: use proper argv0
|
||||
Args.usage(exampleInstance);
|
||||
}
|
||||
finally {
|
||||
System.setErr(oldErr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,11 +33,11 @@ import static org.jetbrains.jet.cli.common.ExitCode.OK;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf extends CompileEnvironmentConfig> {
|
||||
public abstract class CLICompiler<A extends CompilerArguments, C extends CompileEnvironmentConfiguration> {
|
||||
|
||||
@NotNull
|
||||
public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) {
|
||||
CLArgs arguments = createArguments();
|
||||
A arguments = createArguments();
|
||||
if (!parseArguments(errStream, arguments, args)) {
|
||||
return INTERNAL_ERROR;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf exten
|
||||
/**
|
||||
* Returns true if the arguments can be parsed correctly
|
||||
*/
|
||||
protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull CLArgs arguments, @NotNull String[] args) {
|
||||
protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull A arguments, @NotNull String[] args) {
|
||||
try {
|
||||
Args.parse(arguments, args);
|
||||
return true;
|
||||
@@ -66,26 +66,40 @@ public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf exten
|
||||
* Allow derived classes to add additional command line arguments
|
||||
*/
|
||||
protected void usage(@NotNull PrintStream target) {
|
||||
ArgsUtil.printUsage(target, createArguments());
|
||||
// We should say something like
|
||||
// Args.usage(target, K2JVMCompilerArguments.class);
|
||||
// but currently cli-parser we are using does not support that
|
||||
// a corresponding patch has been sent to the authors
|
||||
// For now, we are using this:
|
||||
PrintStream oldErr = System.err;
|
||||
System.setErr(target);
|
||||
try {
|
||||
// TODO: use proper argv0
|
||||
Args.usage(createArguments());
|
||||
}
|
||||
finally {
|
||||
System.setErr(oldErr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strategy method to configure the environment, allowing compiler
|
||||
* based tools to customise their own plugins
|
||||
*/
|
||||
protected void configureEnvironment(@NotNull CEConf configuration, @NotNull CLArgs arguments) {
|
||||
//TODO: add parameter annotations when KT-1863 is resolved
|
||||
protected void configureEnvironment(C configuration, A arguments) {
|
||||
List<CompilerPlugin> plugins = arguments.getCompilerPlugins();
|
||||
configuration.getCompilerPlugins().addAll(plugins);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract CLArgs createArguments();
|
||||
protected abstract A createArguments();
|
||||
|
||||
/**
|
||||
* Executes the compiler on the parsed arguments
|
||||
*/
|
||||
@NotNull
|
||||
public ExitCode exec(final PrintStream errStream, CLArgs arguments) {
|
||||
public ExitCode exec(final PrintStream errStream, A arguments) {
|
||||
if (arguments.isHelp()) {
|
||||
usage(errStream);
|
||||
return OK;
|
||||
@@ -104,15 +118,15 @@ public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf exten
|
||||
|
||||
//TODO: can't declare parameters as not null due to KT-1863
|
||||
@NotNull
|
||||
protected abstract ExitCode doExecute(PrintStream stream, CLArgs arguments, MessageRenderer renderer);
|
||||
protected abstract ExitCode doExecute(PrintStream stream, A arguments, MessageRenderer renderer);
|
||||
|
||||
@NotNull
|
||||
private MessageRenderer getMessageRenderer(@NotNull CLArgs arguments) {
|
||||
private MessageRenderer getMessageRenderer(@NotNull A arguments) {
|
||||
return arguments.isTags() ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
|
||||
}
|
||||
|
||||
protected void printVersionIfNeeded(@NotNull PrintStream errStream,
|
||||
@NotNull CLArgs arguments,
|
||||
@NotNull A arguments,
|
||||
@NotNull MessageRenderer messageRenderer) {
|
||||
if (arguments.isVersion()) {
|
||||
String versionMessage = messageRenderer.render(CompilerMessageSeverity.INFO,
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class CompileEnvironmentConfig {
|
||||
public abstract class CompileEnvironmentConfiguration {
|
||||
|
||||
@NotNull
|
||||
private final MessageCollector messageCollector;
|
||||
@@ -38,7 +38,7 @@ public abstract class CompileEnvironmentConfig {
|
||||
*
|
||||
* @see Disposer
|
||||
*/
|
||||
public CompileEnvironmentConfig(@NotNull MessageCollector messageCollector) {
|
||||
public CompileEnvironmentConfiguration(@NotNull MessageCollector messageCollector) {
|
||||
this.messageCollector = messageCollector;
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ package org.jetbrains.jet.cli.js;
|
||||
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.CompileEnvironmentConfig;
|
||||
import org.jetbrains.jet.cli.common.CompileEnvironmentConfiguration;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class K2JSCompileEnvironmentConfiguration extends CompileEnvironmentConfig {
|
||||
public class K2JSCompileEnvironmentConfiguration extends CompileEnvironmentConfiguration {
|
||||
/**
|
||||
* NOTE: It's very important to call dispose for every object of this class or there will be memory leaks.
|
||||
*
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||
import org.jetbrains.jet.cli.common.ExitCode;
|
||||
import org.jetbrains.jet.cli.common.messages.*;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||
@@ -45,7 +45,7 @@ import static org.jetbrains.jet.cli.common.ExitCode.*;
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEnvironmentConfiguration> {
|
||||
public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMCompileEnvironmentConfiguration> {
|
||||
|
||||
public static void main(String... args) {
|
||||
doMain(new K2JVMCompiler(), args);
|
||||
@@ -89,8 +89,8 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
||||
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
|
||||
|
||||
JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(rootDisposable, dependencies);
|
||||
CompileEnvironmentConfiguration configuration =
|
||||
new CompileEnvironmentConfiguration(environment, dependencies, messageCollector);
|
||||
K2JVMCompileEnvironmentConfiguration configuration =
|
||||
new K2JVMCompileEnvironmentConfiguration(environment, messageCollector);
|
||||
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
@@ -175,16 +175,16 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
||||
|
||||
|
||||
@Override
|
||||
protected void configureEnvironment(@NotNull CompileEnvironmentConfiguration configuration,
|
||||
@NotNull K2JVMCompilerArguments arguments) {
|
||||
protected void configureEnvironment(K2JVMCompileEnvironmentConfiguration configuration, K2JVMCompilerArguments arguments) {
|
||||
super.configureEnvironment(configuration, arguments);
|
||||
|
||||
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
|
||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(),
|
||||
configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
||||
}
|
||||
|
||||
if (arguments.classpath != null) {
|
||||
final Iterable<String> classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath);
|
||||
Iterable<String> classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath);
|
||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class CompileEnvironmentUtil {
|
||||
|
||||
@Nullable
|
||||
public static File getUnpackedRuntimePath() {
|
||||
URL url = CompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class");
|
||||
URL url = K2JVMCompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class");
|
||||
if (url != null && url.getProtocol().equals("file")) {
|
||||
return new File(url.getPath()).getParentFile().getParentFile();
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class CompileEnvironmentUtil {
|
||||
|
||||
@Nullable
|
||||
public static File getRuntimeJarPath() {
|
||||
URL url = CompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class");
|
||||
URL url = K2JVMCompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class");
|
||||
if (url != null && url.getProtocol().equals("jar")) {
|
||||
String path = url.getPath();
|
||||
return new File(path.substring(path.indexOf(":") + 1, path.indexOf("!/")));
|
||||
@@ -163,7 +163,7 @@ public class CompileEnvironmentUtil {
|
||||
scriptEnvironment.addSources(moduleScriptFile);
|
||||
|
||||
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
||||
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false);
|
||||
.analyzeAndGenerate(new K2JVMCompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false);
|
||||
if (generationState == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
}
|
||||
else {
|
||||
loader = new GeneratedClassLoader(factory, CompileEnvironmentConfiguration.class.getClassLoader());
|
||||
loader = new GeneratedClassLoader(factory, K2JVMCompileEnvironmentConfiguration.class.getClassLoader());
|
||||
}
|
||||
try {
|
||||
Class namespaceClass = loader.loadClass(JvmAbi.PACKAGE_CLASS);
|
||||
|
||||
+3
-12
@@ -18,36 +18,27 @@ package org.jetbrains.jet.cli.jvm.compiler;
|
||||
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.CompileEnvironmentConfig;
|
||||
import org.jetbrains.jet.cli.common.CompileEnvironmentConfiguration;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class CompileEnvironmentConfiguration extends CompileEnvironmentConfig {
|
||||
public class K2JVMCompileEnvironmentConfiguration extends CompileEnvironmentConfiguration {
|
||||
private final JetCoreEnvironment environment;
|
||||
private final CompilerDependencies compilerDependencies;
|
||||
|
||||
/**
|
||||
* 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,
|
||||
public K2JVMCompileEnvironmentConfiguration(@NotNull JetCoreEnvironment environment,
|
||||
@NotNull MessageCollector messageCollector) {
|
||||
super(messageCollector);
|
||||
this.compilerDependencies = compilerDependencies;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public JetCoreEnvironment getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompilerDependencies getCompilerDependencies() {
|
||||
return compilerDependencies;
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -59,7 +59,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
@Nullable
|
||||
public static ClassFileFactory compileModule(
|
||||
CompileEnvironmentConfiguration configuration,
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
Module moduleBuilder,
|
||||
File directory
|
||||
) {
|
||||
@@ -82,7 +82,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
public static boolean compileModules(
|
||||
CompileEnvironmentConfiguration configuration,
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
|
||||
@NotNull List<Module> modules,
|
||||
|
||||
@@ -118,7 +118,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
private static boolean compileBunchOfSources(
|
||||
CompileEnvironmentConfiguration configuration,
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
String jar,
|
||||
String outputDir,
|
||||
boolean includeRuntime
|
||||
@@ -163,7 +163,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
public static boolean compileBunchOfSources(
|
||||
CompileEnvironmentConfiguration configuration,
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
|
||||
String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
|
||||
configuration.getEnvironment().addSources(sourceFileOrDir);
|
||||
@@ -172,7 +172,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
public static boolean compileBunchOfSourceDirectories(
|
||||
CompileEnvironmentConfiguration configuration,
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
|
||||
List<String> sources, String jar, String outputDir, boolean includeRuntime) {
|
||||
for (String source : sources) {
|
||||
@@ -184,7 +184,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
@Nullable
|
||||
public static ClassLoader compileText(
|
||||
CompileEnvironmentConfiguration configuration,
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
String code) {
|
||||
configuration.getEnvironment()
|
||||
.addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code));
|
||||
@@ -197,13 +197,13 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GenerationState analyzeAndGenerate(CompileEnvironmentConfiguration configuration) {
|
||||
public static GenerationState analyzeAndGenerate(K2JVMCompileEnvironmentConfiguration configuration) {
|
||||
return analyzeAndGenerate(configuration, configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode().isStubs());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GenerationState analyzeAndGenerate(
|
||||
CompileEnvironmentConfiguration configuration,
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
boolean stubs
|
||||
) {
|
||||
AnalyzeExhaust exhaust = analyze(configuration, stubs);
|
||||
@@ -219,7 +219,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
@Nullable
|
||||
private static AnalyzeExhaust analyze(
|
||||
final CompileEnvironmentConfiguration configuration,
|
||||
final K2JVMCompileEnvironmentConfiguration configuration,
|
||||
boolean stubs) {
|
||||
final JetCoreEnvironment environment = configuration.getEnvironment();
|
||||
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(configuration.getMessageCollector());
|
||||
@@ -243,7 +243,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
@NotNull
|
||||
private static GenerationState generate(
|
||||
final CompileEnvironmentConfiguration configuration,
|
||||
final K2JVMCompileEnvironmentConfiguration configuration,
|
||||
AnalyzeExhaust exhaust,
|
||||
boolean stubs) {
|
||||
JetCoreEnvironment environment = configuration.getEnvironment();
|
||||
|
||||
Reference in New Issue
Block a user