]> source.dussan.org Git - archiva.git/commitdiff
Added factory for ArtifactRepositoryIndex
authorEdwin L. Punzalan <epunzalan@apache.org>
Tue, 3 Jan 2006 09:34:00 +0000 (09:34 +0000)
committerEdwin L. Punzalan <epunzalan@apache.org>
Tue, 3 Jan 2006 09:34:00 +0000 (09:34 +0000)
Removed usage of src/test/index createTestIndex (renamed from testIndex() which gave the wrong impression) will create the index needed

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@365590 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java [new file with mode: 0644]
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java [new file with mode: 0644]
maven-repository-indexer/src/test/index/_2.cfs [deleted file]
maven-repository-indexer/src/test/index/_4.cfs [deleted file]
maven-repository-indexer/src/test/index/deletable [deleted file]
maven-repository-indexer/src/test/index/segments [deleted file]
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java

index 2815183a0f16f718125e8599c1f50e35e5b34a5e..12a3c7ef67946da9fdfd1d567e51c2cdd3f1a922 100644 (file)
@@ -18,7 +18,7 @@ package org.apache.maven.repository.indexing;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 
 import java.io.File;
 import java.io.IOException;
@@ -30,17 +30,18 @@ import java.util.Collection;
  * @author Edwin Punzalan
  */
 public abstract class AbstractRepositoryIndex
