From 70e68e508b716d7459dfa230eabcc1a3e70c0cce Mon Sep 17 00:00:00 2001 From: Martin Mois Date: Mon, 22 Apr 2024 14:37:19 +0000 Subject: [PATCH] #392 added new JApiCompatibilityChangeType.ANNOTATION_MODIFIED --- .../japicmp/compat/CompatibilityChanges.java | 37 +++++++++++-------- .../model/JApiCompatibilityChangeType.java | 1 + src/site/markdown/MavenPlugin.md | 4 ++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/japicmp/src/main/java/japicmp/compat/CompatibilityChanges.java b/japicmp/src/main/java/japicmp/compat/CompatibilityChanges.java index 6e3aa5e6..8afd2560 100755 --- a/japicmp/src/main/java/japicmp/compat/CompatibilityChanges.java +++ b/japicmp/src/main/java/japicmp/compat/CompatibilityChanges.java @@ -477,22 +477,27 @@ private void checkIfAnnotationsChanged(JApiHasAnnotations jApiHasAnnotations, Ma if (status == JApiChangeStatus.REMOVED) { addCompatibilityChange(jApiHasAnnotations, JApiCompatibilityChangeType.ANNOTATION_REMOVED); } else { - final boolean isNoAnnotations = this.jarArchiveComparator.getJarArchiveComparatorOptions().isNoAnnotations(); - final boolean isDeprecated = annotation.getFullyQualifiedName().equals(Deprecated.class.getName()); - final JApiClass annotationClass; - if (isNoAnnotations && !isDeprecated) { - annotationClass = null; - } else { - annotationClass = classMap.computeIfAbsent(annotation.getFullyQualifiedName(), fqn -> loadClass(fqn, EnumSet.allOf(Classpath.class))); - annotation.setJApiClass(annotationClass); - } - if (status == JApiChangeStatus.NEW || status == JApiChangeStatus.MODIFIED) { - addCompatibilityChange(jApiHasAnnotations, isDeprecated ? JApiCompatibilityChangeType.ANNOTATION_DEPRECATED_ADDED : JApiCompatibilityChangeType.ANNOTATION_ADDED); - } else if (annotationClass != null) { - checkIfMethodsHaveChangedIncompatible(annotationClass, classMap); - checkIfFieldsHaveChangedIncompatible(annotationClass, classMap); - if (!annotationClass.isSourceCompatible() || !annotationClass.isBinaryCompatible()) { - addCompatibilityChange(jApiHasAnnotations, JApiCompatibilityChangeType.ANNOTATION_MODIFIED_INCOMPATIBLE); + boolean isNoAnnotations = this.jarArchiveComparator.getJarArchiveComparatorOptions().isNoAnnotations(); + if (!isNoAnnotations) { + boolean isDeprecated = annotation.getFullyQualifiedName().equals(Deprecated.class.getName()); + if (isDeprecated && status == JApiChangeStatus.NEW) { + addCompatibilityChange(jApiHasAnnotations, JApiCompatibilityChangeType.ANNOTATION_DEPRECATED_ADDED); + } else { + JApiClass annotationClass = classMap.computeIfAbsent(annotation.getFullyQualifiedName(), fqn -> loadClass(fqn, EnumSet.allOf(Classpath.class))); + if (annotationClass != null) { + annotation.setJApiClass(annotationClass); + if (status == JApiChangeStatus.NEW) { + addCompatibilityChange(jApiHasAnnotations, JApiCompatibilityChangeType.ANNOTATION_ADDED); + } else { + checkIfMethodsHaveChangedIncompatible(annotationClass, classMap); + checkIfFieldsHaveChangedIncompatible(annotationClass, classMap); + if (!annotationClass.isSourceCompatible() || !annotationClass.isBinaryCompatible()) { + addCompatibilityChange(jApiHasAnnotations, JApiCompatibilityChangeType.ANNOTATION_MODIFIED_INCOMPATIBLE); + } else { + addCompatibilityChange(jApiHasAnnotations, JApiCompatibilityChangeType.ANNOTATION_MODIFIED); + } + } + } } } } diff --git a/japicmp/src/main/java/japicmp/model/JApiCompatibilityChangeType.java b/japicmp/src/main/java/japicmp/model/JApiCompatibilityChangeType.java index 523ecabd..103c10a4 100644 --- a/japicmp/src/main/java/japicmp/model/JApiCompatibilityChangeType.java +++ b/japicmp/src/main/java/japicmp/model/JApiCompatibilityChangeType.java @@ -7,6 +7,7 @@ public enum JApiCompatibilityChangeType { ANNOTATION_ADDED(true, true, JApiSemanticVersionLevel.PATCH), ANNOTATION_DEPRECATED_ADDED(true, true, JApiSemanticVersionLevel.MINOR), + ANNOTATION_MODIFIED(true, true, JApiSemanticVersionLevel.PATCH), ANNOTATION_MODIFIED_INCOMPATIBLE(true, true, JApiSemanticVersionLevel.PATCH), ANNOTATION_REMOVED(true, true, JApiSemanticVersionLevel.PATCH), CLASS_REMOVED(false, false, JApiSemanticVersionLevel.MAJOR), diff --git a/src/site/markdown/MavenPlugin.md b/src/site/markdown/MavenPlugin.md index fa058fc0..bdafe8ed 100644 --- a/src/site/markdown/MavenPlugin.md +++ b/src/site/markdown/MavenPlugin.md @@ -262,7 +262,11 @@ for each check. This allows you to customize the following verifications: | Check | Default binary compatible | Default source compatible | Default semantic version level |-------|---------------------------|---------------------------|--------------------------------| +| ANNOTATION_ADDED | true | true | PATCH | | ANNOTATION_DEPRECATED_ADDED | true | true | MINOR | +| ANNOTATION_MODIFIED | true | true | PATCH | +| ANNOTATION_MODIFIED_INCOMPATIBLE | true | true | PATCH | +| ANNOTATION_REMOVED | true | true | PATCH | | CLASS_REMOVED | false | false | MAJOR | | CLASS_NOW_ABSTRACT | false | false | MAJOR | | CLASS_NOW_FINAL | false | false | MAJOR |