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 2020/07/16 06:07:58 UTC

[sling-org-apache-sling-feature] branch master updated: SLING-9591 : Add method to get all configurations for a factory pid

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.git


The following commit(s) were added to refs/heads/master by this push:
     new 7bc9761  SLING-9591 : Add method to get all configurations for a factory pid
7bc9761 is described below

commit 7bc97616ad8dd4f6069985b582ec316dd00a862b
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Jul 16 08:06:07 2020 +0200

    SLING-9591 : Add method to get all configurations for a factory pid
---
 .../org/apache/sling/feature/Configurations.java   | 18 +++++++++
 .../org/apache/sling/feature/package-info.java     |  2 +-
 .../apache/sling/feature/ConfigurationsTest.java   | 47 ++++++++++++++++++++++
 3 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/feature/Configurations.java b/src/main/java/org/apache/sling/feature/Configurations.java
index b8337f8..464bb89 100644
--- a/src/main/java/org/apache/sling/feature/Configurations.java
+++ b/src/main/java/org/apache/sling/feature/Configurations.java
@@ -17,6 +17,8 @@
 package org.apache.sling.feature;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 
 /**
  * A container for configurations.
@@ -40,4 +42,20 @@ public class Configurations extends ArrayList<Configuration> {
         }
         return null;
     }
+
+    /**
+     * Get all factory configurations matching the factory pid.
+     * @param factoryPid The factory pid of the configurations
+     * @return The configurations - the collection might be empty
+     * @since 1.5
+     */
+    public Collection<Configuration> getFactoryConfigurations(final String factoryPid) {
+        final List<Configuration> result = new ArrayList<>();
+        for(final Configuration cfg : this) {
+            if (factoryPid.equals(cfg.getFactoryPid())) {
+                result.add(cfg);
+            }
+        }
+        return result;
+    }
 }
diff --git a/src/main/java/org/apache/sling/feature/package-info.java b/src/main/java/org/apache/sling/feature/package-info.java
index 4bb6f1f..6ed34c0 100644
--- a/src/main/java/org/apache/sling/feature/package-info.java
+++ b/src/main/java/org/apache/sling/feature/package-info.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@org.osgi.annotation.versioning.Version("1.4.0")
+@org.osgi.annotation.versioning.Version("1.5.0")
 package org.apache.sling.feature;
 
 
diff --git a/src/test/java/org/apache/sling/feature/ConfigurationsTest.java b/src/test/java/org/apache/sling/feature/ConfigurationsTest.java
new file mode 100644
index 0000000..c2ff8ae
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/ConfigurationsTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Test;
+
+public class ConfigurationsTest {
+
+    @Test
+    public void testGetFactoryConfigurations() {
+        final Configurations cfgs = new Configurations();
+
+        cfgs.add(new Configuration("factory~a"));
+        cfgs.add(new Configuration("factory~b"));
+        cfgs.add(new Configuration("pid"));
+
+        final Collection<Configuration> result = cfgs.getFactoryConfigurations("factory");
+        assertEquals(2, result.size());
+        final Set<String> names = new HashSet<>();
+        for(final Configuration c : result) {
+            names.add(c.getName());
+        }
+        assertTrue(names.contains("a"));
+        assertTrue(names.contains("b"));
+    }
+}