Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

Upgrade to Guice 4 and Java 8 #250

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 16 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.facebook</groupId>
<artifactId>facebook-oss-pom</artifactId>
<version>11</version>
<groupId>io.airlift</groupId>
<artifactId>airbase</artifactId>
<version>34</version>
</parent>

<groupId>com.facebook.swift</groupId>
Expand Down Expand Up @@ -72,7 +72,7 @@

<properties>
<!-- This actually wants to be fixed -->
<fb.check.fail-findbugs>false</fb.check.fail-findbugs>
<air.check.skip-extended>true</air.check.skip-extended>

<dep.airlift.version>0.91</dep.airlift.version>
<dep.antlr.version>3.5</dep.antlr.version>
Expand Down Expand Up @@ -118,6 +118,18 @@
<version>1.1.0.Final</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>

<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SwiftDocumentContext(final URI thriftUri,
final TypeRegistry typeRegistry,
final TypedefRegistry typedefRegistry) throws IOException
{
this.document = ThriftIdlParser.parseThriftIdl(Resources.newReaderSupplier(thriftUri.toURL(), Charsets.UTF_8));
this.document = ThriftIdlParser.parseThriftIdl(Resources.asCharSource(thriftUri.toURL(), Charsets.UTF_8));
this.thriftUri = thriftUri;
this.namespace = namespace;
this.generatorConfig = generatorConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.io.InputSupplier;
import com.google.common.io.CharSource;
import com.google.common.io.Resources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -30,23 +30,22 @@
import org.stringtemplate.v4.misc.ErrorManager;
import org.stringtemplate.v4.misc.STMessage;

import javax.annotation.Nonnull;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Map;

import javax.annotation.Nonnull;

public class TemplateLoader
{
private static final Function<String,InputSupplier<InputStreamReader>> FILE_TO_INPUT_SUPPLIER_TRANSFORM =
new Function<String, InputSupplier<InputStreamReader>>()
private static final Function<String,CharSource> FILE_TO_INPUT_SUPPLIER_TRANSFORM =
new Function<String, CharSource>()
{
@Nonnull
@Override
public InputSupplier<InputStreamReader> apply(@Nonnull String templateFileName)
public CharSource apply(@Nonnull String templateFileName)
{
return Resources.newReaderSupplier(Resources.getResource(this.getClass(), "/templates/" + templateFileName), Charsets.UTF_8);
return Resources.asCharSource(Resources.getResource(this.getClass(), "/templates/" + templateFileName), Charsets.UTF_8);
}
};

Expand Down Expand Up @@ -80,7 +79,7 @@ protected STGroup getTemplateGroup(Iterable<String> templateFileNames) throws IO
{
if (stg == null) {
// Convert set of relative paths to .st files into a set of input suppliers
Iterable<InputSupplier<InputStreamReader>> templateInputSuppliers =
Iterable<CharSource> templateInputSuppliers =
Iterables.transform(templateFileNames, FILE_TO_INPUT_SUPPLIER_TRANSFORM);

// Combine the header and all .st files and load everything into a StringTemplateGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.facebook.swift.parser.antlr.ThriftLexer;
import com.facebook.swift.parser.antlr.ThriftParser;
import com.facebook.swift.parser.model.Document;
import com.google.common.io.InputSupplier;
import com.google.common.io.CharSource;
import org.antlr.runtime.ANTLRReaderStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
Expand All @@ -32,7 +32,7 @@

public class ThriftIdlParser
{
public static Document parseThriftIdl(InputSupplier<? extends Reader> input)
public static Document parseThriftIdl(CharSource input)
throws IOException
{
Tree tree = parseTree(input);
Expand All @@ -46,10 +46,10 @@ public static Document parseThriftIdl(InputSupplier<? extends Reader> input)
}
}

static Tree parseTree(InputSupplier<? extends Reader> input)
static Tree parseTree(CharSource input)
throws IOException
{
try (Reader reader = input.getInput()) {
try (Reader reader = input.openStream()) {
ThriftLexer lexer = new ThriftLexer(new ANTLRReaderStream(reader));
ThriftParser parser = new ThriftParser(new CommonTokenStream(lexer));
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
package com.facebook.swift.parser;

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import com.google.common.io.InputSupplier;
import com.google.common.io.CharSource;
import com.google.common.io.Resources;
import org.testng.annotations.Test;

import java.io.InputStreamReader;

import static com.facebook.swift.parser.ThriftIdlParser.parseThriftIdl;
import static com.facebook.swift.parser.ThriftIdlParser.parseTree;
import static com.facebook.swift.parser.TreePrinter.treeToString;
Expand All @@ -33,7 +30,7 @@ public class TestDocument
public void testEmpty()
throws Exception
{
parseThriftIdl(CharStreams.newReaderSupplier(""));
parseThriftIdl(CharSource.wrap(""));
}

@Test
Expand All @@ -54,8 +51,8 @@ public void testDocumentHbase()
System.out.println(parseThriftIdl(resourceReader("Hbase.thrift")));
}

private static InputSupplier<InputStreamReader> resourceReader(String name)
private static CharSource resourceReader(String name)
{
return Resources.newReaderSupplier(Resources.getResource(name), Charsets.UTF_8);
return Resources.asCharSource(Resources.getResource(name), Charsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
package com.facebook.swift.parser;

import com.google.common.base.Charsets;
import com.google.common.io.CharSource;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import java.io.InputStreamReader;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Iterator;
Expand Down Expand Up @@ -64,8 +63,8 @@ public void testParseSample(String sampleDirectory)
}
}

private static InputSupplier<InputStreamReader> pathReader(Path path)
private static CharSource pathReader(Path path)
{
return Files.newReaderSupplier(path.toFile(), Charsets.UTF_8);
return Files.asByteSource(path.toFile()).asCharSource(Charsets.UTF_8);
}
}