You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2022/02/25 13:34:04 UTC

[directory-ldap-api] branch master updated (1755fa3 -> 4497b3b)

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

semancik pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git.


    from 1755fa3  Updating SLF4J to 1.7.36
     new 76f4895  Fixed missing assignment of schemaManager in Ava (+test)
     new 4497b3b  allowDuplicateResources in JarLdifSchemaLoader

The 2 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.


Summary of changes:
 .../directory/api/ldap/model/name/DnTest.java      | 30 +++++++++++++--
 .../apache/directory/api/ldap/model/name/Ava.java  |  1 +
 .../extractor/impl/DefaultSchemaLdifExtractor.java | 21 +++++++++++
 .../ldap/schema/loader/JarLdifSchemaLoader.java    | 44 +++++++++++++++++++++-
 4 files changed, 91 insertions(+), 5 deletions(-)

[directory-ldap-api] 01/02: Fixed missing assignment of schemaManager in Ava (+test)

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

semancik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git

commit 76f4895b55d839806050ec5f11d5a779a8135b17
Author: Radovan Semancik <ra...@evolveum.com>
AuthorDate: Fri Feb 25 09:38:45 2022 +0100

    Fixed missing assignment of schemaManager in Ava (+test)
---
 .../directory/api/ldap/model/name/DnTest.java      | 30 +++++++++++++++++++---
 .../apache/directory/api/ldap/model/name/Ava.java  |  1 +
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/integ/src/test/java/org/apache/directory/api/ldap/model/name/DnTest.java b/integ/src/test/java/org/apache/directory/api/ldap/model/name/DnTest.java
index c8455cd..8b21fe0 100644
--- a/integ/src/test/java/org/apache/directory/api/ldap/model/name/DnTest.java
+++ b/integ/src/test/java/org/apache/directory/api/ldap/model/name/DnTest.java
@@ -1246,13 +1246,13 @@ public class DnTest
 
 
     /**
-     * Class to test for void LdapName(String)
+     * Class to test for Dn(String)
      *
      * @throws Exception
      *             if anything goes wrong.
      */
     @Test
-    public void testLdapNameString() throws Exception
+    public void testDnString() throws Exception
     {
         Dn name = new Dn( "" );
         Dn name50 = new Dn();
@@ -1280,12 +1280,34 @@ public class DnTest
         assertNotSame( name2, name5 );
     }
 
+    /**
+     * Class to test for Dn(SchemaManager, String)
+     *
+     * @throws Exception
+     *             if anything goes wrong.
+     */
+    @Test
+    public void testDnStringSchemaAware() throws Exception
+    {
+
+        Dn dnPeople = new Dn( schemaManager, "ou=People,dc=example,dc=com" );
+        Dn dnPeopleCase = new Dn( schemaManager, "ou=people,dc=ExAmPLE,dc=COM" );
+        Dn dnJack = new Dn( schemaManager, "uid=jack,ou=People,dc=example,dc=com" );
+
+        assertEquals( dnPeople, dnPeopleCase );
+        assertTrue( dnPeople.isAncestorOf( dnJack ) );
+        assertTrue( dnPeopleCase.isAncestorOf( dnJack ) );
+        assertTrue( dnJack.isDescendantOf( dnPeople ) );
+        assertTrue( dnJack.isDescendantOf( dnPeopleCase ) );
+        assertNotSame( dnPeople, dnJack );
+    }
+
 
     /**
-     * Class to test for void LdapName()
+     * Class to test for Dn()
      */
     @Test
