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

kwin pushed a commit to branch bugfix/feature-name-clashes
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git

commit 6655dec78d0dbfb4e0cf337b199f8773713f6e5d
Author: Konrad Windszus <[email protected]>
AuthorDate: Tue Sep 30 15:20:26 2025 +0200

    SLING-12956 Use feature filename including groupId
    
    Otherwise there can be name clashes in the flat feature output
    directory.
---
 .../features/DefaultFeaturesManager.java           | 24 +++++++++++++++
 .../features/DefaultFeaturesManagerTest.java       | 36 ++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
index 2c93153..b39b9b8 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
@@ -23,6 +23,10 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.StringReader;
+import java.math.BigInteger;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -450,6 +454,26 @@ public class DefaultFeaturesManager implements 
FeaturesManager, PackagesEventsEm
         feature.getExtensions().add(apiRegions);
     }
 
+    /**
+     * 
+     * @param featureId
+     * @param prefix
+     * @return a filename for the given featureId and optional prefix.
+     */
+    static String getFeatureFileName(@NotNull ArtifactId featureId, @Nullable 
String prefix) {
+        StringBuilder fileNameBuilder = new StringBuilder()
+                .append((prefix != null) ? prefix : "")
+                .append(featureId.getGroupId())
+                .append('-')
+                .append(featureId.getArtifactId());
+
+        String classifier = featureId.getClassifier();
+        if (classifier != null && !classifier.isEmpty()) {
+            fileNameBuilder.append('-').append(classifier);
+        }
+        return fileNameBuilder.toString();
+    }
+
     @Override
     public void serialize() throws IOException {
         RunmodeMapper runmodeMapper = 
RunmodeMapper.open(featureModelsOutputDirectory);
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManagerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManagerTest.java
new file mode 100644
index 0000000..44c72fd
--- /dev/null
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManagerTest.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.sling.feature.cpconverter.features;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.sling.feature.ArtifactId;
+import org.junit.Test;
+
+public class DefaultFeaturesManagerTest {
+
+    @Test
+    public void testGetFeatureFileName() {
+        ArtifactId id = 
ArtifactId.parse("org.apache.sling:feature-name:1.0.0");
+        assertEquals("org.apache.sling-feature-name", 
DefaultFeaturesManager.getFeatureFileName(id, ""));
+        id = 
ArtifactId.parse("org.apache.sling:feature-name:osgi-feature:myclassifier:1.0.0");
+        assertEquals("org.apache.sling-feature-name-myclassifier", 
DefaultFeaturesManager.getFeatureFileName(id, ""));
+        id = ArtifactId.parse("org.apache.sling:feature-name:1.0.0");
+        assertEquals("prefix-org.apache.sling-feature-name", 
DefaultFeaturesManager.getFeatureFileName(id, "prefix-"));
+    }
+
+}

Reply via email to