diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-12-17 16:06:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-17 16:06:38 +0100 |
commit | 5d80c7f20714621c4bad5d687caffb3345168e7e (patch) | |
tree | e65700a779c7c9b61f367f7235f8ca6de97f994d | |
parent | 9c65860b88dae3eeb202aa1c735fc1ae4d641c80 (diff) | |
parent | e28f68d33d61a4b58e02be852153b0775f9d12d5 (diff) |
Merge pull request #7952 from vespa-engine/iruotsalainen/fix-abispec-dir
Read/write ABI spec to project base directory.
-rw-r--r-- | abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java | 17 |
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"); } |