-    public void testLdapName()
+    public void testDn()
     {
         Dn name = new Dn();
         assertTrue( name.toString().equals( "" ) );
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
index b5e68c7..8feafbf 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
@@ -133,6 +133,7 @@ public class Ava implements Externalizable, Cloneable, Comparable<Ava>
     public Ava( SchemaManager schemaManager, Ava ava ) throws LdapInvalidDnException
     {
         upType = ava.upType;
+        this.schemaManager = schemaManager;
         
         if ( ava.isSchemaAware() )
         {

[directory-ldap-api] 02/02: allowDuplicateResources in JarLdifSchemaLoader

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

semancik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git

commit 4497b3b685d15664a3c71f80369fc8f8399d5b06
Author: Radovan Semancik <ra...@evolveum.com>
AuthorDate: Fri Feb 25 14:33:04 2022 +0100

    allowDuplicateResources in JarLdifSchemaLoader
---
 .../extractor/impl/DefaultSchemaLdifExtractor.java | 21 +++++++++++
 .../ldap/schema/loader/JarLdifSchemaLoader.java    | 44 +++++++++++++++++++++-
 2 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/extractor/impl/DefaultSchemaLdifExtractor.java b/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/extractor/impl/DefaultSchemaLdifExtractor.java
index f626c32..29319e3 100644
--- a/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/extractor/impl/DefaultSchemaLdifExtractor.java
+++ b/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/extractor/impl/DefaultSchemaLdifExtractor.java
@@ -393,6 +393,27 @@ public class DefaultSchemaLdifExtractor implements SchemaLdifExtractor
 
 
     /**
+     * Gets resource from the class loader.
+     * In case of several files with the same name, it returns any of them.
+     * This is useful in cases when the same artefacts are loaded several times, e.g. in some testing scenarios.
+     *
+     * @param resourceName the name of the resource
+     * @param resourceDescription the description of the resource
+     * @return the URL to the resource in the class loader
+     * @throws IOException if there is an IO error
+     */
+    public static URL getAnyResource( String resourceName, String resourceDescription ) throws IOException
+    {
+        Enumeration<URL> resources = DefaultSchemaLdifExtractor.class.getClassLoader().getResources( resourceName );
+        if ( !resources.hasMoreElements() )
+        {
+            throw new UniqueResourceException( resourceName, resourceDescription );
+        }
+        URL result = resources.nextElement();
+        return result;
+    }
+
+    /**
      * Extracts the LDIF schema resource from class loader.
      *
      * @param resource the LDIF schema resource
diff --git a/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/JarLdifSchemaLoader.java b/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/JarLdifSchemaLoader.java
index 0584b31..23ca0c7 100644
--- a/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/JarLdifSchemaLoader.java
+++ b/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/JarLdifSchemaLoader.java
@@ -70,6 +70,7 @@ public class JarLdifSchemaLoader extends AbstractSchemaLoader
     private static final Map<String, Boolean> RESOURCE_MAP = ResourceMap.getResources( Pattern
         .compile( "schema" + SEPARATOR_PATTERN + "ou=schema.*" ) );
 
+    private final boolean allowDuplicateResources;
 
     /**
      * Creates a new LDIF based SchemaLoader. The constructor checks to make
@@ -82,15 +83,56 @@ public class JarLdifSchemaLoader extends AbstractSchemaLoader
      */
     public JarLdifSchemaLoader() throws IOException, LdapException
     {
+        this.allowDuplicateResources = false;
         initializeSchemas();
     }
 
+    /**
+     * Creates a new LDIF based SchemaLoader. The constructor checks to make
+     * sure the supplied base directory exists and contains a schema.ldif file
+     * and if not complains about it.
+     *
+     * @prarm allowDuplicateResources If set to true, loading duplicate resources is allowed.
+     * E.g. loading schema definitions that are loaded several times on the classpath.
+     * In case of several files with the same name, it returns any of them.
+     * This is useful in cases when the same artefacts are loaded several times, e.g. in some testing scenarios
+     * or weird classloading situations.
+     *
+     * @throws LdapException if the base directory does not exist or does not
+     * a valid schema.ldif file
+     * @throws IOException If we can't load the schema
+     */
+    public JarLdifSchemaLoader( boolean allowDuplicateResources ) throws IOException, LdapException
+    {
+        this.allowDuplicateResources = allowDuplicateResources;
+        initializeSchemas();
+    }
+
+    /**
+     * Returns true, if loading duplicate resources is allowed.
+     * E.g. loading schema definitions that are loaded several times on the classpath.
+     * In case of several files with the same name, it returns any of them.
+     * This is useful in cases when the same artefacts are loaded several times, e.g. in some testing scenarios
+     * or weird classloading situations.
+     */
+    public boolean isAllowDuplicateResources()
+    {
+        return allowDuplicateResources;
+    }
+
 
     private URL getResource( String resource, String msg ) throws IOException
     {
         if ( RESOURCE_MAP.get( resource ) )
         {
-            return DefaultSchemaLdifExtractor.getUniqueResource( resource, msg );
+            if ( allowDuplicateResources )
+            {
+                return DefaultSchemaLdifExtractor.getAnyResource( resource, msg );
+            }
+            else
+            {
+                return DefaultSchemaLdifExtractor.getUniqueResource( resource, msg );
+            }
         }
         else
         {