directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r569056 - in /directory/apacheds/trunk/bootstrap-extract/src: main/java/org/apache/directory/server/schema/bootstrap/partition/ test/java/org/apache/directory/server/schema/bootstrap/partition/
Date Thu, 23 Aug 2007 16:09:07 GMT
Author: djencks
Date: Thu Aug 23 09:09:06 2007
New Revision: 569056

URL: http://svn.apache.org/viewvc?rev=569056&view=rev
Log:
better error messages when there's a problem with  bootstrap partition

Added:
    directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceException.java
  (with props)
Modified:
    directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
    directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java
    directory/apacheds/trunk/bootstrap-extract/src/test/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceTest.java

Modified: directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java?rev=569056&r1=569055&r2=569056&view=diff
==============================================================================
--- directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
(original)
+++ directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
Thu Aug 23 09:09:06 2007
@@ -79,7 +79,7 @@
 
         boolean userIndexMode = false;
         String line;
-        BufferedReader in = new BufferedReader( new InputStreamReader( getUniqueResourceAsStream(
"DBFILES" ) ) );
+        BufferedReader in = new BufferedReader( new InputStreamReader( getUniqueResourceAsStream(
"DBFILES", "bootstrap partition database file list.  Be sure there is exactly one bootstrap
partition jar in your classpath." ) ) );
         try
         {
             while ( ( line = in.readLine() ) != null )
@@ -119,34 +119,29 @@
      * is not unique across all the jars.
      *
      * @param resourceName the file name of the resource to load
+     * @param resourceDescription
      * @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
      */
-    public static InputStream getUniqueResourceAsStream( String resourceName ) throws IOException
+    public static InputStream getUniqueResourceAsStream( String resourceName, String resourceDescription
) throws IOException
     {
         resourceName = BASE_PATH + resourceName;
-        URL result = getUniqueResource( resourceName );      
+        URL result = getUniqueResource( resourceName, resourceDescription );
         return result.openStream();
     }
 
-    static URL getUniqueResource( String resourceName )
+    static URL getUniqueResource( String resourceName, String resourceDescription )
             throws IOException
     {
         Enumeration<URL> resources = DbFileListing.class.getClassLoader().getResources(
resourceName );
         if ( !resources.hasMoreElements() )
         {
-            throw new IllegalStateException( "No resource named " + resourceName );
+            throw new UniqueResourceException( resourceName, resourceDescription );
         }
         URL result = resources.nextElement();
         if ( resources.hasMoreElements() )
         {
-            StringBuffer buffer = new StringBuffer( "More than one resource named: " ).append(
resourceName );
-            buffer.append( result ).append( "\n" );
-            while ( resources.hasMoreElements() )
-            {
-                buffer.append( resources.nextElement() ).append( "\n" );
-            }
-            throw new IllegalStateException( buffer.toString() );
+            throw new UniqueResourceException( resourceName, result, resources, resourceDescription);
         }
         return result;
     }

Modified: directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java?rev=569056&r1=569055&r2=569056&view=diff
==============================================================================
--- directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java
(original)
+++ directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java
Thu Aug 23 09:09:06 2007
@@ -74,7 +74,7 @@
     private void extract( String resource ) throws IOException
     {
         byte[] buf = new byte[512];
-        InputStream in = DbFileListing.getUniqueResourceAsStream( resource );
+        InputStream in = DbFileListing.getUniqueResourceAsStream( resource, "database file
in bootstrap partition" );
 
         try
         {

Added: directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceException.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceException.java?rev=569056&view=auto
==============================================================================
--- directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceException.java
(added)
+++ directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceException.java
Thu Aug 23 09:09:06 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.directory.server.schema.bootstrap.partition;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class UniqueResourceException extends RuntimeException
+{
+
+    private final String resourceName;
+    private final List<URL> urls;
+    private final String resourceDescription;
+
+    public UniqueResourceException( String resourceName, String resourceDescription )
+    {
+        this( resourceName, null, resourceDescription );
+    }
+
+    public UniqueResourceException( String resourceName, List<URL> urls, String resourceDescription
)
+    {
+        this.resourceName = resourceName;
+        this.urls = urls;
+        this.resourceDescription = resourceDescription;
+    }
+
+    public UniqueResourceException( String resourceName, URL first, Enumeration<URL>
urlEnum, String resourceDescription )
+    {
+        this( resourceName, toList( first, urlEnum ), resourceDescription );
+    }
+
+    private static List<URL> toList( URL first, Enumeration<URL> urlEnum )
+    {
+        ArrayList<URL> urls = new ArrayList<URL>();
+        urls.add( first );
+        while( urlEnum.hasMoreElements() )
+        {
+            urls.add( urlEnum.nextElement() );
+        }
+        return urls;
+    }
+
+    public String getMessage()
+    {
+        StringBuffer buf = new StringBuffer( "Problem locating " ).append( resourceDescription
).append( "\n" );
+        if ( urls == null )
+        {
+            buf.append( "No resources named '" ).append( resourceName ).append( "' located
on classpath" );
+        } else
+        {
+            buf.append( "Multiple copies of resource named '" ).append( resourceName ).append(
+                    "' located on classpath at urls" );
+            for ( URL url : urls )
+            {
+                buf.append( "\n    " ).append( url );
+            }
+        }
+        return buf.toString();
+    }
+
+
+    public String getResourceName()
+    {
+        return resourceName;
+    }
+
+    public List<URL> getUrls()
+    {
+        return Collections.unmodifiableList( urls );
+    }
+}

Propchange: directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceException.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/apacheds/trunk/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/apacheds/trunk/bootstrap-extract/src/test/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/bootstrap-extract/src/test/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceTest.java?rev=569056&r1=569055&r2=569056&view=diff
==============================================================================
--- directory/apacheds/trunk/bootstrap-extract/src/test/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceTest.java
(original)
+++ directory/apacheds/trunk/bootstrap-extract/src/test/java/org/apache/directory/server/schema/bootstrap/partition/UniqueResourceTest.java
Thu Aug 23 09:09:06 2007
@@ -33,11 +33,11 @@
         //look for META-INF/LICENSE.txt which should be in at least two jars
         try
         {
-            DbFileListing.getUniqueResource( "META-INF/LICENSE.txt" );
+            DbFileListing.getUniqueResource( "META-INF/LICENSE", "foo" );
             fail( "There are at least 2 license files on the classpath, this should have
failed" );
-        } catch ( IllegalStateException e )
+        } catch ( UniqueResourceException e )
         {
-            //ignore
+            assertNotNull("There should be at least 2 LICENSE files on the classpath", e.getUrls());
         }
 
     }



Mime
View raw message