You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by js...@apache.org on 2024/05/23 13:00:12 UTC

(sling-org-apache-sling-jcr-repoinit) branch master updated: SLING-12323 - [RepoInit] Avoid java.nio.file.Path for parsing repository paths (#53)

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

jsedding pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git


The following commit(s) were added to refs/heads/master by this push:
     new 0356e2f  SLING-12323 - [RepoInit] Avoid java.nio.file.Path for parsing repository paths (#53)
0356e2f is described below

commit 0356e2f351d40d04cd3bc3f5f9c58633bb41cf78
Author: Julian Sedding <js...@apache.org>
AuthorDate: Thu May 23 15:00:05 2024 +0200

    SLING-12323 - [RepoInit] Avoid java.nio.file.Path for parsing repository paths (#53)
    
    - modify test case to detect the issue on windows
    - rely on JCR to process relative property paths
---
 .../jcr/repoinit/impl/NodePropertiesVisitor.java   | 43 ++++++----------------
 .../sling/jcr/repoinit/SetPropertiesTest.java      | 24 ++++++------
 2 files changed, 24 insertions(+), 43 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/NodePropertiesVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/NodePropertiesVisitor.java
index 73d056e..7dfce05 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/NodePropertiesVisitor.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/NodePropertiesVisitor.java
@@ -16,8 +16,6 @@
  */
 package org.apache.sling.jcr.repoinit.impl;
 
-import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -103,7 +101,7 @@ class NodePropertiesVisitor extends DoNothingVisitor {
      * requiredType for the specified property
      *
      * @param propName the propertyName to check
-     * @param parentNode the parent node where the property will be set
+     * @param nodeType the node type to be searched for the property definition
      * @return the required type of the property or {@link PropertyType#UNDEFINED} if it could not be determined
      */
     private static @Nullable PropertyDefinition resolvePropertyDefinition(@NotNull String propName, @NotNull NodeType nodeType) {
@@ -118,42 +116,25 @@ class NodePropertiesVisitor extends DoNothingVisitor {
      * is the same as the autocreated default value
      *
      * @param n the node to check
-     * @param pRelPath the property relative path to check
+     * @param propertyPath the property relative path to check
      * @return true or false
      */
-    protected static boolean isUnchangedAutocreatedProperty(Node n, final String pRelPath)
+    protected static boolean isUnchangedAutocreatedProperty(Node n, final String propertyPath)
             throws RepositoryException {
-        boolean sameAsDefault = false;
-
-        // deal with the pRelPath nesting
-        Path path = Paths.get(pRelPath);
-        Path parentPath = path.getParent();
-        String name = path.getFileName().toString();
-        if (parentPath != null) {
-            String relPath = parentPath.toString();
-            if (n.hasNode(relPath)) {
-                n = n.getNode(relPath);
-            } else {
-                n = null;
-            }
-        }
-
-        //  if the property has been set by being autocreated and the value is still
-        //  the same as the default values then also allow changing the value
-        if (n != null && n.hasProperty(name)) {
-            @Nullable
-            PropertyDefinition pd = resolvePropertyDefinition(name, n);
+        if (n.hasProperty(propertyPath)) {
+            final Property property = n.getProperty(propertyPath);
+            final String name = property.getName();
+            final PropertyDefinition pd = resolvePropertyDefinition(name, property.getParent());
             if (pd != null && pd.isAutoCreated()) {
                 // if the current value is the same as the autocreated default values
                 //  then allow the value to be changed.
-                if (pd.isMultiple()) {
-                    sameAsDefault = Arrays.equals(pd.getDefaultValues(), n.getProperty(name).getValues());
-                } else {
-                    sameAsDefault = Arrays.equals(pd.getDefaultValues(), new Value[] {n.getProperty(name).getValue()});
-                }
+                return Arrays.equals(
+                        pd.getDefaultValues(),
+                        property.isMultiple() ? property.getValues() : new Value[] {property.getValue()}
+                );
             }
         }
-        return sameAsDefault;
+        return false;
     }
 
     /**
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/SetPropertiesTest.java b/src/test/java/org/apache/sling/jcr/repoinit/SetPropertiesTest.java
index 60a0688..7893109 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/SetPropertiesTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/SetPropertiesTest.java
@@ -269,7 +269,7 @@ public class SetPropertiesTest {
             throws RepositoryException, RepoInitParsingException {
         U.assertNodeExists(testPath);
         // verify the initial autocreated property values
-        U.assertSVPropertyExists(testPath, "singleVal", vf.createValue("autocreated value"));
+        U.assertSVPropertyExists(testPath, "slingtest:singleVal", vf.createValue("autocreated value"));
         U.assertMVPropertyExists(testPath, "multiVal", new Value[] {
                 vf.createValue("autocreated value1"),
                 vf.createValue("autocreated value2")
@@ -279,11 +279,11 @@ public class SetPropertiesTest {
         //  the same as the autocreated default values
         final String setPropsA =
                 "set properties on " + testPath + "\n" +
-                        "default singleVal to sChanged1a\n" +
+                        "default slingtest:singleVal to sChanged1a\n" +
                         "default multiVal to mChanged1a, mChanged2a\n" +
                 "end";
         U.parseAndExecute(setPropsA);
-        U.assertSVPropertyExists(testPath, "singleVal", vf.createValue("sChanged1a"));
+        U.assertSVPropertyExists(testPath, "slingtest:singleVal", vf.createValue("sChanged1a"));
         U.assertMVPropertyExists(testPath, "multiVal", new Value[] {
                 vf.createValue("mChanged1a"),
                 vf.createValue("mChanged2a")
@@ -293,11 +293,11 @@ public class SetPropertiesTest {
         //  not the same as the autocreated default values
         final String setPropsB =
                 "set properties on " + testPath + "\n" +
-                        "default singleVal to sChanged1b\n" +
+                        "default slingtest:singleVal to sChanged1b\n" +
                         "default multiVal to mChanged1b, mChanged2b\n" +
                 "end";
         U.parseAndExecute(setPropsB);
-        U.assertSVPropertyExists(testPath, "singleVal", vf.createValue("sChanged1a"));
+        U.assertSVPropertyExists(testPath, "slingtest:singleVal", vf.createValue("sChanged1a"));
         U.assertMVPropertyExists(testPath, "multiVal", new Value[] {
                 vf.createValue("mChanged1a"),
                 vf.createValue("mChanged2a")
@@ -328,7 +328,7 @@ public class SetPropertiesTest {
         String testPath = a.getPath() + "/" + name;
         U.assertNodeExists(testPath);
         // verify the initial autocreated property values
-        U.assertSVPropertyExists(testPath, "singleVal", vf.createValue("autocreated value"));
+        U.assertSVPropertyExists(testPath, "slingtest:singleVal", vf.createValue("autocreated value"));
         U.assertMVPropertyExists(testPath, "multiVal", new Value[] {
                 vf.createValue("autocreated value1"),
                 vf.createValue("autocreated value2")
@@ -338,11 +338,11 @@ public class SetPropertiesTest {
         //  the same as the autocreated default values
         final String setPropsA =
                 "set properties on authorizable(" + userid + ")/" + name + "\n" +
-                        "default singleVal to sChanged1a\n" +
+                        "default slingtest:singleVal to sChanged1a\n" +
                         "default multiVal to mChanged1a, mChanged2a\n" +
                 "end";
         U.parseAndExecute(setPropsA);
-        U.assertAuthorizableSVPropertyExists(userid, name + "/singleVal", vf.createValue("sChanged1a"));
+        U.assertAuthorizableSVPropertyExists(userid, name + "/slingtest:singleVal", vf.createValue("sChanged1a"));
         U.assertAuthorizableMVPropertyExists(userid, name + "/multiVal", new Value[] {
                 vf.createValue("mChanged1a"),
                 vf.createValue("mChanged2a")
@@ -352,11 +352,11 @@ public class SetPropertiesTest {
         //  not the same as the autocreated default values
         final String setPropsB =
                 "set properties on authorizable(" + userid + ")/" + name + "\n" +
-                        "default singleVal to sChanged1b\n" +
+                        "default slingtest:singleVal to sChanged1b\n" +
                         "default multiVal to mChanged1b, mChanged2b\n" +
                 "end";
         U.parseAndExecute(setPropsB);
-        U.assertAuthorizableSVPropertyExists(userid, name + "/singleVal", vf.createValue("sChanged1a"));
+        U.assertAuthorizableSVPropertyExists(userid, name + "/slingtest:singleVal", vf.createValue("sChanged1a"));
         U.assertAuthorizableMVPropertyExists(userid, name + "/multiVal", new Value[] {
                 vf.createValue("mChanged1a"),
                 vf.createValue("mChanged2a")
@@ -370,13 +370,13 @@ public class SetPropertiesTest {
                 "<<===\n" +
                 "<< <slingtest='http://sling.apache.org/ns/test/repoinit-it/v1.0'>\n" +
                 "<< [slingtest:sling11293] > nt:unstructured\n" +
-                "<<    - singleVal (String) = 'autocreated value'\n" +
+                "<<    - slingtest:singleVal (String) = 'autocreated value'\n" +
                 "<<       autocreated\n" +
                 "<<    - multiVal (String) = 'autocreated value1', 'autocreated value2'\n" +
                 "<<       multiple autocreated\n" +
                 "<< [slingtest:sling11293mixin]\n" +
                 "<<    mixin\n" +
-                "<<    - singleVal (String) = 'autocreated value'\n" +
+                "<<    - slingtest:singleVal (String) = 'autocreated value'\n" +
                 "<<       autocreated\n" +
                 "<<    - multiVal (String) = 'autocreated value1', 'autocreated value2'\n" +
                 "<<       multiple autocreated\n" +