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

kwin pushed a commit to branch feature/SLING-9555-resourcechange-constants
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-api.git

commit 70ee2189a5cc57048b581cd5a88342546cdea736
Author: Konrad Windszus <[email protected]>
AuthorDate: Sun Jun 28 12:28:50 2020 +0200

    SLING-9555 add constants for values of property "resource.change.types"
---
 .../observation/ResourceChangeListener.java        | 34 ++++++++++++++-
 .../api/resource/observation/package-info.java     |  2 +-
 .../observation/ResourceChangeListenerTest.java    | 51 ++++++++++++++++++++++
 3 files changed, 84 insertions(+), 3 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/api/resource/observation/ResourceChangeListener.java
 
b/src/main/java/org/apache/sling/api/resource/observation/ResourceChangeListener.java
index 0d9a184..e2caf50 100644
--- 
a/src/main/java/org/apache/sling/api/resource/observation/ResourceChangeListener.java
+++ 
b/src/main/java/org/apache/sling/api/resource/observation/ResourceChangeListener.java
@@ -92,12 +92,42 @@ public interface ResourceChangeListener {
      * If this property is missing, added, removed and changed events for 
resources
      * and added and removed events for resource providers are reported.
      * If this property is invalid, the listener is ignored. The type of the 
property
-     * must either be String, or a String array. Valid values are the 
constants from
-     * {@link ResourceChange.ChangeType}.
+     * must either be String, or a String array. Valid values are the 
constants from this class
+     * whose names are starting with {@code CHANGE_}. They map to one of the 
values of {@link ResourceChange.ChangeType}.
      */
     String CHANGES = "resource.change.types";
 
     /**
+     * String constant for {@link ResourceChange.ChangeType#ADDED}.
+     * @since 1.3.0 (Sling API Bundle 2.23.0)
+     */
+    String CHANGE_ADDED = "ADDED";
+
+    /**
+     * String constant for {@link ResourceChange.ChangeType#REMOVED}.
+     * @since 1.3.0 (Sling API Bundle 2.23.0)
+     */
+    String CHANGE_REMOVED = "REMOVED";
+
+    /**
+     * String constant for {@link ResourceChange.ChangeType#CHANGED}.
+     * @since 1.3.0 (Sling API Bundle 2.23.0)
+     */
+    String CHANGE_CHANGED = "CHANGED";
+
+    /**
+     * String constant for {@link ResourceChange.ChangeType#PROVIDER_ADDED}.
+     * @since 1.3.0 (Sling API Bundle 2.23.0)
+     */
+    String CHANGE_PROVIDER_ADDED = "PROVIDER_ADDED";
+
+    /**
+     * String constant for {@link ResourceChange.ChangeType#PROVIDER_REMOVED}.
+     * @since 1.3.0 (Sling API Bundle 2.23.0)
+     */
+    String CHANGE_PROVIDER_REMOVED = "PROVIDER_REMOVED";
+
+    /**
      * An optional hint indicating to the underlying implementation that for
      * changes regarding properties (added/removed/changed) the listener
      * is only interested in those property names listed inhere.
diff --git 
a/src/main/java/org/apache/sling/api/resource/observation/package-info.java 
b/src/main/java/org/apache/sling/api/resource/observation/package-info.java
index 31f2d93..2b46449 100644
--- a/src/main/java/org/apache/sling/api/resource/observation/package-info.java
+++ b/src/main/java/org/apache/sling/api/resource/observation/package-info.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("1.2.2")
+@Version("1.3.0")
 package org.apache.sling.api.resource.observation;
 
 import org.osgi.annotation.versioning.Version;
diff --git 
a/src/test/java/org/apache/sling/api/resource/observation/ResourceChangeListenerTest.java
 
b/src/test/java/org/apache/sling/api/resource/observation/ResourceChangeListenerTest.java
new file mode 100644
index 0000000..26e7a39
--- /dev/null
+++ 
b/src/test/java/org/apache/sling/api/resource/observation/ResourceChangeListenerTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.api.resource.observation;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Test;
+
+public class ResourceChangeListenerTest {
+
+    private final static String CHANGE_CONSTANT_PREFIX = "CHANGE_";
+
+    @Test
+    public void testChangeConstants() throws IllegalArgumentException, 
IllegalAccessException {
+        for (Field field : getChangeConstants()) {
+            ResourceChange.ChangeType.valueOf((String)field.get(null));
+        }
+    }
+
+    static Collection<Field> getChangeConstants() {
+        Field[] declaredFields = 
ResourceChangeListener.class.getDeclaredFields();
+        List<Field> constantChangeFields = new ArrayList<Field>();
+        for (Field field : declaredFields) {
+            if (java.lang.reflect.Modifier.isStatic(field.getModifiers()) && 
java.lang.reflect.Modifier.isFinal(field.getModifiers())) {
+                if (field.getName().startsWith(CHANGE_CONSTANT_PREFIX)) {
+                    constantChangeFields.add(field);
+                }
+            }
+        }
+        return constantChangeFields;
+    }
+}

Reply via email to