[Git][java-team/jsonld-java][upstream] New upstream version 0.13.2

Andrius Merkys gitlab at salsa.debian.org
Mon Sep 28 08:04:05 BST 2020



Andrius Merkys pushed to branch upstream at Debian Java Maintainers / jsonld-java


Commits:
940c8356 by Andrius Merkys at 2020-09-28T02:26:05-04:00
New upstream version 0.13.2
- - - - -


10 changed files:

- README.md
- core/pom.xml
- core/src/main/java/com/github/jsonldjava/core/Context.java
- core/src/main/java/com/github/jsonldjava/core/JsonLdProcessor.java
- core/src/test/java/com/github/jsonldjava/core/ContextCompactionTest.java
- + core/src/test/java/com/github/jsonldjava/core/ContextFlatteningTest.java
- + core/src/test/java/com/github/jsonldjava/core/ContextFramingTest.java
- + core/src/test/java/com/github/jsonldjava/core/ContextSerializationTest.java
- + core/src/test/resources/custom/contexttest-0005.jsonld
- pom.xml


Changes:

=====================================
README.md
=====================================
@@ -16,7 +16,7 @@ From Maven
     <dependency>
         <groupId>com.github.jsonld-java</groupId>
         <artifactId>jsonld-java</artifactId>
-        <version>0.13.0</version>
+        <version>0.13.2</version>
     </dependency>
 
 Code example
@@ -323,11 +323,11 @@ Here is the basic outline for what your module's pom.xml should look like
   <parent>
     <groupId>com.github.jsonld-java</groupId>
     <artifactId>jsonld-java-parent</artifactId>
-    <version>0.13.0</version>
+    <version>0.13.2</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>jsonld-java-{your module}</artifactId>
-  <version>0.13.0-SNAPSHOT</version>
+  <version>0.13.2-SNAPSHOT</version>
   <name>JSONLD Java :: {your module name}</name>
   <description>JSON-LD Java integration module for {RDF Library your module integrates}</description>
   <packaging>jar</packaging>
@@ -450,6 +450,19 @@ Alternatively, we can also host your repository in the jsonld-java organisation
 CHANGELOG
 =========
 
+### 2020-09-24
+* Release 0.13.2
+* Fix Guava dependency shading (Reported by @ggrasso)
+* Fix @context issues when using a remote context (Patch by @umbreak)
+* Deprecate Context.serialize (Patch by @umbreak)
+
+### 2020-09-09
+* Release 0.13.1
+* Fix java.net.URI resolution (Reported by @ebremer and @afs, Patch by @dr0i)
+* Shade Guava failureaccess module (Patch by @peacekeeper)
+* Don't minimize Guava class shading (Patch by @elahrvivaz)
+* Follow link headers to @context files (Patch by @dr0i and @fsteeg)
+
 ### 2019-11-28
 * Release 0.13.0
 * Bump Jackson versions to latest for security updates (Patch by @afs)


=====================================
core/pom.xml
=====================================
@@ -4,7 +4,7 @@
 	<parent>
 		<artifactId>jsonld-java-parent</artifactId>
 		<groupId>com.github.jsonld-java</groupId>
-		<version>0.13.1</version>
+		<version>0.13.2</version>
 	</parent>
 	<modelVersion>4.0.0</modelVersion>
 	<artifactId>jsonld-java</artifactId>
@@ -82,6 +82,10 @@
 							<pattern>com.google.common</pattern>
 							<shadedPattern>com.github.jsonldjava.shaded.com.google.common</shadedPattern>
 						</relocation>
+						<relocation>
+							<pattern>com.google.thirdparty</pattern>
+							<shadedPattern>com.github.jsonldjava.shaded.com.google.thirdparty</shadedPattern>
+						</relocation>
 					</relocations>
 					<filters>
 						<filter>


