kotlin-maven-plugin, ant:withKotlin: skip compilation for empty sources
#KT-7618 Fixed
This commit is contained in:
@@ -87,16 +87,26 @@ public class KotlinCompilerAdapter extends Javac13 {
|
||||
|
||||
kotlinc.getAdditionalArguments().addAll(additionalArguments);
|
||||
|
||||
kotlinc.execute();
|
||||
if (!Integer.valueOf(0).equals(kotlinc.getExitCode())) {
|
||||
// Don't run javac if failOnError = false and there were errors on Kotlin sources
|
||||
return false;
|
||||
// Javac13#execute passes everything in compileList to javac, which doesn't recognize .kt files
|
||||
File[] compileListForJavac = filterOutKotlinSources(compileList);
|
||||
|
||||
boolean hasKotlinFilesInSources = compileListForJavac.length < compileList.length;
|
||||
|
||||
if (hasKotlinFilesInSources) {
|
||||
kotlinc.execute();
|
||||
if (!Integer.valueOf(0).equals(kotlinc.getExitCode())) {
|
||||
// Don't run javac if failOnError = false and there were errors on Kotlin sources
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// This is needed for addRuntimeToJavacClasspath, where kotlinc arguments will be used.
|
||||
kotlinc.fillArguments();
|
||||
}
|
||||
|
||||
javac.log("Running javac...");
|
||||
|
||||
// Javac13#execute passes everything in compileList to javac, which doesn't recognize .kt files
|
||||
compileList = filterOutKotlinSources(compileList);
|
||||
compileList = compileListForJavac;
|
||||
|
||||
addRuntimeToJavacClasspath(kotlinc);
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class KotlinCompilerBaseTask : Task() {
|
||||
|
||||
abstract fun fillSpecificArguments()
|
||||
|
||||
private fun fillArguments() {
|
||||
public fun fillArguments() {
|
||||
val sourcePaths = src ?: throw BuildException("\"src\" should be specified")
|
||||
args.addAll(sourcePaths.list().map { File(it).canonicalPath })
|
||||
|
||||
|
||||
+25
-16
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.maven;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.sampullara.cli.Args;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
@@ -109,22 +111,9 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
||||
|
||||
LOG.info("Kotlin Compiler version " + KotlinVersion.VERSION);
|
||||
|
||||
// Check sources
|
||||
List<String> sources = getSources();
|
||||
if (sources != null && sources.size() > 0) {
|
||||
boolean sourcesExists = false;
|
||||
|
||||
for (String source : sources) {
|
||||
if (new File(source).exists()) {
|
||||
sourcesExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sourcesExists) {
|
||||
LOG.warn("No sources found skipping Kotlin compile");
|
||||
return;
|
||||
}
|
||||
if (!hasKotlinFilesInSources()) {
|
||||
LOG.warn("No sources found skipping Kotlin compile");
|
||||
return;
|
||||
}
|
||||
|
||||
A arguments = createCompilerArguments();
|
||||
@@ -164,6 +153,26 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasKotlinFilesInSources() throws MojoExecutionException {
|
||||
List<String> sources = getSources();
|
||||
if (sources == null || sources.isEmpty()) return false;
|
||||
|
||||
for (String source : sources) {
|
||||
File root = new File(source);
|
||||
if (root.exists()) {
|
||||
boolean sourcesExists = !FileUtil.processFilesRecursively(root, new Processor<File>() {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
return !file.getName().endsWith(".kt");
|
||||
}
|
||||
});
|
||||
if (sourcesExists) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void printCompilerArgumentsIfDebugEnabled(@NotNull A arguments, @NotNull CLICompiler<A> compiler) {
|
||||
if (getLog().isDebugEnabled()) {
|
||||
getLog().debug("Invoking compiler " + compiler + " with arguments:");
|
||||
|
||||
Reference in New Issue
Block a user