-    extends AbstractLogEnabled
     implements RepositoryIndex
 {
     private String indexPath;
-
+    
     private boolean indexOpen;
 
     private IndexReader indexReader;
 
     private IndexWriter indexWriter;
 
+    protected ArtifactRepository repository;
+
     /**
      * method to encapsulate the optimize() method for lucene
      */
@@ -103,7 +104,7 @@ public abstract class AbstractRepositoryIndex
     /**
      * method for opening the index directory for indexing operations
      */
-    public void open( String indexPath )
+    protected void open( String indexPath )
         throws RepositoryIndexException
     {
         try
@@ -169,13 +170,13 @@ public abstract class AbstractRepositoryIndex
             }
             else
             {
-                getLogger().info( "Skipping index field validations for empty index." );
+                //getLogger().info( "Skipping index field validations for empty index." );
             }
         }
         else if ( !indexDir.exists() )
         {
             indexWriter = new IndexWriter( indexPath, getAnalyzer(), true );
-            getLogger().info( "New index directory created in: " + indexDir.getAbsolutePath() );
+            //getLogger().info( "New index directory created in: " + indexDir.getAbsolutePath() );
         }
         else if ( indexDir.isDirectory() )
         {
index a75d58367ffd77e9f3c07ce1b22e7397fbae3ff0..115c989ef8f816884914637f1f3aacf15cbade06 100644 (file)
@@ -30,13 +30,13 @@ import java.util.Enumeration;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 
 
 /**
  * Class used to index Artifact objects in a specified repository
  *
  * @author Edwin Punzalan
- * @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndex" role-hint="artifact" instantiation-strategy="per-lookup"
  * @todo I think we should merge with Abstract*. Don't see that there'd be multiple implementations based on this
  * @todo I think we should instantiate this based on a repository from a factory instead of making it a component of its own
  */
@@ -65,9 +65,17 @@ public class ArtifactRepositoryIndex
 
     private Analyzer analyzer;
 
-    /** @plexus.requirement */
     private Digester digester;
 
+    public ArtifactRepositoryIndex( String indexPath, ArtifactRepository repository, Digester digester )
+        throws RepositoryIndexException
+    {
+        this.repository = repository;
+        this.digester = digester;
+        
+        open( indexPath );
+    }
+
     /**
      * method to get the Analyzer used to create indices
      *
index 91acdc9c9d74508edfe9241b7b502c650d860213..e245486196e6504fb703a7b144562d69bf0eb428 100644 (file)
@@ -84,6 +84,8 @@ public class ArtifactRepositoryIndexSearcher
 
                 artifactList.add( artifact );
             }
+
+            searcher.close();
         }
         catch ( IOException e )
         {
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java
new file mode 100644 (file)
index 0000000..92fa7a8
--- /dev/null
@@ -0,0 +1,44 @@
+package org.apache.maven.repository.indexing;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.repository.digest.Digester;
+
+/**
+ *
+ * @author Edwin Punzalan
+ * @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndexingFactory"
+ */
+public class DefaultRepositoryIndexingFactory
+    implements RepositoryIndexingFactory
+{
+    /** @plexus.requirement */
+    private Digester digester;
+    
+    public ArtifactRepositoryIndexSearcher createArtifactRepositoryIndexSearcher(ArtifactRepositoryIndex index)
+    {
+        return null;
+    }
+
+    public ArtifactRepositoryIndex createArtifactRepositoryIndex( String indexPath, ArtifactRepository repository )
+        throws RepositoryIndexException
+    {
+        return new ArtifactRepositoryIndex( indexPath, repository, digester );
+    }
+}
index 29b8bc5149e5844ca9427efa65bc698624218bb3..f8cac4d63f327d540aea7f80920f063da1666d86 100644 (file)
@@ -35,9 +35,9 @@ public interface RepositoryIndex
     void close()
         throws RepositoryIndexException;
 
-    void open( String indexPath )
+/*    void open( String indexPath )
         throws RepositoryIndexException;
-
+*/
     void optimize()
         throws RepositoryIndexException;
 
index e999a0c376fab23bb6f566e073ecf31282b77a3e..ac592818dc05251806e8ff648766070e6cd9f3a0 100644 (file)
@@ -32,24 +32,7 @@ public interface RepositoryIndexSearcher
      * @param index
      * @param queryString
      * @param searchField
-     
-    List search( RepositoryIndex index, String queryString, String searchField )
-        throws RepositoryIndexSearchException;
-    */
-
-    /**
-     *
      */
-    void addQuery( String queryField, String queryText );
-    
-    /**
-     *
-     */
-    void addQuery( String queryField, String queryText, boolean required );
-    
-    /**
-     * 
-     */
-    List search( RepositoryIndex index )
+    List search( RepositoryIndex index, String queryString, String searchField )
         throws RepositoryIndexSearchException;
 }
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java
new file mode 100644 (file)
index 0000000..5601ec9
--- /dev/null
@@ -0,0 +1,34 @@
+package org.apache.maven.repository.indexing;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.repository.digest.Digester;
+
+/**
+ *
+ * @author Edwin Punzalan
+ */
+public interface RepositoryIndexingFactory
+{
+    String ROLE = RepositoryIndexingFactory.class.getName();
+
+    ArtifactRepositoryIndexSearcher createArtifactRepositoryIndexSearcher( ArtifactRepositoryIndex index );
+    ArtifactRepositoryIndex createArtifactRepositoryIndex( String indexPath, ArtifactRepository repository )
+        throws RepositoryIndexException;
+}
diff --git a/maven-repository-indexer/src/test/index/_2.cfs b/maven-repository-indexer/src/test/index/_2.cfs
deleted file mode 100644 (file)
index f772f8e..0000000
Binary files a/maven-repository-indexer/src/test/index/_2.cfs and /dev/null differ
diff --git a/maven-repository-indexer/src/test/index/_4.cfs b/maven-repository-indexer/src/test/index/_4.cfs
deleted file mode 100644 (file)
index 348d8de..0000000
Binary files a/maven-repository-indexer/src/test/index/_4.cfs and /dev/null differ
diff --git a/maven-repository-indexer/src/test/index/deletable b/maven-repository-indexer/src/test/index/deletable
deleted file mode 100644 (file)
index e71c84c..0000000
Binary files a/maven-repository-indexer/src/test/index/deletable and /dev/null differ
diff --git a/maven-repository-indexer/src/test/index/segments b/maven-repository-indexer/src/test/index/segments
deleted file mode 100644 (file)
index 39fa60a..0000000
Binary files a/maven-repository-indexer/src/test/index/segments and /dev/null differ
index fef34439fefcf8f23eaea986a22b837a57bf4eee..5cf09fdab29cbe945a2e04feea2ceacb7ba14846 100644 (file)
@@ -63,19 +63,18 @@ public class ArtifactRepositoryIndexingTest
         repository = repoFactory.createArtifactRepository( "test", repoDir, layout, null, null );
 
         indexPath = "target/index";
