directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r997052 - in /directory: apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/ apacheds/trunk/ldi...
Date Tue, 14 Sep 2010 19:25:26 GMT
Author: seelmann
Date: Tue Sep 14 19:25:25 2010
New Revision: 997052

URL: http://svn.apache.org/viewvc?rev=997052&view=rev
Log:
Fix for DIRSERVER-1541 (Numerous JUnit tests failing on Windows), thanks to Richard Feezel
for the patch

Modified:
    directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
    directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
    directory/apacheds/trunk/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java
    directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoader.java
    directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SingleLdifSchemaLoader.java
    directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java

Modified: directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java?rev=997052&r1=997051&r2=997052&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
(original)
+++ directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
Tue Sep 14 19:25:25 2010
@@ -165,6 +165,7 @@ public class JdbmStoreTest
     {
         if ( store != null )
         {
+            // make sure all files are closed so that they can be deleted on Windows.
             store.destroy();
         }
 
@@ -217,6 +218,9 @@ public class JdbmStoreTest
         Long id = store2.getEntryId( suffixDn );
         Entry lookup = store2.lookup( id );
         assertEquals( 2, lookup.getDn().size() );
+
+        // make sure all files are closed so that they can be deleted on Windows.
+        store2.destroy();
     }
 
 
@@ -282,6 +286,7 @@ public class JdbmStoreTest
         assertFalse( store.isSyncOnWrite() );
 
         store.sync();
+        // make sure all files are closed so that they can be deleted on Windows.
         store.destroy();
     }
 
@@ -642,7 +647,7 @@ public class JdbmStoreTest
         File testSpecificDir = new File( wkdir, "testConvertIndex" );
         testSpecificDir.mkdirs();
 
-        Index nonJdbmIndex = new GenericIndex( "ou", 10,  testSpecificDir );
+        Index<?, Object, Long> nonJdbmIndex = new GenericIndex<Object, Object, Long>(
"ou", 10, testSpecificDir );
 
         Method convertIndex = store.getClass().getDeclaredMethod( "convertAndInit", Index.class
);
         convertIndex.setAccessible( true );
@@ -650,6 +655,8 @@ public class JdbmStoreTest
 
         assertNotNull( obj );
         assertEquals( JdbmIndex.class, obj.getClass() );
+
+        ( ( JdbmIndex ) obj ).close();
     }
 
 
@@ -924,7 +931,6 @@ public class JdbmStoreTest
         // do not add ou index this time
         store.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID ) );
 
-
         DN suffixDn = new DN( "o=Good Times Co.", schemaManager );
         store.setSuffixDn( suffixDn );
         // init the store to call deleteUnusedIndexFiles() method

