diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-sourceMap/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-sourceMap/pom.xml
new file mode 100644
index 00000000000..4a0ccfeddbd
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-sourceMap/pom.xml
@@ -0,0 +1,42 @@
+
+
+ 4.0.0
+
+ org.jetbrains.kotlin
+ test-js-sourceMap
+ 1.0-SNAPSHOT
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-js
+ ${kotlin.version}
+
+
+
+
+ ${project.basedir}/src/main/kotlin
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${kotlin.version}
+
+
+ compile
+
+ js
+
+
+
+
+ true
+ prefixprefix/
+
+
+
+
+
+
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-sourceMap/src/main/kotlin/org/jetbrains/HelloWorld.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-sourceMap/src/main/kotlin/org/jetbrains/HelloWorld.kt
new file mode 100644
index 00000000000..0b757bce4cd
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-sourceMap/src/main/kotlin/org/jetbrains/HelloWorld.kt
@@ -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"
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-sourceMap/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-sourceMap/verify.bsh
new file mode 100644
index 00000000000..bec94d704f9
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-sourceMap/verify.bsh
@@ -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\"")
diff --git a/libraries/tools/kotlin-maven-plugin-test/verify-common.bsh b/libraries/tools/kotlin-maven-plugin-test/verify-common.bsh
index a38ee0a75d8..ceb10449d21 100644
--- a/libraries/tools/kotlin-maven-plugin-test/verify-common.bsh
+++ b/libraries/tools/kotlin-maven-plugin-test/verify-common.bsh
@@ -1,6 +1,5 @@
-String[] getBuildLogLines() {
- File buildLog = new File(basedir, "build.log");
- BufferedReader reader = new BufferedReader(new FileReader(buildLog));
+String[] getFileLines(File file) {
+ BufferedReader reader = new BufferedReader(new FileReader(file));
List result = new ArrayList();
String line;
while ((line = reader.readLine()) != null){
@@ -11,8 +10,24 @@ String[] getBuildLogLines() {
return result.toArray(new String[0]);
}
+String[] getBuildLogLines() {
+ return getFileLines(new File(basedir, "build.log"));
+}
+
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) {
for (int i = 0; i < buildLog.length; i++) {
@@ -40,8 +55,12 @@ void assertBuildLogHasNoLineThatContains(String content) {
}
int findBuildLogLineThatContains(String content) {
- for (int i = 0; i < buildLog.length; i++) {
- String line = buildLog[i];
+ return findLineThatContains(buildLog, content);
+}
+
+int findLineThatContains(String[] lines, String content) {
+ for (int i = 0; i < lines.length; i++) {
+ String line = lines[i];
if (line.contains(content)) {
return i;
}
diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java
index 8290ac84061..7be5a95e6c8 100644
--- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java
+++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java
@@ -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 KotlinCompileMojoBasecall and noCall.
*/
@@ -93,7 +92,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase sourceRoots) throws MojoExecutionException {
arguments.outputFile = outputFile;
arguments.noStdlib = true;
arguments.metaInfo = metaInfo;
@@ -110,6 +109,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase> collector = getOutputDirectoriesCollector();
@@ -117,6 +117,17 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase paths = collector.computeIfAbsent(key, k -> Collections.synchronizedList(new ArrayList()));
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 getClassPathElements() throws DependencyResolutionRequiredException {
diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java
index 754cf244bf5..27e96616658 100644
--- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java
+++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java
@@ -132,7 +132,7 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase sourceRoots) throws MojoExecutionException {
arguments.destination = output;
// don't include runtime, it should be in maven dependencies
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 55e72daa685..e5e5207ceb7 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
@@ -211,7 +211,7 @@ public abstract class KotlinCompileMojoBase e
List 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 e
@NotNull
protected abstract A createCompilerArguments();
- protected abstract void configureSpecificCompilerArguments(@NotNull A arguments) throws MojoExecutionException;
+ protected abstract void configureSpecificCompilerArguments(@NotNull A arguments, @NotNull List sourceRoots) throws MojoExecutionException;
private List getCompilerPluginClassPaths() {
ArrayList result = new ArrayList();
@@ -451,7 +451,7 @@ public abstract class KotlinCompileMojoBase e
return sourceRoots;
}
- private void configureCompilerArguments(@NotNull A arguments, @NotNull CLICompiler compiler) throws MojoExecutionException {
+ private void configureCompilerArguments(@NotNull A arguments, @NotNull CLICompiler compiler, @NotNull List sourceRoots) throws MojoExecutionException {
if (getLog().isDebugEnabled()) {
arguments.verbose = true;
}
@@ -465,7 +465,7 @@ public abstract class KotlinCompileMojoBase e
arguments.coroutinesState = experimentalCoroutines;
}
- configureSpecificCompilerArguments(arguments);
+ configureSpecificCompilerArguments(arguments, sourceRoots);
try {
compiler.parseArguments(ArrayUtil.toStringArray(args), arguments);
diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java
index d34a001cf93..c91b0ced0fc 100644
--- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java
+++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java
@@ -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 sourceRoots) throws MojoExecutionException {
classpath = testClasspath;
arguments.friendPaths = new String[] { output };
output = testOutput;
- super.configureSpecificCompilerArguments(arguments);
+ super.configureSpecificCompilerArguments(arguments, sourceRoots);
}
@Override
diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestJSCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestJSCompilerMojo.java
index 8026081b1d6..aaf4e2c3d64 100644
--- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestJSCompilerMojo.java
+++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestJSCompilerMojo.java
@@ -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 sourceRoots) throws MojoExecutionException {
List 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;
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
index 9afbb34a6f2..a7ef4879857 100644
--- 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
@@ -44,7 +44,7 @@ public class MetadataMojo extends KotlinCompileMojoBase sourceRoots) throws MojoExecutionException {
arguments.destination = output;
if (!arguments.multiPlatform) {
getLog().info("multiPlatform forced for metadata generation");
diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/TestMetadataMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/TestMetadataMojo.java
index 3da12d177ba..495cabdd5e6 100644
--- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/TestMetadataMojo.java
+++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/TestMetadataMojo.java
@@ -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 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;
diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java
index 7823986a1be..5ecba584c31 100644
--- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java
+++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java
@@ -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 sourceRoots) throws MojoExecutionException {
+ super.configureSpecificCompilerArguments(arguments, sourceRoots);
AnnotationProcessingManager.ResolvedArtifacts resolvedArtifacts;
diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptTestJvmCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptTestJvmCompilerMojo.java
index 0f6a58efa28..e76e20fa96c 100644
--- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptTestJvmCompilerMojo.java
+++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptTestJvmCompilerMojo.java
@@ -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 sourceRoots) throws MojoExecutionException {
classpath = testClasspath;
arguments.friendPaths = new String[] { output };
output = testOutput;
- super.configureSpecificCompilerArguments(arguments);
+ super.configureSpecificCompilerArguments(arguments, sourceRoots);
}
@Override