Add new JS source map config options to Maven plugin

This commit is contained in:
Alexey Andreev
2017-06-13 15:05:10 +03:00
parent cfd3b137d8
commit 49b742ab3d
13 changed files with 123 additions and 27 deletions
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.maven;
import com.intellij.openapi.util.text.StringUtil;
import kotlin.text.StringsKt;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -29,16 +28,13 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
import org.jetbrains.kotlin.utils.LibraryUtils;
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils;
import org.jetbrains.kotlin.js.JavaScript;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -71,6 +67,9 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
@Parameter(defaultValue = "false")
private boolean sourceMap;
@Parameter
private String sourceMapPrefix;
/**
* Main invocation behaviour. Possible values are <b>call</b> and <b>noCall</b>.
*/
@@ -93,7 +92,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
private String moduleKind;
@Override
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments) throws MojoExecutionException {
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
arguments.outputFile = outputFile;
arguments.noStdlib = true;
arguments.metaInfo = metaInfo;
@@ -110,6 +109,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
arguments.libraries = StringUtil.join(libraries, File.pathSeparator);
arguments.sourceMap = sourceMap;
arguments.sourceMapPrefix = sourceMapPrefix;
if (outputFile != null) {
ConcurrentMap<String, List<String>> collector = getOutputDirectoriesCollector();
@@ -117,6 +117,17 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
List<String> paths = collector.computeIfAbsent(key, k -> Collections.synchronizedList(new ArrayList<String>()));
paths.add(new File(outputFile).getParent());
}
StringBuilder sourceMapSourceRoots = new StringBuilder();
if (!sourceRoots.isEmpty()) {
sourceMapSourceRoots.append(sourceRoots.get(0).getAbsolutePath());
for (int i = 1; i < sourceRoots.size(); ++i) {
sourceMapSourceRoots.append(File.pathSeparator);
sourceMapSourceRoots.append(sourceRoots.get(i).getAbsolutePath());
}
}
arguments.sourceMapSourceRoots = sourceMapSourceRoots.toString();
}
protected List<String> getClassPathElements() throws DependencyResolutionRequiredException {
@@ -132,7 +132,7 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
}
@Override
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
arguments.destination = output;
// don't include runtime, it should be in maven dependencies
@@ -211,7 +211,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
List<File> sourceRoots = getSourceRoots();
configureCompilerArguments(arguments, compiler);
configureCompilerArguments(arguments, compiler, sourceRoots);
printCompilerArgumentsIfDebugEnabled(arguments, compiler);
MavenPluginLogMessageCollector messageCollector = new MavenPluginLogMessageCollector(getLog());
@@ -290,7 +290,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
@NotNull
protected abstract A createCompilerArguments();
protected abstract void configureSpecificCompilerArguments(@NotNull A arguments) throws MojoExecutionException;
protected abstract void configureSpecificCompilerArguments(@NotNull A arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException;
private List<String> getCompilerPluginClassPaths() {
ArrayList<String> result = new ArrayList<String>();
@@ -451,7 +451,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
return sourceRoots;
}
private void configureCompilerArguments(@NotNull A arguments, @NotNull CLICompiler<A> compiler) throws MojoExecutionException {
private void configureCompilerArguments(@NotNull A arguments, @NotNull CLICompiler<A> compiler, @NotNull List<File> sourceRoots) throws MojoExecutionException {
if (getLog().isDebugEnabled()) {
arguments.verbose = true;
}
@@ -465,7 +465,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
arguments.coroutinesState = experimentalCoroutines;
}
configureSpecificCompilerArguments(arguments);
configureSpecificCompilerArguments(arguments, sourceRoots);
try {
compiler.parseArguments(ArrayUtil.toStringArray(args), arguments);
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager;
import org.jetbrains.kotlin.maven.kapt.KaptTestJvmCompilerMojo;
import java.io.File;
import java.util.List;
/**
@@ -90,11 +91,11 @@ public class KotlinTestCompileMojo extends K2JVMCompileMojo {
}
@Override
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
classpath = testClasspath;
arguments.friendPaths = new String[] { output };
output = testOutput;
super.configureSpecificCompilerArguments(arguments);
super.configureSpecificCompilerArguments(arguments, sourceRoots);
}
@Override
@@ -80,12 +80,12 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo {
private boolean metaInfo;
@Override
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments) throws MojoExecutionException {
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
List<String> friends = getOutputDirectoriesCollector().getOrDefault(project.getArtifactId(), Collections.emptyList());
arguments.friendModules = StringUtil.join(friends, File.pathSeparator);
output = testOutput;
super.configureSpecificCompilerArguments(arguments);
super.configureSpecificCompilerArguments(arguments, sourceRoots);
arguments.outputFile = outputFile;
arguments.metaInfo = metaInfo;
@@ -44,7 +44,7 @@ public class MetadataMojo extends KotlinCompileMojoBase<K2MetadataCompilerArgume
}
@Override
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments) throws MojoExecutionException {
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
arguments.destination = output;
if (!arguments.multiPlatform) {
getLog().info("multiPlatform forced for metadata generation");
@@ -25,13 +25,13 @@ public class TestMetadataMojo extends MetadataMojo {
}
@Override
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments) throws MojoExecutionException {
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
String productionOutput = output;
classpath = testClasspath;
// arguments.friendPaths = new String[] { productionOutput };
output = testOutput;
super.configureSpecificCompilerArguments(arguments);
super.configureSpecificCompilerArguments(arguments, sourceRoots);
if (arguments.classpath == null) {
arguments.classpath = productionOutput;
@@ -106,8 +106,8 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo {
}
@Override
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
super.configureSpecificCompilerArguments(arguments);
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
super.configureSpecificCompilerArguments(arguments, sourceRoots);
AnnotationProcessingManager.ResolvedArtifacts resolvedArtifacts;
@@ -10,6 +10,7 @@ import org.apache.maven.project.MavenProject;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
import java.io.File;
import java.util.List;
/** Note! This file was majorly copied from {@link org.jetbrains.kotlin.maven.KotlinTestCompileMojo}.
@@ -64,11 +65,11 @@ public class KaptTestJvmCompilerMojo extends KaptJVMCompilerMojo {
}
@Override
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
classpath = testClasspath;
arguments.friendPaths = new String[] { output };
output = testOutput;
super.configureSpecificCompilerArguments(arguments);
super.configureSpecificCompilerArguments(arguments, sourceRoots);
}
@Override