ponziani commented on code in PR #2978:
URL: https://github.com/apache/karaf/pull/2978#discussion_r4562622648
##########
features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceUtils.java:
##########
@@ -91,6 +91,23 @@ public static String getFeatureId(Resource resource) {
return null;
}
+ /**
+ * Returns the feature ID in the same form as {@link
#getFeatureId(Resource)}, which is the form used as key
+ * in the deployment state. The version is normalized the OSGi way, so
<code>1.0.01</code> becomes
+ * <code>1.0.1</code>.
+ */
+ public static String getFeatureId(String name, String version) {
+ return version != null ? name + "/" + VersionTable.getVersion(version)
: name;
Review Comment:
Applied, thanks. Added
`testFeatureWithInvalidVersionDoesNotBreakOtherFeatures`: `f/1.0.0` is
installed first, then a repository with `bad/1.0.0.beta+1` is added. Listing,
`getState`/`isInstalled` of `bad`, and stopping and uninstalling `f` all work.
Without the fallback it fails at `listInstalledFeatures()` with
`IllegalArgumentException: invalid version "1.0.0.beta+1"`.
##########
features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java:
##########
@@ -957,7 +958,8 @@ private String normalize(String feature) {
}
String name = feature.substring(0, idx);
String version = feature.substring(idx + 1);
- return name + VERSION_SEPARATOR + VersionCleaner.clean(version);
+ // same form as the ids in the deployment state, so 1.0.01 matches
1.0.1
+ return ResourceUtils.getFeatureId(name, VersionCleaner.clean(version));
Review Comment:
Covered by the fallback. `normalize()` also no longer cleans the version
itself, because `VersionTable.getVersion` already does that. So for an invalid
version it falls back to the same raw string as `partitionFeatures`.
##########
features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java:
##########
@@ -230,7 +230,8 @@ public void partitionFeatures(Collection<Feature>
featuresList) {
featuresById = new HashMap<>();
for (Feature feature : featuresList) {
features.computeIfAbsent(feature.getName(), name -> new
ArrayList<>()).add(feature);
- featuresById.put(feature.getId(), feature);
+ // keyed like the deployment state, which uses normalized
versions (1.0.01 -> 1.0.1)
+ featuresById.put(getFeatureId(feature.getName(),
feature.getVersion()), feature);
Review Comment:
Covered by the same fallback, and the test follows this order: the
repository with the invalid version is added after `f` was installed. While
there, the config/library loop now uses the `featuresById` key instead of
recomputing it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]