directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r893672 - /directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractor.java
Date Thu, 24 Dec 2009 01:12:47 GMT
Author: akarasulu
Date: Thu Dec 24 01:12:47 2009
New Revision: 893672

URL: http://svn.apache.org/viewvc?rev=893672&view=rev
Log:
added override to extract taking boolean parameter to overwrite schema LDIF file structure
or not - default behavior blows chunks since it presumes overwrites are not allowed

Modified:
    directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractor.java

Modified: directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractor.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractor.java?rev=893672&r1=893671&r2=893672&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractor.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractor.java
Thu Dec 24 01:12:47 2009
@@ -61,13 +61,14 @@
         this.outputDirectory = outputDirectory;
     }
 
-    
+
     /**
      * Extracts the LDIF files from a Jar file or copies exploded LDIF resources.
      *
-     * @throws IOException on IO errors
+     * @param overwrite over write extracted structure if true, false otherwise
+     * @throws IOException if schema already extracted and on IO errors
      */
-    public void extractOrCopy() throws IOException
+    public void extractOrCopy( boolean overwrite ) throws IOException
     {
         if ( ! outputDirectory.exists() )
         {
@@ -75,15 +76,20 @@
         }
 
         File schemaDirectory = new File( outputDirectory, "schema" );
-        
+
         if ( ! schemaDirectory.exists() )
         {
             schemaDirectory.mkdir();
         }
+        else if ( ! overwrite )
+        {
+            throw new IOException( "Cannot overwrite yet schema output directory already
exists: "
+                    + schemaDirectory.getAbsolutePath() );
+        }
 
         Pattern pattern = Pattern.compile( ".*schema/ou=schema.*\\.ldif" );
         Map<String,Boolean> list = ResourceMap.getResources( pattern );
-        
+
         for ( Entry<String,Boolean> entry : list.entrySet() )
         {
             if ( entry.getValue() )
@@ -100,6 +106,19 @@
     
     
     /**
+     * Extracts the LDIF files from a Jar file or copies exploded LDIF
+     * resources without overwriting the resources if the schema has
+     * already been extracted.
+     *
+     * @throws IOException if schema already extracted and on IO errors
+     */
+    public void extractOrCopy() throws IOException
+    {
+        extractOrCopy( false );
+    }
+    
+    
+    /**
      * Copies a file line by line from the source file argument to the 
      * destination file argument.
      *
@@ -124,7 +143,7 @@
         
         FileWriter out = new FileWriter( destination );
         BufferedReader in = new BufferedReader( new FileReader( source ) );
-        String line = null;
+        String line;
         while ( null != ( line = in.readLine() ) )
         {
             out.write( line + "\n" ); 
@@ -182,8 +201,8 @@
 
             fileComponentStack.push( parent.getName() );
             
-            if ( parent.equals( parent.getParentFile() ) 
-                || parent.getParentFile() == null )
+            if ( parent.equals( parent.getParentFile() )
+                    || parent.getParentFile() == null )
             {
                 throw new IllegalStateException( 
                     "Should not be hitting root without schema/schema pattern." );
@@ -191,7 +210,13 @@
             
             parent = parent.getParentFile();
         }
-        
+
+        /*
+
+           this seems retarded so I replaced it for now with what is below it
+           will not break from loop above unless parent == null so the if is
+           never executed - just the else is executed every time
+
         if ( parent != null )
         {
             return assembleDestinationFile( fileComponentStack );
@@ -200,6 +225,10 @@
         {
             throw new IllegalStateException( "parent cannot be null" );
         }
+        
+        */
+
+        throw new IllegalStateException( "parent cannot be null" );
     }
     
     
@@ -209,7 +238,7 @@
      * is not unique across all the jars.
      *
      * @param resourceName the file name of the resource to load
-     * @param resourceDescription
+     * @param resourceDescription human description of the resource
      * @return the InputStream to read the contents of the resource
      * @throws IOException if there are problems reading or finding a unique copy of the
resource
      */                                                                                 
              
@@ -261,6 +290,14 @@
         try
         {
         	File destination = new File( outputDirectory, resource );
+
+            /*
+             * Do not overwrite an LDIF file if it has already been extracted.
+             */
+            if ( destination.exists() )
+            {
+                return;
+            }
         	
         	if ( ! destination.getParentFile().exists() )
         	{



Mime
View raw message