You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2018/11/13 07:10:36 UTC

[sling-slingfeature-maven-plugin] branch master updated: Remove comments before reading feature file

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 453de15  Remove comments before reading feature file
453de15 is described below

commit 453de151952b86e771423b7002a15b2f9848ad14
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Nov 13 08:10:28 2018 +0100

    Remove comments before reading feature file
---
 .../java/org/apache/sling/feature/maven/Preprocessor.java    | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/feature/maven/Preprocessor.java b/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
index 4cfbfe1..de56ed0 100644
--- a/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
+++ b/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Formatter;
 import java.util.HashMap;
@@ -37,6 +38,7 @@ import javax.json.JsonReader;
 import javax.json.JsonValue;
 import javax.json.stream.JsonGenerator;
 
+import org.apache.felix.configurator.impl.json.JSMin;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.utils.io.DirectoryScanner;
@@ -328,7 +330,15 @@ public class Preprocessor {
 
 	protected String preprocessFeature(final Logger logger, final FeatureProjectInfo info,
 			final FeatureProjectConfig config, final File file, final String readJson) {
-        String json = readJson;
+        // minify JSON (remove comments)
+        String json;
+        try (final Writer out = new StringWriter(); final Reader in = new StringReader(readJson)) {
+            final JSMin min = new JSMin(in, out);
+            min.jsmin();
+            json = out.toString();
+        } catch (IOException e) {
+            throw new RuntimeException("Unable to read feature file " + file.getAbsolutePath(), e);
+        }
 
 		// check if "id" is set
 		try (final JsonReader reader = Json.createReader(new StringReader(json)) ) {