Add source directories to classpath in CLI compiler

Move this logic from Ant and Maven plugins
This commit is contained in:
Alexander Udalov
2015-01-27 17:56:18 +03:00
parent 3ea59117ac
commit 93f02aeead
3 changed files with 26 additions and 37 deletions
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.ant
import org.apache.tools.ant.types.Path
import org.apache.tools.ant.types.Reference
import java.io.File
import java.io.File.pathSeparator
public class Kotlin2JvmTask : KotlinCompilerBaseTask() {
@@ -60,18 +59,11 @@ public class Kotlin2JvmTask : KotlinCompilerBaseTask() {
args.add("-d")
args.add(output!!.canonicalPath)
val classpath = arrayListOf<String>()
compileClasspath?.let { classpath.addAll(it.list()) }
src!!.list().forEach {
val file = File(it)
if (file.isDirectory() || file.extension != "kt") {
classpath.add(it)
}
compileClasspath?.let {
args.add("-classpath")
args.add(it.list().join(pathSeparator))
}
args.add("-classpath")
args.add(classpath.join(pathSeparator))
externalAnnotations?.let {
args.add("-annotations")
args.add(it.list().join(pathSeparator))
@@ -81,25 +81,16 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
}
try {
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(paths, arguments));
configuration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, getAnnotationsPath(paths, arguments));
if (!arguments.noJdk) {
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.getJdkClassesRoots());
}
}
catch (Throwable t) {
MessageCollectorUtil.reportException(messageCollector, t);
return INTERNAL_ERROR;
}
if (!arguments.script &&
arguments.module == null &&
arguments.freeArgs.isEmpty() &&
!arguments.version
) {
ReplFromTerminal.run(rootDisposable, configuration);
return ExitCode.OK;
}
else if (arguments.module != null) {
}
else if (arguments.script) {
if (arguments.script) {
if (arguments.freeArgs.isEmpty()) {
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify script source path to evaluate",
CompilerMessageLocation.NO_LOCATION);
@@ -107,8 +98,24 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
}
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, arguments.freeArgs.get(0));
}
else {
else if (arguments.module == null) {
CompileEnvironmentUtil.addSourceFilesCheckingForDuplicates(configuration, arguments.freeArgs);
// Adding all directory sources to classpath to resolve Java symbols from Kotlin
for (String source : arguments.freeArgs) {
File file = new File(source);
if (file.isDirectory()) {
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, file);
}
}
}
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(paths, arguments));
configuration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, getAnnotationsPath(paths, arguments));
if (arguments.module == null && arguments.freeArgs.isEmpty() && !arguments.version) {
ReplFromTerminal.run(rootDisposable, configuration);
return ExitCode.OK;
}
configuration.put(JVMConfigurationKeys.SCRIPT_PARAMETERS, arguments.script
@@ -191,9 +198,6 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
@NotNull
private static List<File> getClasspath(@NotNull KotlinPaths paths, @NotNull K2JVMCompilerArguments arguments) {
List<File> classpath = Lists.newArrayList();
if (!arguments.noJdk) {
classpath.addAll(PathUtil.getJdkClassesRoots());
}
if (arguments.classpath != null) {
for (String element : Splitter.on(File.pathSeparatorChar).split(arguments.classpath)) {
classpath.add(new File(element));
@@ -98,24 +98,17 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
// don't include runtime, it should be in maven dependencies
arguments.noStdlib = true;
ArrayList<String> classpathList = new ArrayList<String>();
if (module != null) {
LOG.info("Compiling Kotlin module " + module);
arguments.module = module;
}
else {
// TODO: Move it compiler
classpathList.addAll(getSources());
}
classpathList.addAll(classpath);
ArrayList<String> classpathList = new ArrayList<String>(classpath);
if (classpathList.remove(output)) {
LOG.debug("Removed target directory from compiler classpath (" + output + ")");
}
if (classpathList.size() > 0) {
if (!classpathList.isEmpty()) {
String classPathString = join(classpathList, File.pathSeparator);
LOG.info("Classpath: " + classPathString);
arguments.classpath = classPathString;