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

Update errorProneSupportVersion to v0.19.1 #176

Merged
merged 2 commits into from
Dec 21, 2024
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ junitVersion=5.11.4
assertjVersion=3.27.0
cucumberVersion=7.20.1
errorProneVersion=2.36.0
errorProneSupportVersion=0.18.0
errorProneSupportVersion=0.19.1
51 changes: 25 additions & 26 deletions src/main/java/dev/gokhun/convert/ConversionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ private interface Writer {

enum FileType {
CSV(ImmutableSet.of("csv")) {
private static final CsvMapper mapper = new CsvMapper().enable(ALWAYS_QUOTE_STRINGS);
private static final CsvSchema schema = CsvSchema.emptySchema().withHeader();
private static final CsvMapper MAPPER = new CsvMapper().enable(ALWAYS_QUOTE_STRINGS);
private static final CsvSchema CSV_SCHEMA = CsvSchema.emptySchema().withHeader();

@Override
Reader reader(ConversionOptions options) {
return file -> {
var it = mapper
var it = MAPPER
.readerFor(new TypeReference<LinkedHashMap<String, String>>() {})
.with(schema.withColumnSeparator(options.csvSeparator()))
.with(CSV_SCHEMA.withColumnSeparator(options.csvSeparator()))
.readValues(file);
var factory = JsonNodeFactory.instance;
var result = factory.arrayNode();
while (it.hasNextValue()) {
result.add(mapper.convertValue(it.next(), JsonNode.class));
result.add(MAPPER.convertValue(it.next(), JsonNode.class));
}
return result;
};
Expand All @@ -71,7 +71,7 @@ Writer writer(ConversionOptions options) {
var csvSchemaBuilder = CsvSchema.builder();
var firstObject = jsonNode instanceof ArrayNode ? jsonNode.elements().next() : jsonNode;
firstObject.fieldNames().forEachRemaining(csvSchemaBuilder::addColumn);
mapper
MAPPER
.writerFor(JsonNode.class)
.with(csvSchemaBuilder
.build()
Expand All @@ -82,21 +82,21 @@ Writer writer(ConversionOptions options) {
}
},
TSV(ImmutableSet.of("tsv")) {
private static final CsvMapper mapper = new CsvMapper().enable(ALWAYS_QUOTE_STRINGS);
private static final CsvSchema schema = CsvSchema.emptySchema().withHeader();
private static final CsvMapper MAPPER = new CsvMapper().enable(ALWAYS_QUOTE_STRINGS);
private static final CsvSchema CSV_SCHEMA = CsvSchema.emptySchema().withHeader();
private static final char HORIZONTAL_TABULATION = '\t';

@Override
Reader reader(ConversionOptions options) {
return file -> {
var it = mapper
var it = MAPPER
.readerFor(new TypeReference<LinkedHashMap<String, String>>() {})
.with(schema.withColumnSeparator(HORIZONTAL_TABULATION))
.with(CSV_SCHEMA.withColumnSeparator(HORIZONTAL_TABULATION))
.readValues(file);
var factory = JsonNodeFactory.instance;
var result = factory.arrayNode();
while (it.hasNextValue()) {
result.add(mapper.convertValue(it.next(), JsonNode.class));
result.add(MAPPER.convertValue(it.next(), JsonNode.class));
}
return result;
};
Expand All @@ -108,7 +108,7 @@ Writer writer(ConversionOptions options) {
var csvSchemaBuilder = CsvSchema.builder();
var firstObject = jsonNode instanceof ArrayNode ? jsonNode.elements().next() : jsonNode;
firstObject.fieldNames().forEachRemaining(csvSchemaBuilder::addColumn);
mapper
MAPPER
.writerFor(JsonNode.class)
.with(csvSchemaBuilder
.build()
Expand All @@ -119,61 +119,60 @@ Writer writer(ConversionOptions options) {
}
},
JSON(ImmutableSet.of("json")) {
private static final JsonMapper mapper = new JsonMapper();
private static final JsonMapper MAPPER = new JsonMapper();

@Override
Reader reader(ConversionOptions options) {
return mapper::readTree;
return MAPPER::readTree;
}

@Override
Writer writer(ConversionOptions options) {
return (file, jsonNode) -> (options.pretty()
? mapper.writerWithDefaultPrettyPrinter()
: mapper.writer())
? MAPPER.writerWithDefaultPrettyPrinter()
: MAPPER.writer())
.writeValue(file, jsonNode);
}
},
PROPERTIES(ImmutableSet.of("properties")) {
private static final JavaPropsMapper mapper = JavaPropsMapper.builder()
private static final JavaPropsMapper MAPPER = JavaPropsMapper.builder()
.configure(SORT_PROPERTIES_ALPHABETICALLY, true)
.build();

@Override
Reader reader(ConversionOptions options) {
return mapper::readTree;
return MAPPER::readTree;
}

@Override
Writer writer(ConversionOptions options) {
return mapper::writeValue;
return MAPPER::writeValue;
}
},
TOML(ImmutableSet.of("toml")) {

private static final TomlMapper mapper = new TomlMapper();
private static final TomlMapper MAPPER = new TomlMapper();

@Override
Reader reader(ConversionOptions options) {
return mapper::readTree;
return MAPPER::readTree;
}

@Override
Writer writer(ConversionOptions options) {
return mapper::writeValue;
return MAPPER::writeValue;
}
},
YAML(ImmutableSet.of("yaml", "yml")) {
private static final YAMLMapper mapper = new YAMLMapper();
private static final YAMLMapper MAPPER = new YAMLMapper();

@Override
Reader reader(ConversionOptions options) {
return file -> mapper.valueToTree(new Yaml().load(new FileInputStream(file)));
return file -> MAPPER.valueToTree(new Yaml().load(new FileInputStream(file)));
}

@Override
Writer writer(ConversionOptions options) {
return (file, jsonNode) -> mapper
return (file, jsonNode) -> MAPPER
.configure(INDENT_ARRAYS, options.indentYaml())
.configure(INDENT_ARRAYS_WITH_INDICATOR, options.indentYaml())
.configure(MINIMIZE_QUOTES, options.minimizeYamlQuotes())
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/dev/gokhun/convert/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
usageHelpWidth = 120,
versionProvider = VersionProvider.class)
public final class Convert implements Callable<Integer> {
private static final SystemManager systemManager = new DefaultSystemManager();
private static final ColorScheme colorScheme = defaultColorScheme(ON);
private static final IExecutionExceptionHandler exceptionHandler =
private static final SystemManager SYSTEM_MANAGER = new DefaultSystemManager();
private static final ColorScheme COLOR_SCHEME = defaultColorScheme(ON);
private static final IExecutionExceptionHandler EXCEPTION_HANDLER =
new ExecutionExceptionHandler();
private static final CommandLine cmd = new CommandLine(new Convert())
.setOut(systemManager.getOut())
.setErr(systemManager.getErr())
.setExecutionExceptionHandler(exceptionHandler)
.setColorScheme(colorScheme);
private static final CommandLine CMD = new CommandLine(new Convert())
.setOut(SYSTEM_MANAGER.getOut())
.setErr(SYSTEM_MANAGER.getErr())
.setExecutionExceptionHandler(EXCEPTION_HANDLER)
.setColorScheme(COLOR_SCHEME);

@Option(
names = {"--from", "--input", "-f", "-i"},
Expand Down Expand Up @@ -108,7 +108,7 @@ public Integer call() {
}

public static void main(String... args) {
systemManager.exit(cmd.execute(args));
SYSTEM_MANAGER.exit(CMD.execute(args));
}

interface SystemManager {
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/dev/gokhun/convert/ConvertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import picocli.CommandLine.IExecutionExceptionHandler;

final class ConvertTest {
private static final IExecutionExceptionHandler exceptionHandler =
private static final IExecutionExceptionHandler EXCEPTION_HANDLER =
new ExecutionExceptionHandler();
private static final String SEMVER_REGEX =
"^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
Expand All @@ -41,7 +41,7 @@ void version1() {
systemManager.exit(new CommandLine(new Convert())
.setOut(systemManager.getOut())
.setErr(systemManager.getErr())
.setExecutionExceptionHandler(exceptionHandler)
.setExecutionExceptionHandler(EXCEPTION_HANDLER)
.execute("-V"));

assertThat(systemManager.getExitStatus()).isEqualTo(OK);
Expand All @@ -56,7 +56,7 @@ void help1() {
systemManager.exit(new CommandLine(new Convert())
.setOut(systemManager.getOut())
.setErr(systemManager.getErr())
.setExecutionExceptionHandler(exceptionHandler)
.setExecutionExceptionHandler(EXCEPTION_HANDLER)
.execute());

assertThat(systemManager.getExitStatus()).isEqualTo(USAGE);
Expand Down Expand Up @@ -106,7 +106,7 @@ void conversion1(String input, String output, String expected) {
systemManager.exit(new CommandLine(new Convert())
.setOut(systemManager.getOut())
.setErr(systemManager.getErr())
.setExecutionExceptionHandler(exceptionHandler)
.setExecutionExceptionHandler(EXCEPTION_HANDLER)
.execute("-i", getTestResourcePath(input), "-o", outputPath));

assertThat(systemManager.getOutput()).isEmpty();
Expand Down Expand Up @@ -170,7 +170,7 @@ void fromJson1() {
systemManager.exit(new CommandLine(new Convert())
.setOut(systemManager.getOut())
.setErr(systemManager.getErr())
.setExecutionExceptionHandler(exceptionHandler)
.setExecutionExceptionHandler(EXCEPTION_HANDLER)
.execute("-i", input, "-o", output, "--pretty"));

assertThat(systemManager.getExitStatus()).isEqualTo(OK);
Expand All @@ -188,7 +188,7 @@ void fromJson2() {
systemManager.exit(new CommandLine(new Convert())
.setOut(systemManager.getOut())
.setErr(systemManager.getErr())
.setExecutionExceptionHandler(exceptionHandler)
.setExecutionExceptionHandler(EXCEPTION_HANDLER)
.execute("-i", input, "-o", output));

assertThat(systemManager.getExitStatus()).isEqualTo(OK);
Expand All @@ -211,7 +211,7 @@ void deduplicate1(String input, String output, String expected) {
systemManager.exit(new CommandLine(new Convert())
.setOut(systemManager.getOut())
.setErr(systemManager.getErr())
.setExecutionExceptionHandler(exceptionHandler)
.setExecutionExceptionHandler(EXCEPTION_HANDLER)
.execute(
"-i",
getTestResourcePath(input),
Expand Down Expand Up @@ -255,7 +255,7 @@ void csv1(String input, String output, String expected, boolean dedup) {
systemManager.exit(new CommandLine(new Convert())
.setOut(systemManager.getOut())
.setErr(systemManager.getErr())
.setExecutionExceptionHandler(exceptionHandler)
.setExecutionExceptionHandler(EXCEPTION_HANDLER)
.execute(args.build().toArray(String[]::new)));

assertThat(systemManager.getOutput()).isEmpty();
Expand All @@ -279,7 +279,7 @@ void tsv1(String input, String output, String expected, boolean dedup) {
systemManager.exit(new CommandLine(new Convert())
.setOut(systemManager.getOut())
.setErr(systemManager.getErr())
.setExecutionExceptionHandler(exceptionHandler)
.setExecutionExceptionHandler(EXCEPTION_HANDLER)
.execute(args.build().toArray(String[]::new)));

assertThat(systemManager.getOutput()).isEmpty();
Expand Down
Loading