You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2021/12/15 14:17:48 UTC
[sling-org-apache-sling-feature-extension-apiregions] branch master updated: SLING-11003 : Provide option to store bundle symbolic name and version in metadata
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-apiregions.git
The following commit(s) were added to refs/heads/master by this push:
new 8f95636 SLING-11003 : Provide option to store bundle symbolic name and version in metadata
8f95636 is described below
commit 8f956365feab785f4ac047968c4896badf3dcb95
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Dec 15 15:17:40 2021 +0100
SLING-11003 : Provide option to store bundle symbolic name and version in metadata
---
.../apiregions/launcher/LauncherProperties.java | 43 ++++++++++------------
.../launcher/LauncherPropertiesTest.java | 17 +++++++++
2 files changed, 37 insertions(+), 23 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/extension/apiregions/launcher/LauncherProperties.java b/src/main/java/org/apache/sling/feature/extension/apiregions/launcher/LauncherProperties.java
index 9cfc1f7..047ac0a 100644
--- a/src/main/java/org/apache/sling/feature/extension/apiregions/launcher/LauncherProperties.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/launcher/LauncherProperties.java
@@ -48,32 +48,29 @@ public class LauncherProperties
private static final String REGION_ORDER = "__region.order__";
public static Properties getBundleIDtoBSNandVersionMap(Feature app, ArtifactProvider artifactProvider) {
- Map<ArtifactId, String> map = new HashMap<>();
+ Properties result = new Properties();
- for (Artifact bundle : app.getBundles())
- {
- map.computeIfAbsent(bundle.getId(), id ->
- {
- try(JarFile jarFile = IOUtils.getJarFileFromURL(artifactProvider.provide(id), true, null)) {
- Attributes manifest = jarFile.getManifest().getMainAttributes();
- String bsn = manifest.getValue(Constants.BUNDLE_SYMBOLICNAME);
- if (bsn != null && !bsn.trim().isEmpty())
- {
- return bsn.trim() + "~" + Version.parseVersion(manifest.getValue(Constants.BUNDLE_VERSION));
- }
- else {
- return null;
+ for (Artifact bundle : app.getBundles()) {
+ final String key = bundle.getId().toMvnId();
+ if ( result.getProperty(key) == null ) {
+ String bsn = bundle.getMetadata().get(Constants.BUNDLE_SYMBOLICNAME);
+ String version = bundle.getMetadata().get(Constants.BUNDLE_VERSION);
+ if ( bsn == null || version == null ) {
+ try(JarFile jarFile = IOUtils.getJarFileFromURL(artifactProvider.provide(bundle.getId()), true, null)) {
+ Attributes manifest = jarFile.getManifest().getMainAttributes();
+ bsn = manifest.getValue(Constants.BUNDLE_SYMBOLICNAME);
+ if (bsn != null) {
+ version = manifest.getValue(Constants.BUNDLE_VERSION);
+ }
+ } catch (IOException ex) {
+ throw new UncheckedIOException(ex);
}
- } catch (IOException ex) {
- throw new UncheckedIOException(ex);
+
}
- });
- }
-
- Properties result = new Properties();
-
- for (Map.Entry<ArtifactId, String> entry : map.entrySet()) {
- result.setProperty(entry.getKey().toMvnId(), entry.getValue());
+ if ( bsn != null && version != null ) {
+ result.setProperty(key, bsn.concat("~").concat(Version.parseVersion(version).toString()));
+ }
+ }
}
return result;
diff --git a/src/test/java/org/apache/sling/feature/extension/apiregions/launcher/LauncherPropertiesTest.java b/src/test/java/org/apache/sling/feature/extension/apiregions/launcher/LauncherPropertiesTest.java
index ba2a355..ff71541 100644
--- a/src/test/java/org/apache/sling/feature/extension/apiregions/launcher/LauncherPropertiesTest.java
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/launcher/LauncherPropertiesTest.java
@@ -25,6 +25,7 @@ import org.apache.sling.feature.Feature;
import org.apache.sling.feature.extension.apiregions.api.ApiRegions;
import org.junit.Assert;
import org.junit.Test;
+import org.osgi.framework.Constants;
public class LauncherPropertiesTest
{
@@ -94,4 +95,20 @@ public class LauncherPropertiesTest
Assert.assertEquals(1, prop.size());
Assert.assertEquals(featureId.toMvnId(), prop.get(artifactId.toMvnId()));
}
+
+ @Test
+ public void testGetBundleIDtoBSNandVersionMap() {
+ final ArtifactId featureId = ArtifactId.parse("g:f:1");
+ final ArtifactId artifactId = ArtifactId.parse("g:a:2");
+
+ final Feature f = new Feature(featureId);
+ final Artifact a = new Artifact(artifactId);
+ a.getMetadata().put(Constants.BUNDLE_SYMBOLICNAME, "my.bundle");
+ a.getMetadata().put(Constants.BUNDLE_VERSION, "1.0");
+ f.getBundles().add(a);
+
+ final Properties prop = LauncherProperties.getBundleIDtoBSNandVersionMap(f, null);
+ Assert.assertEquals(1, prop.size());
+ Assert.assertEquals("my.bundle~1.0.0", prop.get(a.getId().toMvnId()));
+ }
}