You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2021/07/01 15:42:44 UTC

[sling-whiteboard] branch master updated: Support JSMin comments

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new d3c8415  Support JSMin comments
d3c8415 is described below

commit d3c8415c92a9c1dc8d97bc7e2c4677f2dfcca42e
Author: David Bosschaert <da...@apache.org>
AuthorDate: Thu Jul 1 16:42:24 2021 +0100

    Support JSMin comments
---
 .../feature/osgi/impl/FeatureServiceImpl.java      |  5 ++++-
 .../feature/osgi/impl/FeatureServiceImplTest.java  | 26 ++++++++++++++++++++--
 .../src/test/resources/features/test-feature2.json | 19 ++++++++--------
 3 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/FeatureServiceImpl.java b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/FeatureServiceImpl.java
index 3ae3a91..226a400 100644
--- a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/FeatureServiceImpl.java
+++ b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/FeatureServiceImpl.java
@@ -38,6 +38,7 @@ import javax.json.JsonWriterFactory;
 import javax.json.stream.JsonGenerator;
 import javax.json.stream.JsonGeneratorFactory;
 
+import org.apache.felix.cm.json.impl.JsonSupport;
 import org.apache.felix.cm.json.impl.TypeConverter;
 import org.osgi.service.feature.BuilderFactory;
 import org.osgi.service.feature.Feature;
@@ -79,7 +80,8 @@ public class FeatureServiceImpl implements FeatureService {
 	}
 
 	public Feature readFeature(Reader jsonReader) throws IOException {
-        JsonObject json = Json.createReader(jsonReader).readObject();
+        JsonObject json = Json.createReader(
+        		JsonSupport.createCommentRemovingReader(jsonReader)).readObject();
 
         String id = json.getString("id");
         FeatureBuilder builder = builderFactory.newFeatureBuilder(getIDfromMavenCoordinates(id));
@@ -184,6 +186,7 @@ public class FeatureServiceImpl implements FeatureService {
             	}
             	
                 JsonValue val = value.getValue();
+                // TODO ensure that binary support works as well
                 Object v = TypeConverter.convertObjectToType(val, typeInfo);                
                 builder.addValue(key, v);
             }
diff --git a/osgi-featuremodel/src/test/java/org/apache/sling/feature/osgi/impl/FeatureServiceImplTest.java b/osgi-featuremodel/src/test/java/org/apache/sling/feature/osgi/impl/FeatureServiceImplTest.java
index 28b59f3..cbefb72 100644
--- a/osgi-featuremodel/src/test/java/org/apache/sling/feature/osgi/impl/FeatureServiceImplTest.java
+++ b/osgi-featuremodel/src/test/java/org/apache/sling/feature/osgi/impl/FeatureServiceImplTest.java
@@ -16,8 +16,9 @@
  */
 package org.apache.sling.feature.osgi.impl;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
@@ -60,6 +61,10 @@ public class FeatureServiceImplTest {
 
             assertTrue(f.getName().isEmpty());
             assertEquals("The feature description", f.getDescription().get());
+            assertFalse(f.getDocURL().isPresent());
+            assertFalse(f.getLicense().isPresent());
+            assertFalse(f.getSCM().isPresent());
+            assertFalse(f.getVendor().isPresent());
 
             List<FeatureBundle> bundles = f.getBundles();
             assertEquals(3, bundles.size());
@@ -96,6 +101,24 @@ public class FeatureServiceImplTest {
             assertArrayEquals(new String[] {"yeah", "yeah", "yeah"}, (String[]) values2.get("a.value"));
         }
     }
+    
+    @Test
+    public void testReadFeature2() throws Exception {
+        URL res = getClass().getResource("/features/test-feature2.json");
+        try (Reader r = new InputStreamReader(res.openStream())) {
+            Feature f = features.readFeature(r);
+
+            assertEquals("org.apache.sling:test-feature2:osgifeature:cls_abc:1.1", f.getID().toString());
+            assertEquals("test-feature2", f.getName().get());
+            assertEquals("The feature description", f.getDescription().get());
+            assertEquals(List.of("foo", "bar"), f.getCategories());
+            assertEquals("http://foo.bar.com/abc", f.getDocURL().get());
+            assertEquals("Apache-2.0; link=\"http://opensource.org/licenses/apache2.0.php\"", f.getLicense().get());
+            assertEquals("url=https://github.com/apache/sling-aggregator, connection=scm:git:https://github.com/apache/sling-aggregator.git, developerConnection=scm:git:git@github.com:apache/sling-aggregator.git", 
+            		f.getSCM().get());
+            assertEquals("The Apache Software Foundation", f.getVendor().get());
+        }    	
+    }
 
     @Test
     public void testWriteFeature() throws Exception {
@@ -110,7 +133,6 @@ public class FeatureServiceImplTest {
         Feature f = builder.build();
         StringWriter sw = new StringWriter();
         features.writeFeature(f, sw);
-        System.out.println("***" + sw.toString());
         
         // Now check the generated JSON
         JsonReader jr = Json.createReader(new StringReader(sw.toString()));
diff --git a/osgi-featuremodel/src/test/resources/features/test-feature2.json b/osgi-featuremodel/src/test/resources/features/test-feature2.json
index 2747d21..e12d2d8 100644
--- a/osgi-featuremodel/src/test/resources/features/test-feature2.json
+++ b/osgi-featuremodel/src/test/resources/features/test-feature2.json
@@ -1,15 +1,16 @@
 {
-    "id" : "org.apache.sling:test-feature2:1.1",
+    /** This is a JSMin comment */
+    "id" : "org.apache.sling:test-feature2:osgifeature:cls_abc:1.1",
+    "name": "test-feature2",
     "description": "The feature description",
+    "categories": ["foo", "bar"],
+    "docURL": "http://foo.bar.com/abc",
+    "license": "Apache-2.0; link=\"http://opensource.org/licenses/apache2.0.php\"",
+    "scm": "url=https://github.com/apache/sling-aggregator, connection=scm:git:https://github.com/apache/sling-aggregator.git, developerConnection=scm:git:git@github.com:apache/sling-aggregator.git",
+    "vendor": "The Apache Software Foundation",
 
-    "bundles" :[
-            {
-              "id" : "org.slf4j:slf4j-api:1.7.30"
-            },
-            {
-              "id" : "org.slf4j:slf4j-nop:1.7.30"
-            }            
-    ],
+	// complex entities below here
+	
     "configurations" : {
         "my.pid" : {
            "bar" : "toast"