]> source.dussan.org Git - archiva.git/commitdiff
More unit tests
authorEdwin L. Punzalan <epunzalan@apache.org>
Thu, 22 Dec 2005 08:38:32 +0000 (08:38 +0000)
committerEdwin L. Punzalan <epunzalan@apache.org>
Thu, 22 Dec 2005 08:38:32 +0000 (08:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@358530 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-indexer/pom.xml
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java

index ba6eea9960529444753c7323d2c7a827871d0a2a..7d1fc5fd9e06773bcd152beb2769d0ca024de7d0 100644 (file)
       <artifactId>lucene</artifactId>
       <version>1.4.3</version>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-container-default</artifactId>
index 79ba90b25bc572f9301a9fb7f3b2c2201f155d1c..41f8494b43ddbbe8db1ca9f90721d64f596faf58 100644 (file)
@@ -17,6 +17,7 @@ package org.apache.maven.repository.indexing;
  * limitations under the License.
  */
 
+import java.io.File;
 import java.io.IOException;
 import java.util.Collection;
 
@@ -110,7 +111,7 @@ public abstract class AbstractRepositoryIndexer
     {
         if ( indexWriter == null )
         {
-            indexWriter = new IndexWriter( indexPath, getAnalyzer(), true );
+            indexWriter = new IndexWriter( indexPath, getAnalyzer(), false );
         }
     }
 
@@ -131,26 +132,56 @@ public abstract class AbstractRepositoryIndexer
     protected void validateIndex()
         throws RepositoryIndexerException
     {
-        indexOpen = true;
-        if ( true ) return;
-        try
+        File indexDir = new File( indexPath );
+        if ( indexDir.exists() )
         {
-            getIndexReader();
-            Collection fields = indexReader.getFieldNames();
-            String[] indexFields = getIndexFields();
-            for( int idx=0; idx<indexFields.length; idx++ )
+            if ( indexDir.isDirectory() )
             {
-                if ( !fields.contains( indexFields[ idx ] ) )
+                if ( indexDir.listFiles().length > 1 )
+                {
+                    try
+                    {
+                        getIndexReader();
+                        Collection fields = indexReader.getFieldNames();
+                        String[] indexFields = getIndexFields();
+                        for( int idx=0; idx<indexFields.length; idx++ )
+                        {
+                            if ( !fields.contains( indexFields[ idx ] ) )
+                            {
+                                throw new RepositoryIndexerException( "The Field " + indexFields[ idx ] + " does not exist in " +
+                                        "index path " + indexPath + "." );
+                            }
+                        }
+                    }
+                    catch ( IOException e )
+                    {
+                        throw new RepositoryIndexerException( e );
+                    }
+                }
+                else
                 {
-                    throw new RepositoryIndexerException( "The Field " + indexFields[ idx ] + " does not exist in " +
-                            "index path " + indexPath + "." );
+                    System.out.println( "Skipping validation of an empty index in: " + indexDir.getAbsolutePath() );
                 }
             }
-            indexOpen = true;
+            else
+            {
+                throw new RepositoryIndexerException( "Specified index path is not a directory: " + 
+                                                      indexDir.getAbsolutePath() );
+            }
         }
-        catch ( IOException e )
+        else
         {
-            throw new RepositoryIndexerException( e );
+            try
+            {
+                indexWriter = new IndexWriter( indexPath, getAnalyzer(), true );
+                System.out.println( "New index directory created in: " + indexDir.getAbsolutePath() );
+            }
+            catch( Exception e )
+            {
+                throw new RepositoryIndexerException( e );
+            }
         }
+
+        indexOpen = true;
     }
 }
index c8382945a9a0d777c75aea198673ebea9ea97e19..82708f8fc44d62165b1ff01158f9d500e5b1c386 100644 (file)
@@ -180,7 +180,6 @@ public class ArtifactRepositoryIndexer
         for ( Enumeration entries = jar.entries(); entries.hasMoreElements(); )
         {
             ZipEntry entry = (ZipEntry) entries.nextElement();
-            System.out.println( entry.getName() );
             if ( addIfClassEntry( entry ) )
             {
                 addClassPackage( entry.getName() );
index 0a5ded3915721f6a14a00fbbd07b845a960ceeaa..1bb2ddc4d8f1e0d41f5810d4d577ee5cbf7624de 100644 (file)
@@ -67,6 +67,24 @@ public class ArtifactRepositoryIndexingTest
         indexer.close();
     }
 
+    public void testIndexerExceptions()
+        throws Exception
+    {
+        //test closed index
+        try
+        {
+            indexer.close();
+            Artifact artifact = getArtifact( "test", "test-artifactId", "1.0" );
+            artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
+            indexer.addArtifactIndex( artifact );
+            fail( "Must throw exception on closed index." );
+        }
+        catch( RepositoryIndexerException e )
+        {
+            //expected
+        }
+    }
+
     protected Artifact getArtifact( String groupId, String artifactId, String version )
     {
         return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );