jsedding commented on code in PR #54:
URL:
https://github.com/apache/sling-org-apache-sling-jcr-repoinit/pull/54#discussion_r1616876096
##########
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:
Not sure if SLING-12107 helps. That is the ticket where the "new" ordering
was introduced.
We also don't have enough context to explain what the issue is. However, it
may be worthwhile including the `originalFailure` exception, or at least its
message, in the log message.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]