diff --git a/build-caching/src/main/java/com/vertispan/j2cl/build/PropertyTrackingConfig.java b/build-caching/src/main/java/com/vertispan/j2cl/build/PropertyTrackingConfig.java index af8a3d4b..20d27c3a 100644 --- a/build-caching/src/main/java/com/vertispan/j2cl/build/PropertyTrackingConfig.java +++ b/build-caching/src/main/java/com/vertispan/j2cl/build/PropertyTrackingConfig.java @@ -161,6 +161,11 @@ public boolean getSourcemapsEnabled() { return Boolean.parseBoolean(getString("enableSourcemaps")); } + @Override + public boolean getEnableIncrementalSourcemaps() { + return Boolean.parseBoolean(getString("enableIncrementalSourcemaps")); + } + @Override public String getInitialScriptFilename() { return getString("initialScriptFilename"); diff --git a/build-caching/src/main/java/com/vertispan/j2cl/build/task/Config.java b/build-caching/src/main/java/com/vertispan/j2cl/build/task/Config.java index 9e40d98d..97661543 100644 --- a/build-caching/src/main/java/com/vertispan/j2cl/build/task/Config.java +++ b/build-caching/src/main/java/com/vertispan/j2cl/build/task/Config.java @@ -29,6 +29,8 @@ public interface Config { boolean getSourcemapsEnabled(); + boolean getEnableIncrementalSourcemaps(); + String getInitialScriptFilename(); Map getDefines(); diff --git a/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/BuildMojo.java b/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/BuildMojo.java index 755a5a5d..864c61aa 100644 --- a/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/BuildMojo.java +++ b/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/BuildMojo.java @@ -171,6 +171,12 @@ public class BuildMojo extends AbstractBuildMojo { @Parameter(defaultValue = "false") protected boolean enableSourcemaps; + /** + * True to copy only changed source files to the output directory. This is a performance optimization. + */ + @Parameter(defaultValue = "false") + protected boolean enableIncrementalSourcemaps; + @Override public void execute() throws MojoExecutionException, MojoFailureException { // pre-create the directory so it is easier to find up front, even if it starts off empty diff --git a/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/TestMojo.java b/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/TestMojo.java index 001d4448..1809dd5b 100644 --- a/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/TestMojo.java +++ b/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/TestMojo.java @@ -246,6 +246,12 @@ public class TestMojo extends AbstractBuildMojo { @Parameter(defaultValue = "false") protected boolean enableSourcemaps; + /** + * True to copy only changed source files to the output directory. This is a performance optimization. + */ + @Parameter(defaultValue = "false") + protected boolean enableIncrementalSourcemaps; + /** * Closure flag: "Source of translated messages. Currently only supports XTB." */ diff --git a/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/WatchMojo.java b/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/WatchMojo.java index 383562c8..f05ea713 100644 --- a/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/WatchMojo.java +++ b/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/WatchMojo.java @@ -129,6 +129,12 @@ public class WatchMojo extends AbstractBuildMojo { @Parameter(defaultValue = "true") protected boolean enableSourcemaps; + /** + * True to copy only changed source files to the output directory. This is a performance optimization. + */ + @Parameter(defaultValue = "false") + protected boolean enableIncrementalSourcemaps; + /** * @deprecated Will be removed in 0.21 */ 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..a516d589 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 @@ -74,6 +74,8 @@ public Task resolve(Project project, Config config) { } File initialScriptFile = config.getWebappDirectory().resolve(config.getInitialScriptFilename()).toFile(); + boolean sourcemapsEnabled = config.getSourcemapsEnabled() && !config.getEnableIncrementalSourcemaps(); + Map defines = new LinkedHashMap<>(config.getDefines()); List outputToCopy = Stream.concat( @@ -113,11 +115,14 @@ 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); + // Copy sources to the output directory, if sourcemaps are enabled and incremental source maps is not. + if (sourcemapsEnabled) { + 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 { 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..46e63ca8 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 @@ -92,6 +92,8 @@ public Task resolve(Project project, Config config) { // Consider treating this always as true, since the build doesnt get more costly to be incremental boolean incrementalEnabled = config.isIncrementalEnabled(); + boolean sourcemapsEnabled = config.getSourcemapsEnabled() && config.getEnableIncrementalSourcemaps(); + Path sourceMapsFolder = sourcemapsEnabled ? prepareSourcesFolder(config) : null; Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); @@ -197,6 +199,10 @@ public Task resolve(Project project, Config config) { "" )).useEval(true); + if (sourcemapsEnabled) { + FileUtils.copyDirectory(context.outputPath().resolve("sources").toFile(), sourceMapsFolder.toFile()); + } + try (OutputStream outputStream = Files.newOutputStream(Paths.get(outputFile)); BufferedWriter bundleOut = new BufferedWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))) { for (DependencyInfoAndSource info : sorter.getSortedList()) { @@ -238,6 +244,16 @@ public Task resolve(Project project, Config config) { }; } + private Path prepareSourcesFolder(Config config) { + try { + Path initialScriptFile = config.getWebappDirectory().resolve(config.getInitialScriptFilename()); + Path destSourcesDir = Files.createDirectories(initialScriptFile.getParent()).resolve(Closure.SOURCES_DIRECTORY_NAME); + return Files.createDirectories(destSourcesDir); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + public interface SourceSupplier { String get() throws IOException; } @@ -313,9 +329,9 @@ public boolean getHasNoCompileAnnotation() { public static class DependencyInfoFormat implements DependencyInfo { private String name; -// private String pathRelativeToClosureBase = name; + // private String pathRelativeToClosureBase = name; private List provides; -// private List requires; //skipping requires as it isnt used by the dep sorter + // private List requires; //skipping requires as it isnt used by the dep sorter private List requiredSymbols; private List typeRequires; private Map loadFlags;