This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git


The following commit(s) were added to refs/heads/master by this push:
     new dbcfabd  SLING-11075: strip attributes from bsn (#127)
dbcfabd is described below

commit dbcfabd2ba13582e1e0662908eb5057f614c072a
Author: Karl Pauls <[email protected]>
AuthorDate: Wed Jan 19 13:22:39 2022 +0100

    SLING-11075: strip attributes from bsn (#127)
---
 .../cpconverter/handlers/BundleEntryHandler.java       |  12 ++++++++----
 .../handlers/AbstractBundleEntryHandlerTest.java       |   1 +
 .../handlers/BundleEntryHandlerGAVTest.java            |  13 +++++++++++++
 .../sling/feature/cpconverter/handlers/peaberry.jar    | Bin 0 -> 193114 bytes
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
index 4412fea..87f2ca8 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
@@ -34,6 +34,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.utils.manifest.Clause;
 import org.apache.felix.utils.manifest.Parser;
 import org.apache.jackrabbit.vault.fs.io.Archive;
@@ -236,7 +237,7 @@ public class BundleEntryHandler extends 
AbstractRegexEntryHandler {
 
         if (groupId == null) {
             // maybe the included jar is just an OSGi bundle but not a valid 
Maven artifact
-            groupId = getCheckedProperty(jarFile.getManifest(), 
Constants.BUNDLE_SYMBOLICNAME);
+            groupId = 
StringUtils.substringBefore(getCheckedProperty(jarFile.getManifest(), 
Constants.BUNDLE_SYMBOLICNAME), ";");
             // Make sure there are not spaces in the name to adhere to the 
Maven Group Id specification
             groupId = groupId.replace(' ', '_').replace(':', '_').replace('/', 
'_').replace('\\', '_');
             if (groupId.indexOf('.') != -1) {
@@ -252,14 +253,17 @@ public class BundleEntryHandler extends 
AbstractRegexEntryHandler {
 
         // create artifact and store symbolic name and version in metadata
         final Artifact result = new Artifact(new ArtifactId(groupId, 
artifactId, version, classifier, JAR_TYPE));
-        setMetadataFromManifest(jarFile.getManifest(), 
Constants.BUNDLE_VERSION, result);
-        setMetadataFromManifest(jarFile.getManifest(), 
Constants.BUNDLE_SYMBOLICNAME, result);
+        setMetadataFromManifest(jarFile.getManifest(), 
Constants.BUNDLE_VERSION, result, false);
+        setMetadataFromManifest(jarFile.getManifest(), 
Constants.BUNDLE_SYMBOLICNAME, result, true);
 
         return result;
     }
 
-    private static void setMetadataFromManifest(@NotNull Manifest manifest, 
@NotNull String name, @NotNull Artifact artifact) {
+    private static void setMetadataFromManifest(@NotNull Manifest manifest, 
@NotNull String name, @NotNull Artifact artifact, boolean strip) {
         String value = manifest.getMainAttributes().getValue(name);
+        if (strip) {
+            value = StringUtils.substringBefore(value, ";");
+        }
         if (value != null) {
             artifact.getMetadata().put(name, value);
         }
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/AbstractBundleEntryHandlerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/AbstractBundleEntryHandlerTest.java
index a4b1162..edd539f 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/AbstractBundleEntryHandlerTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/AbstractBundleEntryHandlerTest.java
@@ -60,6 +60,7 @@ public abstract class AbstractBundleEntryHandlerTest {
     @Before
     public void setUp() throws IOException {
         handler = new BundleEntryHandler();
+        
handler.setSlingInitialContentPolicy(ContentPackage2FeatureModelConverter.SlingInitialContentPolicy.KEEP);
         ArtifactsDeployer deployer = Mockito.spy(ArtifactsDeployer.class);
         when(converter.getArtifactsDeployer()).thenReturn(deployer);
         when(converter.getTempDirectory()).thenReturn(tmpFolder.getRoot());
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandlerGAVTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandlerGAVTest.java
index 820e737..c013f80 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandlerGAVTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandlerGAVTest.java
@@ -74,6 +74,19 @@ public class BundleEntryHandlerGAVTest extends 
AbstractBundleEntryHandlerTest {
     }
 
     @Test
+    public void testNoGAVNoMeta() throws Exception {
+        setUpArchive("/jcr_root/apps/gav/install/peaberry.jar", 
"peaberry.jar");
+        handler.handle("/jcr_root/apps/gav/install/peaberry.jar", archive, 
entry, converter);
+        ArgumentCaptor<Artifact> captor = 
ArgumentCaptor.forClass(Artifact.class);
+        Mockito.verify(featuresManager).addArtifact(Mockito.isNull(), 
captor.capture(), Mockito.isNull());
+        final Artifact result = captor.getValue();
+        assertNotNull(result);
+        assertEquals(ArtifactId.fromMvnId("org.ops4j:peaberry:jar:1.3.0"), 
result.getId());
+        assertEquals("org.ops4j.peaberry", 
result.getMetadata().get(Constants.BUNDLE_SYMBOLICNAME));
+        assertEquals("1.3.0", 
result.getMetadata().get(Constants.BUNDLE_VERSION));
+    }
+
+    @Test
     public void testBundleBelowConfigFolderWithEnforcement() throws Exception {
         handler.setEnforceBundlesBelowInstallFolder(true);
         when(entry.getName()).thenReturn("mybundle.jar");
diff --git 
a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/peaberry.jar 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/peaberry.jar
new file mode 100644
index 0000000..eb6b5c0
Binary files /dev/null and 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/peaberry.jar 
differ

Reply via email to