You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2021/01/20 14:57:19 UTC

[sling-org-apache-sling-feature-cpconverter] branch SLING-10078 created (now fd5dc48)

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

angela pushed a change to branch SLING-10078
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git.


      at fd5dc48  SLING-10079 : Review DefaultAclManager.computePathWithTypes

This branch includes the following new commits:

     new fd5dc48  SLING-10079 : Review DefaultAclManager.computePathWithTypes

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-feature-cpconverter] 01/01: SLING-10079 : Review DefaultAclManager.computePathWithTypes

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

angela pushed a commit to branch SLING-10078
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git

commit fd5dc48317f97958256c0eaf90d639a0115f9ebc
Author: angela <an...@adobe.com>
AuthorDate: Wed Jan 20 15:56:59 2021 +0100

    SLING-10079 : Review DefaultAclManager.computePathWithTypes
---
 .../accesscontrol/DefaultAclManager.java           | 62 ++++++++++++----------
 1 file changed, 35 insertions(+), 27 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
index 1508a78..e4c9313 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
@@ -294,43 +294,51 @@ public class DefaultAclManager implements AclManager {
         privilegeDefinitions = null;
     }
 
-     protected @Nullable String computePathWithTypes(@NotNull RepoPath path, @NotNull List<VaultPackageAssembler> packageAssemblers) {
-        path = new RepoPath(PlatformNameFormat.getPlatformPath(path.toString()));
-
-        boolean type = false;
+    protected @Nullable String computePathWithTypes(@NotNull RepoPath path, @NotNull List<VaultPackageAssembler> packageAssemblers) {
+        String[] parts = PlatformNameFormat.getPlatformPath(path.toString()).substring(1).split("/");
+        boolean foundType = false;
         String current = "";
-        for (String part : path.toString().substring(1).split("/")) {
+        for (String part : parts) {
             current += current.isEmpty() ? part : "/" + part;
             for (VaultPackageAssembler packageAssembler : packageAssemblers) {
                 File currentContent = packageAssembler.getEntry(current + "/" + CONTENT_XML_FILE_NAME);
                 if (currentContent.isFile()) {
-                    String primary;
-                    String mixin;
-                    try (FileInputStream input = new FileInputStream(currentContent);
-                         FileInputStream input2 = new FileInputStream(currentContent)) {
-                        primary = new PrimaryTypeParser().parse(input);
-                        mixin = new MixinParser().parse(input2);
-                        current += "(" + primary;
-                        if (mixin != null) {
-                            mixin = mixin.trim();
-                            if (mixin.startsWith("[")) {
-                                mixin = mixin.substring(1, mixin.length() - 1);
-                            }
-                            current += " mixin " + mixin;
-                        }
-                        current += ")";
-                        type = true;
-                    } catch (Exception e) {
-                        throw new RuntimeException("A fatal error occurred while parsing the '"
-                                + currentContent
-                                + "' file, see nested exceptions: "
-                                + e);
+                    String typeNames = extractTypeNames(currentContent);
+                    if (typeNames != null) {
+                        current += typeNames;
+                        foundType = true;
                     }
                 }
             }
         }
+        return foundType ? new RepoPath(current).toString() : null;
+    }
 
-        return type ? new RepoPath(current).toString() : null;
+    @Nullable
+    private String extractTypeNames(@NotNull File currentContent) {
+        String typeNames = null;
+        try (FileInputStream input = new FileInputStream(currentContent);
+             FileInputStream input2 = new FileInputStream(currentContent)) {
+            String primary = new PrimaryTypeParser().parse(input);
+            if (primary != null) {
+                typeNames = "(" + primary;
+                String mixin = new MixinParser().parse(input2);
+                if (mixin != null) {
+                    mixin = mixin.trim();
+                    if (mixin.startsWith("[")) {
+                        mixin = mixin.substring(1, mixin.length() - 1);
+                    }
+                    typeNames += " mixin " + mixin;
+                }
+                typeNames += ")";
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("A fatal error occurred while parsing the '"
+                    + currentContent
+                    + "' file, see nested exceptions: "
+                    + e);
+        }
+        return typeNames;
     }
 
     @NotNull