Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(java): remove dependency on google Guava #681

Merged
merged 3 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/jsii-java-runtime/pom.xml.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ process.stdout.write(`<?xml version="1.0" encoding="UTF-8"?>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Versions of the dependencies -->
<findbugs.version>[3.0.2,3.1.0)</findbugs.version>
<guava.version>[27.0.1-jre,27.1)</guava.version>
<jackson.version>[2.9.8,2.10.0)</jackson.version>
<javax.annotations.version>[1.3.2,1.4.0)</javax.annotations.version>
<junit.version>[5.4.1,5.5.0)</junit.version>
Expand All @@ -73,13 +72,6 @@ process.stdout.write(`<?xml version="1.0" encoding="UTF-8"?>
<version>\${jackson.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>\${guava.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305 -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -88,7 +87,6 @@ private JsiiObjectMapper() {
this(JsiiEngine.getInstance());
}

@VisibleForTesting
JsiiObjectMapper(final JsiiEngine jsiiEngine) {
this.jsiiEngine = jsiiEngine;

Expand All @@ -105,7 +103,6 @@ private JsiiObjectMapper() {
this.objectMapper.registerModule(module);
}

@VisibleForTesting
ObjectMapper getObjectMapper() {
return this.objectMapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.StandardCharsets;
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;
Expand Down Expand Up @@ -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, 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);

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));
}
}
}

Expand Down