Move doMain method to CLICompiler.
This commit is contained in:
@@ -19,11 +19,13 @@ package org.jetbrains.jet.cli.common;
|
||||
import com.sampullara.cli.Args;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.INTERNAL_ERROR;
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.OK;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -77,5 +79,22 @@ public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf exten
|
||||
protected abstract CLArgs createArguments();
|
||||
|
||||
@NotNull
|
||||
public abstract ExitCode exec(final PrintStream errStream, CLArgs arguments);
|
||||
public abstract ExitCode exec(PrintStream errStream, CLArgs arguments);
|
||||
|
||||
/**
|
||||
* Useful main for derived command line tools
|
||||
*/
|
||||
public static void doMain(@NotNull CLICompiler compiler, @NotNull String[] args) {
|
||||
try {
|
||||
ExitCode rc = compiler.exec(System.out, args);
|
||||
if (rc != OK) {
|
||||
System.err.println("exec() finished with " + rc + " return code");
|
||||
System.exit(rc.getCode());
|
||||
}
|
||||
}
|
||||
catch (CompileEnvironmentException e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(INTERNAL_ERROR.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class CompileEnvironmentConfig {
|
||||
@NotNull
|
||||
private final MessageCollector messageCollector;
|
||||
@NotNull
|
||||
private List<CompilerPlugin> compilerPlugins = Lists.newArrayList();
|
||||
private final List<CompilerPlugin> compilerPlugins = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* NOTE: It's very important to call dispose for every object of this class or there will be memory leaks.
|
||||
|
||||
@@ -25,7 +25,10 @@ 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.*;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||
import org.jetbrains.jet.codegen.CompilationException;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
@@ -48,24 +51,6 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
||||
doMain(new K2JVMCompiler(), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Useful main for derived command line tools
|
||||
*/
|
||||
public static void doMain(K2JVMCompiler compiler, String[] args) {
|
||||
try {
|
||||
ExitCode rc = compiler.exec(System.out, args);
|
||||
if (rc != OK) {
|
||||
System.err.println("exec() finished with " + rc + " return code");
|
||||
System.exit(rc.getCode());
|
||||
}
|
||||
}
|
||||
catch (CompileEnvironmentException e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(INTERNAL_ERROR.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes the compiler on the parsed arguments
|
||||
*/
|
||||
|
||||
@@ -4,14 +4,16 @@ import java.io.File
|
||||
import java.io.PrintStream
|
||||
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
||||
import org.jetbrains.jet.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.jet.cli.common.CLICompiler
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration
|
||||
import org.jetbrains.kotlin.doc.highlighter.HtmlCompilerPlugin
|
||||
import org.jetbrains.jet.cli.common.ExitCode
|
||||
|
||||
/**
|
||||
* Main for running the KDocCompiler
|
||||
*/
|
||||
fun main(args: Array<String?>): Unit {
|
||||
K2JVMCompiler.doMain(KDocCompiler(), args);
|
||||
CLICompiler.doMain(KDocCompiler(), args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -20,7 +22,7 @@ fun main(args: Array<String?>): Unit {
|
||||
*/
|
||||
class KDocCompiler() : K2JVMCompiler() {
|
||||
|
||||
protected override fun configureEnvironment(configuration : CompileEnvironmentConfiguration, arguments : K2JVMCompilerArguments) {
|
||||
protected override fun configureEnvironment(configuration : CompileEnvironmentConfiguration?, arguments : K2JVMCompilerArguments?) {
|
||||
super.configureEnvironment(configuration, arguments)
|
||||
val coreEnvironment = configuration?.getEnvironment()
|
||||
if (coreEnvironment != null) {
|
||||
|
||||
Reference in New Issue
Block a user