You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2020/06/25 13:22:17 UTC

[sling-org-apache-sling-installer-core] branch feature/extended-run-mode-support created (now 3759e38)

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

kwin pushed a change to branch feature/extended-run-mode-support
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-core.git.


      at 3759e38  SLING-9031 SLING-8548 helper class for disjunctive run modes and not operators

This branch includes the following new commits:

     new 3759e38  SLING-9031 SLING-8548 helper class for disjunctive run modes and not operators

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-core] 01/01: SLING-9031 SLING-8548 helper class for disjunctive run modes and not operators

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/extended-run-mode-support
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-core.git

commit 3759e38209577df181ba78a77a2ce61a754c8843
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Jun 25 15:21:53 2020 +0200

    SLING-9031 SLING-8548 helper class for disjunctive run modes and not
    operators
---
 .../installer/api/provider/RunModeSupport.java     | 64 ++++++++++++++++++++++
 .../sling/installer/api/provider/package-info.java | 21 +++++++
 .../installer/api/provider/RunModeSupportTest.java | 39 +++++++++++++
 3 files changed, 124 insertions(+)

diff --git a/src/main/java/org/apache/sling/installer/api/provider/RunModeSupport.java b/src/main/java/org/apache/sling/installer/api/provider/RunModeSupport.java
new file mode 100644
index 0000000..b0d021d
--- /dev/null
+++ b/src/main/java/org/apache/sling/installer/api/provider/RunModeSupport.java
@@ -0,0 +1,64 @@
+/*
+ * 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.installer.api.provider;
+
+import java.util.Set;
+import java.util.regex.Pattern;
+
+public final class RunModeSupport {
+
+    private static final String OR_SEPARATOR = ",";
+    private static final String AND_SEPARATOR = ".";
+    private static final String NOT_PREFIX = "-";
+
+    private RunModeSupport() {
+        // not supposed to be instantiated
+    }
+
+    public static int getMatchingRunmodesFromDisjunctions(String disjunctions, Set<String> activeRunModes) {
+        int numMatchingRunModes = 0;
+        // 1. support OR
+        for (String discjunctivePart : disjunctions.split(Pattern.quote(OR_SEPARATOR))) {
+            int newNumMatchingRunModes = getMatchingRunModesFromConjunctions(discjunctivePart, activeRunModes);
+            if (newNumMatchingRunModes > numMatchingRunModes) {
+                numMatchingRunModes = newNumMatchingRunModes;
+            }
+        }
+        return numMatchingRunModes;
+    }
+
+    private static int getMatchingRunModesFromConjunctions(String conjunctions, Set<String> activeRunModes) {
+        int numMatchingRunModes = 0;
+        // 2. support AND
+        for (String conjunctivePart : conjunctions.split(Pattern.quote(AND_SEPARATOR))) {
+            // 3. support NOT operator
+            if (conjunctivePart.startsWith(NOT_PREFIX)) {
+                if (activeRunModes.contains(conjunctivePart.substring(NOT_PREFIX.length()))) {
+                    return 0;
+                }
+            } else {
+                if (!activeRunModes.contains(conjunctivePart)) {
+                    return 0;
+                }
+            }
+            numMatchingRunModes++;
+        }
+        return numMatchingRunModes;
+    }
+}
diff --git a/src/main/java/org/apache/sling/installer/api/provider/package-info.java b/src/main/java/org/apache/sling/installer/api/provider/package-info.java
new file mode 100644
index 0000000..53a2e40
--- /dev/null
+++ b/src/main/java/org/apache/sling/installer/api/provider/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.installer.api.provider;
diff --git a/src/test/java/org/apache/sling/installer/api/provider/RunModeSupportTest.java b/src/test/java/org/apache/sling/installer/api/provider/RunModeSupportTest.java
new file mode 100644
index 0000000..44ec2c2
--- /dev/null
+++ b/src/test/java/org/apache/sling/installer/api/provider/RunModeSupportTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.installer.api.provider;
+
+import java.util.Collections;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class RunModeSupportTest {
+
+    @Test
+    public void testGetMatchingRunmodesFromName() {
+        Assert.assertEquals(0, RunModeSupport.getMatchingRunmodesFromDisjunctions("test1.test2,-test3.test4", Collections.singleton("test5")));
+        Assert.assertEquals(0, RunModeSupport.getMatchingRunmodesFromDisjunctions("test1.test2,-test3.test4", Stream.of("test1", "test3").collect(Collectors.toSet())));
+        Assert.assertEquals(0, RunModeSupport.getMatchingRunmodesFromDisjunctions("test1.test2,-test3.test4", Stream.of("test2", "test3").collect(Collectors.toSet())));
+        Assert.assertEquals(2, RunModeSupport.getMatchingRunmodesFromDisjunctions("test1.test2,-test3.test4", Stream.of("test1", "test2").collect(Collectors.toSet())));
+        Assert.assertEquals(2, RunModeSupport.getMatchingRunmodesFromDisjunctions("test1.test2,-test3.test4", Stream.of("test2", "test4").collect(Collectors.toSet())));
+        Assert.assertEquals(3, RunModeSupport.getMatchingRunmodesFromDisjunctions("test1.test2,-test3.test4,test5.test6.test7", Stream.of("test1", "test2", "test4", "test5", "test6", "test7").collect(Collectors.toSet())));
+    }
+}