Maven: metadata mojo initial implementation

This commit is contained in:
Sergey Mashkov
2016-12-29 18:15:18 +03:00
parent b81268cca1
commit 60f95e078f
2 changed files with 56 additions and 0 deletions
@@ -72,6 +72,9 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
@Parameter
private List<String> pluginOptions;
@Parameter
private boolean multiPlatform = false;
private List<String> getAppliedCompilerPlugins() {
return (compilerPlugins == null) ? Collections.<String>emptyList() : compilerPlugins;
}
@@ -359,6 +362,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
arguments.suppressWarnings = nowarn;
arguments.languageVersion = languageVersion;
arguments.apiVersion = apiVersion;
arguments.multiPlatform = multiPlatform;
getLog().info("Compiling Kotlin sources from " + sources);
@@ -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<K2MetadataCompilerArguments> {
@Parameter(defaultValue = "${project.compileClasspathElements}", required = true, readonly = true)
public List<String> classpath;
@NotNull
@Override
protected CLICompiler<K2MetadataCompilerArguments> 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<String> classpathList = filterClassPath(project.getBasedir(), classpath);
if (!classpathList.isEmpty()) {
String classPathString = join(classpathList, File.pathSeparator);
getLog().debug("Classpath: " + classPathString);
arguments.classpath = classPathString;
}
}
}