Refactor cli: all the jvm stuff goes under org.jetbrains.jet.cli.jvm, common stuff under org.jetbrains.jet.cli.common

This commit is contained in:
pTalanov
2012-04-25 20:19:15 +04:00
parent b1b9446f13
commit d0d5b147f2
67 changed files with 113 additions and 4056 deletions
@@ -17,8 +17,8 @@
package org.jetbrains.kotlin.maven.doc;
import org.apache.maven.plugin.MojoExecutionException;
import org.jetbrains.jet.cli.CompilerArguments;
import org.jetbrains.jet.cli.KotlinCompiler;
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import org.jetbrains.kotlin.doc.KDocArguments;
import org.jetbrains.kotlin.doc.KDocCompiler;
import org.jetbrains.kotlin.doc.KDocConfig;
@@ -164,17 +164,17 @@ public class KDocMojo extends KotlinCompileMojoBase {
private Map<String, String> packageSummaryText;
@Override
protected KotlinCompiler createCompiler() {
protected K2JVMCompiler createCompiler() {
return new KDocCompiler();
}
@Override
protected CompilerArguments createCompilerArguments() {
protected K2JVMCompilerArguments createCompilerArguments() {
return new KDocArguments();
}
@Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
protected void configureCompilerArguments(K2JVMCompilerArguments arguments) throws MojoExecutionException {
configureBaseCompilerArguments(getLog(), arguments, docModule, sources, classpath, output);
if (arguments instanceof KDocArguments) {
@@ -15,7 +15,7 @@ import java.util.*
import com.intellij.psi.PsiElement
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.resolve.BindingContext.*
import org.jetbrains.jet.compiler.CompilerPlugin
import org.jetbrains.jet.cli.common.CompilerPlugin
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor
import org.jetbrains.jet.lexer.JetTokens
@@ -15,7 +15,7 @@ import java.util.Collection
import com.intellij.psi.PsiElement
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.resolve.BindingContext.*
import org.jetbrains.jet.compiler.CompilerPlugin
import org.jetbrains.jet.cli.common.CompilerPlugin
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor
import org.jetbrains.jet.lexer.JetTokens
@@ -2,25 +2,25 @@ package org.jetbrains.kotlin.doc
import java.io.File
import java.io.PrintStream
import org.jetbrains.jet.cli.CompilerArguments
import org.jetbrains.jet.cli.KotlinCompiler
import org.jetbrains.jet.compiler.CompileEnvironmentConfiguration
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
import org.jetbrains.jet.cli.jvm.K2JVMCompiler
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration
import org.jetbrains.kotlin.doc.highlighter.HtmlCompilerPlugin
/**
* Main for running the KDocCompiler
*/
fun main(args: Array<String?>): Unit {
KotlinCompiler.doMain(KDocCompiler(), args);
K2JVMCompiler.doMain(KDocCompiler(), args);
}
/**
* A version of the [[KotlinCompiler]] which includes the [[KDoc]] compiler plugin and allows
* A version of the [[K2JVMCompiler]] which includes the [[KDoc]] compiler plugin and allows
* command line validation or for the configuration to be provided via [[KDocArguments]]
*/
class KDocCompiler() : KotlinCompiler() {
class KDocCompiler() : K2JVMCompiler() {
protected override fun configureEnvironment(configuration : CompileEnvironmentConfiguration?, arguments : CompilerArguments?) {
protected override fun configureEnvironment(configuration : CompileEnvironmentConfiguration?, arguments : K2JVMCompilerArguments?) {
super.configureEnvironment(configuration, arguments)
val coreEnvironment = configuration?.getEnvironment()
if (coreEnvironment != null) {
@@ -38,7 +38,7 @@ class KDocCompiler() : KotlinCompiler() {
}
}
protected override fun createArguments() : CompilerArguments? {
protected override fun createArguments() : K2JVMCompilerArguments? {
return KDocArguments()
}
@@ -47,7 +47,7 @@ class KDocCompiler() : KotlinCompiler() {
}
}
class KDocArguments() : CompilerArguments() {
class KDocArguments() : K2JVMCompilerArguments() {
public var docConfig: KDocConfig = KDocConfig()
@@ -1,7 +1,7 @@
package org.jetbrains.kotlin.doc.highlighter
import org.jetbrains.jet.compiler.CompilerPlugin
import org.jetbrains.jet.compiler.CompilerPluginContext
import org.jetbrains.jet.cli.common.CompilerPlugin
import org.jetbrains.jet.cli.common.CompilerPluginContext
/**
*/
@@ -1,7 +1,7 @@
package org.jetbrains.kotlin.doc.model
import org.jetbrains.jet.compiler.CompilerPlugin
import org.jetbrains.jet.compiler.CompilerPluginContext
import org.jetbrains.jet.cli.common.CompilerPlugin
import org.jetbrains.jet.cli.common.CompilerPluginContext
import org.jetbrains.kotlin.doc.KDocConfig
/** Base class for any compiler plugin which needs to process a KModel */
@@ -2,8 +2,8 @@ package test.kotlin.kdoc
import java.io.File
import kotlin.test.assertTrue
import org.jetbrains.jet.cli.CompilerArguments
import org.jetbrains.jet.cli.KotlinCompiler
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
import org.jetbrains.jet.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.doc.highlighter.HtmlCompilerPlugin
import org.junit.Test
@@ -20,12 +20,12 @@ class HtmlVisitorTest {
val outDir = File(dir, "target/htmldocs")
println("Generating source HTML to $outDir")
val args = CompilerArguments()
val args = K2JVMCompilerArguments()
args.setSrc(srcDir.toString())
args.setOutputDir(File(dir, "target/classes-htmldocs").toString())
args.getCompilerPlugins()?.add(HtmlCompilerPlugin())
val compiler = KotlinCompiler()
val compiler = K2JVMCompiler()
compiler.exec(System.out, args)
}
}
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.maven;
import org.apache.maven.plugin.MojoExecutionException;
import org.jetbrains.jet.cli.CompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments;
/**
* Converts Kotlin to JavaScript code
@@ -36,7 +36,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
private String outFile;
@Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
protected void configureCompilerArguments(K2JVMCompilerArguments arguments) throws MojoExecutionException {
super.configureCompilerArguments(arguments);
K2JSCompilerPlugin plugin = new K2JSCompilerPlugin();
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.maven;
import com.google.common.io.Files;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.compiler.CompilerPlugin;
import org.jetbrains.jet.compiler.CompilerPluginContext;
import org.jetbrains.jet.cli.common.CompilerPlugin;
import org.jetbrains.jet.cli.common.CompilerPluginContext;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.k2js.config.Config;
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.maven;
import org.apache.maven.plugin.MojoExecutionException;
import org.jetbrains.jet.cli.CompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments;
/**
* Compiles kotlin sources
@@ -29,7 +29,7 @@ import org.jetbrains.jet.cli.CompilerArguments;
*/
public class KotlinCompileMojo extends KotlinCompileMojoBase {
@Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
protected void configureCompilerArguments(K2JVMCompilerArguments arguments) throws MojoExecutionException {
configureBaseCompilerArguments(getLog(), arguments, module, sources, classpath, output);
}
}
@@ -23,8 +23,10 @@ import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.jetbrains.jet.cli.CompilerArguments;
import org.jetbrains.jet.cli.KotlinCompiler;
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import org.jetbrains.jet.cli.common.ExitCode.*;
import org.jetbrains.jet.cli.common.ExitCode;
import java.io.File;
import java.io.IOException;
@@ -104,15 +106,15 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
final CompilerArguments arguments = createCompilerArguments();
final K2JVMCompilerArguments arguments = createCompilerArguments();
configureCompilerArguments(arguments);
final KotlinCompiler compiler = createCompiler();
final K2JVMCompiler compiler = createCompiler();
printCompilerArgumentsIfDebugEnabled(arguments, compiler);
final KotlinCompiler.ExitCode exitCode = compiler.exec(System.err, arguments);
final ExitCode exitCode = compiler.exec(System.err, arguments);
switch (exitCode) {
case COMPILATION_ERROR:
@@ -123,7 +125,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
}
}
private void printCompilerArgumentsIfDebugEnabled(CompilerArguments arguments, KotlinCompiler compiler) {
private void printCompilerArgumentsIfDebugEnabled(K2JVMCompilerArguments arguments, K2JVMCompiler compiler) {
if (getLog().isDebugEnabled()) {
getLog().debug("Invoking compiler " + compiler + " with arguments:");
try {
@@ -142,24 +144,24 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
}
}
protected KotlinCompiler createCompiler() {
return new KotlinCompiler();
protected K2JVMCompiler createCompiler() {
return new K2JVMCompiler();
}
/**
* Derived classes can create custom compiler argument implementations
* such as for KDoc
*/
protected CompilerArguments createCompilerArguments() {
return new CompilerArguments();
protected K2JVMCompilerArguments createCompilerArguments() {
return new K2JVMCompilerArguments();
}
/**
* Derived classes can register custom plugins or configurations
*/
protected abstract void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException;
protected abstract void configureCompilerArguments(K2JVMCompilerArguments arguments) throws MojoExecutionException;
protected void configureBaseCompilerArguments(Log log, CompilerArguments arguments, String module,
protected void configureBaseCompilerArguments(Log log, K2JVMCompilerArguments arguments, String module,
List<String> sources, List<String> classpath, String output) throws MojoExecutionException {
// don't include runtime, it should be in maven dependencies
arguments.mode = "stdlib";
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.maven;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.jetbrains.jet.cli.CompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments;
/**
* Compiles Kotlin test sources
@@ -47,7 +47,7 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
}
@Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
protected void configureCompilerArguments(K2JVMCompilerArguments arguments) throws MojoExecutionException {
configureBaseCompilerArguments(
getLog(), arguments,
testModule, testSources, testClasspath, testOutput);