You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by di...@apache.org on 2021/06/30 15:51:35 UTC
[sling-org-apache-sling-installer-factory-feature] branch
issue/SLING-10575 created (now 2571b03)
This is an automated email from the ASF dual-hosted git repository.
diru pushed a change to branch issue/SLING-10575
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-factory-feature.git.
at 2571b03 SLING-10575: fill empty bundle to feature mappings with originally installed feature
This branch includes the following new commits:
new 2571b03 SLING-10575: fill empty bundle to feature mappings with originally installed feature
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-org-apache-sling-installer-factory-feature] 01/01:
SLING-10575: fill empty bundle to feature mappings with originally
installed feature
Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
diru pushed a commit to branch issue/SLING-10575
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-factory-feature.git
commit 2571b031bc0cb31b09973e53ee3d23cf2da068cc
Author: drudolph <dr...@adobe.com>
AuthorDate: Wed Jun 30 17:50:24 2021 +0200
SLING-10575: fill empty bundle to feature mappings with originally installed feature
---
.../model/impl/APIRegionsExtensionHandler.java | 25 ++++++++++-
.../model/impl/APIRegionsExtensionHandlerTest.java | 47 ++++++++++++++++++++-
.../bundle-with-origin-1.jar | Bin 0 -> 380 bytes
.../bundle-without-origin-1.jar | Bin 0 -> 383 bytes
4 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/installer/factory/model/impl/APIRegionsExtensionHandler.java b/src/main/java/org/apache/sling/installer/factory/model/impl/APIRegionsExtensionHandler.java
index 619540d..5dddf1d 100644
--- a/src/main/java/org/apache/sling/installer/factory/model/impl/APIRegionsExtensionHandler.java
+++ b/src/main/java/org/apache/sling/installer/factory/model/impl/APIRegionsExtensionHandler.java
@@ -18,6 +18,8 @@
*/
package org.apache.sling.installer.factory.model.impl;
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Extension;
import org.apache.sling.feature.ExtensionType;
import org.apache.sling.feature.Feature;
@@ -28,11 +30,16 @@ import org.apache.sling.feature.spi.context.ExtensionHandlerContext;
import org.osgi.service.component.annotations.Component;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Dictionary;
+import java.util.HashSet;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
@Component
public class APIRegionsExtensionHandler implements ExtensionHandler {
@@ -55,7 +62,7 @@ public class APIRegionsExtensionHandler implements ExtensionHandler {
final String configPid = REGION_FACTORY_PID.concat(feature.getId().toMvnName().replace('-', '_'));
final Dictionary<String, Object> props = new Hashtable<>();
props.put(PROP_idbsnver, convert(LauncherProperties.getBundleIDtoBSNandVersionMap(feature, context.getArtifactProvider())));
- props.put(PROP_bundleFeatures, convert(LauncherProperties.getBundleIDtoFeaturesMap(feature)));
+ props.put(PROP_bundleFeatures, convert(getBundleIDToFeatureMap(feature)));
props.put(PROP_featureRegions, convert(LauncherProperties.getFeatureIDtoRegionsMap(regions)));
props.put(PROP_regionPackage, convert(LauncherProperties.getRegionNametoPackagesMap(regions)));
@@ -71,4 +78,20 @@ public class APIRegionsExtensionHandler implements ExtensionHandler {
}
return result.toArray(new String[result.size()]);
}
+
+ private static Properties getBundleIDToFeatureMap(Feature feature) {
+ Properties bundleToFeatureMapping = LauncherProperties.getBundleIDtoFeaturesMap(feature);
+ Properties result = new Properties();
+ String featureId = feature.getId().toMvnId();
+
+ for (Map.Entry<Object, Object> entry : bundleToFeatureMapping.entrySet()) {
+ String value = entry.getValue().toString();
+ if (value.isEmpty()) {
+ value = featureId;
+ }
+ result.setProperty(entry.getKey().toString(), value);
+ }
+
+ return result;
+ }
}
diff --git a/src/test/java/org/apache/sling/installer/factory/model/impl/APIRegionsExtensionHandlerTest.java b/src/test/java/org/apache/sling/installer/factory/model/impl/APIRegionsExtensionHandlerTest.java
index 6ffb93d..fa1f798 100644
--- a/src/test/java/org/apache/sling/installer/factory/model/impl/APIRegionsExtensionHandlerTest.java
+++ b/src/test/java/org/apache/sling/installer/factory/model/impl/APIRegionsExtensionHandlerTest.java
@@ -18,28 +18,36 @@
*/
package org.apache.sling.installer.factory.model.impl;
+import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Extension;
import org.apache.sling.feature.ExtensionState;
import org.apache.sling.feature.ExtensionType;
import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.builder.ArtifactProvider;
import org.apache.sling.feature.spi.context.ExtensionHandlerContext;
import org.junit.Test;
import org.mockito.Mockito;
+import java.net.URL;
import java.util.Arrays;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class APIRegionsExtensionHandlerTest {
- private static String FEATURE_EXT_1 =
+ private static final String FEATURE_EXT_1 =
"[" +
" {" +
" \"name\": \"my-region\"," +
" \"exports\": [\"org.foo.bar\", \"la.di.da\"]" +
" }" +
"]";
+ private static final String FEATURE_EXT_NOOP = "[]";
+ private static final URL BUNDLE_WITH_ORIGIN_RESOURCE = APIRegionsExtensionHandlerTest.class
+ .getResource("/APIRegionsExtensionHandlerTest/bundle-with-origin-1.jar");
+ private static final URL BUNDLE_WITHOUT_ORIGIN_RESOURCE = APIRegionsExtensionHandlerTest.class
+ .getResource("/APIRegionsExtensionHandlerTest/bundle-without-origin-1.jar");
@Test
public void testHandle() throws Exception {
@@ -68,4 +76,41 @@ public class APIRegionsExtensionHandlerTest {
Extension ext = new Extension(ExtensionType.TEXT, "api-regions", ExtensionState.REQUIRED);
assertFalse(areh.handle(null, ext, null));
}
+
+ @Test
+ public void testBundleToFeatureMappingWithAndWithoutFeatureOrigin() throws Exception {
+ APIRegionsExtensionHandler areh = new APIRegionsExtensionHandler();
+ // define a bundle artifact that has a feature-origin set
+ ArtifactId bundleWithOriginId = ArtifactId.fromMvnId("bundle:with-origin:1");
+ Artifact artifactWithOrigin = new Artifact(bundleWithOriginId);
+ artifactWithOrigin.setFeatureOrigins(ArtifactId.fromMvnId("my:origin:1"));
+ // define another bundle artifact that does not has a feature-origin set
+ ArtifactId bundleWithoutOriginId = ArtifactId.fromMvnId("bundle:without-origin:1");
+ Artifact artifactWithoutOrigin = new Artifact(bundleWithoutOriginId);
+
+ ExtensionHandlerContext ctx = Mockito.mock(ExtensionHandlerContext.class);
+ ArtifactProvider artifactProvider = Mockito.mock(ArtifactProvider.class);
+ Mockito.when(ctx.getArtifactProvider()).thenReturn(artifactProvider);
+ Mockito.when(artifactProvider.provide(bundleWithOriginId)).thenReturn(BUNDLE_WITH_ORIGIN_RESOURCE);
+ Mockito.when(artifactProvider.provide(bundleWithoutOriginId)).thenReturn(BUNDLE_WITHOUT_ORIGIN_RESOURCE);
+
+ Extension ext = new Extension(ExtensionType.JSON, "api-regions", ExtensionState.REQUIRED);
+ ext.setJSON(FEATURE_EXT_NOOP);
+
+ Feature feat = new Feature(ArtifactId.fromMvnId("x:y:8"));
+ feat.getBundles().add(artifactWithOrigin);
+ feat.getBundles().add(artifactWithoutOrigin);
+
+ assertTrue(areh.handle(ctx, ext, feat));
+
+ Mockito.verify(ctx).addConfiguration(Mockito.isNull(),
+ Mockito.eq("org.apache.sling.feature.apiregions.factory~y_8.jar"),
+ Mockito.argThat(p -> {
+ String[] pkgs = (String[]) p.get("mapping.bundleid.features");
+ return Arrays.deepEquals(new String [] {
+ "bundle:with-origin:1=my:origin:1",
+ "bundle:without-origin:1=x:y:8",
+ }, pkgs);
+ }));
+ }
}
diff --git a/src/test/resources/APIRegionsExtensionHandlerTest/bundle-with-origin-1.jar b/src/test/resources/APIRegionsExtensionHandlerTest/bundle-with-origin-1.jar
new file mode 100644
index 0000000..f7efd97
Binary files /dev/null and b/src/test/resources/APIRegionsExtensionHandlerTest/bundle-with-origin-1.jar differ
diff --git a/src/test/resources/APIRegionsExtensionHandlerTest/bundle-without-origin-1.jar b/src/test/resources/APIRegionsExtensionHandlerTest/bundle-without-origin-1.jar
new file mode 100644
index 0000000..b1bf391
Binary files /dev/null and b/src/test/resources/APIRegionsExtensionHandlerTest/bundle-without-origin-1.jar differ