summaryrefslogtreecommitdiffstats
path: root/abi-check-plugin
diff options
context:
space:
mode:
authorIlpo Ruotsalainen <ilpo.ruotsalainen@oath.com>2018-12-17 15:50:37 +0100
committerIlpo Ruotsalainen <ilpo.ruotsalainen@oath.com>2018-12-17 15:50:37 +0100
commite28f68d33d61a4b58e02be852153b0775f9d12d5 (patch)
tree15591f46d523eebbdb0421c17eca38785b4946a2 /abi-check-plugin
parentb3e51f84ba5c8bc01c8bbff84621e82a375b54f2 (diff)
Read/write ABI spec to project base directory.
Diffstat (limited to 'abi-check-plugin')
-rw-r--r--abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java17
1 files changed, 10 insertions, 7 deletions
diff --git a/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java b/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java
index 06d2628228c..3ae1102014d 100644
--- a/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java
+++ b/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java
@@ -10,6 +10,7 @@ import com.yahoo.abicheck.collector.AnnotationCollector;
import com.yahoo.abicheck.collector.PublicSignatureCollector;
import com.yahoo.abicheck.setmatcher.SetMatcher;
import com.yahoo.abicheck.signature.JavaClassSignature;
+import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@@ -52,8 +53,8 @@ public class AbiCheck extends AbstractMojo {
// CLOVER:OFF
// Testing that Gson can read JSON files is not very useful
- private static Map<String, JavaClassSignature> readSpec(String fileName) throws IOException {
- try (FileReader reader = new FileReader(fileName)) {
+ private static Map<String, JavaClassSignature> readSpec(File file) throws IOException {
+ try (FileReader reader = new FileReader(file)) {
TypeToken<Map<String, JavaClassSignature>> typeToken =
new TypeToken<Map<String, JavaClassSignature>>() {
};
@@ -65,10 +66,10 @@ public class AbiCheck extends AbstractMojo {
// CLOVER:OFF
// Testing that Gson can write JSON files is not very useful
- private static void writeSpec(Map<String, JavaClassSignature> signatures, String fileName)
+ private static void writeSpec(Map<String, JavaClassSignature> signatures, File file)
throws IOException {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
- try (FileWriter writer = new FileWriter(fileName)) {
+ try (FileWriter writer = new FileWriter(file)) {
gson.toJson(signatures, writer);
}
}
@@ -157,6 +158,7 @@ public class AbiCheck extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Artifact mainArtifact = project.getArtifact();
+ File specFile = new File(project.getBasedir(), specFileName);
if (mainArtifact.getFile() == null) {
throw new MojoExecutionException("Missing project artifact file");
} else if (!mainArtifact.getType().equals("jar")) {
@@ -165,6 +167,7 @@ public class AbiCheck extends AbstractMojo {
getLog().debug("Analyzing " + mainArtifact.getFile());
+
try (JarFile jarFile = new JarFile(mainArtifact.getFile())) {
ClassFileTree tree = ClassFileTree.fromJar(jarFile);
Map<String, JavaClassSignature> signatures = new LinkedHashMap<>();
@@ -172,10 +175,10 @@ public class AbiCheck extends AbstractMojo {
signatures.putAll(collectPublicAbiSignatures(pkg, publicApiAnnotation));
}
if (System.getProperty(WRITE_SPEC_PROPERTY) != null) {
- getLog().info("Writing ABI specs to " + specFileName);
- writeSpec(signatures, specFileName);
+ getLog().info("Writing ABI specs to " + specFile.getPath());
+ writeSpec(signatures, specFile);
} else {
- Map<String, JavaClassSignature> abiSpec = readSpec(specFileName);
+ Map<String, JavaClassSignature> abiSpec = readSpec(specFile);
if (!compareSignatures(abiSpec, signatures, getLog())) {
throw new MojoFailureException("ABI spec mismatch");
}