Skip to content

Commit

Permalink
feat(java): remove dependency on google Guava (#681)
Browse files Browse the repository at this point in the history
The dependency was used only for a small amount of trivial utilities
that can be replicated locally without much effort. Removed the
dependency here.
  • Loading branch information
RomainMuller authored Aug 7, 2019
1 parent 6aaec85 commit e86bfdc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
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

0 comments on commit e86bfdc

Please sign in to comment.