Modified: directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java?rev=997052&r1=997051&r2=997052&view=diff
==============================================================================
--- directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
(original)
+++ directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
Tue Sep 14 19:25:25 2010
@@ -66,8 +66,8 @@ import org.slf4j.LoggerFactory;
 
 
 /**
- * A LDIF based partition. Data are stored on disk as LDIF, following this organisation :
- * <li> each entry is associated with a file, postfixed with LDIF
+ * A LDIF based partition. Data are stored on disk as LDIF, following this organization :
+ * <li> each entry is associated with a file, post-fixed with LDIF
  * <li> each entry having at least one child will have a directory created using its
name.
  * The root is the partition's suffix.
  * <br>
@@ -429,7 +429,6 @@ public class LdifPartition extends BTree
             throw new LdapOperationException( e.getMessage() );
         }
 
-
         // And delete the old entry's LDIF file
         File file = getFile( oldEntryDn, DELETE );
         boolean deleted = deleteFile( file );
@@ -540,7 +539,7 @@ public class LdifPartition extends BTree
 
         String parentDir = null;
 
-        if( entryDn.equals( suffix ) )
+        if ( entryDn.equals( suffix ) )
         {
             parentDir = suffixDirectory.getParent() + File.separator;
         }
@@ -593,7 +592,7 @@ public class LdifPartition extends BTree
             // Now, get the normalized value
             String normValue = ava.getNormValue().getString();
 
-            fileName.append( atName ).append(  "=" ).append( normValue );
+            fileName.append( atName ).append( "=" ).append( normValue );
 
             if ( iterator.hasNext() )
             {
@@ -651,7 +650,7 @@ public class LdifPartition extends BTree
         if ( SystemUtils.IS_OS_WINDOWS )
         {
             // On Windows, we escape '/', '<', '>', '\', '|', '"', ':', '+', ' ', '[',
']',
-            // '*', [0x00-0x1F], '?'
+            // '*', [0x00-0x1F], '?', and '%' with "%xx" where xx is the hex value of the
character.
             StringBuilder sb = new StringBuilder();
 
             for ( char c : fileName.toCharArray() )
@@ -690,10 +689,6 @@ public class LdifPartition extends BTree
                     case 0x1D:
                     case 0x1E:
                     case 0x1F:
-                        sb.append( "\\" ).append( StringTools.dumpHex( ( byte ) ( c >>
4 ) ) ).append(
-                            StringTools.dumpHex( ( byte ) ( c & 0x04 ) ) );
-                        break;
-
                     case '/':
                     case '\\':
                     case '<':
@@ -707,7 +702,9 @@ public class LdifPartition extends BTree
                     case ']':
                     case '*':
                     case '?':
-                        sb.append( '\\' ).append( c );
+                    case '%':
+                        sb.append( "%" ).append( StringTools.dumpHex( ( byte ) ( c >>
4 ) ) )
+                                        .append( StringTools.dumpHex( ( byte ) ( c &
0xF ) ) );
                         break;
 
                     default:

Modified: directory/apacheds/trunk/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java?rev=997052&r1=997051&r2=997052&view=diff
==============================================================================
--- directory/apacheds/trunk/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java
(original)
+++ directory/apacheds/trunk/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java
Tue Sep 14 19:25:25 2010
@@ -20,6 +20,7 @@
 
 package org.apache.directory.server.core.partition;
 
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -72,6 +73,7 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  * Unit test cases for the LDIF partition test
  *
@@ -126,9 +128,9 @@ public class LdifPartitionTest
     {
         String contextEntry =
             "dn: ou=test, ou=system\n" +
-            "objectclass: organizationalUnit\n" +
-            "objectclass: top\n" +
-            "ou: test";
+                "objectclass: organizationalUnit\n" +
+                "objectclass: top\n" +
+                "ou: test";
 
         // setup the working directory for the store
         wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
@@ -184,7 +186,8 @@ public class LdifPartitionTest
     public void testLdifAddEntries() throws Exception
     {
         DN adminDn = new DN( "uid=admin,ou=system", schemaManager );
-        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
), new MockDirectoryService( 1 ) );
+        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
),
+            new MockDirectoryService( 1 ) );
         AddOperationContext addCtx = new AddOperationContext( session );
 
         ClonedServerEntry entry1 = createEntry( "dc=test,ou=test,ou=system" );
@@ -214,8 +217,10 @@ public class LdifPartitionTest
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=test.ldif" ).exists() );
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=test" ).exists() );
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=test/dc=test.ldif" ).exists()
);
-        assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain"
).exists() );
-        assertTrue( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain"
).exists()
+            || new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn%2bobjectclass=domain"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain.ldif"
).exists()
+            || new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn%2bobjectclass=domain.ldif"
).exists() );
     }
 
 
@@ -228,7 +233,8 @@ public class LdifPartitionTest
     public void testLdifAddExistingEntry() throws Exception
     {
         DN adminDn = new DN( "uid=admin,ou=system", schemaManager );
-        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
), new MockDirectoryService( 1 ) );
+        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
),
+            new MockDirectoryService( 1 ) );
         AddOperationContext addCtx = new AddOperationContext( session );
 
         ClonedServerEntry entry1 = createEntry( "dc=test,ou=test,ou=system" );
@@ -281,7 +287,8 @@ public class LdifPartitionTest
     public void testLdifDeleteExistingEntry() throws Exception
     {
         DN adminDn = new DN( "uid=admin,ou=system", schemaManager );
-        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
), new MockDirectoryService( 1 ) );
+        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
),
+            new MockDirectoryService( 1 ) );
         AddOperationContext addCtx = new AddOperationContext( session );
 
         ClonedServerEntry entry1 = createEntry( "dc=test,ou=test,ou=system" );
@@ -328,8 +335,10 @@ public class LdifPartitionTest
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=test1.ldif" ).exists()
);
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=test2" ).exists() );
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=test/dc=test2.ldif" ).exists()
);
-        assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain"
).exists() );
-        assertTrue( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain"
).exists()
+            || new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn%2bobjectclass=domain"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain.ldif"
).exists()
+            || new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn%2bobjectclass=domain.ldif"
).exists() );
 
         dn = new DN( "dc=test2,dc=test,ou=test,ou=system", schemaManager );
 
@@ -349,9 +358,13 @@ public class LdifPartitionTest
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=test.ldif" ).exists() );
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=test2" ).exists() );
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=test2.ldif" ).exists()
);
-        assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain"
).exists() );
-        assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain"
).exists()
+            || new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn%2bobjectclass=domain"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn+objectclass=domain.ldif"
).exists()
+            || new File( wkdir, "ou=test,ou=system/dc=test/dc=mvrdn%2bobjectclass=domain.ldif"
).exists() );
     }
+
+
     //-------------------------------------------------------------------------
     // Partition.delete() tests
     //-------------------------------------------------------------------------
@@ -364,7 +377,8 @@ public class LdifPartitionTest
     public void testLdifSearchExistingEntry() throws Exception
     {
         DN adminDn = new DN( "uid=admin,ou=system", schemaManager );
-        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
), new MockDirectoryService( 1 ) );
+        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
),
+            new MockDirectoryService( 1 ) );
         AddOperationContext addCtx = new AddOperationContext( session );
 
         ClonedServerEntry entry1 = createEntry( "dc=test,ou=test,ou=system" );
@@ -431,8 +445,10 @@ public class LdifPartitionTest
     {
         CoreSession session = injectEntries();
 
-        ClonedServerEntry childEntry1 = partition.lookup( partition.getEntryId( new DN( "dc=child1,ou=test,ou=system",
schemaManager ) ) );
-        ClonedServerEntry childEntry2 = partition.lookup( partition.getEntryId( new DN( "dc=child2,ou=test,ou=system",
schemaManager ) ) );
+        ClonedServerEntry childEntry1 = partition.lookup( partition.getEntryId( new DN( "dc=child1,ou=test,ou=system",
+            schemaManager ) ) );
+        ClonedServerEntry childEntry2 = partition.lookup( partition.getEntryId( new DN( "dc=child2,ou=test,ou=system",
+            schemaManager ) ) );
 
         MoveOperationContext moveOpCtx = new MoveOperationContext( session, childEntry1.getDn(),
childEntry2.getDn() );
         partition.move( moveOpCtx );
@@ -447,8 +463,10 @@ public class LdifPartitionTest
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=child1/dc=grandchild11.ldif"
).exists() );
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=child1/dc=grandchild12"
).exists() );
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=child1/dc=grandchild12.ldif"
).exists() );
-        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=child1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
-        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=child1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=child1/dc=grandchild11/dc=greatgrandchild111"
)
+            .exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=child1/dc=grandchild11/dc=greatgrandchild111.ldif"
)
+            .exists() );
     }
 
 
@@ -472,8 +490,10 @@ public class LdifPartitionTest
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11.ldif"
).exists() );
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild12"
).exists() );
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild12.ldif"
).exists() );
-        assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
-        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111"
)
+            .exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
)
+            .exists() );
     }
 
 
@@ -497,8 +517,10 @@ public class LdifPartitionTest
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11.ldif"
).exists() );
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild12"
).exists() );
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild12.ldif"
).exists() );
-        assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
-        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111"
)
+            .exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
)
+            .exists() );
 
         // the renamed LDIF must contain the old an new RDN attribute
         String content = FileUtils.readFileToString( new File( wkdir, "ou=test,ou=system/dc=renamedchild1.ldif"
) );
@@ -517,7 +539,8 @@ public class LdifPartitionTest
         DN childDn2 = new DN( "dc=child2,ou=test,ou=system", schemaManager );
 
         RDN newRdn = new RDN( SchemaConstants.DC_AT + "=" + "movedChild1" );
-        MoveAndRenameOperationContext moveAndRenameOpCtx = new MoveAndRenameOperationContext(
session, childDn1, childDn2, newRdn, true );
+        MoveAndRenameOperationContext moveAndRenameOpCtx = new MoveAndRenameOperationContext(
session, childDn1,
+            childDn2, newRdn, true );
         partition.moveAndRename( moveAndRenameOpCtx );
 
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=child1" ).exists() );
@@ -529,8 +552,10 @@ public class LdifPartitionTest
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11.ldif"
).exists() );
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild12"
).exists() );
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild12.ldif"
).exists() );
-        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
-        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+        assertFalse( new File( wkdir,
+            "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
+        assertTrue( new File( wkdir,
+            "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
     }
 
 
@@ -544,7 +569,8 @@ public class LdifPartitionTest
         DN childDn2 = new DN( "dc=child2,ou=test,ou=system", schemaManager );
 
         RDN newRdn = new RDN( SchemaConstants.DC_AT + "=" + "movedChild1" );
-        MoveAndRenameOperationContext moveAndRenameOpCtx = new MoveAndRenameOperationContext(
session, childDn1, childDn2, newRdn, false );
+        MoveAndRenameOperationContext moveAndRenameOpCtx = new MoveAndRenameOperationContext(
session, childDn1,
+            childDn2, newRdn, false );
         partition.moveAndRename( moveAndRenameOpCtx );
 
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=child1" ).exists() );
@@ -556,8 +582,10 @@ public class LdifPartitionTest
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11.ldif"
).exists() );
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild12"
).exists() );
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild12.ldif"
).exists() );
-        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
-        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+        assertFalse( new File( wkdir,
+            "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
+        assertTrue( new File( wkdir,
+            "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
 
         // the renamed LDIF must contain the old an new RDN attribute
         String content = FileUtils
@@ -570,7 +598,8 @@ public class LdifPartitionTest
     private CoreSession injectEntries() throws Exception
     {
         DN adminDn = new DN( "uid=admin,ou=system", schemaManager );
-        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
), new MockDirectoryService( 1 ) );
+        CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG
),
+            new MockDirectoryService( 1 ) );
         AddOperationContext addCtx = new AddOperationContext( session );
 
         ClonedServerEntry rootEntry = createEntry( "ou=test,ou=system" );
@@ -594,7 +623,6 @@ public class LdifPartitionTest
 
         partition.add( addCtx );
 
-
         ClonedServerEntry grandChild11 = createEntry( "dc=grandChild11,dc=child1,ou=test,ou=system"
);
         grandChild11.put( "ObjectClass", "top", "domain" );
         grandChild11.put( "dc", "grandChild11" );
@@ -627,7 +655,8 @@ public class LdifPartitionTest
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=child1/dc=grandchild12" ).exists()
);
         assertTrue( new File( wkdir, "ou=test,ou=system/dc=child1/dc=grandchild12.ldif" ).exists()
);
         assertFalse( new File( wkdir, "ou=test,ou=system/dc=child1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
-        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child1/dc=grandchild11/dc=greatgrandchild111.ldif"
)
+            .exists() );
 
         return session;
     }

Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java?rev=997052&r1=997051&r2=997052&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java
(original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java
Tue Sep 14 19:25:25 2010
@@ -56,6 +56,10 @@ public class LdifConfigExtractor
 
     private static final Logger LOG = LoggerFactory.getLogger( LdifConfigExtractor.class
);
 
+    // java.util.regex.Pattern is immutable so only one instance is needed for all uses.
+    private static final Pattern EXTRACT_PATTERN = Pattern.compile( ".*config"
+                            + "[/\\Q\\\\E]" + "ou=config.*\\.ldif" );
+
 
     /**
      * Extracts the LDIF files from a Jar file or copies exploded LDIF resources.
@@ -85,8 +89,7 @@ public class LdifConfigExtractor
 
         LOG.debug( "extracting the configuration to the directory at {}", configDirectory.getAbsolutePath()
);
 
-        Pattern pattern = Pattern.compile( ".*config" + File.separator + "ou=config.*\\.ldif"
);
-        Map<String, Boolean> list = ResourceMap.getResources( pattern );
+        Map<String, Boolean> list = ResourceMap.getResources( EXTRACT_PATTERN );
 
         for ( Entry<String, Boolean> entry : list.entrySet() )
         {

Modified: directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoader.java?rev=997052&r1=997051&r2=997052&view=diff
==============================================================================
--- directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoader.java
(original)
+++ directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoader.java
Tue Sep 14 19:25:25 2010
@@ -53,6 +53,9 @@ import org.slf4j.LoggerFactory;
  */
 public class JarLdifSchemaLoader extends AbstractSchemaLoader
 {
+    // java.util.regex.Pattern is immutable so only one instance is needed for all uses.
+    private static final String SEPARATOR_PATTERN = "[/\\Q\\\\E]";
+
     /** ldif file extension used */
     private static final String LDIF_EXT = "ldif";
 
@@ -64,7 +67,7 @@ public class JarLdifSchemaLoader extends
 
     /** a map of all the resources in this jar */
     private static final Map<String, Boolean> RESOURCE_MAP = ResourceMap.getResources(
Pattern
-        .compile( ".*schema/ou=schema.*" ) );
+        .compile( ".*schema" + SEPARATOR_PATTERN + "ou=schema.*" ) );
 
 
     /**
@@ -107,10 +110,11 @@ public class JarLdifSchemaLoader extends
             LOG.debug( "Initializing schema" );
         }
 
+        Pattern pat = Pattern.compile( ".*schema" + SEPARATOR_PATTERN + "ou=schema"
+                + SEPARATOR_PATTERN + "cn=[a-z0-9-_]*\\." + LDIF_EXT );
+
         for ( String file : RESOURCE_MAP.keySet() )
         {
-            Pattern pat = Pattern.compile( ".*schema/ou=schema/cn=[a-z0-9-_]*\\." + LDIF_EXT
);
-
             if ( pat.matcher( file ).matches() )
             {
                 URL resource = getResource( file, "schema LDIF file" );
@@ -144,14 +148,15 @@ public class JarLdifSchemaLoader extends
 
 
     /**
-     * Utility method to get the path for a schema directory.
+     * Utility method to get a regex.Pattern fragment for the path for a schema directory.
      *
      * @param schema the schema to get the path for
-     * @return the path for the specific schema directory
+     * @return the regex.Pattern fragment for the path for the specified schema directory
      */
     private final String getSchemaDirectory( Schema schema )
     {
-        return "schema/ou=schema/cn=" + schema.getSchemaName();
+        return "schema" + SEPARATOR_PATTERN + "ou=schema" + SEPARATOR_PATTERN
+                        + "cn=" + schema.getSchemaName() + SEPARATOR_PATTERN;
     }
 
 
