Pull some code from K2JVMCompiler to CLICompiler. Also requires a hack due to compiler bug.
This commit is contained in:
@@ -18,7 +18,10 @@ package org.jetbrains.jet.cli.common;
|
|||||||
|
|
||||||
import com.sampullara.cli.Args;
|
import com.sampullara.cli.Args;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
|
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
|
||||||
|
import org.jetbrains.jet.cli.jvm.K2JVMCompilerVersion;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
@@ -78,8 +81,44 @@ public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf exten
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected abstract CLArgs createArguments();
|
protected abstract CLArgs createArguments();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the compiler on the parsed arguments
|
||||||
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public abstract ExitCode exec(PrintStream errStream, CLArgs arguments);
|
public ExitCode exec(final PrintStream errStream, CLArgs arguments) {
|
||||||
|
if (arguments.isHelp()) {
|
||||||
|
usage(errStream);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
System.setProperty("java.awt.headless", "true");
|
||||||
|
final MessageRenderer messageRenderer = getMessageRenderer(arguments);
|
||||||
|
errStream.print(messageRenderer.renderPreamble());
|
||||||
|
try {
|
||||||
|
return doExecute(errStream, arguments, messageRenderer);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
errStream.print(messageRenderer.renderConclusion());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: can't declare parameters as not null due to KT-1863
|
||||||
|
@NotNull
|
||||||
|
protected abstract ExitCode doExecute(PrintStream stream, CLArgs arguments, MessageRenderer renderer);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private MessageRenderer getMessageRenderer(@NotNull CLArgs arguments) {
|
||||||
|
return arguments.isTags() ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void printVersionIfNeeded(@NotNull PrintStream errStream,
|
||||||
|
@NotNull CLArgs arguments,
|
||||||
|
@NotNull MessageRenderer messageRenderer) {
|
||||||
|
if (arguments.isVersion()) {
|
||||||
|
errStream.println(messageRenderer
|
||||||
|
.render(CompilerMessageSeverity.INFO, "Kotlin Compiler version " + K2JVMCompilerVersion.VERSION,
|
||||||
|
CompilerMessageLocation.NO_LOCATION));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful main for derived command line tools
|
* Useful main for derived command line tools
|
||||||
|
|||||||
@@ -51,28 +51,12 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
|||||||
doMain(new K2JVMCompiler(), args);
|
doMain(new K2JVMCompiler(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the compiler on the parsed arguments
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public ExitCode exec(final PrintStream errStream, K2JVMCompilerArguments arguments) {
|
@NotNull
|
||||||
if (arguments.help) {
|
protected ExitCode doExecute(PrintStream errStream,
|
||||||
usage(errStream);
|
K2JVMCompilerArguments arguments,
|
||||||
return OK;
|
MessageRenderer messageRenderer) {
|
||||||
}
|
printVersionIfNeeded(errStream, arguments, messageRenderer);
|
||||||
System.setProperty("java.awt.headless", "true");
|
|
||||||
|
|
||||||
final MessageRenderer messageRenderer = arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
|
|
||||||
|
|
||||||
errStream.print(messageRenderer.renderPreamble());
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (arguments.version) {
|
|
||||||
errStream.println(messageRenderer
|
|
||||||
.render(CompilerMessageSeverity.INFO, "Kotlin Compiler version " + K2JVMCompilerVersion.VERSION,
|
|
||||||
CompilerMessageLocation.NO_LOCATION));
|
|
||||||
}
|
|
||||||
|
|
||||||
CompilerSpecialMode mode = parseCompilerSpecialMode(arguments);
|
CompilerSpecialMode mode = parseCompilerSpecialMode(arguments);
|
||||||
|
|
||||||
@@ -155,10 +139,6 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
|||||||
messageCollector.printToErrStream();
|
messageCollector.printToErrStream();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
errStream.print(messageRenderer.renderConclusion());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static CompilerSpecialMode parseCompilerSpecialMode(@NotNull K2JVMCompilerArguments arguments) {
|
private static CompilerSpecialMode parseCompilerSpecialMode(@NotNull K2JVMCompilerArguments arguments) {
|
||||||
@@ -186,6 +166,15 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
|||||||
return new K2JVMCompilerArguments();
|
return new K2JVMCompilerArguments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Hacked! Be sure that our kotlin stuff builds correctly before you remove.
|
||||||
|
// our compiler throws method not found error
|
||||||
|
// probably relates to KT-1863... well, may be not
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ExitCode exec(PrintStream errStream, K2JVMCompilerArguments arguments) {
|
||||||
|
return super.exec(errStream, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureEnvironment(@NotNull CompileEnvironmentConfiguration configuration,
|
protected void configureEnvironment(@NotNull CompileEnvironmentConfiguration configuration,
|
||||||
|
|||||||
Reference in New Issue
Block a user