Always run kotlinc in <withKotlin/> Ant task
This change requires withKotlin to be run with Ant of version at least 1.8.2. Some test data changed because now compileList contains both Java and Kotlin sources #KT-7870 Fixed
This commit is contained in:
@@ -16,13 +16,21 @@
|
||||
|
||||
package org.jetbrains.kotlin.ant;
|
||||
|
||||
import kotlin.KotlinPackage;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.taskdefs.Javac;
|
||||
import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
|
||||
import org.apache.tools.ant.taskdefs.compilers.Javac13;
|
||||
import org.apache.tools.ant.types.Path;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class KotlinCompilerAdapter extends Javac13 {
|
||||
private static final List<String> KOTLIN_EXTENSIONS = Arrays.asList("kt", "kts");
|
||||
|
||||
public class KotlinCompilerAdapter extends DefaultCompilerAdapter {
|
||||
private Path externalAnnotations;
|
||||
|
||||
public void setExternalAnnotations(Path externalAnnotations) {
|
||||
@@ -36,27 +44,53 @@ public class KotlinCompilerAdapter extends DefaultCompilerAdapter {
|
||||
return externalAnnotations.createPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSupportedFileExtensions() {
|
||||
List<String> result = KotlinPackage.plus(Arrays.asList(super.getSupportedFileExtensions()), KOTLIN_EXTENSIONS);
|
||||
//noinspection SSBasedInspection
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() throws BuildException {
|
||||
Javac javac = getJavac();
|
||||
|
||||
Kotlin2JvmTask kotlinTask = new Kotlin2JvmTask();
|
||||
kotlinTask.setOutput(javac.getDestdir());
|
||||
Kotlin2JvmTask kotlinc = new Kotlin2JvmTask();
|
||||
kotlinc.setOutput(javac.getDestdir());
|
||||
|
||||
Path classpath = javac.getClasspath();
|
||||
if (classpath != null) {
|
||||
kotlinTask.setClasspath(classpath);
|
||||
kotlinc.setClasspath(classpath);
|
||||
}
|
||||
|
||||
kotlinTask.setSrc(javac.getSrcdir());
|
||||
kotlinTask.setExternalAnnotations(externalAnnotations);
|
||||
// We use the provided src dir instead of compileList, because the latter is insane:
|
||||
// it is constructed only of sources which are newer than classes with the same name
|
||||
kotlinc.setSrc(javac.getSrcdir());
|
||||
|
||||
kotlinTask.execute();
|
||||
kotlinc.setExternalAnnotations(externalAnnotations);
|
||||
|
||||
kotlinc.execute();
|
||||
|
||||
javac.log("Running javac...");
|
||||
|
||||
Javac13 javac13 = new Javac13();
|
||||
javac13.setJavac(javac);
|
||||
return javac13.execute();
|
||||
// Javac13#execute passes everything in compileList to javac, which doesn't recognize .kt files
|
||||
compileList = filterOutKotlinSources(compileList);
|
||||
|
||||
return compileList.length == 0 || super.execute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File[] filterOutKotlinSources(@NotNull File[] files) {
|
||||
List<File> nonKotlinSources = KotlinPackage.filterNot(files, new Function1<File, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(File file) {
|
||||
for (String extension : KOTLIN_EXTENSIONS) {
|
||||
if (file.getPath().endsWith("." + extension)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return nonKotlinSources.toArray(new File[nonKotlinSources.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user