diff --git a/j2cl-tasks/pom.xml b/j2cl-tasks/pom.xml
index bc063eb2..022d7da9 100644
--- a/j2cl-tasks/pom.xml
+++ b/j2cl-tasks/pom.xml
@@ -95,4 +95,4 @@
test
-
\ No newline at end of file
+
diff --git a/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/BundleJarTask.java b/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/BundleJarTask.java
index ab383c36..a0916ca0 100644
--- a/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/BundleJarTask.java
+++ b/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/BundleJarTask.java
@@ -113,13 +113,6 @@ public void finish(TaskContext taskContext) throws IOException {
Files.copy(bundle.getAbsolutePath(), targetFile, StandardCopyOption.REPLACE_EXISTING);
}
- File destSourcesDir = outputDir.toPath().resolve(Closure.SOURCES_DIRECTORY_NAME).toFile();
- destSourcesDir.mkdirs();
- for (Path dir : jsSources.stream().map(Input::getParentPaths).flatMap(Collection::stream).map(p -> p.resolve(Closure
- .SOURCES_DIRECTORY_NAME)).collect(Collectors.toSet())) {
- FileUtils.copyDirectory(dir.toFile(), destSourcesDir);
- }
-
try {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String scriptsArray = gson.toJson(sourceOrder.stream()
diff --git a/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/ClosureBundleTask.java b/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/ClosureBundleTask.java
index a951891e..2c2d2ed6 100644
--- a/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/ClosureBundleTask.java
+++ b/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/ClosureBundleTask.java
@@ -132,6 +132,7 @@ public Task resolve(Project project, Config config) {
depInfoMap = deps.stream()
.map(info -> new DependencyInfoAndSource(
info,
+ fileNameKey,
() -> Files.readString(lastOutput.resolve(Closure.SOURCES_DIRECTORY_NAME).resolve(info.getName())))
)
.collect(Collectors.toMap(DependencyInfo::getName, Function.identity()));
@@ -151,7 +152,7 @@ public Task resolve(Project project, Config config) {
input.setCompiler(jsCompiler);
depInfoMap.put(
change.getSourcePath().toString(),
- new DependencyInfoAndSource(input, input::getCode)
+ new DependencyInfoAndSource(input, fileNameKey, input::getCode)
);
}
}
@@ -170,8 +171,7 @@ public Task resolve(Project project, Config config) {
.withOriginalPath(path.getSourcePath().toString())
.build());
input.setCompiler(jsCompiler);
-
- dependencyInfos.add(new DependencyInfoAndSource(input, input::getCode));
+ dependencyInfos.add(new DependencyInfoAndSource(input, fileNameKey, input::getCode));
}
}
}
@@ -202,6 +202,7 @@ public Task resolve(Project project, Config config) {
for (DependencyInfoAndSource info : sorter.getSortedList()) {
String code = info.getSource();
String name = info.getName();
+ String projectName = info.getProject();
//TODO do we actually need this?
if (Compiler.isFillFileName(name) && code.isEmpty()) {
@@ -210,7 +211,7 @@ public Task resolve(Project project, Config config) {
// append this file and a comment where it came from
bundleOut.append("//").append(name).append("\n");
- bundler.withPath(name).withSourceUrl(Closure.SOURCES_DIRECTORY_NAME + "/" + name).appendTo(bundleOut, info, code);
+ bundler.withPath(name).withSourceUrl(Closure.SOURCES_DIRECTORY_NAME + "/" + projectName + "/" + name).appendTo(bundleOut, info, code);
bundleOut.append("\n");
}
@@ -245,8 +246,11 @@ public static class DependencyInfoAndSource implements DependencyInfo {
private final DependencyInfo delegate;
private final SourceSupplier sourceSupplier;
- public DependencyInfoAndSource(DependencyInfo delegate, SourceSupplier sourceSupplier) {
+ private final String project;
+
+ public DependencyInfoAndSource(DependencyInfo delegate, String project, SourceSupplier sourceSupplier) {
this.delegate = delegate;
+ this.project = project.replaceAll("\\.", "-");
this.sourceSupplier = sourceSupplier;
}
@@ -309,6 +313,10 @@ public boolean getHasExternsAnnotation() {
public boolean getHasNoCompileAnnotation() {
return delegate.getHasNoCompileAnnotation();
}
+
+ public String getProject() {
+ return project;
+ }
}
public static class DependencyInfoFormat implements DependencyInfo {
diff --git a/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/J2clTask.java b/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/J2clTask.java
index bd3b87ec..e1d42cea 100644
--- a/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/J2clTask.java
+++ b/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/J2clTask.java
@@ -2,10 +2,15 @@
import com.google.auto.service.AutoService;
import com.google.j2cl.common.SourceUtils;
+import com.google.javascript.jscomp.CompilationLevel;
import com.vertispan.j2cl.build.task.*;
+import com.vertispan.j2cl.tools.Closure;
import com.vertispan.j2cl.tools.J2cl;
+import org.apache.commons.io.FileUtils;
import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.util.Collections;
@@ -51,6 +56,11 @@ public Task resolve(Project project, Config config) {
File bootstrapClasspath = config.getBootstrapClasspath();
List extraClasspath = config.getExtraClasspath();
+
+ //*******
+ boolean sourcemapsEnabled = config.getSourcemapsEnabled();
+ Path sourceMapsFolder = sourcemapsEnabled ? prepareSourcesFolder(config, project) : null;
+
return context -> {
if (ownJavaSources.getFilesAndHashes().isEmpty()) {
return;// nothing to do
@@ -82,6 +92,28 @@ public Task resolve(Project project, Config config) {
if (!j2cl.transpile(javaSources, nativeSources)) {
throw new IllegalStateException("Error while running J2CL");
}
+
+ if(sourcemapsEnabled) {
+ if(sourceMapsFolder.toFile().exists()) {
+ FileUtils.deleteDirectory(sourceMapsFolder.toFile());
+ }
+ sourceMapsFolder.toFile().mkdirs();
+ FileUtils.copyDirectory(context.outputPath().toFile(), sourceMapsFolder.toFile());
+ }
};
}
+
+ private Path prepareSourcesFolder(Config config, Project project) {
+ try {
+ Path initialScriptFile = config.getWebappDirectory().resolve(config.getInitialScriptFilename());
+ Path outputDir = initialScriptFile.getParent();
+ Files.createDirectories(outputDir);
+ Path destSourcesDir = outputDir.resolve(Closure.SOURCES_DIRECTORY_NAME);
+ Files.createDirectories(destSourcesDir);
+ Path dist = destSourcesDir.resolve(project.getKey().replaceAll("\\.","-").replaceAll(":","-"));
+ return dist;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}