Refactor to extract a method.
@@ -99,13 +99,7 @@ public class AbiCheck extends AbstractMojo {
getLog().info("Writing ABI specs to " + specFileName);
writeSpec(signatures, specFileName);
} else {
- Gson gson = new GsonBuilder().create();
- try (FileReader reader = new FileReader(specFileName)) {
- TypeToken<Map<String, JavaClassSignature>> typeToken =
- new TypeToken<Map<String, JavaClassSignature>>() {
- };
- Map<String, JavaClassSignature> abiSpec = gson
- .fromJson(reader, typeToken.getType());
+ Map<String, JavaClassSignature> abiSpec = readSpec(specFileName);
if (!matchingItemSets(abiSpec.keySet(), signatures.keySet(),
item -> matchingClasses(item, abiSpec.get(item), signatures.get(item)),
(item, error) -> getLog()
@@ -113,12 +107,21 @@ public class AbiCheck extends AbstractMojo {
throw new MojoFailureException("ABI spec mismatch");
}
}
- }
} catch (IOException e) {
throw new MojoExecutionException("Error processing class signatures", e);
}
}
+ private static Map<String, JavaClassSignature> readSpec(String fileName) throws IOException {
+ try (FileReader reader = new FileReader(fileName)) {
+ TypeToken<Map<String, JavaClassSignature>> typeToken =
+ new TypeToken<Map<String, JavaClassSignature>>() {
+ };
+ Gson gson = new GsonBuilder().create();
+ return gson.fromJson(reader, typeToken.getType());
+ }
+ }
+
private static void writeSpec(Map<String, JavaClassSignature> signatures, String fileName)
throws IOException {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
