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
@@ -16,13 +16,13 @@
package org.jetbrains.jet.cli.common.arguments; package org.jetbrains.jet.cli.common.arguments;
import com.intellij.util.SmartList;
import com.sampullara.cli.Argument; import com.sampullara.cli.Argument;
import java.util.List;
import static org.jetbrains.jet.cli.common.arguments.CommonArgumentConstants.SUPPRESS_WARNINGS; import static org.jetbrains.jet.cli.common.arguments.CommonArgumentConstants.SUPPRESS_WARNINGS;
public abstract class CommonCompilerArguments extends CompilerArguments { public abstract class CommonCompilerArguments {
public static final CommonCompilerArguments DUMMY = new DummyImpl();
@Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag") @Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
public boolean tags; public boolean tags;
@Argument(value = "verbose", description = "Enable verbose logging output") @Argument(value = "verbose", description = "Enable verbose logging output")
@@ -31,54 +31,17 @@ public abstract class CommonCompilerArguments extends CompilerArguments {
public boolean version; public boolean version;
@Argument(value = "help", alias = "h", description = "Show help") @Argument(value = "help", alias = "h", description = "Show help")
public boolean help; public boolean help;
@Argument(value = "suppress", description = "Suppress compiler messages by severity (warnings)") @Argument(value = "suppress", description = "Suppress compiler messages by severity (" + SUPPRESS_WARNINGS + ")")
public String suppress; public String suppress;
@Argument(value = "printArgs", description = "Print commandline arguments") @Argument(value = "printArgs", description = "Print commandline arguments")
public boolean printArgs; public boolean printArgs;
@Override public List<String> freeArgs = new SmartList<String>();
public boolean isHelp() {
return help;
}
public void setHelp(boolean help) {
this.help = help;
}
@Override
public boolean isTags() {
return tags;
}
@Override
public boolean isVersion() {
return version;
}
@Override
public boolean isVerbose() {
return verbose;
}
@Override
public boolean isPrintArgs() {
return printArgs;
}
public void setTags(boolean tags) {
this.tags = tags;
}
@Override
public boolean suppressAllWarnings() { public boolean suppressAllWarnings() {
return SUPPRESS_WARNINGS.equalsIgnoreCase(suppress); return SUPPRESS_WARNINGS.equalsIgnoreCase(suppress);
} }
// Used only for serialize and deserialize settings. Don't use in other places! // Used only for serialize and deserialize settings. Don't use in other places!
public static final class DummyImpl extends CommonCompilerArguments { public static final class DummyImpl extends CommonCompilerArguments {}
@Override
public String getSrc() {
return null;
}
}
} }
@@ -1,35 +0,0 @@
/*
* Copyright 2010-2013 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.arguments;
import com.intellij.util.SmartList;
import java.util.List;
public abstract class CompilerArguments {
public List<String> freeArgs = new SmartList<String>();
public abstract boolean isHelp();
public abstract boolean isTags();
public abstract boolean isVersion();
public abstract boolean isVerbose();
public abstract boolean isPrintArgs();
public abstract String getSrc();
public abstract boolean suppressAllWarnings();
}
@@ -45,9 +45,4 @@ public class K2JSCompilerArguments extends CommonCompilerArguments {
@Argument(value = "main", description = "Whether a main function should be called; either '" + CALL + @Argument(value = "main", description = "Whether a main function should be called; either '" + CALL +
"' or '" + NO_CALL + "', default '" + CALL + "' (main function will be auto detected)") "' or '" + NO_CALL + "', default '" + CALL + "' (main function will be auto detected)")
public String main; public String main;
@Override
public String getSrc() {
throw new IllegalStateException();
}
} }
@@ -19,24 +19,11 @@ package org.jetbrains.jet.cli.common.arguments;
import com.sampullara.cli.Argument; import com.sampullara.cli.Argument;
import java.util.List;
/** /**
* Command line arguments for the {@link K2JVMCompiler} * Command line arguments for the {@link K2JVMCompiler}
*/ */
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
public class K2JVMCompilerArguments extends CommonCompilerArguments { public class K2JVMCompilerArguments extends CommonCompilerArguments {
// TODO ideally we'd unify this with 'src' to just having a single field that supports multiple files/dirs
private List<String> sourceDirs;
public List<String> getSourceDirs() {
return sourceDirs;
}
public void setSourceDirs(List<String> sourceDirs) {
this.sourceDirs = sourceDirs;
}
@Argument(value = "jar", description = "jar file name") @Argument(value = "jar", description = "jar file name")
public String jar; public String jar;
@@ -78,65 +65,4 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "kotlinHome", description = "Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery") @Argument(value = "kotlinHome", description = "Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery")
public String kotlinHome; public String kotlinHome;
public String getKotlinHome() {
return kotlinHome;
}
public void setKotlinHome(String kotlinHome) {
this.kotlinHome = kotlinHome;
}
public String getClasspath() {
return classpath;
}
public void setClasspath(String classpath) {
this.classpath = classpath;
}
public boolean isIncludeRuntime() {
return includeRuntime;
}
public void setIncludeRuntime(boolean includeRuntime) {
this.includeRuntime = includeRuntime;
}
public String getJar() {
return jar;
}
public void setJar(String jar) {
this.jar = jar;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
public String getOutputDir() {
return outputDir;
}
public void setOutputDir(String outputDir) {
this.outputDir = outputDir;
}
@Override
public String getSrc() {
return src;
}
public void setSrc(String src) {
this.src = src;
}
public void setNoStdlib(boolean noStdlib) {
this.noStdlib = noStdlib;
}
} }
@@ -24,7 +24,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.sampullara.cli.Args; import com.sampullara.cli.Args;
import com.sampullara.cli.ArgumentUtils; import com.sampullara.cli.ArgumentUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.arguments.CompilerArguments; import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.messages.*; import org.jetbrains.jet.cli.common.messages.*;
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
import org.jetbrains.jet.config.CompilerConfiguration; import org.jetbrains.jet.config.CompilerConfiguration;
@@ -34,7 +34,7 @@ import java.util.List;
import static org.jetbrains.jet.cli.common.ExitCode.*; import static org.jetbrains.jet.cli.common.ExitCode.*;
public abstract class CLICompiler<A extends CompilerArguments> { public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull @NotNull
private List<CompilerPlugin> compilerPlugins = Lists.newArrayList(); private List<CompilerPlugin> compilerPlugins = Lists.newArrayList();
@@ -112,7 +112,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
*/ */
@NotNull @NotNull
public ExitCode exec(@NotNull PrintStream errStream, @NotNull A arguments) { public ExitCode exec(@NotNull PrintStream errStream, @NotNull A arguments) {
if (arguments.isHelp()) { if (arguments.help) {
usage(errStream); usage(errStream);
return OK; return OK;
} }
@@ -123,7 +123,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
printArgumentsIfNeeded(errStream, arguments, messageRenderer); printArgumentsIfNeeded(errStream, arguments, messageRenderer);
printVersionIfNeeded(errStream, arguments, messageRenderer); printVersionIfNeeded(errStream, arguments, messageRenderer);
MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.isVerbose()); MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
if (arguments.suppressAllWarnings()) { if (arguments.suppressAllWarnings()) {
collector = new FilteringMessageCollector(collector, Predicates.equalTo(CompilerMessageSeverity.WARNING)); collector = new FilteringMessageCollector(collector, Predicates.equalTo(CompilerMessageSeverity.WARNING));
@@ -167,7 +167,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
//TODO: can we make it private? //TODO: can we make it private?
@NotNull @NotNull
protected MessageRenderer getMessageRenderer(@NotNull A arguments) { protected MessageRenderer getMessageRenderer(@NotNull A arguments) {
return arguments.isTags() ? MessageRenderer.TAGS : MessageRenderer.PLAIN; return arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
} }
protected void printVersionIfNeeded( protected void printVersionIfNeeded(
@@ -175,7 +175,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
@NotNull A arguments, @NotNull A arguments,
@NotNull MessageRenderer messageRenderer @NotNull MessageRenderer messageRenderer
) { ) {
if (arguments.isVersion()) { if (arguments.version) {
String versionMessage = messageRenderer.render(CompilerMessageSeverity.INFO, String versionMessage = messageRenderer.render(CompilerMessageSeverity.INFO,
"Kotlin Compiler version " + KotlinVersion.VERSION, "Kotlin Compiler version " + KotlinVersion.VERSION,
CompilerMessageLocation.NO_LOCATION); CompilerMessageLocation.NO_LOCATION);
@@ -188,7 +188,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
@NotNull A arguments, @NotNull A arguments,
@NotNull MessageRenderer messageRenderer @NotNull MessageRenderer messageRenderer
) { ) {
if (arguments.isPrintArgs()) { if (arguments.printArgs) {
String freeArgs = StringUtil.join(arguments.freeArgs, ""); String freeArgs = StringUtil.join(arguments.freeArgs, "");
String argumentsAsString = ArgumentUtils.convertArgumentsToString(arguments, createArguments()); String argumentsAsString = ArgumentUtils.convertArgumentsToString(arguments, createArguments());
String printArgsMessage = messageRenderer.render(CompilerMessageSeverity.INFO, String printArgsMessage = messageRenderer.render(CompilerMessageSeverity.INFO,
@@ -89,7 +89,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
List<JetFile> sourceFiles = sourceLoader.findSourceFiles(); List<JetFile> sourceFiles = sourceLoader.findSourceFiles();
environmentForJS.getSourceFiles().addAll(sourceFiles); environmentForJS.getSourceFiles().addAll(sourceFiles);
if (arguments.isVerbose()) { if (arguments.verbose) {
reportCompiledSourcesList(messageCollector, environmentForJS); reportCompiledSourcesList(messageCollector, environmentForJS);
} }
@@ -77,13 +77,11 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
return INTERNAL_ERROR; return INTERNAL_ERROR;
} }
List<String> argumentsSourceDirs = arguments.getSourceDirs();
if (!arguments.script && if (!arguments.script &&
arguments.module == null && arguments.module == null &&
arguments.src == null && arguments.src == null &&
arguments.freeArgs.isEmpty() && arguments.freeArgs.isEmpty()
(argumentsSourceDirs == null || argumentsSourceDirs.size() == 0)) { ) {
ReplFromTerminal.run(rootDisposable, configuration); ReplFromTerminal.run(rootDisposable, configuration);
return ExitCode.OK; return ExitCode.OK;
} }
@@ -93,21 +91,13 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, arguments.freeArgs.get(0)); configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, arguments.freeArgs.get(0));
} }
else { else {
// TODO ideally we'd unify to just having a single field that supports multiple files/dirs if (arguments.src != null) {
if (arguments.getSourceDirs() != null) { List<String> sourcePathsSplitByPathSeparator
for (String source : arguments.getSourceDirs()) { = Arrays.asList(arguments.src.split(StringUtil.escapeToRegexp(File.pathSeparator)));
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, source); configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, sourcePathsSplitByPathSeparator);
}
} }
else { for (String freeArg : arguments.freeArgs) {
if (arguments.src != null) { configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, freeArg);
List<String> sourcePathsSplitByPathSeparator
= Arrays.asList(arguments.src.split(StringUtil.escapeToRegexp(File.pathSeparator)));
configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, sourcePathsSplitByPathSeparator);
}
for (String freeArg : arguments.freeArgs) {
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, freeArg);
}
} }
} }
@@ -19,7 +19,7 @@ package org.jetbrains.jet.compiler.runner;
import com.intellij.util.Function; import com.intellij.util.Function;
import com.intellij.util.xmlb.XmlSerializer; import com.intellij.util.xmlb.XmlSerializer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.arguments.CompilerArguments; import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.preloading.ClassPreloadingUtils; import org.jetbrains.jet.preloading.ClassPreloadingUtils;
import org.jetbrains.jet.utils.KotlinPaths; import org.jetbrains.jet.utils.KotlinPaths;
@@ -41,7 +41,7 @@ import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.ERRO
public class CompilerRunnerUtil { public class CompilerRunnerUtil {
private static final String STRING_ARRAY_CLASS_NAME = String[].class.getName(); private static final String STRING_ARRAY_CLASS_NAME = String[].class.getName();
private static final String COMPILER_ARGUMENTS_CLASS_NAME = CompilerArguments.class.getName(); private static final String COMPILER_ARGUMENTS_CLASS_NAME = CommonCompilerArguments.class.getName();
private static SoftReference<ClassLoader> ourClassLoaderRef = new SoftReference<ClassLoader>(null); private static SoftReference<ClassLoader> ourClassLoaderRef = new SoftReference<ClassLoader>(null);
public static List<File> kompilerClasspath(KotlinPaths paths, MessageCollector messageCollector) { public static List<File> kompilerClasspath(KotlinPaths paths, MessageCollector messageCollector) {
@@ -112,7 +112,7 @@ public class CompilerRunnerUtil {
} }
public static Object invokeExecMethod( public static Object invokeExecMethod(
String compilerClassName, CompilerArguments arguments, CompilerEnvironment environment, String compilerClassName, CommonCompilerArguments arguments, CompilerEnvironment environment,
MessageCollector messageCollector, PrintStream out, boolean usePreloader MessageCollector messageCollector, PrintStream out, boolean usePreloader
) throws Exception { ) throws Exception {
return invokeExecMethod(compilerClassName, COMPILER_ARGUMENTS_CLASS_NAME, arguments, environment, messageCollector, out, usePreloader); return invokeExecMethod(compilerClassName, COMPILER_ARGUMENTS_CLASS_NAME, arguments, environment, messageCollector, out, usePreloader);
@@ -36,7 +36,7 @@ public class KotlinCommonCompilerSettings extends BaseKotlinCompilerSettings<Com
@NotNull @NotNull
@Override @Override
protected CommonCompilerArguments createSettings() { protected CommonCompilerArguments createSettings() {
return CommonCompilerArguments.DUMMY; return new CommonCompilerArguments.DummyImpl();
} }
public static KotlinCommonCompilerSettings getInstance(Project project) { public static KotlinCommonCompilerSettings getInstance(Project project) {
@@ -29,7 +29,7 @@ public class JpsKotlinCompilerSettings extends JpsElementBase<JpsKotlinCompilerS
static final JpsElementChildRole<JpsKotlinCompilerSettings> ROLE = JpsElementChildRoleBase.create("Kotlin Compiler Settings"); static final JpsElementChildRole<JpsKotlinCompilerSettings> ROLE = JpsElementChildRoleBase.create("Kotlin Compiler Settings");
@NotNull @NotNull
public CommonCompilerArguments commonCompilerSettings = CommonCompilerArguments.DUMMY; public CommonCompilerArguments commonCompilerSettings = new CommonCompilerArguments.DummyImpl();
@NotNull @NotNull
public K2JVMCompilerArguments k2JvmCompilerSettings = new K2JVMCompilerArguments(); public K2JVMCompilerArguments k2JvmCompilerSettings = new K2JVMCompilerArguments();
@NotNull @NotNull
@@ -36,7 +36,7 @@ class KotlinCommonCompilerSettingsSerializer extends JpsProjectExtensionSerializ
public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) { public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
CommonCompilerArguments settings = XmlSerializer.deserialize(componentTag, CommonCompilerArguments.DummyImpl.class); CommonCompilerArguments settings = XmlSerializer.deserialize(componentTag, CommonCompilerArguments.DummyImpl.class);
if (settings == null) { if (settings == null) {
settings = CommonCompilerArguments.DUMMY; settings = new CommonCompilerArguments.DummyImpl();
} }
JpsKotlinCompilerSettings.setCommonSettings(project, settings); JpsKotlinCompilerSettings.setCommonSettings(project, settings);
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.maven.doc; package org.jetbrains.kotlin.maven.doc;
import org.apache.maven.plugin.MojoExecutionException; 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.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler; import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import org.jetbrains.kotlin.doc.KDocArguments; import org.jetbrains.kotlin.doc.KDocArguments;
@@ -184,7 +184,7 @@ public class KDocMojo extends KotlinCompileMojoBase {
} }
@Override @Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException { protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
if (arguments instanceof K2JVMCompilerArguments) { if (arguments instanceof K2JVMCompilerArguments) {
configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, docModule, sources, classpath, output); configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, docModule, sources, classpath, output);
} }
@@ -27,9 +27,9 @@ class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : Doclet
private val sourceDirs: List<File> = private val sourceDirs: List<File> =
compilerArguments compilerArguments
.getSourceDirs() .src
.orEmpty() .orEmpty()
.requireNoNulls() .split(File.pathSeparatorChar)
.map { path -> File(path).getCanonicalFile()!! } .map { path -> File(path).getCanonicalFile()!! }
private val sourceDirPaths: List<String> = sourceDirs.map { d -> d.getPath()!! } private val sourceDirPaths: List<String> = sourceDirs.map { d -> d.getPath()!! }
@@ -17,7 +17,7 @@ abstract class KModelCompilerPlugin(
public override fun processFiles(context: CompilerPluginContext) { public override fun processFiles(context: CompilerPluginContext) {
val bindingContext = context.getContext() val bindingContext = context.getContext()
val sources = context.getFiles() 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()) val model = KModel(bindingContext, arguments.apply(), sourceDirs, sources.requireNoNulls())
processModel(model) processModel(model)
@@ -22,8 +22,8 @@ class HtmlVisitorTest {
val args = K2JVMCompilerArguments() val args = K2JVMCompilerArguments()
args.kotlinHome = "../../../dist/kotlinc" args.kotlinHome = "../../../dist/kotlinc"
args.setSrc(srcDir.toString()) args.src = srcDir.toString()
args.setOutputDir(File(dir, "target/classes-htmldocs").toString()) args.outputDir = File(dir, "target/classes-htmldocs").toString()
val compiler = K2JVMCompiler() val compiler = K2JVMCompiler()
compiler.getCompilerPlugins().add(HtmlCompilerPlugin()) compiler.getCompilerPlugins().add(HtmlCompilerPlugin())
@@ -40,7 +40,7 @@ class KDocSampleTest {
val args = KDocArguments() val args = KDocArguments()
args.kotlinHome = "../../../dist/kotlinc" args.kotlinHome = "../../../dist/kotlinc"
args.setSourceDirs(arrayList("src/test/sample")) args.src = "src/test/sample"
val outputDir = File("target/apidocs-sample") val outputDir = File("target/apidocs-sample")
outputDir.rmrf() outputDir.rmrf()
@@ -8,6 +8,7 @@ import org.jetbrains.kotlin.doc.KDocArguments
import org.jetbrains.kotlin.doc.KDocCompiler import org.jetbrains.kotlin.doc.KDocCompiler
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import com.intellij.openapi.util.text.StringUtil
/** /**
*/ */
@@ -24,16 +25,15 @@ class KDocTest {
println("Generating library KDocs to $outDir") println("Generating library KDocs to $outDir")
val args = KDocArguments() val args = KDocArguments()
//args.setModule(moduleName) //args.module = moduleName
args.kotlinHome = "../../../dist/kotlinc" args.kotlinHome = "../../../dist/kotlinc"
val sourceDirs = ArrayList<String>() val sourceDirs = listOf("../../stdlib/src",
sourceDirs.add("../../stdlib/src") "../../kunit/src/main/kotlin",
sourceDirs.add("../../kunit/src/main/kotlin") "../../kotlin-jdbc/src/main/kotlin")
sourceDirs.add("../../kotlin-jdbc/src/main/kotlin") args.src = sourceDirs.makeString(File.pathSeparator)
args.setSourceDirs(sourceDirs) args.outputDir = "target/classes-stdlib"
args.setOutputDir("target/classes-stdlib") args.noStdlib = true
args.setNoStdlib(true) args.classpath = "../runtime/target/kotlin-runtime-0.1-SNAPSHOT.jar${File.pathSeparator}../../lib/junit-4.9.jar"
args.setClasspath("../runtime/target/kotlin-runtime-0.1-SNAPSHOT.jar${File.pathSeparator}../../lib/junit-4.9.jar")
val config = args.docConfig val config = args.docConfig
config.docOutputDir = outDir.toString() config.docOutputDir = outDir.toString()
@@ -90,16 +90,16 @@ public open class KotlinCompile(): AbstractCompile() {
return return
} }
val customSources = args.getSourceDirs(); val customSources = args.src;
if (customSources == null || customSources.isEmpty()) { 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)) { if (StringUtils.isEmpty(kotlinOptions.classpath)) {
val existingClasspathEntries = getClasspath().filter(KSpec<File?>({ it != null && it.exists() })) val existingClasspathEntries = getClasspath().filter(KSpec<File?>({ it != null && it.exists() }))
val effectiveClassPath = (javaSrcRoots + existingClasspathEntries).makeString(File.pathSeparator) 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 } 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.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.jetbrains.jet.cli.common.CLICompiler; 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.common.arguments.K2JSCompilerArguments;
import org.jetbrains.jet.cli.js.K2JSCompiler; import org.jetbrains.jet.cli.js.K2JSCompiler;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
@@ -150,7 +150,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
} }
@Override @Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException { protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
super.configureCompilerArguments(arguments); super.configureCompilerArguments(arguments);
if (arguments instanceof K2JSCompilerArguments) { if (arguments instanceof K2JSCompilerArguments) {
@@ -168,7 +168,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
} }
@Override @Override
protected CompilerArguments createCompilerArguments() { protected CommonCompilerArguments createCompilerArguments() {
return new K2JSCompilerArguments(); return new K2JSCompilerArguments();
} }
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.maven; package org.jetbrains.kotlin.maven;
import org.apache.maven.plugin.MojoExecutionException; 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.common.arguments.K2JVMCompilerArguments;
/** /**
@@ -30,7 +30,7 @@ import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
*/ */
public class KotlinCompileMojo extends KotlinCompileMojoBase { public class KotlinCompileMojo extends KotlinCompileMojoBase {
@Override @Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException { protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
if (arguments instanceof K2JVMCompilerArguments) { if (arguments instanceof K2JVMCompilerArguments) {
configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, module, getSources(), classpath, output); configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, module, getSources(), classpath, output);
} }
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.maven; package org.jetbrains.kotlin.maven;
import com.google.common.base.Joiner;
import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtil;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo; 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.CLICompiler;
import org.jetbrains.jet.cli.common.ExitCode; import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.cli.common.KotlinVersion; 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.CompilerMessageLocation;
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
import org.jetbrains.jet.cli.common.messages.MessageCollector; 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 org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import java.io.File; import java.io.File;
@@ -172,7 +171,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
} }
} }
final CompilerArguments arguments = createCompilerArguments(); final CommonCompilerArguments arguments = createCompilerArguments();
configureCompilerArguments(arguments); configureCompilerArguments(arguments);
final CLICompiler compiler = createCompiler(); 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()) { if (getLog().isDebugEnabled()) {
getLog().debug("Invoking compiler " + compiler + " with arguments:"); getLog().debug("Invoking compiler " + compiler + " with arguments:");
try { try {
@@ -247,14 +246,14 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
* Derived classes can create custom compiler argument implementations * Derived classes can create custom compiler argument implementations
* such as for KDoc * such as for KDoc
*/ */
protected CompilerArguments createCompilerArguments() { protected CommonCompilerArguments createCompilerArguments() {
return new K2JVMCompilerArguments(); return new K2JVMCompilerArguments();
} }
/** /**
* Derived classes can register custom plugins or configurations * 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, protected void configureBaseCompilerArguments(Log log, K2JVMCompilerArguments arguments, String module,
List<String> sources, List<String> classpath, String output) throws MojoExecutionException { List<String> sources, List<String> classpath, String output) throws MojoExecutionException {
@@ -265,14 +264,14 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
if (module != null) { if (module != null) {
log.info("Compiling Kotlin module " + module); log.info("Compiling Kotlin module " + module);
arguments.setModule(module); arguments.module = module;
} }
else { else {
if (sources.size() <= 0) if (sources.size() <= 0)
throw new MojoExecutionException("No source roots to compile"); throw new MojoExecutionException("No source roots to compile");
arguments.setSourceDirs(sources); arguments.src = join(sources, File.pathSeparator);
log.info("Compiling Kotlin sources from " + arguments.getSourceDirs()); log.info("Compiling Kotlin sources from " + arguments.src);
// TODO: Move it compiler // TODO: Move it compiler
classpathList.addAll(sources); classpathList.addAll(sources);
@@ -285,13 +284,13 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
} }
if (classpathList.size() > 0) { if (classpathList.size() > 0) {
final String classPathString = Joiner.on(File.pathSeparator).join(classpathList); String classPathString = join(classpathList, File.pathSeparator);
log.info("Classpath: " + classPathString); log.info("Classpath: " + classPathString);
arguments.setClasspath(classPathString); arguments.classpath = classPathString;
} }
log.info("Classes directory is " + output); log.info("Classes directory is " + output);
arguments.setOutputDir(output); arguments.outputDir = output;
arguments.noJdkAnnotations = true; arguments.noJdkAnnotations = true;
arguments.annotations = getFullAnnotationsPath(log, annotationPaths); 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.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; 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 org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
import java.util.List; import java.util.List;
@@ -86,7 +86,7 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
} }
@Override @Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException { protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
if (arguments instanceof K2JVMCompilerArguments) { if (arguments instanceof K2JVMCompilerArguments) {
configureBaseCompilerArguments( configureBaseCompilerArguments(
getLog(), (K2JVMCompilerArguments) arguments, getLog(), (K2JVMCompilerArguments) arguments,