From c843d2341653572b1806bf0f844d3abdb093d1ea Mon Sep 17 00:00:00 2001 From: James Strachan Date: Thu, 25 Oct 2012 10:57:31 +0100 Subject: [PATCH] allow the maven plugin to have its source directories to be configured on a per execution basis (e.g. so that you can have different directories for JS compilation as to JVM based compilation). Its a shame to require 2 fields for configuration; but tried all other permutations I could think of but could not figure out a cleaner way -better approaches welcome! :) --- .../kotlin/maven/K2JSCompilerMojo.java | 2 + .../kotlin/maven/KotlinCompileMojo.java | 2 +- .../kotlin/maven/KotlinCompileMojoBase.java | 38 ++++++++++++------ .../kotlin/maven/KotlinTestCompileMojo.java | 40 ++++++++++++++++++- 4 files changed, 67 insertions(+), 15 deletions(-) diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java index 5d63d556cfb..f7bd001c11b 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java @@ -30,6 +30,7 @@ import org.jetbrains.k2js.config.MetaInfServices; import java.io.*; import java.nio.charset.Charset; import java.util.Arrays; +import java.util.List; /** * Converts Kotlin to JavaScript code @@ -163,6 +164,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo { if (verbose != null) { k2jsArgs.verbose = verbose; } + List sources = getSources(); if (sources.size() > 0) { k2jsArgs.sourceFiles = sources.toArray(new String[sources.size()]); } diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojo.java index a4dc2576d3a..54dd400718a 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojo.java @@ -32,7 +32,7 @@ public class KotlinCompileMojo extends KotlinCompileMojoBase { @Override protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException { if (arguments instanceof K2JVMCompilerArguments) { - configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, module, sources, classpath, output); + configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, module, getSources(), classpath, output); } } } diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java index f8d1d52036e..7e43239e6ab 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java @@ -39,17 +39,32 @@ import java.util.List; import static org.jetbrains.jet.internal.com.intellij.openapi.util.text.StringUtil.join; public abstract class KotlinCompileMojoBase extends AbstractMojo { + + + // TODO it would be nice to avoid using 2 injected fields for sources + // but I've not figured out how to have a defaulted parameter value + // which is also customisable inside an in a maven pom.xml + // so for now lets just use 2 fields + /** - * The source directories containing the sources to be compiled. + * The default source directories containing the sources to be compiled. * * @parameter default-value="${project.compileSourceRoots}" * @required - * @readonly */ - public List sources; + private List defaultSourceDirs; - // TODO not sure why this doesn't work :( - // * @parameter default-value="$(project.basedir}/src/main/resources" + /** + * The source directories containing the sources to be compiled. + * + * @parameter + */ + private List sourceDirs; + + public List getSources() { + if (sourceDirs != null && !sourceDirs.isEmpty()) return sourceDirs; + return defaultSourceDirs; + } /** * The directories used to scan for annotation.xml files for Kotlin annotations @@ -58,14 +73,10 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo { */ public List annotationPaths; - /** - * The source directories containing the sources to be compiled for tests. - * - * @parameter default-value="${project.testCompileSourceRoots}" - * @required - * @readonly - */ - protected List testSources; + // TODO not sure why this doesn't work :( + // * @parameter default-value="$(project.basedir}/src/main/resources" + + /** * Project classpath. @@ -120,6 +131,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { // Check sources + List sources = getSources(); if (sources != null && sources.size() > 0) { boolean sourcesExists = false; diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java index 0253ad02bea..3fa45beb741 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java @@ -21,6 +21,8 @@ import org.apache.maven.plugin.MojoFailureException; import org.jetbrains.jet.cli.common.CompilerArguments; import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments; +import java.util.List; + /** * Compiles Kotlin test sources * @@ -38,6 +40,42 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase { */ private boolean skip; + + // TODO it would be nice to avoid using 2 injected fields for sources + // but I've not figured out how to have a defaulted parameter value + // which is also customisable inside an in a maven pom.xml + // so for now lets just use 2 fields + + /** + * The default source directories containing the sources to be compiled. + * + * @parameter default-value="${project.testCompileSourceRoots}" + * @required + */ + private List defaultSourceDirs; + + /** + * The source directories containing the sources to be compiled. + * + * @parameter + */ + private List sourceDirs; + + @Override + public List getSources() { + if (sourceDirs != null && !sourceDirs.isEmpty()) return sourceDirs; + return defaultSourceDirs; + } + + /** + * The source directories containing the sources to be compiled for tests. + * + * @parameter default-value="${project.testCompileSourceRoots}" + * @required + * @readonly + */ + private List defaultSourceDir; + public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info("Test compilation is skipped"); @@ -52,7 +90,7 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase { if (arguments instanceof K2JVMCompilerArguments) { configureBaseCompilerArguments( getLog(), (K2JVMCompilerArguments) arguments, - testModule, testSources, testClasspath, testOutput); + testModule, getSources(), testClasspath, testOutput); } } }