KT-12074 Building Kotlin maven projects using a parent pom will silently fail

We should consider module's basedir if there is relative source directory specified for the execution
This commit is contained in:
Sergey Mashkov
2016-05-10 23:11:06 +03:00
parent add07ad1a5
commit 77df2e07ad
5 changed files with 27 additions and 15 deletions
@@ -1,4 +1,3 @@
[INFO] Kotlin Compiler version @snapshot@
[INFO] Compiling Kotlin sources from [/src/main/kotlin]
[INFO] Classes directory is /target/classes
[INFO] Module name is test-project
@@ -89,11 +89,11 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
if (!classpathList.isEmpty()) {
String classPathString = join(classpathList, File.pathSeparator);
getLog().info("Classpath: " + classPathString);
getLog().debug("Classpath: " + classPathString);
arguments.classpath = classPathString;
}
getLog().info("Classes directory is " + output);
getLog().debug("Classes directory is " + output);
arguments.destination = output;
arguments.moduleName = moduleName;
@@ -22,7 +22,6 @@ import com.intellij.util.Processor;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.jetbrains.annotations.NotNull;
@@ -30,8 +29,6 @@ import org.jetbrains.kotlin.cli.common.CLICompiler;
import org.jetbrains.kotlin.cli.common.ExitCode;
import org.jetbrains.kotlin.cli.common.KotlinVersion;
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation;
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity;
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
import org.jetbrains.kotlin.config.Services;
@@ -59,11 +56,28 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
@Parameter
private List<String> sourceDirs;
public List<String> getSources() {
protected List<String> getSourceFilePaths() {
if (sourceDirs != null && !sourceDirs.isEmpty()) return sourceDirs;
return defaultSourceDirs;
}
public List<File> getSourceDirs() {
List<String> sources = getSourceFilePaths();
List<File> result = new ArrayList<File>(sources.size());
File baseDir = project.getBasedir();
for (String source : sources) {
File f = new File(source);
if (f.isAbsolute()) {
result.add(f);
} else {
result.add(new File(baseDir, source));
}
}
return result;
}
/**
* Suppress all warnings.
*/
@@ -133,11 +147,10 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
}
private boolean hasKotlinFilesInSources() throws MojoExecutionException {
List<String> sources = getSources();
List<File> sources = getSourceDirs();
if (sources == null || sources.isEmpty()) return false;
for (String source : sources) {
File root = new File(source);
for (File root : sources) {
if (root.exists()) {
boolean sourcesExists = !FileUtil.processFilesRecursively(root, new Processor<File>() {
@Override
@@ -211,9 +224,9 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
}
List<String> sources = new ArrayList<String>();
for (String source : getSources()) {
if (new File(source).exists()) {
sources.add(source);
for (File source : getSourceDirs()) {
if (source.exists()) {
sources.add(source.getPath());
}
else {
getLog().warn("Source root doesn't exist: " + source);
@@ -61,7 +61,7 @@ public class KotlinTestCompileMojo extends K2JVMCompileMojo {
private List<String> sourceDirs;
@Override
public List<String> getSources() {
public List<String> getSourceFilePaths() {
if (sourceDirs != null && !sourceDirs.isEmpty()) return sourceDirs;
return defaultSourceDirs;
}
@@ -65,7 +65,7 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo {
private List<String> sourceDirs;
@Override
public List<String> getSources() {
public List<String> getSourceFilePaths() {
if (sourceDirs != null && !sourceDirs.isEmpty()) return sourceDirs;
return defaultSourceDirs;
}