sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-testing-sling-mock] 14/37: SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
Date Tue, 07 Nov 2017 10:23:30 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.testing.sling-mock-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 853e02b00aaf0750d56a20ce5d91c644bf6fd3e8
Author: Stefan Seifert <sseifert@apache.org>
AuthorDate: Sat Sep 26 21:47:39 2015 +0000

    SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1705487
13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/context/NodeTypeDefinitionScanner.java   | 27 ++++++++++++++++------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
b/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
index da5f33a..bec7900 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
@@ -58,33 +58,46 @@ public final class NodeTypeDefinitionScanner {
         nodeTypeDefinitions = findeNodeTypeDefinitions();
     }
     
+    /**
+     * @return Node type definitions found in classpath as registered in OSGi bundle headers
+     */
     public List<String> getNodeTypeDefinitions() {
         return nodeTypeDefinitions;
     }
 
     /**
      * Registers node types found in classpath in JCR repository.
-     * @param Session session
+     * @param session Session
      */
     public void register(Session session) throws RepositoryException {
+      List<String> nodeTypeResources = getNodeTypeDefinitions();
+      register(session, nodeTypeResources);
+    }
+    
+    /**
+     * Registers node types found in classpath in JCR repository.
+     * @param session Session
+     * @param nodeTypeResources List of classpath resource URLs pointing to node type definitions
+     */
+    public void register(Session session, List<String> nodeTypeResources) throws RepositoryException
{
       ClassLoader classLoader = getClass().getClassLoader();
       Workspace workspace = session.getWorkspace();
       NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
       NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
       ValueFactory valueFactory = session.getValueFactory();
 
-      // try registering node types multiple times because the ecact order is not known
-      List<String> nodeTypeResources = new ArrayList<String>(NodeTypeDefinitionScanner.get().getNodeTypeDefinitions());
+      // try registering node types multiple times because the eyact order is not known
       int iteration = 0;
-      while (!nodeTypeResources.isEmpty()) {
-          registerAndRemoveSucceeds(nodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry,
valueFactory, false);
+      List<String> remainingNodeTypeResources = new ArrayList<String>(nodeTypeResources);
+      while (!remainingNodeTypeResources.isEmpty()) {
+          registerAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager,
namespaceRegistry, valueFactory, false);
           iteration++;
           if (iteration >= MAX_ITERATIONS) {
               break;
           }
       }
-      if (!nodeTypeResources.isEmpty()) {
-          registerAndRemoveSucceeds(nodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry,
valueFactory, true);
+      if (!remainingNodeTypeResources.isEmpty()) {
+          registerAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager,
namespaceRegistry, valueFactory, true);
       }
     }
     

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message