CLI: drop CompilerArguments and unnecessary methods from *CompilerArguments classes

This commit is contained in:
Zalim Bashorov
2013-10-15 17:56:06 +04:00
parent 5e0ef68d64
commit 31a4d91122
22 changed files with 67 additions and 229 deletions
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.maven.doc;
import org.apache.maven.plugin.MojoExecutionException;
import org.jetbrains.jet.cli.common.arguments.CompilerArguments;
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import org.jetbrains.kotlin.doc.KDocArguments;
@@ -184,7 +184,7 @@ public class KDocMojo extends KotlinCompileMojoBase {
}
@Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
if (arguments instanceof K2JVMCompilerArguments) {
configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, docModule, sources, classpath, output);
}
@@ -27,9 +27,9 @@ class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : Doclet
private val sourceDirs: List<File> =
compilerArguments
.getSourceDirs()
.src
.orEmpty()
.requireNoNulls()
.split(File.pathSeparatorChar)
.map { path -> File(path).getCanonicalFile()!! }
private val sourceDirPaths: List<String> = sourceDirs.map { d -> d.getPath()!! }
@@ -17,7 +17,7 @@ abstract class KModelCompilerPlugin(
public override fun processFiles(context: CompilerPluginContext) {
val bindingContext = context.getContext()
val sources = context.getFiles()
val sourceDirs: List<File> = arguments.getSourceDirs().orEmpty().requireNoNulls().map { path -> File(path) }
val sourceDirs: List<File> = arguments.src.orEmpty().split(File.pathSeparatorChar).map { path -> File(path) }
val model = KModel(bindingContext, arguments.apply(), sourceDirs, sources.requireNoNulls())
processModel(model)
@@ -22,8 +22,8 @@ class HtmlVisitorTest {
val args = K2JVMCompilerArguments()
args.kotlinHome = "../../../dist/kotlinc"
args.setSrc(srcDir.toString())
args.setOutputDir(File(dir, "target/classes-htmldocs").toString())
args.src = srcDir.toString()
args.outputDir = File(dir, "target/classes-htmldocs").toString()
val compiler = K2JVMCompiler()
compiler.getCompilerPlugins().add(HtmlCompilerPlugin())
@@ -40,7 +40,7 @@ class KDocSampleTest {
val args = KDocArguments()
args.kotlinHome = "../../../dist/kotlinc"
args.setSourceDirs(arrayList("src/test/sample"))
args.src = "src/test/sample"
val outputDir = File("target/apidocs-sample")
outputDir.rmrf()
@@ -8,6 +8,7 @@ import org.jetbrains.kotlin.doc.KDocArguments
import org.jetbrains.kotlin.doc.KDocCompiler
import org.junit.Assert
import org.junit.Test
import com.intellij.openapi.util.text.StringUtil
/**
*/
@@ -24,16 +25,15 @@ class KDocTest {
println("Generating library KDocs to $outDir")
val args = KDocArguments()
//args.setModule(moduleName)
//args.module = moduleName
args.kotlinHome = "../../../dist/kotlinc"
val sourceDirs = ArrayList<String>()
sourceDirs.add("../../stdlib/src")
sourceDirs.add("../../kunit/src/main/kotlin")
sourceDirs.add("../../kotlin-jdbc/src/main/kotlin")
args.setSourceDirs(sourceDirs)
args.setOutputDir("target/classes-stdlib")
args.setNoStdlib(true)
args.setClasspath("../runtime/target/kotlin-runtime-0.1-SNAPSHOT.jar${File.pathSeparator}../../lib/junit-4.9.jar")
val sourceDirs = listOf("../../stdlib/src",
"../../kunit/src/main/kotlin",
"../../kotlin-jdbc/src/main/kotlin")
args.src = sourceDirs.makeString(File.pathSeparator)
args.outputDir = "target/classes-stdlib"
args.noStdlib = true
args.classpath = "../runtime/target/kotlin-runtime-0.1-SNAPSHOT.jar${File.pathSeparator}../../lib/junit-4.9.jar"
val config = args.docConfig
config.docOutputDir = outDir.toString()
@@ -90,16 +90,16 @@ public open class KotlinCompile(): AbstractCompile() {
return
}
val customSources = args.getSourceDirs();
val customSources = args.src;
if (customSources == null || customSources.isEmpty()) {
args.setSourceDirs(sources.map { it.getAbsolutePath() })
args.src = sources.map { it.getAbsolutePath() } .makeString(File.pathSeparator)
}
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
val existingClasspathEntries = getClasspath().filter(KSpec<File?>({ it != null && it.exists() }))
val effectiveClassPath = (javaSrcRoots + existingClasspathEntries).makeString(File.pathSeparator)
args.setClasspath(effectiveClassPath)
args.classpath = effectiveClassPath
}
args.outputDir = if (StringUtils.isEmpty(kotlinOptions.outputDir)) { kotlinDestinationDir?.getPath() } else { kotlinOptions.outputDir }
@@ -21,7 +21,7 @@ import com.google.common.io.InputSupplier;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.jetbrains.jet.cli.common.CLICompiler;
import org.jetbrains.jet.cli.common.arguments.CompilerArguments;
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments;
import org.jetbrains.jet.cli.js.K2JSCompiler;
import com.intellij.openapi.util.io.FileUtil;
@@ -150,7 +150,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
}
@Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
super.configureCompilerArguments(arguments);
if (arguments instanceof K2JSCompilerArguments) {
@@ -168,7 +168,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
}
@Override
protected CompilerArguments createCompilerArguments() {
protected CommonCompilerArguments createCompilerArguments() {
return new K2JSCompilerArguments();
}
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.maven;
import org.apache.maven.plugin.MojoExecutionException;
import org.jetbrains.jet.cli.common.arguments.CompilerArguments;
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
/**
@@ -30,7 +30,7 @@ import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
*/
public class KotlinCompileMojo extends KotlinCompileMojoBase {
@Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
if (arguments instanceof K2JVMCompilerArguments) {
configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, module, getSources(), classpath, output);
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.maven;
import com.google.common.base.Joiner;
import com.intellij.openapi.util.text.StringUtil;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
@@ -28,11 +27,11 @@ 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.KotlinVersion;
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.common.arguments.CompilerArguments;
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import java.io.File;
@@ -172,7 +171,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
}
}
final CompilerArguments arguments = createCompilerArguments();
final CommonCompilerArguments arguments = createCompilerArguments();
configureCompilerArguments(arguments);
final CLICompiler compiler = createCompiler();
@@ -210,7 +209,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
}
}
private void printCompilerArgumentsIfDebugEnabled(CompilerArguments arguments, CLICompiler compiler) {
private void printCompilerArgumentsIfDebugEnabled(CommonCompilerArguments arguments, CLICompiler compiler) {
if (getLog().isDebugEnabled()) {
getLog().debug("Invoking compiler " + compiler + " with arguments:");
try {
@@ -247,14 +246,14 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
* Derived classes can create custom compiler argument implementations
* such as for KDoc
*/
protected CompilerArguments createCompilerArguments() {
protected CommonCompilerArguments createCompilerArguments() {
return new K2JVMCompilerArguments();
}
/**
* Derived classes can register custom plugins or configurations
*/
protected abstract void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException;
protected abstract void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException;
protected void configureBaseCompilerArguments(Log log, K2JVMCompilerArguments arguments, String module,
List<String> sources, List<String> classpath, String output) throws MojoExecutionException {
@@ -265,14 +264,14 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
if (module != null) {
log.info("Compiling Kotlin module " + module);
arguments.setModule(module);
arguments.module = module;
}
else {
if (sources.size() <= 0)
throw new MojoExecutionException("No source roots to compile");
arguments.setSourceDirs(sources);
log.info("Compiling Kotlin sources from " + arguments.getSourceDirs());
arguments.src = join(sources, File.pathSeparator);
log.info("Compiling Kotlin sources from " + arguments.src);
// TODO: Move it compiler
classpathList.addAll(sources);
@@ -285,13 +284,13 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
}
if (classpathList.size() > 0) {
final String classPathString = Joiner.on(File.pathSeparator).join(classpathList);
String classPathString = join(classpathList, File.pathSeparator);
log.info("Classpath: " + classPathString);
arguments.setClasspath(classPathString);
arguments.classpath = classPathString;
}
log.info("Classes directory is " + output);
arguments.setOutputDir(output);
arguments.outputDir = output;
arguments.noJdkAnnotations = true;
arguments.annotations = getFullAnnotationsPath(log, annotationPaths);
@@ -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.common.arguments.CompilerArguments;
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
import java.util.List;
@@ -86,7 +86,7 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
}
@Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
if (arguments instanceof K2JVMCompilerArguments) {
configureBaseCompilerArguments(
getLog(), (K2JVMCompilerArguments) arguments,