Skip to content

Commit

Permalink
Suggest a micro change for added interface fields
Browse files Browse the repository at this point in the history
If one adds a field to an interface this will not result in any problem
for the consumer or the provider of the interface.

Because of this these changes can be made in a micro package version
increment.
  • Loading branch information
laeubi committed Jan 14, 2025
1 parent 4ca541b commit 6985cde
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2307,14 +2307,41 @@ private void checkApiComponentPackageVersions(BundleComponent referenceBundle, B
.collect(Collectors.toMap(ExportPackageDescription::getName, Function.identity()));
// a mapping between a package name and a required change
Map<String, RequiredPackageVersionChange> requiredChanges = new HashMap<>();
Set<IDelta> microChanged = new HashSet<>();
// here we check for problems that are actually only a micro change in package
// version in the compatible category
for (IDelta delta : compatibleChanges) {
if (isMicroPackageChange(delta)) {
microChanged.add(delta);
analyzePackageDelta(delta, IApiProblem.MICRO_VERSION_CHANGE_PACKAGE, referencePackages,
componentPackages, requiredChanges);
}
}
// here we check for problems that are actually only a micro change in package
// version in the breaking category
for (IDelta delta : breakingChanges) {
if (isMicroPackageChange(delta)) {
microChanged.add(delta);
analyzePackageDelta(delta, IApiProblem.MICRO_VERSION_CHANGE_PACKAGE, referencePackages,
componentPackages, requiredChanges);
}
}
// we must compare compatible changes first, so these where overwritten later by
// breaking changes probably
// breaking changes for a package probably
for (IDelta delta : compatibleChanges) {
if (microChanged.contains(delta)) {
// we have already identified the delta as a micro change
continue;
}
// a compatible change must result in a minor package version increment
analyzePackageDelta(delta, IApiProblem.MINOR_VERSION_CHANGE_PACKAGE, referencePackages, componentPackages,
requiredChanges);
}
for (IDelta delta : breakingChanges) {
if (microChanged.contains(delta)) {
// we have already identified the delta as a micro change
continue;
}
// a breaking change must result in a major package change
analyzePackageDelta(delta, IApiProblem.MAJOR_VERSION_CHANGE_PACKAGE, referencePackages, componentPackages,
requiredChanges);
Expand All @@ -2330,6 +2357,21 @@ private void checkApiComponentPackageVersions(BundleComponent referenceBundle, B
}
}

private boolean isMicroPackageChange(IDelta delta) {
if (delta.getElementType() == IDelta.INTERFACE_ELEMENT_TYPE) {
// for interface types we can have some changes that are actually compatible
// even with provider version range
if (delta.getKind() == IDelta.ADDED) {
if (delta.getFlags() == IDelta.FIELD) {
// adding a field to an interface is a binary compatible change for provider and
// consumer
return true;
}
}
}
return false;
}

private void analyzePackageDelta(IDelta delta, int category,
Map<String, ExportPackageDescription> referencePackages,
Map<String, ExportPackageDescription> componentPackages,
Expand All @@ -2353,7 +2395,10 @@ private void analyzePackageDelta(IDelta delta, int category,
return;
}
Version suggested;
if (IApiProblem.MINOR_VERSION_CHANGE_PACKAGE == category) {
if (IApiProblem.MICRO_VERSION_CHANGE_PACKAGE == category) {
suggested = new Version(baselineVersion.getMajor(), baselineVersion.getMinor(),
baselineVersion.getMicro() + 1);
} else if (IApiProblem.MINOR_VERSION_CHANGE_PACKAGE == category) {
suggested = new Version(baselineVersion.getMajor(), baselineVersion.getMinor() + 1, 0);
} else {
suggested = new Version(baselineVersion.getMajor() + 1, baselineVersion.getMinor(), 0);
Expand All @@ -2366,11 +2411,17 @@ private void analyzePackageDelta(IDelta delta, int category,
if (compVersion.getMajor() > baselineVersion.getMajor()) {
return;
}
if (IApiProblem.MINOR_VERSION_CHANGE_PACKAGE == category) {
if (IApiProblem.MINOR_VERSION_CHANGE_PACKAGE == category
|| IApiProblem.MICRO_VERSION_CHANGE_PACKAGE == category) {
if (compVersion.getMinor() > baselineVersion.getMinor()) {
return;
}
}
if (IApiProblem.MICRO_VERSION_CHANGE_PACKAGE == category) {
if (compVersion.getMicro() > baselineVersion.getMicro()) {
return;
}
}
requiredChanges.put(packageName,
new RequiredPackageVersionChange(category, baselineVersion, compVersion, suggested));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ public static int getProblemMessageId(int category, int element, int kind, int f
return 65;
case IApiProblem.MINOR_VERSION_CHANGE_PACKAGE:
return 63;
case IApiProblem.MICRO_VERSION_CHANGE_PACKAGE:
return 68;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
# available message ids 68, 70, 71, 75, 80,
# available message ids 70, 71, 75, 80,
# 82, 83, 88, 90, 93

#API baseline
Expand Down Expand Up @@ -39,6 +39,7 @@
62 = The major version should be incremented in version {0}, because the bundle {1} is no longer re-exported
63 = The minor version for the package ''{0}'' should be incremented to version {1}, since new APIs have been added since version {2}
65 = The major version for the package ''{0}'' should be incremented to version {1}, since API breakage occurred since version {2}
68 = The micro version for the package ''{0}'' should be incremented to version {1}, since API changes occurred since version {2}

#API usage problems
#{0} = referenced type name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ public interface IApiProblem {
*/
public static final int MINOR_VERSION_CHANGE_PACKAGE = 12;

/**
* Constant representing the value of the micro version change
* {@link IApiProblem} kind for a package. <br>
* Value is: <code>13</code>
*
* @see #getKind()
* @see #CATEGORY_VERSION
*/
public static final int MICRO_VERSION_CHANGE_PACKAGE = 13;

public static final int ILLEGAL_EXTEND = 1;

/**
Expand Down

0 comments on commit 6985cde

Please sign in to comment.