Skip to content

Commit

Permalink
Merge branch '384'
Browse files Browse the repository at this point in the history
  • Loading branch information
siom79 committed Mar 3, 2024
2 parents 0d86e4e + d73231c commit dea2bc3
Show file tree
Hide file tree
Showing 20 changed files with 578 additions and 481 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import japicmp.exception.JApiCmpException;
import japicmp.model.AccessModifier;
import japicmp.model.JApiClass;
import japicmp.model.JApiCompatibilityChange;
import japicmp.model.JApiCompatibilityChangeType;
import japicmp.model.JApiSemanticVersionLevel;
import japicmp.output.incompatible.IncompatibleErrorOutput;
import japicmp.output.semver.SemverOut;
Expand Down Expand Up @@ -159,15 +159,15 @@ private void setUpOverrideCompatibilityChanges(JarArchiveComparatorOptions compa
for (Parameter.OverrideCompatibilityChangeParameter configChange : overrideCompatibilityChangeParameters) {

String compatibilityChange = configChange.getCompatibilityChange();
JApiCompatibilityChange foundChange = null;
for (JApiCompatibilityChange change : JApiCompatibilityChange.values()) {
JApiCompatibilityChangeType foundChange = null;
for (JApiCompatibilityChangeType change : JApiCompatibilityChangeType.values()) {
if (change.name().equalsIgnoreCase(compatibilityChange)) {
foundChange = change;
break;
}
}
if (foundChange == null) {
throw new MojoFailureException("Unknown compatibility change '" + compatibilityChange + "'. Supported values: " + Joiner.on(',').join(JApiCompatibilityChange.values()));
throw new MojoFailureException("Unknown compatibility change '" + compatibilityChange + "'. Supported values: " + Joiner.on(',').join(JApiCompatibilityChangeType.values()));
}

JApiSemanticVersionLevel foundSemanticVersionLevel = foundChange.getSemanticVersionLevel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.compat.CompatibilityChanges;
import japicmp.model.*;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;

import static japicmp.test.util.Helper.getArchive;
import static japicmp.test.util.Helper.getJApiAnnotation;
import static japicmp.test.util.Helper.getJApiAnnotationElement;
import static japicmp.test.util.Helper.getJApiClass;
import static japicmp.test.util.Helper.getJApiField;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static japicmp.test.util.Helper.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

public class AnnotationsTest {
private static List<JApiClass> jApiClasses;
Expand Down Expand Up @@ -95,12 +88,12 @@ public void testFieldAnnotationValueRemoved() {
JApiAnnotationElement element = getJApiAnnotationElement(fieldAnnotation.getElements(), "value");
assertThat(element.getChangeStatus(), is(JApiChangeStatus.REMOVED));
}

@Test
public void testNewAnnotation() {
JApiClass jApiClass = getJApiClass(jApiClasses, Annotations.NewTypeAnnotation.class.getName());
assertThat(jApiClass.isSourceCompatible(), is(true));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.getCompatibilityChanges(), not(hasItem(JApiCompatibilityChange.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE)));
assertThat(jApiClass.getCompatibilityChanges(), not(hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import japicmp.model.JApiChangeStatus;
import japicmp.model.JApiClass;
import japicmp.model.JApiCompatibilityChange;
import org.hamcrest.MatcherAssert;
import japicmp.model.JApiCompatibilityChangeType;
import org.junit.BeforeClass;
import org.junit.Test;

Expand All @@ -15,44 +15,44 @@
import static japicmp.test.util.Helper.getJApiClass;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertThat;

public class DefaultMethodTest {
private static List<JApiClass> jApiClasses;
@BeforeClass
public static void beforeClass() {
JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(new JarArchiveComparatorOptions());
jApiClasses = jarArchiveComparator.compare(getArchive("japicmp-test-v1.jar"), getArchive("japicmp-test-v2.jar"));
}
@Test
public void testCompatibilityChangeDefaultMethod() {
JApiClass jApiClass = getJApiClass(jApiClasses, DefaultMethod.CDefault.class.getName());
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.UNCHANGED));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.isSourceCompatible(), is(true));
MatcherAssert.assertThat(jApiClass.getCompatibilityChanges(), hasItem(JApiCompatibilityChange.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE));
}
@Test
public void testCompatibilityChangeAbstractMethod() {
JApiClass jApiClass = getJApiClass(jApiClasses, DefaultMethod.CAbstract.class.getName());
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.UNCHANGED));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.isSourceCompatible(), is(false));
MatcherAssert.assertThat(jApiClass.getCompatibilityChanges(), hasItem(JApiCompatibilityChange.METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE));
}
private static List<JApiClass> jApiClasses;

@BeforeClass
public static void beforeClass() {
JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(new JarArchiveComparatorOptions());
jApiClasses = jarArchiveComparator.compare(getArchive("japicmp-test-v1.jar"), getArchive("japicmp-test-v2.jar"));
}

@Test
public void testCompatibilityChangeDefaultMethod() {
JApiClass jApiClass = getJApiClass(jApiClasses, DefaultMethod.CDefault.class.getName());
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.UNCHANGED));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.isSourceCompatible(), is(true));
assertThat(jApiClass.getCompatibilityChanges(), hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE)));
}

