From 7e81829f781de1f261c246e01c84a986b9f34ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=A8=F0=9F=8F=BC=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier-Muller?= Date: Tue, 6 Aug 2019 14:06:53 -0700 Subject: [PATCH 1/2] feat(java): remove dependency on google Guava The dependency was used only for a small amount of trivial utilities that can be replicated locally without much effort. Removed the dependency here. --- packages/jsii-java-runtime/pom.xml.t.js | 8 ----- .../java/software/amazon/jsii/JsiiEngine.java | 9 +++-- .../amazon/jsii/JsiiObjectMapper.java | 3 -- .../amazon/jsii/JsiiObjectMapperTest.java | 34 +++++++++++-------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/jsii-java-runtime/pom.xml.t.js b/packages/jsii-java-runtime/pom.xml.t.js index ddf1ef65fc..ba5aad4a17 100644 --- a/packages/jsii-java-runtime/pom.xml.t.js +++ b/packages/jsii-java-runtime/pom.xml.t.js @@ -51,7 +51,6 @@ process.stdout.write(` UTF-8 [3.0.2,3.1.0) - [27.0.1-jre,27.1) [2.9.8,2.10.0) [1.3.2,1.4.0) [5.4.1,5.5.0) @@ -73,13 +72,6 @@ process.stdout.write(` \${jackson.version} - - - com.google.guava - guava - \${guava.version} - - com.google.code.findbugs diff --git a/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java b/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java index c957574a31..09b568896a 100644 --- a/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java +++ b/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java @@ -8,8 +8,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; -import com.google.common.base.Throwables; +import java.io.PrintWriter; +import java.io.StringWriter; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -388,7 +389,11 @@ private Object invokeMethod(final Object obj, final Method method, final Object. try { return method.invoke(obj, args); } catch (Exception e) { - this.log("Error while invoking %s with %s: %s", method, Arrays.toString(args), Throwables.getStackTraceAsString(e)); + final StringWriter sw = new StringWriter(); + try (final PrintWriter pw = new PrintWriter(sw)) { + e.printStackTrace(pw); + } + this.log("Error while invoking %s with %s: %s", method, Arrays.toString(args), sw.toString()); throw e; } } catch (InvocationTargetException e) { diff --git a/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObjectMapper.java b/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObjectMapper.java index c3e59799cd..6e4c025bab 100644 --- a/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObjectMapper.java +++ b/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObjectMapper.java @@ -26,7 +26,6 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.type.MapLikeType; import com.fasterxml.jackson.databind.type.MapType; -import com.google.common.annotations.VisibleForTesting; /** * Provides a correctly configured JSON processor for handling JSII requests and responses. @@ -88,7 +87,6 @@ private JsiiObjectMapper() { this(JsiiEngine.getInstance()); } - @VisibleForTesting JsiiObjectMapper(final JsiiEngine jsiiEngine) { this.jsiiEngine = jsiiEngine; @@ -105,7 +103,6 @@ private JsiiObjectMapper() { this.objectMapper.registerModule(module); } - @VisibleForTesting ObjectMapper getObjectMapper() { return this.objectMapper; } diff --git a/packages/jsii-java-runtime/project/src/test/java/software/amazon/jsii/JsiiObjectMapperTest.java b/packages/jsii-java-runtime/project/src/test/java/software/amazon/jsii/JsiiObjectMapperTest.java index c12f129e6d..96fe871c15 100644 --- a/packages/jsii-java-runtime/project/src/test/java/software/amazon/jsii/JsiiObjectMapperTest.java +++ b/packages/jsii-java-runtime/project/src/test/java/software/amazon/jsii/JsiiObjectMapperTest.java @@ -4,12 +4,15 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.Charset; import java.time.Instant; import java.util.List; +import java.util.stream.Collectors; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Charsets; -import com.google.common.io.Resources; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -38,18 +41,21 @@ public void testDeserialization() throws Exception { when((TestEnum) jsiiEngine.findEnumValue("module.Enum#value")).thenReturn(TestEnum.DUMMY); - final String json = - Resources.toString(Resources.getResource(this.getClass(), "complex-callback.json"), Charsets.UTF_8); - final TestCallback callback = subject.treeToValue(subject.readTree(json), TestCallback.class); - - assertEquals("CallbackID", callback.getCbid()); - assertNotNull(callback.getInvoke()); - if (callback.getCbid() != null) { - assertEquals("methodName", callback.getInvoke().getMethod()); - assertEquals(1337, callback.getInvoke().getArgs().get(0)); - assertEquals(mockObject1, callback.getInvoke().getArgs().get(1)); - assertEquals(Instant.ofEpochMilli(1553624863569L), callback.getInvoke().getArgs().get(2)); - assertEquals(TestEnum.DUMMY, callback.getInvoke().getArgs().get(3)); + try (final InputStream stream = this.getClass().getResourceAsStream("complex-callback.json"); + final InputStreamReader reader = new InputStreamReader(stream, Charset.forName("UTF-8")); + final BufferedReader buffered = new BufferedReader(reader)) { + final String json = buffered.lines().collect(Collectors.joining("\n")); + final TestCallback callback = subject.treeToValue(subject.readTree(json), TestCallback.class); + + assertEquals("CallbackID", callback.getCbid()); + assertNotNull(callback.getInvoke()); + if (callback.getCbid() != null) { + assertEquals("methodName", callback.getInvoke().getMethod()); + assertEquals(1337, callback.getInvoke().getArgs().get(0)); + assertEquals(mockObject1, callback.getInvoke().getArgs().get(1)); + assertEquals(Instant.ofEpochMilli(1553624863569L), callback.getInvoke().getArgs().get(2)); + assertEquals(TestEnum.DUMMY, callback.getInvoke().getArgs().get(3)); + } } } From b45106eeb40159f21bdcb0dc8318f470a33be18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=A8=F0=9F=8F=BC=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier-Muller?= Date: Tue, 6 Aug 2019 17:09:15 -0700 Subject: [PATCH 2/2] use StandardCharsets.UTF8 --- .../test/java/software/amazon/jsii/JsiiObjectMapperTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jsii-java-runtime/project/src/test/java/software/amazon/jsii/JsiiObjectMapperTest.java b/packages/jsii-java-runtime/project/src/test/java/software/amazon/jsii/JsiiObjectMapperTest.java index 96fe871c15..fd5fe1d028 100644 --- a/packages/jsii-java-runtime/project/src/test/java/software/amazon/jsii/JsiiObjectMapperTest.java +++ b/packages/jsii-java-runtime/project/src/test/java/software/amazon/jsii/JsiiObjectMapperTest.java @@ -7,7 +7,7 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.List; import java.util.stream.Collectors; @@ -42,7 +42,7 @@ public void testDeserialization() throws Exception { when((TestEnum) jsiiEngine.findEnumValue("module.Enum#value")).thenReturn(TestEnum.DUMMY); try (final InputStream stream = this.getClass().getResourceAsStream("complex-callback.json"); - final InputStreamReader reader = new InputStreamReader(stream, Charset.forName("UTF-8")); + final InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8); final BufferedReader buffered = new BufferedReader(reader)) { final String json = buffered.lines().collect(Collectors.joining("\n")); final TestCallback callback = subject.treeToValue(subject.readTree(json), TestCallback.class);