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! :)

This commit is contained in:
James Strachan
2012-10-25 10:57:31 +01:00
parent 3043577949
commit c843d23416
4 changed files with 67 additions and 15 deletions
@@ -30,6 +30,7 @@ import org.jetbrains.k2js.config.MetaInfServices;
import java.io.*; import java.io.*;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
/** /**
* Converts Kotlin to JavaScript code * Converts Kotlin to JavaScript code
@@ -163,6 +164,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
if (verbose != null) { if (verbose != null) {
k2jsArgs.verbose = verbose; k2jsArgs.verbose = verbose;
} }
List<String> sources = getSources();
if (sources.size() > 0) { if (sources.size() > 0) {
k2jsArgs.sourceFiles = sources.toArray(new String[sources.size()]); k2jsArgs.sourceFiles = sources.toArray(new String[sources.size()]);
} }
@@ -32,7 +32,7 @@ public class KotlinCompileMojo extends KotlinCompileMojoBase {
@Override @Override
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException { protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
if (arguments instanceof K2JVMCompilerArguments) { if (arguments instanceof K2JVMCompilerArguments) {
configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, module, sources, classpath, output); configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, module, getSources(), classpath, output);
} }
} }
} }
@@ -39,17 +39,32 @@ import java.util.List;
import static org.jetbrains.jet.internal.com.intellij.openapi.util.text.StringUtil.join; import static org.jetbrains.jet.internal.com.intellij.openapi.util.text.StringUtil.join;
public abstract class KotlinCompileMojoBase extends AbstractMojo { 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 <execution> 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}" * @parameter default-value="${project.compileSourceRoots}"
* @required * @required
* @readonly
*/ */
public List<String> sources; private List<String> 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<String> sourceDirs;
public List<String> getSources() {
if (sourceDirs != null && !sourceDirs.isEmpty()) return sourceDirs;
return defaultSourceDirs;
}
/** /**
* The directories used to scan for annotation.xml files for Kotlin annotations * The directories used to scan for annotation.xml files for Kotlin annotations
@@ -58,14 +73,10 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
*/ */
public List<String> annotationPaths; public List<String> annotationPaths;
/** // TODO not sure why this doesn't work :(
* The source directories containing the sources to be compiled for tests. // * @parameter default-value="$(project.basedir}/src/main/resources"
*
* @parameter default-value="${project.testCompileSourceRoots}"
* @required
* @readonly
*/
protected List<String> testSources;
/** /**
* Project classpath. * Project classpath.
@@ -120,6 +131,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
@Override @Override
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
// Check sources // Check sources
List<String> sources = getSources();
if (sources != null && sources.size() > 0) { if (sources != null && sources.size() > 0) {
boolean sourcesExists = false; boolean sourcesExists = false;
@@ -21,6 +21,8 @@ import org.apache.maven.plugin.MojoFailureException;
import org.jetbrains.jet.cli.common.CompilerArguments; import org.jetbrains.jet.cli.common.CompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments; import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments;
import java.util.List;
/** /**
* Compiles Kotlin test sources * Compiles Kotlin test sources
* *
@@ -38,6 +40,42 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
*/ */
private boolean skip; 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 <execution> 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<String> defaultSourceDirs;
/**
* The source directories containing the sources to be compiled.
*
* @parameter
*/
private List<String> sourceDirs;
@Override
public List<String> 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<String> defaultSourceDir;
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) { if (skip) {
getLog().info("Test compilation is skipped"); getLog().info("Test compilation is skipped");
@@ -52,7 +90,7 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
if (arguments instanceof K2JVMCompilerArguments) { if (arguments instanceof K2JVMCompilerArguments) {
configureBaseCompilerArguments( configureBaseCompilerArguments(
getLog(), (K2JVMCompilerArguments) arguments, getLog(), (K2JVMCompilerArguments) arguments,
testModule, testSources, testClasspath, testOutput); testModule, getSources(), testClasspath, testOutput);
} }
} }
} }