From 60f95e078fa22cbbb8537ee5bcb641eccab28b24 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Thu, 29 Dec 2016 18:15:18 +0300 Subject: [PATCH] Maven: metadata mojo initial implementation --- .../kotlin/maven/KotlinCompileMojoBase.java | 4 ++ .../jetbrains/kotlin/maven/MetadataMojo.java | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MetadataMojo.java 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 03890118097..61091633d89 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 @@ -72,6 +72,9 @@ public abstract class KotlinCompileMojoBase e @Parameter private List pluginOptions; + @Parameter + private boolean multiPlatform = false; + private List getAppliedCompilerPlugins() { return (compilerPlugins == null) ? Collections.emptyList() : compilerPlugins; } @@ -359,6 +362,7 @@ public abstract class KotlinCompileMojoBase e arguments.suppressWarnings = nowarn; arguments.languageVersion = languageVersion; arguments.apiVersion = apiVersion; + arguments.multiPlatform = multiPlatform; getLog().info("Compiling Kotlin sources from " + sources); diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MetadataMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MetadataMojo.java new file mode 100644 index 00000000000..acb19578e7a --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MetadataMojo.java @@ -0,0 +1,52 @@ +package org.jetbrains.kotlin.maven; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.cli.common.CLICompiler; +import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments; +import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler; + +import java.io.File; +import java.util.List; + +import static com.intellij.openapi.util.text.StringUtil.join; +import static org.jetbrains.kotlin.maven.Util.filterClassPath; + +@Mojo(name = "metadata", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE) +public class MetadataMojo extends KotlinCompileMojoBase { + @Parameter(defaultValue = "${project.compileClasspathElements}", required = true, readonly = true) + public List classpath; + + @NotNull + @Override + protected CLICompiler createCompiler() { + return new K2MetadataCompiler(); + } + + @NotNull + @Override + protected K2MetadataCompilerArguments createCompilerArguments() { + return new K2MetadataCompilerArguments(); + } + + @Override + protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments) throws MojoExecutionException { + arguments.destination = output; + if (!arguments.multiPlatform) { + getLog().info("multiPlatform forced for metadata generation"); + arguments.multiPlatform = true; + } + + List classpathList = filterClassPath(project.getBasedir(), classpath); + + if (!classpathList.isEmpty()) { + String classPathString = join(classpathList, File.pathSeparator); + getLog().debug("Classpath: " + classPathString); + arguments.classpath = classPathString; + } + } +}