@@ -169,12 +174,11 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            String comparatorsDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.COMPARATORS_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.COMPARATORS_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + comparatorsDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "comparator LDIF file" );
@@ -205,12 +209,11 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            String syntaxCheckersDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.SYNTAX_CHECKERS_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.SYNTAX_CHECKERS_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + syntaxCheckersDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "syntaxChecker LDIF file" );
@@ -241,12 +244,11 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            String normalizersDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.NORMALIZERS_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.NORMALIZERS_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + normalizersDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "normalizer LDIF file" );
@@ -277,12 +279,11 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            String matchingRulesDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.MATCHING_RULES_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.MATCHING_RULES_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + matchingRulesDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "matchingRules LDIF file" );
@@ -313,12 +314,11 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            String syntaxesDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.SYNTAXES_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.SYNTAXES_PATH + SEPARATOR_PATTERN + "m-oid=.*\\." +
LDIF_EXT );
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + syntaxesDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "syntax LDIF file" );
@@ -350,13 +350,12 @@ public class JarLdifSchemaLoader extends
         for ( Schema schema : schemas )
         {
             // check that the attributeTypes directory exists for the schema
-            String attributeTypesDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.ATTRIBUTES_TYPE_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.ATTRIBUTES_TYPE_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
 
             // get list of attributeType LDIF schema files in attributeTypes
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + attributeTypesDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "attributeType LDIF file" );
@@ -387,13 +386,11 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            String matchingRuleUsesDirectory = getSchemaDirectory( schema ) + "/"
-                + SchemaConstants.MATCHING_RULE_USE_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.MATCHING_RULE_USE_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + matchingRuleUsesDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "matchingRuleUse LDIF file"
);
@@ -424,12 +421,11 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            String nameFormsDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.NAME_FORMS_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.NAME_FORMS_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + nameFormsDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "nameForm LDIF file" );
@@ -460,13 +456,11 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            String ditContentRulesDirectory = getSchemaDirectory( schema ) + "/"
-                + SchemaConstants.DIT_CONTENT_RULES_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.DIT_CONTENT_RULES_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + ditContentRulesDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "ditContentRule LDIF file"
);
@@ -497,13 +491,12 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            String ditStructureRulesDirectory = getSchemaDirectory( schema ) + "/"
-                + SchemaConstants.DIT_STRUCTURE_RULES_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.DIT_STRUCTURE_RULES_PATH
+                                                + SEPARATOR_PATTERN + "m-oid=.*\\." + LDIF_EXT
);
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + ditStructureRulesDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "ditStructureRule LDIF file"
);
@@ -535,12 +528,11 @@ public class JarLdifSchemaLoader extends
         for ( Schema schema : schemas )
         {
             // get objectClasses directory, check if exists, return if not
-            String objectClassesDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.OBJECT_CLASSES_PATH;
+            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
+                    + SchemaConstants.OBJECT_CLASSES_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                Pattern regex = Pattern.compile( ".*" + objectClassesDirectory + "/m-oid=.*\\."
+ LDIF_EXT );
-
                 if ( regex.matcher( resourcePath ).matches() )
                 {
                     URL resource = getResource( resourcePath, "objectClass LDIF file" );

Modified: directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SingleLdifSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SingleLdifSchemaLoader.java?rev=997052&r1=997051&r2=997052&view=diff
==============================================================================
--- directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SingleLdifSchemaLoader.java
(original)
+++ directory/shared/trunk/ldap-schema-loader/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SingleLdifSchemaLoader.java
Tue Sep 14 19:25:25 2010
@@ -49,6 +49,9 @@ import org.slf4j.LoggerFactory;
  */
 public class SingleLdifSchemaLoader extends AbstractSchemaLoader
 {
+    // java.util.regex.Pattern is immutable so only one instance is needed for all uses.
+    private static final Pattern SCHEMA_START_PATTERN = Pattern
+        .compile( "cn\\s*=\\s*[a-z0-9-_]*\\s*,\\s*ou\\s*=\\s*schema" );
 
     private static final Logger LOG = LoggerFactory.getLogger( SingleLdifSchemaLoader.class
);
 
@@ -85,8 +88,6 @@ public class SingleLdifSchemaLoader exte
 
     private void initializeSchemas( InputStream in ) throws Exception
     {
-        Pattern schemaStartPattern = Pattern.compile( "cn\\s*=\\s*[a-z0-9-_]*\\s*,\\s*ou\\s*=\\s*schema"
);
-
         LdifReader ldifReader = new LdifReader( in );
 
         Schema currentSchema = null;
@@ -96,7 +97,7 @@ public class SingleLdifSchemaLoader exte
             LdifEntry ldifEntry = ldifReader.next();
             String dn = ldifEntry.getDn().getName();
 
-            if ( schemaStartPattern.matcher( dn ).matches() )
+            if ( SCHEMA_START_PATTERN.matcher( dn ).matches() )
             {
                 Schema schema = getSchema( ldifEntry.getEntry() );
                 schemaMap.put( schema.getSchemaName(), schema );
@@ -116,7 +117,8 @@ public class SingleLdifSchemaLoader exte
     {
         for ( String scObjTypeRdn : schemaObjectTypeRdns )
         {
-            Pattern regex = Pattern.compile( "m-oid\\s*=\\s*[0-9\\.]*\\s*" + ",\\s*ou\\s*=\\s*"
+ scObjTypeRdn + "\\s*,\\s*cn\\s*=\\s*" + schemaName
+            Pattern regex = Pattern.compile( "m-oid\\s*=\\s*[0-9\\.]*\\s*" + ",\\s*ou\\s*=\\s*"
+ scObjTypeRdn
+                + "\\s*,\\s*cn\\s*=\\s*" + schemaName
                 + "\\s*,\\s*ou=schema\\s*", Pattern.CASE_INSENSITIVE );
 
             String dn = ldifEntry.getDn().getName();

Modified: directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java?rev=997052&r1=997051&r2=997052&view=diff
==============================================================================
--- directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java
(original)
+++ directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java
Tue Sep 14 19:25:25 2010
@@ -60,6 +60,9 @@ public class DefaultSchemaLdifExtractor 
 
     private static final Logger LOG = LoggerFactory.getLogger( DefaultSchemaLdifExtractor.class
);
 
+    // java.util.regex.Pattern is immutable so only one instance is needed for all uses.
+    private static final Pattern EXTRACT_PATTERN = Pattern.compile( ".*schema" + "[/\\Q\\\\E]"
+ "ou=schema.*\\.ldif" );
+
     private boolean extracted;
 
     private File outputDirectory;
@@ -145,8 +148,7 @@ public class DefaultSchemaLdifExtractor 
             throw new IOException( I18n.err( I18n.ERR_08001, schemaDirectory.getAbsolutePath()
) );
         }
 
-        Pattern pattern = Pattern.compile( ".*schema/ou=schema.*\\.ldif" );
-        Map<String, Boolean> list = ResourceMap.getResources( pattern );
+        Map<String, Boolean> list = ResourceMap.getResources( EXTRACT_PATTERN );
 
         for ( Entry<String, Boolean> entry : list.entrySet() )
         {



Mime
View raw message