maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From epunza...@apache.org
Subject svn commit: r358530 - in /maven/repository-manager/trunk/maven-repository-indexer: ./ src/main/java/org/apache/maven/repository/indexing/ src/test/java/org/apache/maven/repository/indexing/
Date Thu, 22 Dec 2005 08:38:56 GMT
Author: epunzalan
Date: Thu Dec 22 00:38:32 2005
New Revision: 358530

URL: http://svn.apache.org/viewcvs?rev=358530&view=rev
Log:
More unit tests

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

Modified: maven/repository-manager/trunk/maven-repository-indexer/pom.xml
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/pom.xml?rev=358530&r1=358529&r2=358530&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/pom.xml (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/pom.xml Thu Dec 22 00:38:32 2005
@@ -26,6 +26,11 @@
     </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>
     </dependency>
     <dependency>

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java?rev=358530&r1=358529&r2=358530&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
(original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
Thu Dec 22 00:38:32 2005
@@ -17,6 +17,7 @@
  * limitations under the License.
  */
 
+import java.io.File;
 import java.io.IOException;
 import java.util.Collection;
 
@@ -110,7 +111,7 @@
     {
         if ( indexWriter == null )
         {
-            indexWriter = new IndexWriter( indexPath, getAnalyzer(), true );
+            indexWriter = new IndexWriter( indexPath, getAnalyzer(), false );
         }
     }
 
@@ -131,26 +132,56 @@
     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;
     }
 }

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java?rev=358530&r1=358529&r2=358530&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
(original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
Thu Dec 22 00:38:32 2005
@@ -180,7 +180,6 @@
         for ( Enumeration entries = jar.entries(); entries.hasMoreElements(); )
         {
             ZipEntry entry = (ZipEntry) entries.nextElement();
-            System.out.println( entry.getName() );
             if ( addIfClassEntry( entry ) )
             {
                 addClassPackage( entry.getName() );

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java?rev=358530&r1=358529&r2=358530&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java
(original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java
Thu Dec 22 00:38:32 2005
@@ -67,6 +67,24 @@
         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" );



Mime
View raw message