Skip to content

Commit 9cc68ec

Browse files
committed
Suggest a micro change for default added interface methods and fields
If one adds a field to an interface or a default method 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.
1 parent 4ca541b commit 9cc68ec

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/BaseApiAnalyzer.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,14 +2307,41 @@ private void checkApiComponentPackageVersions(BundleComponent referenceBundle, B
23072307
.collect(Collectors.toMap(ExportPackageDescription::getName, Function.identity()));
23082308
// a mapping between a package name and a required change
23092309
Map<String, RequiredPackageVersionChange> requiredChanges = new HashMap<>();
2310+
Set<IDelta> microChanged = new HashSet<>();
2311+
// here we check for problems that are actually only a micro change in package
2312+
// version in the compatible category
2313+
for (IDelta delta : compatibleChanges) {
2314+
if (isMicroPackageChange(delta)) {
2315+
microChanged.add(delta);
2316+
analyzePackageDelta(delta, IApiProblem.MICRO_VERSION_CHANGE_PACKAGE, referencePackages,
2317+
componentPackages, requiredChanges);
2318+
}
2319+
}
2320+
// here we check for problems that are actually only a micro change in package
2321+
// version in the compatible category
2322+
for (IDelta delta : breakingChanges) {
2323+
if (isMicroPackageChange(delta)) {
2324+
microChanged.add(delta);
2325+
analyzePackageDelta(delta, IApiProblem.MICRO_VERSION_CHANGE_PACKAGE, referencePackages,
2326+
componentPackages, requiredChanges);
2327+
}
2328+
}
23102329
// we must compare compatible changes first, so these where overwritten later by
23112330
// breaking changes probably
23122331
for (IDelta delta : compatibleChanges) {
2332+
if (microChanged.contains(delta)) {
2333+
// we have already identified the delta as a micro change
2334+
continue;
2335+
}
23132336
// a compatible change must result in a minor package version increment
23142337
analyzePackageDelta(delta, IApiProblem.MINOR_VERSION_CHANGE_PACKAGE, referencePackages, componentPackages,
23152338
requiredChanges);
23162339
}
23172340
for (IDelta delta : breakingChanges) {
2341+
if (microChanged.contains(delta)) {
2342+
// we have already identified the delta as a micro change
2343+
continue;
2344+
}
23182345
// a breaking change must result in a major package change
23192346
analyzePackageDelta(delta, IApiProblem.MAJOR_VERSION_CHANGE_PACKAGE, referencePackages, componentPackages,
23202347
requiredChanges);
@@ -2330,6 +2357,25 @@ private void checkApiComponentPackageVersions(BundleComponent referenceBundle, B
23302357
}
23312358
}
23322359

2360+
private boolean isMicroPackageChange(IDelta delta) {
2361+
if (delta.getElementType() == IDelta.INTERFACE_ELEMENT_TYPE) {
2362+
// for interface types we can have some changes that are actually compatible
2363+
// even with provider version range
2364+
if (delta.getKind() == IDelta.ADDED) {
2365+
if (delta.getFlags() == IDelta.DEFAULT_METHOD) {
2366+
// adding a default method to an interface is not required to change the
2367+
// implementation
2368+
return true;
2369+
}
2370+
if (delta.getFlags() == IDelta.FIELD) {
2371+
// adding a field does not harm neither consumer nor providers
2372+
return true;
2373+
}
2374+
}
2375+
}
2376+
return false;
2377+
}
2378+
23332379
private void analyzePackageDelta(IDelta delta, int category,
23342380
Map<String, ExportPackageDescription> referencePackages,
23352381
Map<String, ExportPackageDescription> componentPackages,
@@ -2353,7 +2399,10 @@ private void analyzePackageDelta(IDelta delta, int category,
23532399
return;
23542400
}
23552401
Version suggested;
2356-
if (IApiProblem.MINOR_VERSION_CHANGE_PACKAGE == category) {
2402+
if (IApiProblem.MICRO_VERSION_CHANGE_PACKAGE == category) {
2403+
suggested = new Version(baselineVersion.getMajor(), baselineVersion.getMinor(),
2404+
baselineVersion.getMicro() + 1);
2405+
} else if (IApiProblem.MINOR_VERSION_CHANGE_PACKAGE == category) {
23572406
suggested = new Version(baselineVersion.getMajor(), baselineVersion.getMinor() + 1, 0);
23582407
} else {
23592408
suggested = new Version(baselineVersion.getMajor() + 1, baselineVersion.getMinor(), 0);
@@ -2366,11 +2415,17 @@ private void analyzePackageDelta(IDelta delta, int category,
23662415
if (compVersion.getMajor() > baselineVersion.getMajor()) {
23672416
return;
23682417
}
2369-
if (IApiProblem.MINOR_VERSION_CHANGE_PACKAGE == category) {
2418+
if (IApiProblem.MINOR_VERSION_CHANGE_PACKAGE == category
2419+
|| IApiProblem.MICRO_VERSION_CHANGE_PACKAGE == category) {
23702420
if (compVersion.getMinor() > baselineVersion.getMinor()) {
23712421
return;
23722422
}
23732423
}
2424+
if (IApiProblem.MICRO_VERSION_CHANGE_PACKAGE == category) {
2425+
if (compVersion.getMicro() > baselineVersion.getMicro()) {
2426+
return;
2427+
}
2428+
}
23742429
requiredChanges.put(packageName,
23752430
new RequiredPackageVersionChange(category, baselineVersion, compVersion, suggested));
23762431
}

apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/problems/ApiProblemFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ public static int getProblemMessageId(int category, int element, int kind, int f
594594
return 65;
595595
case IApiProblem.MINOR_VERSION_CHANGE_PACKAGE:
596596
return 63;
597+
case IApiProblem.MICRO_VERSION_CHANGE_PACKAGE:
598+
return 68;
597599
default:
598600
break;
599601
}

apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/problems/problemmessages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Contributors:
1212
# IBM Corporation - initial API and implementation
1313
###############################################################################
14-
# available message ids 68, 70, 71, 75, 80,
14+
# available message ids 70, 71, 75, 80,
1515
# 82, 83, 88, 90, 93
1616

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

4344
#API usage problems
4445
#{0} = referenced type name

apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/problems/IApiProblem.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ public interface IApiProblem {
262262
*/
263263
public static final int MINOR_VERSION_CHANGE_PACKAGE = 12;
264264

265+
/**
266+
* Constant representing the value of the micro version change
267+
* {@link IApiProblem} kind for a package. <br>
268+
* Value is: <code>13</code>
269+
*
270+
* @see #getKind()
271+
* @see #CATEGORY_VERSION
272+
*/
273+
public static final int MICRO_VERSION_CHANGE_PACKAGE = 13;
274+
265275
public static final int ILLEGAL_EXTEND = 1;
266276

267277
/**

0 commit comments

Comments
 (0)