Add source directories to classpath in CLI compiler
Move this logic from Ant and Maven plugins
This commit is contained in:
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.ant
|
|||||||
|
|
||||||
import org.apache.tools.ant.types.Path
|
import org.apache.tools.ant.types.Path
|
||||||
import org.apache.tools.ant.types.Reference
|
import org.apache.tools.ant.types.Reference
|
||||||
import java.io.File
|
|
||||||
import java.io.File.pathSeparator
|
import java.io.File.pathSeparator
|
||||||
|
|
||||||
public class Kotlin2JvmTask : KotlinCompilerBaseTask() {
|
public class Kotlin2JvmTask : KotlinCompilerBaseTask() {
|
||||||
@@ -60,18 +59,11 @@ public class Kotlin2JvmTask : KotlinCompilerBaseTask() {
|
|||||||
args.add("-d")
|
args.add("-d")
|
||||||
args.add(output!!.canonicalPath)
|
args.add(output!!.canonicalPath)
|
||||||
|
|
||||||
val classpath = arrayListOf<String>()
|
compileClasspath?.let {
|
||||||
compileClasspath?.let { classpath.addAll(it.list()) }
|
args.add("-classpath")
|
||||||
src!!.list().forEach {
|
args.add(it.list().join(pathSeparator))
|
||||||
val file = File(it)
|
|
||||||
if (file.isDirectory() || file.extension != "kt") {
|
|
||||||
classpath.add(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args.add("-classpath")
|
|
||||||
args.add(classpath.join(pathSeparator))
|
|
||||||
|
|
||||||
externalAnnotations?.let {
|
externalAnnotations?.let {
|
||||||
args.add("-annotations")
|
args.add("-annotations")
|
||||||
args.add(it.list().join(pathSeparator))
|
args.add(it.list().join(pathSeparator))
|
||||||
|
|||||||
@@ -81,25 +81,16 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(paths, arguments));
|
if (!arguments.noJdk) {
|
||||||
configuration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, getAnnotationsPath(paths, arguments));
|
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.getJdkClassesRoots());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
MessageCollectorUtil.reportException(messageCollector, t);
|
MessageCollectorUtil.reportException(messageCollector, t);
|
||||||
return INTERNAL_ERROR;
|
return INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!arguments.script &&
|
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.freeArgs.isEmpty()) {
|
if (arguments.freeArgs.isEmpty()) {
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify script source path to evaluate",
|
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify script source path to evaluate",
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
@@ -107,8 +98,24 @@ 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 if (arguments.module == null) {
|
||||||
CompileEnvironmentUtil.addSourceFilesCheckingForDuplicates(configuration, arguments.freeArgs);
|
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
|
configuration.put(JVMConfigurationKeys.SCRIPT_PARAMETERS, arguments.script
|
||||||
@@ -191,9 +198,6 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static List<File> getClasspath(@NotNull KotlinPaths paths, @NotNull K2JVMCompilerArguments arguments) {
|
private static List<File> getClasspath(@NotNull KotlinPaths paths, @NotNull K2JVMCompilerArguments arguments) {
|
||||||
List<File> classpath = Lists.newArrayList();
|
List<File> classpath = Lists.newArrayList();
|
||||||
if (!arguments.noJdk) {
|
|
||||||
classpath.addAll(PathUtil.getJdkClassesRoots());
|
|
||||||
}
|
|
||||||
if (arguments.classpath != null) {
|
if (arguments.classpath != null) {
|
||||||
for (String element : Splitter.on(File.pathSeparatorChar).split(arguments.classpath)) {
|
for (String element : Splitter.on(File.pathSeparatorChar).split(arguments.classpath)) {
|
||||||
classpath.add(new File(element));
|
classpath.add(new File(element));
|
||||||
|
|||||||
+2
-9
@@ -98,24 +98,17 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
|||||||
// don't include runtime, it should be in maven dependencies
|
// don't include runtime, it should be in maven dependencies
|
||||||
arguments.noStdlib = true;
|
arguments.noStdlib = true;
|
||||||
|
|
||||||
ArrayList<String> classpathList = new ArrayList<String>();
|
|
||||||
|
|
||||||
if (module != null) {
|
if (module != null) {
|
||||||
LOG.info("Compiling Kotlin module " + module);
|
LOG.info("Compiling Kotlin module " + module);
|
||||||
arguments.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)) {
|
if (classpathList.remove(output)) {
|
||||||
LOG.debug("Removed target directory from compiler classpath (" + output + ")");
|
LOG.debug("Removed target directory from compiler classpath (" + output + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classpathList.size() > 0) {
|
if (!classpathList.isEmpty()) {
|
||||||
String classPathString = join(classpathList, File.pathSeparator);
|
String classPathString = join(classpathList, File.pathSeparator);
|
||||||
LOG.info("Classpath: " + classPathString);
|
LOG.info("Classpath: " + classPathString);
|
||||||
arguments.classpath = classPathString;
|
arguments.classpath = classPathString;
|
||||||
|
|||||||
Reference in New Issue
Block a user