You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/01/03 10:35:09 UTC

svn commit: r365590 - in /maven/repository-manager/trunk/maven-repository-indexer/src: main/java/org/apache/maven/repository/indexing/ test/index/ test/java/org/apache/maven/repository/indexing/

Author: epunzalan
Date: Tue Jan  3 01:34:00 2006
New Revision: 365590

URL: http://svn.apache.org/viewcvs?rev=365590&view=rev
Log:
Added factory for ArtifactRepositoryIndex
Removed usage of src/test/index createTestIndex (renamed from testIndex() which gave the wrong impression) will create the index needed

Added:
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java   (with props)
Removed:
    maven/repository-manager/trunk/maven-repository-indexer/src/test/index/
Modified:
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.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/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java?rev=365590&r1=365589&r2=365590&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java Tue Jan  3 01:34:00 2006
@@ -18,7 +18,7 @@
 
 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 @@
  * @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 @@
     /**
      * 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 @@
             }
             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() )
         {

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java?rev=365590&r1=365589&r2=365590&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java Tue Jan  3 01:34:00 2006
@@ -30,13 +30,13 @@
 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,8 +65,16 @@
 
     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

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java?rev=365590&r1=365589&r2=365590&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java Tue Jan  3 01:34:00 2006
@@ -84,6 +84,8 @@
 
                 artifactList.add( artifact );
             }
+
+            searcher.close();
         }
         catch ( IOException e )
         {

Added: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java?rev=365590&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java Tue Jan  3 01:34:00 2006
@@ -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 );
+    }
+}

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java?rev=365590&r1=365589&r2=365590&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java Tue Jan  3 01:34:00 2006
@@ -35,9 +35,9 @@
     void close()
         throws RepositoryIndexException;
 
-    void open( String indexPath )
+/*    void open( String indexPath )
         throws RepositoryIndexException;
-
+*/
     void optimize()
         throws RepositoryIndexException;
 

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java?rev=365590&r1=365589&r2=365590&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java Tue Jan  3 01:34:00 2006
@@ -32,24 +32,7 @@
      * @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;
 }

Added: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java?rev=365590&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java Tue Jan  3 01:34:00 2006
@@ -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;
+}

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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=365590&r1=365589&r2=365590&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 Tue Jan  3 01:34:00 2006
@@ -63,19 +63,18 @@
         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 @@
         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 @@
             //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 @@
             //expected
         }
 
-        indexer.open( indexPath );
+        indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
 
         try
         {
@@ -136,12 +134,11 @@
         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 @@
         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 @@
 
         artifacts = repoSearcher.search( indexer, "2", VERSION );
         assertEquals( 2, artifacts.size() );
+
+        indexer.close();
     }
 
     private Artifact getArtifact( String groupId, String artifactId, String version )
@@ -209,5 +206,14 @@
         }
 
         return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
+    }
+
+    protected void tearDown()
+        throws Exception
+    {
+        repository = null;
+        FileUtils.deleteDirectory( indexPath );
+
+        super.tearDown();
     }
 }