Skip to content

Commit 6e1f43f

Browse files
committed
Remove Guava. Build and tests now run on Java 6-11.
1 parent 39090e3 commit 6e1f43f

18 files changed

+234
-146
lines changed

project.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ targetCompatibility = JavaVersion.VERSION_1_6; // defaults to sourceCompatibilit
3030
*/
3131
dependencies {
3232
implementation(group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.9.9");
33-
implementation(group: "com.google.guava", name: "guava", version: "25.1-jre");
3433
implementation(group: "com.github.fge", name: "msg-simple", version: "1.1");
3534
implementation(group: "com.google.code.findbugs", name: "jsr305", version: "2.0.1");
3635
testImplementation(group: "org.testng", name: "testng", version: "6.8.7") {
@@ -42,8 +41,6 @@ dependencies {
4241
}
4342

4443
javadoc.options.links("http://docs.oracle.com/javase/6/docs/api/");
45-
javadoc.options.links("http://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.1/");
4644
javadoc.options.links("http://fasterxml.github.com/jackson-databind/javadoc/2.2.0/");
47-
javadoc.options.links("http://www.javadoc.io/doc/com.google.guava/guava/28.1-jre/");
4845
javadoc.options.links("http://fge.github.io/msg-simple/");
4946

src/main/java/com/github/fge/jackson/JacksonUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package com.github.fge.jackson;
2121

2222
import com.fasterxml.jackson.core.JsonGenerationException;
23+
import com.fasterxml.jackson.core.JsonGenerator;
2324
import com.fasterxml.jackson.databind.DeserializationFeature;
2425
import com.fasterxml.jackson.databind.JsonMappingException;
2526
import com.fasterxml.jackson.databind.JsonNode;
@@ -28,11 +29,11 @@
2829
import com.fasterxml.jackson.databind.ObjectWriter;
2930
import com.fasterxml.jackson.databind.SerializationFeature;
3031
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
31-
import com.google.common.collect.Maps;
3232

3333
import java.io.IOException;
3434
import java.io.StringWriter;
3535
import java.util.Collections;
36+
import java.util.HashMap;
3637
import java.util.Iterator;
3738
import java.util.Map;
3839

@@ -98,7 +99,7 @@ public static Map<String, JsonNode> asMap(final JsonNode node)
9899
return Collections.emptyMap();
99100

100101
final Iterator<Map.Entry<String, JsonNode>> iterator = node.fields();
101-
final Map<String, JsonNode> ret = Maps.newHashMap();
102+
final Map<String, JsonNode> ret = new HashMap<String, JsonNode>();
102103

103104
Map.Entry<String, JsonNode> entry;
104105

@@ -142,7 +143,7 @@ public static String prettyPrint(final JsonNode node)
142143
*
143144
* <ul>
144145
* <li>{@link DeserializationFeature#USE_BIG_DECIMAL_FOR_FLOATS};</li>
145-
* <li>{@link SerializationFeature#WRITE_BIGDECIMAL_AS_PLAIN};</li>
146+
* <li>{@link JsonGenerator.Feature#WRITE_BIGDECIMAL_AS_PLAIN};</li>
146147
* <li>{@link SerializationFeature#INDENT_OUTPUT}.</li>
147148
* </ul>
148149
*
@@ -154,7 +155,7 @@ public static ObjectMapper newMapper()
154155
{
155156
return new ObjectMapper().setNodeFactory(FACTORY)
156157
.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
157-
.enable(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN)
158+
.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN)
158159
.enable(SerializationFeature.INDENT_OUTPUT);
159160
}
160161
}

src/main/java/com/github/fge/jackson/JsonLoader.java

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
package com.github.fge.jackson;
2121

2222
import com.fasterxml.jackson.databind.JsonNode;
23-
import com.google.common.base.Preconditions;
24-
import com.google.common.io.Closer;
2523

2624
import javax.annotation.Nonnull;
27-
2825
import java.io.File;
2926
import java.io.FileInputStream;
3027
import java.io.IOException;
@@ -74,50 +71,44 @@ private JsonLoader()
7471
public static JsonNode fromResource(@Nonnull final String resource)
7572
throws IOException
7673
{
77-
Preconditions.checkNotNull(resource);
78-
Preconditions.checkArgument(resource.startsWith("/"),
79-
"resource path does not start with a '/'");
74+
if (resource == null) {
75+
throw new NullPointerException();
76+
}
77+
if (!resource.startsWith("/")) {
78+
throw new IllegalArgumentException("resource path does not start with a '/'");
79+
}
8080
URL url;
8181
url = JsonLoader.class.getResource(resource);
8282
if (url == null) {
83-
final ClassLoader classLoader = firstNonNull(
84-
Thread.currentThread().getContextClassLoader(),
85-
JsonLoader.class.getClassLoader()
86-
);
83+
final ClassLoader classLoader;
84+
if (Thread.currentThread().getContextClassLoader() != null) {
85+
classLoader = Thread.currentThread().getContextClassLoader();
86+
} else if (JsonLoader.class.getClassLoader() != null) {
87+
classLoader = JsonLoader.class.getClassLoader();
88+
} else {
89+
throw new NullPointerException();
90+
}
8791
final String s = INITIAL_SLASH.matcher(resource).replaceFirst("");
8892
url = classLoader.getResource(s);
8993
}
9094
if (url == null)
9195
throw new IOException("resource " + resource + " not found");
9296

93-
final Closer closer = Closer.create();
9497
final JsonNode ret;
95-
final InputStream in;
98+
InputStream in = null;
9699

97100
try {
98-
in = closer.register(url.openStream());
101+
in = url.openStream();
99102
ret = READER.fromInputStream(in);
100103
} finally {
101-
closer.close();
104+
if (in != null) {
105+
in.close();
106+
}
102107
}
103108

104109
return ret;
105110
}
106111

107-
/**
108-
* Returns the first non-null parameter.
109-
*
110-
* Implementation note: Avoids the Guava method of the same name, to mitigate 'Dependency Hell'.
111-
* This can be replaced by {@code MoreObjects.firstNonNull} when moving to Guava >= 18.0
112-
* (Tip: Guava 20 seems like a good choice if Java 6 support is still necessary.)
113-
*
114-
* @throws NullPointerException if both are null.
115-
*/
116-
private static ClassLoader firstNonNull(ClassLoader first, ClassLoader second)
117-
{
118-
return first != null ? first : Preconditions.checkNotNull(second);
119-
}
120-
121112
/**
122113
* Read a {@link JsonNode} from an URL.
123114
*
@@ -141,15 +132,16 @@ public static JsonNode fromURL(final URL url)
141132
public static JsonNode fromPath(final String path)
142133
throws IOException
143134
{
144-
final Closer closer = Closer.create();
145135
final JsonNode ret;
146-
final FileInputStream in;
136+
FileInputStream in = null;
147137

148138
try {
149-
in = closer.register(new FileInputStream(path));
139+
in = new FileInputStream(path);
150140
ret = READER.fromInputStream(in);
151141
} finally {
152-
closer.close();
142+
if (in != null) {
143+
in.close();
144+
}
153145
}
154146

155147
return ret;
@@ -166,15 +158,16 @@ public static JsonNode fromPath(final String path)
166158
public static JsonNode fromFile(final File file)
167159
throws IOException
168160
{
169-
final Closer closer = Closer.create();
170161
final JsonNode ret;
171-
final FileInputStream in;
162+
FileInputStream in = null;
172163

173164
try {
174-
in = closer.register(new FileInputStream(file));
165+
in = new FileInputStream(file);
175166
ret = READER.fromInputStream(in);
176167
} finally {
177-
closer.close();
168+
if (in != null) {
169+
in.close();
170+
}
178171
}
179172

180173
return ret;

src/main/java/com/github/fge/jackson/JsonNodeReader.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.github.fge.Builder;
3131
import com.github.fge.msgsimple.bundle.MessageBundle;
3232
import com.github.fge.msgsimple.bundle.PropertiesBundle;
33-
import com.google.common.io.Closer;
3433

3534
import javax.annotation.Nonnull;
3635
import javax.annotation.concurrent.ThreadSafe;
@@ -71,7 +70,7 @@ public final class JsonNodeReader
7170
public JsonNodeReader(final ObjectMapper mapper)
7271
{
7372
reader = mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true)
74-
.reader(JsonNode.class);
73+
.readerFor(JsonNode.class);
7574
}
7675

7776
/**
@@ -93,16 +92,20 @@ public JsonNodeReader()
9392
public JsonNode fromInputStream(final InputStream in)
9493
throws IOException
9594
{
96-
final Closer closer = Closer.create();
97-
final JsonParser parser;
98-
final MappingIterator<JsonNode> iterator;
95+
JsonParser parser = null;
96+
MappingIterator<JsonNode> iterator = null;
9997

10098
try {
101-
parser = closer.register(reader.getFactory().createParser(in));
99+
parser = reader.getFactory().createParser(in);
102100
iterator = reader.readValues(parser);
103-
return readNode(closer.register(iterator));
101+
return readNode(iterator);
104102
} finally {
105-
closer.close();
103+
if (parser != null) {
104+
parser.close();
105+
}
106+
if (iterator != null) {
107+
iterator.close();
108+
}
106109
}
107110
}
108111

@@ -117,16 +120,20 @@ public JsonNode fromInputStream(final InputStream in)
117120
public JsonNode fromReader(final Reader r)
118121
throws IOException
119122
{
120-
final Closer closer = Closer.create();
121-
final JsonParser parser;
122-
final MappingIterator<JsonNode> iterator;
123+
JsonParser parser = null;
124+
MappingIterator<JsonNode> iterator = null;
123125

124126
try {
125-
parser = closer.register(reader.getFactory().createParser(r));
127+
parser = reader.getFactory().createParser(r);
126128
iterator = reader.readValues(parser);
127-
return readNode(closer.register(iterator));
129+
return readNode(iterator);
128130
} finally {
129-
closer.close();
131+
if (parser != null) {
132+
parser.close();
133+
}
134+
if (iterator != null) {
135+
iterator.close();
136+
}
130137
}
131138
}
132139

0 commit comments

Comments
 (0)