joerghoh commented on code in PR #54:
URL: 
https://github.com/apache/sling-org-apache-sling-jcr-repoinit/pull/54#discussion_r1616847657


##########
src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java:
##########
@@ -38,28 +44,70 @@
         })
 public class JcrRepoInitOpsProcessorImpl implements JcrRepoInitOpsProcessor {
 
+    private static final Logger log = 
LoggerFactory.getLogger(JcrRepoInitOpsProcessorImpl.class);
+
     /**
      * Apply the supplied operations: first the namespaces and nodetypes
      * registrations, then the service users, paths and ACLs.
      */
     @Override
     public void apply(Session session, List<Operation> ops) {
-        Stream.of(
-                // register namespaces first
-                singleton(new NamespacesVisitor(session)),
-                // then create node types and privileges, both use namespaces
-                asList(
+        AtomicReference<Operation> lastAttemptedOperation = new 
AtomicReference<>();
+        try {
+            Stream.of(
+                    // register namespaces first
+                    singleton(new NamespacesVisitor(session)),
+                    // then create node types and privileges, both use 
namespaces
+                    asList(
+                            new NodetypesVisitor(session),
+                            new PrivilegeVisitor(session)),
+                    // finally apply everything else
+                    asList(
+                            new UserVisitor(session),
+                            new NodeVisitor(session),
+                            new AclVisitor(session),
+                            new GroupMembershipVisitor(session),
+                            new NodePropertiesVisitor(session))
+            ).forEach(visitorGroup -> {
+                ops.forEach(op -> {
+                    lastAttemptedOperation.set(op);
+                    visitorGroup.forEach(op::accept);
+                });
+            });
+        } catch (RepoInitException originalFailure) {
+            // support legacy statement reordering for backwards compatibility
+            try {

Review Comment:
   can you please extract this complete section into a dedicated method?



##########
src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java:
##########
@@ -38,28 +44,70 @@
         })
 public class JcrRepoInitOpsProcessorImpl implements JcrRepoInitOpsProcessor {
 
+    private static final Logger log = 
LoggerFactory.getLogger(JcrRepoInitOpsProcessorImpl.class);
+
     /**
      * Apply the supplied operations: first the namespaces and nodetypes
      * registrations, then the service users, paths and ACLs.
      */
     @Override
     public void apply(Session session, List<Operation> ops) {
-        Stream.of(
-                // register namespaces first
-                singleton(new NamespacesVisitor(session)),
-                // then create node types and privileges, both use namespaces
-                asList(
+        AtomicReference<Operation> lastAttemptedOperation = new 
AtomicReference<>();
+        try {
+            Stream.of(
+                    // register namespaces first
+                    singleton(new NamespacesVisitor(session)),
+                    // then create node types and privileges, both use 
namespaces
+                    asList(
+                            new NodetypesVisitor(session),
+                            new PrivilegeVisitor(session)),
+                    // finally apply everything else
+                    asList(
+                            new UserVisitor(session),
+                            new NodeVisitor(session),
+                            new AclVisitor(session),
+                            new GroupMembershipVisitor(session),
+                            new NodePropertiesVisitor(session))
+            ).forEach(visitorGroup -> {
+                ops.forEach(op -> {
+                    lastAttemptedOperation.set(op);
+                    visitorGroup.forEach(op::accept);
+                });
+            });
+        } catch (RepoInitException originalFailure) {
+            // support legacy statement reordering for backwards compatibility
+            try {
+                session.refresh(false); // drop transient changes
+
+                final OperationVisitor[] visitors = {
+                        new NamespacesVisitor(session),
                         new NodetypesVisitor(session),
-                        new PrivilegeVisitor(session)),
-                // finally apply everything else
-                asList(
+                        new PrivilegeVisitor(session),
                         new UserVisitor(session),
                         new NodeVisitor(session),
                         new AclVisitor(session),
                         new GroupMembershipVisitor(session),
-                        new NodePropertiesVisitor(session))
-        ).forEach(visitorGroup -> {
-            ops.forEach(op -> visitorGroup.forEach(op::accept));
-        });
+                        new NodePropertiesVisitor(session)
+                };
+
+                for (OperationVisitor v : visitors) {
+                    for (Operation op : ops) {
+                        op.accept(v);
+                    }
+                }
+
+                log.warn("DEPRECATION - The repoinit script being executed 
relies on a bug causing repoinit " +

Review Comment:
   Do we have a Jira ID or something we can reference when it comes to fixing? 
This warning is hardly actionable for anyone not familiar with repoinit.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@sling.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to