=====================================
core/src/main/java/com/github/jsonldjava/core/Context.java
=====================================
@@ -304,9 +304,7 @@ public class Context extends LinkedHashMap<String, Object> {
      *
      * http://json-ld.org/spec/latest/json-ld-api/#create-term-definition
      *
-     * @param result
      * @param context
-     * @param key
      * @param defined
      * @throws JsonLdError
      */
@@ -572,7 +570,7 @@ public class Context extends LinkedHashMap<String, Object> {
      *            the IRI to compact.
      * @param value
      *            the value to check or null.
-     * @param relativeTo
+     * @param relativeToVocab
      *            options for how to compact IRIs: vocab: true to split
      *            after @vocab, false not to.
      * @param reverse
@@ -1147,6 +1145,7 @@ public class Context extends LinkedHashMap<String, Object> {
         return rval;
     }
 
+    @Deprecated
     public Map<String, Object> serialize() {
         final Map<String, Object> ctx = newMap();
         if (this.get(JsonLdConsts.BASE) != null


=====================================
core/src/main/java/com/github/jsonldjava/core/JsonLdProcessor.java
=====================================
@@ -70,19 +70,12 @@ public class JsonLdProcessor {
                 compacted = tmp;
             }
         }
-        if (compacted != null && context != null) {
-            // TODO: figure out if we can make "@context" appear at the start of
-            // the keySet
-            if ((context instanceof Map && !((Map<String, Object>) context).isEmpty())
-                    || (context instanceof List && !((List<Object>) context).isEmpty())) {
-
-                if (context instanceof List && ((List<Object>) context).size() == 1
-                        && opts.getCompactArrays()) {
-                    ((Map<String, Object>) compacted).put(JsonLdConsts.CONTEXT,
-                            ((List<Object>) context).get(0));
-                } else {
-                    ((Map<String, Object>) compacted).put(JsonLdConsts.CONTEXT, context);
-                }
+        if (compacted != null) {
+            final Object returnedContext = returnedContext(context, opts);
+            if(returnedContext != null) {
+                // TODO: figure out if we can make "@context" appear at the start of
+                // the keySet
+                ((Map<String, Object>) compacted).put(JsonLdConsts.CONTEXT, returnedContext);
             }
         }
 
@@ -250,7 +243,11 @@ public class JsonLdProcessor {
                 compacted = tmp;
             }
             final String alias = activeCtx.compactIri(JsonLdConsts.GRAPH);
-            final Map<String, Object> rval = activeCtx.serialize();
+            final Map<String, Object> rval = newMap();
+            final Object returnedContext = returnedContext(context, opts);
+            if(returnedContext != null) {
+                rval.put(JsonLdConsts.CONTEXT, returnedContext);
+            }
             rval.put(alias, compacted);
             return rval;
         }
@@ -319,14 +316,18 @@ public class JsonLdProcessor {
         // to a new empty
         // context, otherwise.
         final JsonLdApi api = new JsonLdApi(expandedInput, opts);
-        final Context activeCtx = api.context
-                .parse(((Map<String, Object>) frame).get(JsonLdConsts.CONTEXT));
+        final Object context = ((Map<String, Object>) frame).get(JsonLdConsts.CONTEXT);
+        final Context activeCtx = api.context.parse(context);
         final List<Object> framed = api.frame(expandedInput, expandedFrame);
         if (opts.getPruneBlankNodeIdentifiers()) {
             JsonLdUtils.pruneBlankNodes(framed);
         }
         Object compacted = api.compact(activeCtx, null, framed, opts.getCompactArrays());
-        final Map<String, Object> rval = activeCtx.serialize();
+        final Map<String, Object> rval = newMap();
+        final Object returnedContext = returnedContext(context, opts);
+        if(returnedContext != null) {
+            rval.put(JsonLdConsts.CONTEXT, returnedContext);
+        }
         final boolean addGraph = ((!(compacted instanceof List)) && !opts.getOmitGraph());
         if (addGraph && !(compacted instanceof List)) {
             final List<Object> tmp = new ArrayList<Object>();
@@ -343,6 +344,28 @@ public class JsonLdProcessor {
         return rval;
     }
 
+    /**
+     * Builds the context to be returned in framing, flattening and compaction algorithms.
+     * In cases where the context is empty or from an unexpected type, it returns null.
+     * When JsonLdOptions compactArrays is set to true and the context contains a List with a single element,
+     * the element is returned instead of the list
+     */
+    private static Object returnedContext(Object context, JsonLdOptions opts) {
+        if (context != null &&
+                ((context instanceof Map && !((Map<String, Object>) context).isEmpty())
+                        || (context instanceof List && !((List<Object>) context).isEmpty())
+                        || (context instanceof String && !((String) context).isEmpty()))) {
+
+            if (context instanceof List && ((List<Object>) context).size() == 1
+                    && opts.getCompactArrays()) {
+                return ((List<Object>) context).get(0);
+            }
+            return context;
+        } else {
+            return null;
+        }
+    }
+
     /**
      * A registry for RDF Parsers (in this case, JSONLDSerializers) used by
      * fromRDF if no specific serializer is specified and options.format is set.


=====================================
core/src/test/java/com/github/jsonldjava/core/ContextCompactionTest.java
=====================================
@@ -1,20 +1,21 @@
 package com.github.jsonldjava.core;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import com.github.jsonldjava.utils.JsonUtils;
 import org.junit.Test;
 
+
 public class ContextCompactionTest {
 
-    // @Ignore("Disable until schema.org is fixed")
     @Test
-    public void testCompaction() throws Exception {
+    public void testCompaction() {
 
         final Map<String, Object> contextAbbrevs = new HashMap<String, Object>();
         contextAbbrevs.put("so", "http://schema.org/");
@@ -34,19 +35,30 @@ public class ContextCompactionTest {
         options.setBase("http://schema.org/");
         options.setCompactArrays(true);
 
-        // System.out.println("Before compact");
-        // System.out.println(JsonUtils.toPrettyString(json));
-
         final List<String> newContexts = new LinkedList<String>();
         newContexts.add("http://schema.org/");
         final Map<String, Object> compacted = JsonLdProcessor.compact(json, newContexts, options);
 
-        // System.out.println("\n\nAfter compact:");
-        // System.out.println(JsonUtils.toPrettyString(compacted));
-
         assertTrue("Compaction removed the context", compacted.containsKey("@context"));
         assertFalse("Compaction of context should be a string, not a list",
                 compacted.get("@context") instanceof List);
     }
 
+    @Test
+    public void testCompactionSingleRemoteContext() throws Exception {
+        final String jsonString = "[{\"@type\": [\"http://schema.org/Person\"] } ]";
+        final String ctxStr = "{\"@context\": \"http://schema.org/\"}";
+
+        final Object json = JsonUtils.fromString(jsonString);
+        final Object ctx = JsonUtils.fromString(ctxStr);
+
+        final JsonLdOptions options = new JsonLdOptions();
+
+        final Map<String, Object> compacted = JsonLdProcessor.compact(json, ctx, options);
+
+        assertEquals("Wrong returned context", "http://schema.org/", compacted.get("@context"));
+        assertEquals("Wrong type", "Person", compacted.get("type"));
+        assertEquals("Wrong number of Json entries",2, compacted.size());
+    }
+
 }


=====================================
core/src/test/java/com/github/jsonldjava/core/ContextFlatteningTest.java
=====================================
@@ -0,0 +1,66 @@
+package com.github.jsonldjava.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import com.github.jsonldjava.utils.JsonUtils;
+import org.junit.Test;
+
+public class ContextFlatteningTest {
+
+    @Test
+    public void testFlatenning() throws Exception {
+
+        final Map<String, Object> contextAbbrevs = new HashMap<>();
+        contextAbbrevs.put("so", "http://schema.org/");
+
+        final Map<String, Object> json = new HashMap<>();
+        json.put("@context", contextAbbrevs);
+        json.put("@id", "http://example.org/my_work");
+
+        final List<Object> types = new LinkedList<>();
+        types.add("so:CreativeWork");
+
+        json.put("@type", types);
+        json.put("so:name", "My Work");
+        json.put("so:url", "http://example.org/my_work");
+
+        final JsonLdOptions options = new JsonLdOptions();
+        options.setBase("http://schema.org/");
+        options.setCompactArrays(true);
+        options.setOmitGraph(true);
+
+        final String flattenStr = "{\"@id\": \"http://schema.org/myid\", \"@context\": \"http://schema.org/\"}";
+        final Object flatten = JsonUtils.fromString(flattenStr);
+
+        final Map<String, Object> flattened = ((Map<String, Object>)JsonLdProcessor.flatten(json, flatten, options));
+
+        assertTrue("Flattening removed the context", flattened.containsKey("@context"));
+        assertFalse("Flattening of context should be a string, not a list",
+                flattened.get("@context") instanceof List);
+    }
+
+    @Test
+    public void testFlatteningRemoteContext() throws Exception {
+        final String jsonString =
+                "{\"@context\": {\"@vocab\": \"http://schema.org/\"}, \"knows\": [{\"name\": \"a\"}, {\"name\": \"b\"}] }";
+        final String flattenStr = "{\"@context\": \"http://schema.org/\"}";
+
+        final Object json = JsonUtils.fromString(jsonString);
+        final Object flatten = JsonUtils.fromString(flattenStr);
+
+        final JsonLdOptions options = new JsonLdOptions();
+        options.setOmitGraph(true);
+
+        final Map<String, Object> flattened = ((Map<String, Object>)JsonLdProcessor.flatten(json, flatten, options));
+
+        assertEquals("Wrong returned context", "http://schema.org/", flattened.get("@context"));
+        assertEquals("Wrong number of Json entries",2, flattened.size());
+    }
+
+}


=====================================
core/src/test/java/com/github/jsonldjava/core/ContextFramingTest.java
=====================================
@@ -0,0 +1,67 @@
+package com.github.jsonldjava.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import com.github.jsonldjava.utils.JsonUtils;
+import org.junit.Test;
+
+public class ContextFramingTest {
+
+    @Test
+    public void testFraming() throws Exception {
+
+        final Map<String, Object> contextAbbrevs = new HashMap<>();
+        contextAbbrevs.put("so", "http://schema.org/");
+
+        final Map<String, Object> json = new HashMap<>();
+        json.put("@context", contextAbbrevs);
+        json.put("@id", "http://example.org/my_work");
+
+        final List<Object> types = new LinkedList<>();
+        types.add("so:CreativeWork");
+
+        json.put("@type", types);
+        json.put("so:name", "My Work");
+        json.put("so:url", "http://example.org/my_work");
+
+        final JsonLdOptions options = new JsonLdOptions();
+        options.setBase("http://schema.org/");
+        options.setCompactArrays(true);
+        options.setOmitGraph(true);
+
+        final String frameStr = "{\"@id\": \"http://schema.org/myid\", \"@context\": \"http://schema.org/\"}";
+        final Object frame = JsonUtils.fromString(frameStr);
+
+        final Map<String, Object> framed = JsonLdProcessor.frame(json, frame, options);
+
+        assertTrue("Framing removed the context", framed.containsKey("@context"));
+        assertFalse("Framing of context should be a string, not a list",
+                framed.get("@context") instanceof List);
+    }
+
+    @Test
+    public void testFramingRemoteContext() throws Exception {
+        final String jsonString = "{\"@id\": \"http://schema.org/myid\", \"@type\": [\"http://schema.org/Person\"]}";
+        final String frameStr = "{\"@id\": \"http://schema.org/myid\", \"@context\": \"http://schema.org/\"}";
+
+        final Object json = JsonUtils.fromString(jsonString);
+        final Object frame = JsonUtils.fromString(frameStr);
+
+        final JsonLdOptions options = new JsonLdOptions();
+        options.setOmitGraph(true);
+
+        final Map<String, Object> framed = JsonLdProcessor.frame(json, frame, options);
+
+        assertEquals("Wrong returned context", "http://schema.org/", framed.get("@context"));
+        assertEquals("Wrong id", "schema:myid", framed.get("id"));
+        assertEquals("Wrong type", "Person", framed.get("type"));
+        assertEquals("Wrong number of Json entries",3, framed.size());
+    }
+
+}


=====================================
core/src/test/java/com/github/jsonldjava/core/ContextSerializationTest.java
=====================================
@@ -0,0 +1,24 @@
+package com.github.jsonldjava.core;
+
+import com.github.jsonldjava.utils.JsonUtils;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class ContextSerializationTest {
+
+    @Test
+    // Added in order to have some coverage on the serialize method since is not used anywhere.
+    public void serializeTest() throws IOException {
+        final Map<String, Object> json = (Map<String, Object>)JsonUtils
+                .fromInputStream(getClass().getResourceAsStream("/custom/contexttest-0005.jsonld"));
+
+        final Map<String, Object> contextValue = (Map<String, Object>)json.get(JsonLdConsts.CONTEXT);
+        final Map<String, Object> serializedContext = new Context().parse(contextValue).serialize();
+
+        assertEquals("Wrong serialized context", json, serializedContext);
+    }
+}


=====================================
core/src/test/resources/custom/contexttest-0005.jsonld
=====================================
@@ -0,0 +1,12 @@
+{
+  "@context": {
+    "@base": "http://ex.com/base/",
+    "@vocab": "http://ex.com/vocab/",
+    "xsd": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+    "integer": {
+      "@id": "http://example.com/vocab/integer",
+      "@type": "xsd:integer"
+    },
+    "@language": "en"
+  }
+}
\ No newline at end of file


=====================================
pom.xml
=====================================
@@ -4,7 +4,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>com.github.jsonld-java</groupId>
 	<artifactId>jsonld-java-parent</artifactId>
-	<version>0.13.1</version>
+	<version>0.13.2</version>
 	<name>JSONLD Java :: Parent</name>
 	<description>Json-LD Java Parent POM</description>
 	<packaging>pom</packaging>
@@ -198,11 +198,12 @@
 				<groupId>org.mockito</groupId>
 				<artifactId>mockito-core</artifactId>
 				<version>2.28.2</version>
+				<scope>test</scope>
 			</dependency>
 			<dependency>
 				<groupId>commons-io</groupId>
 				<artifactId>commons-io</artifactId>
-				<version>2.7</version>
+				<version>2.8.0</version>
 			</dependency>
 			<!-- Reuse Guava, but shade it to avoid transitive classpath issues for 
 				users given the high major release rate -->



View it on GitLab: https://salsa.debian.org/java-team/jsonld-java/-/commit/940c835644d199357d7f0bb5944b6e7e5b4154ce

-- 
View it on GitLab: https://salsa.debian.org/java-team/jsonld-java/-/commit/940c835644d199357d7f0bb5944b6e7e5b4154ce
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20200928/defe7c77/attachment.html>


More information about the pkg-java-commits mailing list