summaryrefslogtreecommitdiffstats
path: root/abi-check-plugin
diff options
context:
space:
mode:
authorIlpo Ruotsalainen <ilpo.ruotsalainen@oath.com>2019-01-09 11:28:21 +0100
committerIlpo Ruotsalainen <ilpo.ruotsalainen@oath.com>2019-01-09 11:28:21 +0100
commit3f9796c5aec7ecc2461cb1c4819ed0adfedfead3 (patch)
treef5af74cf9e7901864a42113e6853c6d1ee2b0bed /abi-check-plugin
parent5251626df44e98457ea111f440d9a79cb6033075 (diff)
Revert "Revert "Enable ABI checking on modules with public APIs""
This reverts commit cd470d8ac8a58c943748f028a37d864507628e99.
Diffstat (limited to 'abi-check-plugin')
-rw-r--r--abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java17
1 files changed, 13 insertions, 4 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 3ae1102014d..2ee7bd495b3 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
@@ -1,5 +1,6 @@
package com.yahoo.abicheck.mojo;
+import com.google.common.collect.Ordering;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
@@ -15,11 +16,14 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.jar.JarFile;
+import java.util.stream.Collectors;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -68,7 +72,7 @@ public class AbiCheck extends AbstractMojo {
// Testing that Gson can write JSON files is not very useful
private static void writeSpec(Map<String, JavaClassSignature> signatures, File file)
throws IOException {
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
try (FileWriter writer = new FileWriter(file)) {
gson.toJson(signatures, writer);
}
@@ -132,14 +136,19 @@ public class AbiCheck extends AbstractMojo {
Map<String, JavaClassSignature> signatures = new LinkedHashMap<>();
if (isPublicAbiPackage(pkg, publicApiAnnotation)) {
PublicSignatureCollector collector = new PublicSignatureCollector();
- for (ClassFile klazz : pkg.getClassFiles()) {
+ List<ClassFileTree.ClassFile> sortedClassFiles = pkg.getClassFiles().stream()
+ .sorted(Comparator.comparing(ClassFile::getName)).collect(Collectors.toList());
+ for (ClassFile klazz : sortedClassFiles) {
try (InputStream is = klazz.getInputStream()) {
new ClassReader(is).accept(collector, 0);
}
}
signatures.putAll(collector.getClassSignatures());
}
- for (ClassFileTree.Package subPkg : pkg.getSubPackages()) {
+ List<ClassFileTree.Package> sortedSubPackages = pkg.getSubPackages().stream()
+ .sorted(Comparator.comparing(Package::getFullyQualifiedName))
+ .collect(Collectors.toList());
+ for (ClassFileTree.Package subPkg : sortedSubPackages) {
signatures.putAll(collectPublicAbiSignatures(subPkg, publicApiAnnotation));
}
return signatures;
@@ -161,7 +170,7 @@ public class AbiCheck extends AbstractMojo {
File specFile = new File(project.getBasedir(), specFileName);
if (mainArtifact.getFile() == null) {
throw new MojoExecutionException("Missing project artifact file");
- } else if (!mainArtifact.getType().equals("jar")) {
+ } else if (!mainArtifact.getFile().getName().endsWith(".jar")) {
throw new MojoExecutionException("Project artifact is not a JAR");
}