@Test
public void testCompatibilityChangeAbstractMethod() {
JApiClass jApiClass = getJApiClass(jApiClasses, DefaultMethod.CAbstract.class.getName());
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.UNCHANGED));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.isSourceCompatible(), is(false));
assertThat(jApiClass.getCompatibilityChanges(), hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE)));
}

@Test
public void testCompatibilityAddMethodAndDefaultInSubInterfaces() {
JApiClass jApiClass = getJApiClass(jApiClasses, DefaultMethod.DefaultInSubInterface.CClass.class.getName());
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.UNCHANGED));
MatcherAssert.assertThat(
jApiClass.getCompatibilityChanges(),
containsInAnyOrder(
JApiCompatibilityChange.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE));
assertThat(
jApiClass.getCompatibilityChanges(),
containsInAnyOrder(
new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE)));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.isSourceCompatible(), is(true));
}
Expand All @@ -61,11 +61,11 @@ public void testCompatibilityAddMethodAndDefaultInSubInterfaces() {
public void testCompatibilityAddMethodAndDefaultInSubInterfacesChecksForExactMatch() {
JApiClass jApiClass = getJApiClass(jApiClasses, DefaultMethod.UnrelatedDefaultInSubInterface.CClass.class.getName());
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.UNCHANGED));
MatcherAssert.assertThat(
jApiClass.getCompatibilityChanges(),
containsInAnyOrder(
JApiCompatibilityChange.METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE,
JApiCompatibilityChange.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE));
assertThat(
jApiClass.getCompatibilityChanges(),
containsInAnyOrder(
new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE),
new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE)));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.isSourceCompatible(), is(false));
}
Expand All @@ -74,11 +74,11 @@ public void testCompatibilityAddMethodAndDefaultInSubInterfacesChecksForExactMat
public void testCompatibilityAddMethodWithDefaultAndOverrideInSubInterfaces() {
JApiClass jApiClass = getJApiClass(jApiClasses, DefaultMethod.DefaultInParentInterface.CClass.class.getName());
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.UNCHANGED));
MatcherAssert.assertThat(
jApiClass.getCompatibilityChanges(),
containsInAnyOrder(
JApiCompatibilityChange.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE,
JApiCompatibilityChange.METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE));
assertThat(
jApiClass.getCompatibilityChanges(),
containsInAnyOrder(
new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE),
new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE)));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.isSourceCompatible(), is(false));
}
Expand All @@ -87,10 +87,10 @@ public void testCompatibilityAddMethodWithDefaultAndOverrideInSubInterfaces() {
public void testCompatibilityAddSuperClass() {
JApiClass jApiClass = getJApiClass(jApiClasses, DefaultMethod.DefaultInSubInterfaceAddedSuperclass.CClass.class.getName());
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.MODIFIED));
MatcherAssert.assertThat(
jApiClass.getCompatibilityChanges(),
containsInAnyOrder(
JApiCompatibilityChange.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE));
assertThat(
jApiClass.getCompatibilityChanges(),
containsInAnyOrder(
new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE)));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.isSourceCompatible(), is(true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.model.JApiClass;
import japicmp.model.JApiCompatibilityChange;
import japicmp.model.JApiCompatibilityChangeType;
import japicmp.test.Enums.AbcToAb;
import japicmp.test.Enums.AbcToAbcd;
import org.junit.BeforeClass;
Expand All @@ -14,7 +15,7 @@
import static japicmp.test.util.Helper.getArchive;
import static japicmp.test.util.Helper.getJApiClass;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

public class EnumsTest {
private static List<JApiClass> jApiClasses;
Expand All @@ -36,13 +37,13 @@ public void testRemovedEnumConstant() {
JApiClass abcToAb = getJApiClass(jApiClasses, AbcToAb.class.getName());
assertThat(abcToAb.isBinaryCompatible(), is(false));
}

@Test
public void testNewEnum() {
JApiClass abcToAb = getJApiClass(jApiClasses, Enums.NewEnum.class.getName());
assertThat(abcToAb.isBinaryCompatible(), is(true));
assertThat(abcToAb.isSourceCompatible(), is(true));
assertThat(abcToAb.getCompatibilityChanges().size(), is(1));
assertThat(abcToAb.getCompatibilityChanges().get(0), is(JApiCompatibilityChange.INTERFACE_ADDED));
assertThat(abcToAb.getCompatibilityChanges().get(0), is(new JApiCompatibilityChange(JApiCompatibilityChangeType.INTERFACE_ADDED)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import japicmp.model.JApiChangeStatus;
import japicmp.model.JApiClass;
import japicmp.model.JApiCompatibilityChange;
import japicmp.model.JApiCompatibilityChangeType;
import japicmp.test.semver.finalpublicmethod.ClassWithFinalPublicMethod;
import japicmp.test.semver.finalpublicmethod.ClassWithFinalPublicMethodInSuperClass;
import org.hamcrest.MatcherAssert;
import org.junit.BeforeClass;
import org.junit.Test;

Expand All @@ -18,8 +18,8 @@
import static japicmp.test.util.Helper.getArchive;
import static japicmp.test.util.Helper.getJApiClass;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertThat;

public class FinalMethodTest {
private static List<JApiClass> jApiClasses;
Expand All @@ -36,9 +36,9 @@ public void testCompatibilityAddFinalToMethod() {
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.MODIFIED));
assertThat(jApiClass.isBinaryCompatible(), is(false));
assertThat(jApiClass.isSourceCompatible(), is(false));
MatcherAssert.assertThat(
assertThat(
getMethodCompatibilityChanges(jApiClass),
containsInAnyOrder(JApiCompatibilityChange.METHOD_NOW_FINAL));
containsInAnyOrder(JApiCompatibilityChangeType.METHOD_NOW_FINAL));
}

@Test
Expand All @@ -47,12 +47,14 @@ public void testCompatibilityAddFinalToMethodAndMoveToSuperclass() {
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.MODIFIED));
assertThat(jApiClass.isBinaryCompatible(), is(false));
assertThat(jApiClass.isSourceCompatible(), is(false));
MatcherAssert.assertThat(
assertThat(
getMethodCompatibilityChanges(jApiClass),
containsInAnyOrder(JApiCompatibilityChange.METHOD_NOW_FINAL, JApiCompatibilityChange.METHOD_MOVED_TO_SUPERCLASS));
containsInAnyOrder(JApiCompatibilityChangeType.METHOD_NOW_FINAL, JApiCompatibilityChangeType.METHOD_MOVED_TO_SUPERCLASS));
}

private static Collection<JApiCompatibilityChange> getMethodCompatibilityChanges(JApiClass jApiClass) {
return jApiClass.getMethods().stream().flatMap(method -> method.getCompatibilityChanges().stream()).collect(Collectors.toList());
private static Collection<JApiCompatibilityChangeType> getMethodCompatibilityChanges(JApiClass jApiClass) {
return jApiClass.getMethods().stream()
.flatMap(method -> method.getCompatibilityChanges().stream().map(JApiCompatibilityChange::getType).collect(Collectors.toList()).stream())
.collect(Collectors.toList());
}
}
8 changes: 4 additions & 4 deletions japicmp/src/main/java/japicmp/cmp/JarArchiveComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import japicmp.filter.Filters;
import japicmp.filter.JavadocLikePackageFilter;
import japicmp.model.JApiClass;
import japicmp.model.JApiCompatibilityChange;
import japicmp.model.JApiCompatibilityChangeType;
import japicmp.model.JavaObjectSerializationCompatibility;
import japicmp.output.OutputFilter;
import japicmp.util.AnnotationHelper;
Expand Down Expand Up @@ -52,12 +52,12 @@ public JarArchiveComparator(JarArchiveComparatorOptions options) {
}

private void setupCompatibilityChanges(JarArchiveComparatorOptions options) {
for (JApiCompatibilityChange jApiCompatibility : JApiCompatibilityChange.values()) {
for (JApiCompatibilityChangeType jApiCompatibility : JApiCompatibilityChangeType.values()) {
jApiCompatibility.resetOverrides();
}
for (JarArchiveComparatorOptions.OverrideCompatibilityChange change : options.getOverrideCompatibilityChanges()) {
JApiCompatibilityChange compatibilityChange = change.getCompatibilityChange();
for (JApiCompatibilityChange jApiCompatibility : JApiCompatibilityChange.values()) {
JApiCompatibilityChangeType compatibilityChange = change.getCompatibilityChange();
for (JApiCompatibilityChangeType jApiCompatibility : JApiCompatibilityChangeType.values()) {
if (jApiCompatibility == compatibilityChange) {
jApiCompatibility.setBinaryCompatible(change.isBinaryCompatible());
jApiCompatibility.setSourceCompatible(change.isSourceCompatible());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package japicmp.cmp;

import japicmp.model.JApiCompatibilityChange;
import japicmp.model.JApiSemanticVersionLevel;
import japicmp.util.Optional;
import japicmp.config.IgnoreMissingClasses;
import japicmp.config.Options;
import japicmp.exception.JApiCmpException;
import japicmp.filter.Filters;
import japicmp.model.AccessModifier;
import japicmp.model.JApiCompatibilityChangeType;
import japicmp.model.JApiSemanticVersionLevel;
import japicmp.util.Optional;

import java.io.File;
import java.util.ArrayList;
Expand All @@ -32,20 +32,20 @@ public class JarArchiveComparatorOptions {
private List<OverrideCompatibilityChange> overrideCompatibilityChanges = new ArrayList<>();

public static class OverrideCompatibilityChange {
private JApiCompatibilityChange compatibilityChange;
private JApiCompatibilityChangeType compatibilityChange;
private boolean binaryCompatible;
private boolean sourceCompatible;
private JApiSemanticVersionLevel semanticVersionLevel;

public OverrideCompatibilityChange(JApiCompatibilityChange compatibilityChange, boolean binaryCompatible,
boolean sourceCompatible, JApiSemanticVersionLevel semanticVersionLevel) {
public OverrideCompatibilityChange(JApiCompatibilityChangeType compatibilityChange, boolean binaryCompatible,
boolean sourceCompatible, JApiSemanticVersionLevel semanticVersionLevel) {
this.compatibilityChange = compatibilityChange;
this.binaryCompatible = binaryCompatible;
this.sourceCompatible = sourceCompatible;
this.semanticVersionLevel = semanticVersionLevel;
}

public JApiCompatibilityChange getCompatibilityChange() {
public JApiCompatibilityChangeType getCompatibilityChange() {
return compatibilityChange;
}

Expand Down
Loading

0 comments on commit dea2bc3

Please sign in to comment.