-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
BugPattern{,Test}Extractor
tests more maintainable
As we're moving to a Java-based website generator located in the same package as the `Extractor` implementations, there is no need to validate the exact format of generated files; only that the data can be deserialized again. While there, track the source file from which data is extracted.
- Loading branch information
1 parent
c7a288c
commit 5d9c0a8
Showing
18 changed files
with
335 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
documentation-support/src/main/java/tech/picnic/errorprone/documentation/Json.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package tech.picnic.errorprone.documentation; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; | ||
import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.guava.GuavaModule; | ||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; | ||
import com.google.errorprone.annotations.FormatMethod; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Utility class that offers mutually consistent JSON serialization and deserialization operations, | ||
* without further specifying the exact schema used. | ||
*/ | ||
final class Json { | ||
private static final ObjectMapper OBJECT_MAPPER = | ||
new ObjectMapper() | ||
.setVisibility(PropertyAccessor.FIELD, Visibility.ANY) | ||
.registerModules(new GuavaModule(), new ParameterNamesModule()); | ||
|
||
private Json() {} | ||
|
||
static <T> T read(Path path, Class<T> clazz) { | ||
try { | ||
return OBJECT_MAPPER.readValue(path.toFile(), clazz); | ||
} catch (IOException e) { | ||
throw failure(e, "Failure reading from '%s'", path); | ||
} | ||
} | ||
|
||
static <T> void write(Path path, T object) { | ||
try { | ||
OBJECT_MAPPER.writeValue(path.toFile(), object); | ||
} catch (IOException e) { | ||
throw failure(e, "Failure writing to '%s'", path); | ||
} | ||
} | ||
|
||
@FormatMethod | ||
private static UncheckedIOException failure(IOException cause, String format, Object... args) { | ||
return new UncheckedIOException(String.format(format, args), cause); | ||
} | ||
} |
Oops, something went wrong.