-
-        FileUtils.deleteDirectory( indexPath );
     }
 
     public void testIndexerExceptions()
         throws Exception
     {
         ArtifactRepositoryIndex indexer;
+        RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+
         try
         {
             String notIndexDir = new File( "pom.xml" ).getAbsolutePath();
-            indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
-            indexer.open( notIndexDir );
+            indexer = factory.createArtifactRepositoryIndex( notIndexDir, repository );
             fail( "Must throw exception on non-directory index directory" );
         }
         catch ( RepositoryIndexException e )
@@ -86,8 +85,7 @@ public class ArtifactRepositoryIndexingTest
         try
         {
             String notIndexDir = new File( "" ).getAbsolutePath();
-            indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
-            indexer.open( notIndexDir );
+            indexer = factory.createArtifactRepositoryIndex( notIndexDir, repository );
             fail( "Must throw an exception on a non-index directory" );
         }
         catch ( RepositoryIndexException e )
@@ -95,12 +93,12 @@ public class ArtifactRepositoryIndexingTest
             //expected
         }
 
-        //indexer = (ArtifactRepositoryIndex) factory.getArtifactRepositoryIndexer( indexPath, repository );
-        //indexer.close();
-        indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
         Artifact artifact = getArtifact( "test", "test-artifactId", "1.0" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
 
+        indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
+        indexer.close();
+        
         try
         {
             indexer.indexArtifact( artifact );
@@ -121,7 +119,7 @@ public class ArtifactRepositoryIndexingTest
             //expected
         }
 
-        indexer.open( indexPath );
+        indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
 
         try
         {
@@ -136,12 +134,11 @@ public class ArtifactRepositoryIndexingTest
         indexer.close();
     }
 
-    public void testIndex()
+    public void createTestIndex()
         throws Exception
     {
-        //indexer = (ArtifactRepositoryIndex) factory.getArtifactRepositoryIndexer( indexPath, repository );
-        ArtifactRepositoryIndex indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
-        indexer.open( indexPath );
+        RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+        ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
 
         Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
@@ -151,23 +148,21 @@ public class ArtifactRepositoryIndexingTest
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
         indexer.indexArtifact( artifact );
 
-        indexer.optimize();
-        indexer.close();
-
-        indexer.open( indexPath );
         artifact = getArtifact( "test", "test-artifactId", "1.0" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
         indexer.index( artifact );
-        indexer.close();
 
-        // TODO: assert something!
+        indexer.optimize();
+        indexer.close();
     }
 
     public void testSearch()
         throws Exception
     {
-        ArtifactRepositoryIndex indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
-        indexer.open( getTestPath( "src/test/index" ) );
+        createTestIndex();
+
+        RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+        ArtifactRepositoryIndex indexer = indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
 
         RepositoryIndexSearcher repoSearcher =
             (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE, "artifact" );
@@ -198,6 +193,8 @@ public class ArtifactRepositoryIndexingTest
 
         artifacts = repoSearcher.search( indexer, "2", VERSION );
         assertEquals( 2, artifacts.size() );
+
+        indexer.close();
     }
 
     private Artifact getArtifact( String groupId, String artifactId, String version )
@@ -210,4 +207,13 @@ public class ArtifactRepositoryIndexingTest
 
         return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
     }
+
+    protected void tearDown()
+        throws Exception
+    {
+        repository = null;
+        FileUtils.deleteDirectory( indexPath );
+
+        super.tearDown();
+    }
 }