Add new JS source map config options to Maven plugin
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>test-js-sourceMap</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib-js</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<goals>
|
||||||
|
<goal>js</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<sourceMap>true</sourceMap>
|
||||||
|
<sourceMapPrefix>prefixprefix/</sourceMapPrefix>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains
|
||||||
|
|
||||||
|
fun bar() = "OK"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
source(new File(basedir, "../../../verify-common.bsh").getAbsolutePath());
|
||||||
|
|
||||||
|
assertFileContains("target/js/test-js-sourceMap.js.map", "\"prefixprefix/org/jetbrains/HelloWorld.kt\"")
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
String[] getBuildLogLines() {
|
String[] getFileLines(File file) {
|
||||||
File buildLog = new File(basedir, "build.log");
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(buildLog));
|
|
||||||
List result = new ArrayList();
|
List result = new ArrayList();
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null){
|
while ((line = reader.readLine()) != null){
|
||||||
@@ -11,8 +10,24 @@ String[] getBuildLogLines() {
|
|||||||
return result.toArray(new String[0]);
|
return result.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[] getBuildLogLines() {
|
||||||
|
return getFileLines(new File(basedir, "build.log"));
|
||||||
|
}
|
||||||
|
|
||||||
String[] buildLog = getBuildLogLines();
|
String[] buildLog = getBuildLogLines();
|
||||||
|
|
||||||
|
void assertFileContains(String relativePath, String content) {
|
||||||
|
File file = new File(basedir, relativePath);
|
||||||
|
if (!file.exists()) {
|
||||||
|
throw new Exception("File was not found: " + relativePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] lines = getFileLines(file);
|
||||||
|
int lineNumber = findLineThatContains(lines, content);
|
||||||
|
if (lineNumber < 0) {
|
||||||
|
throw new Exception("Expected file " + relativePath + " to contain: \"" + content + "\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void assertBuildLogHasLine(String expectedLine) {
|
void assertBuildLogHasLine(String expectedLine) {
|
||||||
for (int i = 0; i < buildLog.length; i++) {
|
for (int i = 0; i < buildLog.length; i++) {
|
||||||
@@ -40,8 +55,12 @@ void assertBuildLogHasNoLineThatContains(String content) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int findBuildLogLineThatContains(String content) {
|
int findBuildLogLineThatContains(String content) {
|
||||||
for (int i = 0; i < buildLog.length; i++) {
|
return findLineThatContains(buildLog, content);
|
||||||
String line = buildLog[i];
|
}
|
||||||
|
|
||||||
|
int findLineThatContains(String[] lines, String content) {
|
||||||
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
String line = lines[i];
|
||||||
if (line.contains(content)) {
|
if (line.contains(content)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-6
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.maven;
|
package org.jetbrains.kotlin.maven;
|
||||||
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import kotlin.text.StringsKt;
|
|
||||||
import org.apache.maven.artifact.DependencyResolutionRequiredException;
|
import org.apache.maven.artifact.DependencyResolutionRequiredException;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
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.common.arguments.K2JSCompilerArguments;
|
||||||
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
||||||
import org.jetbrains.kotlin.utils.LibraryUtils;
|
import org.jetbrains.kotlin.utils.LibraryUtils;
|
||||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils;
|
|
||||||
import org.jetbrains.kotlin.js.JavaScript;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@@ -71,6 +67,9 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
|
|||||||
@Parameter(defaultValue = "false")
|
@Parameter(defaultValue = "false")
|
||||||
private boolean sourceMap;
|
private boolean sourceMap;
|
||||||
|
|
||||||
|
@Parameter
|
||||||
|
private String sourceMapPrefix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main invocation behaviour. Possible values are <b>call</b> and <b>noCall</b>.
|
* 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;
|
private String moduleKind;
|
||||||
|
|
||||||
@Override
|
@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.outputFile = outputFile;
|
||||||
arguments.noStdlib = true;
|
arguments.noStdlib = true;
|
||||||
arguments.metaInfo = metaInfo;
|
arguments.metaInfo = metaInfo;
|
||||||
@@ -110,6 +109,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
|
|||||||
arguments.libraries = StringUtil.join(libraries, File.pathSeparator);
|
arguments.libraries = StringUtil.join(libraries, File.pathSeparator);
|
||||||
|
|
||||||
arguments.sourceMap = sourceMap;
|
arguments.sourceMap = sourceMap;
|
||||||
|
arguments.sourceMapPrefix = sourceMapPrefix;
|
||||||
|
|
||||||
if (outputFile != null) {
|
if (outputFile != null) {
|
||||||
ConcurrentMap<String, List<String>> collector = getOutputDirectoriesCollector();
|
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>()));
|
List<String> paths = collector.computeIfAbsent(key, k -> Collections.synchronizedList(new ArrayList<String>()));
|
||||||
paths.add(new File(outputFile).getParent());
|
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 {
|
protected List<String> getClassPathElements() throws DependencyResolutionRequiredException {
|
||||||
|
|||||||
+1
-1
@@ -132,7 +132,7 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
|
||||||
arguments.destination = output;
|
arguments.destination = output;
|
||||||
|
|
||||||
// don't include runtime, it should be in maven dependencies
|
// don't include runtime, it should be in maven dependencies
|
||||||
|
|||||||
+4
-4
@@ -211,7 +211,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
|||||||
|
|
||||||
List<File> sourceRoots = getSourceRoots();
|
List<File> sourceRoots = getSourceRoots();
|
||||||
|
|
||||||
configureCompilerArguments(arguments, compiler);
|
configureCompilerArguments(arguments, compiler, sourceRoots);
|
||||||
printCompilerArgumentsIfDebugEnabled(arguments, compiler);
|
printCompilerArgumentsIfDebugEnabled(arguments, compiler);
|
||||||
|
|
||||||
MavenPluginLogMessageCollector messageCollector = new MavenPluginLogMessageCollector(getLog());
|
MavenPluginLogMessageCollector messageCollector = new MavenPluginLogMessageCollector(getLog());
|
||||||
@@ -290,7 +290,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected abstract A createCompilerArguments();
|
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() {
|
private List<String> getCompilerPluginClassPaths() {
|
||||||
ArrayList<String> result = new ArrayList<String>();
|
ArrayList<String> result = new ArrayList<String>();
|
||||||
@@ -451,7 +451,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
|||||||
return sourceRoots;
|
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()) {
|
if (getLog().isDebugEnabled()) {
|
||||||
arguments.verbose = true;
|
arguments.verbose = true;
|
||||||
}
|
}
|
||||||
@@ -465,7 +465,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
|||||||
arguments.coroutinesState = experimentalCoroutines;
|
arguments.coroutinesState = experimentalCoroutines;
|
||||||
}
|
}
|
||||||
|
|
||||||
configureSpecificCompilerArguments(arguments);
|
configureSpecificCompilerArguments(arguments, sourceRoots);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
compiler.parseArguments(ArrayUtil.toStringArray(args), arguments);
|
compiler.parseArguments(ArrayUtil.toStringArray(args), arguments);
|
||||||
|
|||||||
+3
-2
@@ -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.AnnotationProcessingManager;
|
||||||
import org.jetbrains.kotlin.maven.kapt.KaptTestJvmCompilerMojo;
|
import org.jetbrains.kotlin.maven.kapt.KaptTestJvmCompilerMojo;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,11 +91,11 @@ public class KotlinTestCompileMojo extends K2JVMCompileMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
|
||||||
classpath = testClasspath;
|
classpath = testClasspath;
|
||||||
arguments.friendPaths = new String[] { output };
|
arguments.friendPaths = new String[] { output };
|
||||||
output = testOutput;
|
output = testOutput;
|
||||||
super.configureSpecificCompilerArguments(arguments);
|
super.configureSpecificCompilerArguments(arguments, sourceRoots);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-2
@@ -80,12 +80,12 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo {
|
|||||||
private boolean metaInfo;
|
private boolean metaInfo;
|
||||||
|
|
||||||
@Override
|
@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());
|
List<String> friends = getOutputDirectoriesCollector().getOrDefault(project.getArtifactId(), Collections.emptyList());
|
||||||
arguments.friendModules = StringUtil.join(friends, File.pathSeparator);
|
arguments.friendModules = StringUtil.join(friends, File.pathSeparator);
|
||||||
output = testOutput;
|
output = testOutput;
|
||||||
|
|
||||||
super.configureSpecificCompilerArguments(arguments);
|
super.configureSpecificCompilerArguments(arguments, sourceRoots);
|
||||||
|
|
||||||
arguments.outputFile = outputFile;
|
arguments.outputFile = outputFile;
|
||||||
arguments.metaInfo = metaInfo;
|
arguments.metaInfo = metaInfo;
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ public class MetadataMojo extends KotlinCompileMojoBase<K2MetadataCompilerArgume
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
|
||||||
arguments.destination = output;
|
arguments.destination = output;
|
||||||
if (!arguments.multiPlatform) {
|
if (!arguments.multiPlatform) {
|
||||||
getLog().info("multiPlatform forced for metadata generation");
|
getLog().info("multiPlatform forced for metadata generation");
|
||||||
|
|||||||
+2
-2
@@ -25,13 +25,13 @@ public class TestMetadataMojo extends MetadataMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
|
||||||
String productionOutput = output;
|
String productionOutput = output;
|
||||||
|
|
||||||
classpath = testClasspath;
|
classpath = testClasspath;
|
||||||
// arguments.friendPaths = new String[] { productionOutput };
|
// arguments.friendPaths = new String[] { productionOutput };
|
||||||
output = testOutput;
|
output = testOutput;
|
||||||
super.configureSpecificCompilerArguments(arguments);
|
super.configureSpecificCompilerArguments(arguments, sourceRoots);
|
||||||
|
|
||||||
if (arguments.classpath == null) {
|
if (arguments.classpath == null) {
|
||||||
arguments.classpath = productionOutput;
|
arguments.classpath = productionOutput;
|
||||||
|
|||||||
+2
-2
@@ -106,8 +106,8 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
|
||||||
super.configureSpecificCompilerArguments(arguments);
|
super.configureSpecificCompilerArguments(arguments, sourceRoots);
|
||||||
|
|
||||||
AnnotationProcessingManager.ResolvedArtifacts resolvedArtifacts;
|
AnnotationProcessingManager.ResolvedArtifacts resolvedArtifacts;
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -10,6 +10,7 @@ import org.apache.maven.project.MavenProject;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Note! This file was majorly copied from {@link org.jetbrains.kotlin.maven.KotlinTestCompileMojo}.
|
/** Note! This file was majorly copied from {@link org.jetbrains.kotlin.maven.KotlinTestCompileMojo}.
|
||||||
@@ -64,11 +65,11 @@ public class KaptTestJvmCompilerMojo extends KaptJVMCompilerMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
|
||||||
classpath = testClasspath;
|
classpath = testClasspath;
|
||||||
arguments.friendPaths = new String[] { output };
|
arguments.friendPaths = new String[] { output };
|
||||||
output = testOutput;
|
output = testOutput;
|
||||||
super.configureSpecificCompilerArguments(arguments);
|
super.configureSpecificCompilerArguments(arguments, sourceRoots);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user