maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r426403 - in /maven/repository-manager/trunk: maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/ maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/ maven-repository-reports-standard/s...
Date Fri, 28 Jul 2006 06:41:57 GMT
Author: brett
Date: Thu Jul 27 23:41:56 2006
New Revision: 426403

URL: http://svn.apache.org/viewvc?rev=426403&view=rev
Log:
[MNG-127] move other repoman code to use new indexer

Modified:
    maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml
    maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java
    maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java
    maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp

Modified: maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java?rev=426403&r1=426402&r2=426403&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java
(original)
+++ maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java
Thu Jul 27 23:41:56 2006
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.repository.configuration.Configuration;
 import org.apache.maven.repository.configuration.ConfigurationStore;
@@ -23,15 +24,15 @@
 import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory;
 import org.apache.maven.repository.discovery.ArtifactDiscoverer;
 import org.apache.maven.repository.discovery.DiscovererException;
-import org.apache.maven.repository.discovery.MetadataDiscoverer;
-import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
-import org.apache.maven.repository.indexing.MetadataRepositoryIndex;
-import org.apache.maven.repository.indexing.RepositoryIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
 import org.apache.maven.repository.indexing.RepositoryIndexException;
-import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
+import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -55,7 +56,7 @@
     /**
      * @plexus.requirement
      */
-    private RepositoryIndexingFactory indexFactory;
+    private RepositoryArtifactIndexFactory indexFactory;
 
     /**
      * @plexus.requirement
@@ -68,9 +69,9 @@
     private Map artifactDiscoverers;
 
     /**
-     * @plexus.requirement role="org.apache.maven.repository.discovery.MetadataDiscoverer"
+     * @plexus.requirement role-hint="standard"
      */
-    private Map metadataDiscoverers;
+    private RepositoryIndexRecordFactory recordFactory;
 
     public void execute()
         throws TaskExecutionException
@@ -112,15 +113,6 @@
                 getLogger().info( "Indexing " + artifacts.size() + " new artifacts" );
                 indexArtifact( artifacts, indexPath, defaultRepository );
             }
-
-            MetadataDiscoverer metadataDiscoverer = (MetadataDiscoverer) metadataDiscoverers.get(
layoutProperty );
-            List metadataList =
-                metadataDiscoverer.discoverMetadata( defaultRepository, "indexer", blacklistedPatterns
);
-            if ( !metadataList.isEmpty() )
-            {
-                getLogger().info( "Indexing " + metadataList.size() + " new metadata files"
);
-                indexMetadata( metadataList, indexPath, defaultRepository );
-            }
         }
         catch ( RepositoryIndexException e )
         {
@@ -153,8 +145,8 @@
         try
         {
             ArtifactRepository repository = repoFactory.createRepository( configuration );
-            RepositoryIndex artifactIndex = indexFactory.createArtifactRepositoryIndex( indexPath,
repository );
-            if ( !artifactIndex.indexExists() )
+            RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath,
repository );
+            if ( !artifactIndex.exists() )
             {
                 execute( configuration, indexPath );
             }
@@ -165,32 +157,16 @@
         }
     }
 
-    /**
-     * Index the artifacts in the list
-     *
-     * @param artifacts  the artifacts to be indexed
-     * @param indexPath  the path to the index file
-     * @param repository the repository where the artifacts are located
-     */
-    protected void indexArtifact( List artifacts, File indexPath, ArtifactRepository repository
)
+    private void indexArtifact( List artifacts, File indexPath, ArtifactRepository repository
)
         throws RepositoryIndexException
     {
-        ArtifactRepositoryIndex artifactIndex = indexFactory.createArtifactRepositoryIndex(
indexPath, repository );
-        artifactIndex.indexArtifacts( artifacts );
-        artifactIndex.optimize();
-    }
-
-    /**
-     * Index the metadata in the list
-     *
-     * @param metadataList the metadata to be indexed
-     * @param indexPath    the path to the index file
-     */
-    protected void indexMetadata( List metadataList, File indexPath, ArtifactRepository repository
)
-        throws RepositoryIndexException
-    {
-        MetadataRepositoryIndex metadataIndex = indexFactory.createMetadataRepositoryIndex(
indexPath, repository );
-        metadataIndex.indexMetadata( metadataList );
-        metadataIndex.optimize();
+        RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath,
repository );
+        List records = new ArrayList();
+        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+        {
+            Artifact a = (Artifact) i.next();
+            records.add( recordFactory.createRecord( a ) );
+        }
+        artifactIndex.indexRecords( records );
     }
 }

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java?rev=426403&r1=426402&r2=426403&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java
(original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java
Thu Jul 27 23:41:56 2006
@@ -133,21 +133,36 @@
                                              artifact.getRepository().pathOf( pomArtifact
) );
                     if ( pomFile.exists() )
                     {
-                        populatePomEntries( readPom( pomArtifact, artifact.getRepository()
), record );
+                        try
+                        {
+                            populatePomEntries( readPom( pomArtifact, artifact.getRepository()
), record );
+                        }
+                        catch ( ProjectBuildingException e )
+                        {
+                            getLogger().error( "Error reading POM file, not populating in
index: " + e.getMessage() );
+                        }
                     }
                 }
                 else
                 {
-                    Model model = readPom( artifact, artifact.getRepository() );
-
-                    if ( !"pom".equals( model.getPackaging() ) )
+                    Model model;
+                    try
                     {
-                        // Don't return a record for a POM that is does not belong on its
own
-                        record = null;
+                        model = readPom( artifact, artifact.getRepository() );
+
+                        if ( !"pom".equals( model.getPackaging() ) )
+                        {
+                            // Don't return a record for a POM that is does not belong on
its own
+                            record = null;
+                        }
+                        else
+                        {
+                            populatePomEntries( model, record );
+                        }
                     }
-                    else
+                    catch ( ProjectBuildingException e )
                     {
-                        populatePomEntries( model, record );
+                        getLogger().error( "Error reading POM file, not populating in index:
" + e.getMessage() );
                     }
                 }
             }
@@ -172,20 +187,11 @@
     }
 
     private Model readPom( Artifact artifact, ArtifactRepository repository )
-        throws RepositoryIndexException
+        throws RepositoryIndexException, ProjectBuildingException
     {
         // TODO: will this pollute with local repo metadata?
-        Model model;
-        try
-        {
-            MavenProject project = projectBuilder.buildFromRepository( artifact, Collections.EMPTY_LIST,
repository );
-            model = project.getModel();
-        }
-        catch ( ProjectBuildingException e )
-        {
-            throw new RepositoryIndexException( "Unable to read project: " + e.getMessage(),
e );
-        }
-        return model;
+        MavenProject project = projectBuilder.buildFromRepository( artifact, Collections.EMPTY_LIST,
repository );
+        return project.getModel();
     }
 
     private void populateArchiveEntries( List files, StandardArtifactIndexRecord record,
File artifactFile )

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java?rev=426403&r1=426402&r2=426403&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java
(original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java
Thu Jul 27 23:41:56 2006
@@ -16,25 +16,26 @@
  * limitations under the License.
  */
 
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.TermQuery;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Model;
 import org.apache.maven.repository.digest.Digester;
 import org.apache.maven.repository.digest.DigesterException;
-import org.apache.maven.repository.indexing.RepositoryIndex;
-import org.apache.maven.repository.indexing.RepositoryIndexException;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
-import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;
-import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
-import org.apache.maven.repository.indexing.SearchResult;
-import org.apache.maven.repository.indexing.query.SingleTermQuery;
+import org.apache.maven.repository.indexing.lucene.LuceneQuery;
+import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord;
+import org.apache.maven.repository.indexing.record.StandardIndexRecordFields;
 
 import java.io.File;
 import java.util.Iterator;
 import java.util.List;
 
 /**
- * Validates an artifact file for duplicates within the same groupId based from what's available
in a RepositoryIndex
+ * Validates an artifact file for duplicates within the same groupId based from what's available
in a repository index.
  *
  * @author Edwin Punzalan
  * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor"
role-hint="duplicate"
@@ -50,41 +51,25 @@
     /**
      * @plexus.requirement
      */
-    private RepositoryIndexingFactory indexFactory;
-
-    /**
-     * @plexus.requirement
-     */
-    private RepositoryIndexSearchLayer searchLayer;
+    private RepositoryArtifactIndexFactory indexFactory;
 
     /**
      * @plexus.configuration
      */
     private String indexDirectory;
 
-    //@todo configurable?
-    private String algorithm = RepositoryIndex.FLD_MD5;
-
     public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
                                  ArtifactRepository repository )
         throws ReportProcessorException
     {
         if ( artifact.getFile() != null )
         {
-            RepositoryIndex index;
-            try
-            {
-                index = indexFactory.createArtifactRepositoryIndex( new File( indexDirectory
), repository );
-            }
-            catch ( RepositoryIndexException e )
-            {
-                throw new ReportProcessorException( "Unable to create RepositoryIndex instance",
e );
-            }
+            RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory
), repository );
 
             String checksum;
             try
             {
-                checksum = digester.createChecksum( artifact.getFile(), algorithm );
+                checksum = digester.createChecksum( artifact.getFile(), Digester.MD5 );
             }
             catch ( DigesterException e )
             {
@@ -93,7 +78,8 @@
 
             try
             {
-                List results = searchLayer.searchAdvanced( new SingleTermQuery( algorithm,
checksum.trim() ), index );
+                List results = index.search( new LuceneQuery(
+                    new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase()
) ) ) );
 
                 if ( results.isEmpty() )
                 {
@@ -101,23 +87,20 @@
                 }
                 else
                 {
-                    String id = artifact.getId();
-
                     boolean hasDuplicates = false;
-                    for ( Iterator hits = results.iterator(); hits.hasNext(); )
+                    for ( Iterator i = results.iterator(); i.hasNext(); )
                     {
-                        SearchResult result = (SearchResult) hits.next();
-                        Artifact artifactMatch = result.getArtifact();
+                        StandardArtifactIndexRecord result = (StandardArtifactIndexRecord)
i.next();
 
                         //make sure it is not the same artifact
-                        if ( !id.equals( artifactMatch.getId() ) )
+                        if ( !result.getFilename().equals( repository.pathOf( artifact )
) )
                         {
                             //report only duplicates from the same groupId
                             String groupId = artifact.getGroupId();
-                            if ( groupId.equals( artifactMatch.getGroupId() ) )
+                            if ( groupId.equals( result.getGroupId() ) )
                             {
                                 hasDuplicates = true;
-                                reporter.addFailure( artifact, "Found duplicate for " + artifactMatch.getId()
);
+                                reporter.addFailure( artifact, "Found duplicate for " + artifact.getId()
);
                             }
                         }
                     }

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java?rev=426403&r1=426402&r2=426403&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java
(original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java
Thu Jul 27 23:41:56 2006
@@ -19,10 +19,13 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.model.Model;
-import org.apache.maven.repository.digest.Digester;
-import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
+import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
+import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
+import java.util.Collections;
 
 /**
  * @author Edwin Punzalan
@@ -47,37 +50,25 @@
     {
         super.setUp();
 
-        Digester digester = (Digester) lookup( Digester.ROLE );
-
         indexDirectory = getTestFile( "target/indexDirectory" );
-
-        if ( !indexDirectory.exists() )
-        {
-            indexDirectory.mkdirs();
-        }
+        FileUtils.deleteDirectory( indexDirectory );
 
         artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
         artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1",
"jar" );
         reporter = new MockArtifactReporter();
         model = new Model();
 
-        ArtifactRepositoryIndex index = new ArtifactRepositoryIndex( indexDirectory, repository,
digester );
-        index.indexArtifact( artifact );
-        index.optimize();
+        RepositoryArtifactIndexFactory factory =
+            (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE,
"lucene" );
 
-        processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate"
);
-    }
+        RepositoryArtifactIndex index = factory.createStandardIndex( indexDirectory, repository
);
 
-    protected void tearDown()
-        throws Exception
-    {
-        //FileUtils.deleteDirectory( indexDirectory );
+        RepositoryIndexRecordFactory recordFactory =
+            (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard"
);
 
-        processor = null;
-        model = null;
-        artifact = null;
-        reporter = null;
-        super.tearDown();
+        index.indexRecords( Collections.singletonList( recordFactory.createRecord( artifact
) ) );
+
+        processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate"
);
     }
 
     public void testNullArtifactFile()
@@ -139,10 +130,7 @@
         assertEquals( "Check no failures", 1, reporter.getFailures() );
     }
 
-    private Artifact createArtifact( String groupId,
-                                     String artifactId,
-                                     String baseVersion,
-                                     String version,
+    private Artifact createArtifact( String groupId, String artifactId, String baseVersion,
String version,
                                      String type )
     {
         Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version,
null, type );

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml?rev=426403&r1=426402&r2=426403&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml
(original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml
Thu Jul 27 23:41:56 2006
@@ -9,10 +9,7 @@
           <role>org.apache.maven.repository.digest.Digester</role>
         </requirement>
         <requirement>
-          <role>org.apache.maven.repository.indexing.RepositoryIndexingFactory</role>
-        </requirement>
-        <requirement>
-          <role>org.apache.maven.repository.indexing.RepositoryIndexSearchLayer</role>
+          <role>org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory</role>
         </requirement>
       </requirements>
       <configuration>

Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java?rev=426403&r1=426402&r2=426403&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java
(original)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java
Thu Jul 27 23:41:56 2006
@@ -17,30 +17,42 @@
  */
 
 import com.opensymphony.xwork.ActionSupport;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.TermQuery;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.repository.configuration.Configuration;
 import org.apache.maven.repository.configuration.ConfigurationStore;
 import org.apache.maven.repository.configuration.ConfigurationStoreException;
 import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory;
-import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
 import org.apache.maven.repository.indexing.RepositoryIndexException;
-import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;
-import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
+import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
+import org.apache.maven.repository.indexing.lucene.LuceneQuery;
+import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord;
+import org.apache.maven.repository.indexing.record.StandardIndexRecordFields;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.TreeMap;
+import java.util.TreeSet;
 
 /**
  * Browse the repository.
  *
- * @todo the tree part probably belongs in a browsing component, along with the methods currently
in the indexer
+ * @todo the tree part probably belongs in a browsing component, and the indexer could optimize
how it retrieves the terms rather than querying everything
  * @plexus.component role="com.opensymphony.xwork.Action" role-hint="browseAction"
  */
 public class BrowseAction
@@ -49,12 +61,7 @@
     /**
      * @plexus.requirement
      */
-    private RepositoryIndexingFactory factory;
-
-    /**
-     * @plexus.requirement
-     */
-    private RepositoryIndexSearchLayer searchLayer;
+    private RepositoryArtifactIndexFactory factory;
 
     /**
      * @plexus.requirement
@@ -79,11 +86,11 @@
     private List versions;
 
     public String browse()
-        throws ConfigurationStoreException, RepositoryIndexException, IOException
+        throws ConfigurationStoreException, RepositoryIndexException, IOException, RepositoryIndexSearchException
     {
-        ArtifactRepositoryIndex index = getIndex();
+        RepositoryArtifactIndex index = getIndex();
 
-        if ( !index.indexExists() )
+        if ( !index.exists() )
         {
             addActionError( "The repository is not yet indexed. Please wait, and then try
again." );
             return ERROR;
@@ -97,11 +104,11 @@
     }
 
     public String browseGroup()
-        throws ConfigurationStoreException, RepositoryIndexException, IOException
+        throws ConfigurationStoreException, RepositoryIndexException, IOException, RepositoryIndexSearchException
     {
-        ArtifactRepositoryIndex index = getIndex();
+        RepositoryArtifactIndex index = getIndex();
 
-        if ( !index.indexExists() )
+        if ( !index.exists() )
         {
             addActionError( "The repository is not yet indexed. Please wait, and then try
again." );
             return ERROR;
@@ -135,15 +142,26 @@
 
         this.groups = collateGroups( rootNode );
 
-        this.artifactIds = index.getArtifacts( groupId.replaceAll( GROUP_SEPARATOR, "." )
);
+        String groupId = this.groupId.replaceAll( GROUP_SEPARATOR, "." );
+        List records = index.search(
+            new LuceneQuery( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT,
groupId ) ) ) );
+
+        Set artifactIds = new HashSet();
+        for ( Iterator i = records.iterator(); i.hasNext(); )
+        {
+            StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next();
+            artifactIds.add( record.getArtifactId() );
+        }
+        this.artifactIds = new ArrayList( artifactIds );
+        Collections.sort( this.artifactIds );
 
         return SUCCESS;
     }
 
     public String browseArtifact()
-        throws ConfigurationStoreException, RepositoryIndexException, IOException
+        throws ConfigurationStoreException, RepositoryIndexException, IOException, RepositoryIndexSearchException
     {
-        ArtifactRepositoryIndex index = getIndex();
+        RepositoryArtifactIndex index = getIndex();
 
         if ( StringUtils.isEmpty( groupId ) )
         {
@@ -159,26 +177,51 @@
             return ERROR;
         }
 
-        versions = index.getVersions( groupId.replaceAll( GROUP_SEPARATOR, "." ), artifactId
);
+        String groupId = this.groupId.replaceAll( GROUP_SEPARATOR, "." );
+
+        BooleanQuery query = new BooleanQuery();
+        query.add( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, groupId
) ),
+                   BooleanClause.Occur.MUST );
+        query.add( new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, artifactId
) ),
+                   BooleanClause.Occur.MUST );
 
-        if ( versions.isEmpty() )
+        List records = index.search( new LuceneQuery( query ) );
+
+        if ( records.isEmpty() )
         {
             // TODO: i18n
             addActionError( "Could not find any artifacts with the given group and artifact
ID" );
             return ERROR;
         }
 
+        Set versions = new HashSet();
+        for ( Iterator i = records.iterator(); i.hasNext(); )
+        {
+            StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next();
+            versions.add( record.getVersion() );
+        }
+
+        this.versions = new ArrayList( versions );
+        Collections.sort( this.versions );
+
         return SUCCESS;
     }
 
-    private GroupTreeNode buildGroupTree( ArtifactRepositoryIndex index )
-        throws IOException
+    private GroupTreeNode buildGroupTree( RepositoryArtifactIndex index )
+        throws IOException, RepositoryIndexSearchException
     {
         // TODO: give action message if indexing is in progress
 
         // TODO: this will be inefficient over a very large number of artifacts, should be
cached
 
-        List groups = index.enumerateGroupIds();
+        List records = index.search( new LuceneQuery( new MatchAllDocsQuery() ) );
+
+        Set groups = new TreeSet();
+        for ( Iterator i = records.iterator(); i.hasNext(); )
+        {
+            StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next();
+            groups.add( record.getGroupId() );
+        }
 
         GroupTreeNode rootNode = new GroupTreeNode();
 
@@ -227,7 +270,7 @@
         return groups;
     }
 
-    private ArtifactRepositoryIndex getIndex()
+    private RepositoryArtifactIndex getIndex()
         throws ConfigurationStoreException, RepositoryIndexException
     {
         Configuration configuration = configurationStore.getConfigurationFromStore();
@@ -235,7 +278,7 @@
 
         ArtifactRepository repository = repositoryFactory.createRepository( configuration
);
 
-        return factory.createArtifactRepositoryIndex( indexPath, repository );
+        return factory.createStandardIndex( indexPath, repository );
     }
 
     public List getGroups()

Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java?rev=426403&r1=426402&r2=426403&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java
(original)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java
Thu Jul 27 23:41:56 2006
@@ -17,17 +17,22 @@
  */
 
 import com.opensymphony.xwork.ActionSupport;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.queryParser.MultiFieldQueryParser;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.TermQuery;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.repository.configuration.Configuration;
 import org.apache.maven.repository.configuration.ConfigurationStore;
 import org.apache.maven.repository.configuration.ConfigurationStoreException;
 import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory;
-import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
 import org.apache.maven.repository.indexing.RepositoryIndexException;
 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
-import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;
-import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
-import org.apache.maven.repository.indexing.query.SingleTermQuery;
+import org.apache.maven.repository.indexing.lucene.LuceneQuery;
+import org.apache.maven.repository.indexing.record.StandardIndexRecordFields;
 
 import java.io.File;
 import java.net.MalformedURLException;
@@ -59,12 +64,7 @@
     /**
      * @plexus.requirement
      */
-    private RepositoryIndexingFactory factory;
-
-    /**
-     * @plexus.requirement
-     */
-    private RepositoryIndexSearchLayer searchLayer;
+    private RepositoryArtifactIndexFactory factory;
 
     /**
      * @plexus.requirement
@@ -78,21 +78,27 @@
 
     public String quickSearch()
         throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException,
-        ConfigurationStoreException
+        ConfigurationStoreException, ParseException
     {
         // TODO: give action message if indexing is in progress
 
         assert q != null && q.length() != 0;
 
-        ArtifactRepositoryIndex index = getIndex();
+        RepositoryArtifactIndex index = getIndex();
 
-        if ( !index.indexExists() )
+        if ( !index.exists() )
         {
             addActionError( "The repository is not yet indexed. Please wait, and then try
again." );
             return ERROR;
         }
 
-        searchResults = searchLayer.searchGeneral( q, index );
+        // TODO! this is correct, but ugly
+        MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{StandardIndexRecordFields.GROUPID,
+            StandardIndexRecordFields.ARTIFACTID, StandardIndexRecordFields.BASE_VERSION,
+            StandardIndexRecordFields.CLASSIFIER, StandardIndexRecordFields.CLASSES, StandardIndexRecordFields.FILES,
+            StandardIndexRecordFields.TYPE, StandardIndexRecordFields.PROJECT_NAME,
+            StandardIndexRecordFields.PROJECT_DESCRIPTION}, new StandardAnalyzer() );
+        searchResults = index.search( new LuceneQuery( parser.parse( q ) ) );
 
         return SUCCESS;
     }
@@ -104,20 +110,21 @@
 
         assert md5 != null && md5.length() != 0;
 
-        ArtifactRepositoryIndex index = getIndex();
+        RepositoryArtifactIndex index = getIndex();
 
-        if ( !index.indexExists() )
+        if ( !index.exists() )
         {
             addActionError( "The repository is not yet indexed. Please wait, and then try
again." );
             return ERROR;
         }
 
-        searchResults = searchLayer.searchAdvanced( new SingleTermQuery( "md5", md5 ), index
);
+        searchResults = index.search(
+            new LuceneQuery( new TermQuery( new Term( StandardIndexRecordFields.MD5, md5.toLowerCase()
) ) ) );
 
         return SUCCESS;
     }
 
-    private ArtifactRepositoryIndex getIndex()
+    private RepositoryArtifactIndex getIndex()
         throws ConfigurationStoreException, RepositoryIndexException
     {
         Configuration configuration = configurationStore.getConfigurationFromStore();
@@ -125,7 +132,7 @@
 
         ArtifactRepository repository = repositoryFactory.createRepository( configuration
);
 
-        return factory.createArtifactRepositoryIndex( indexPath, repository );
+        return factory.createStandardIndex( indexPath, repository );
     }
 
     public String doInput()

Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp?rev=426403&r1=426402&r2=426403&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp
(original)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp
Thu Jul 27 23:41:56 2006
@@ -1,5 +1,3 @@
-<%@ taglib uri="/webwork" prefix="ww" %>
-<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 <%--
   ~ Copyright 2005-2006 The Apache Software Foundation.
   ~
@@ -16,6 +14,9 @@
   ~ limitations under the License.
   --%>
 
+<%@ taglib uri="/webwork" prefix="ww" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+
 <html>
 <head>
   <title>Search Results</title>
@@ -42,11 +43,17 @@
           --%>
         </tr>
         <ww:set name="searchResults" value="searchResults" />
-        <c:forEach items="${searchResults}" var="result" varStatus="i">
+        <c:forEach items="${searchResults}" var="record" varStatus="i">
           <tr class="${i.index % 2 == 0 ? "b" : "a"}">
-            <td><c:out value="${result.artifact.groupId}" /></td>
-            <td><c:out value="${result.artifact.artifactId}" /></td>
-            <td><c:out value="${result.artifact.version}" /></td>
+            <td>
+              <c:out value="${record.groupId}" />
+            </td>
+            <td>
+              <c:out value="${record.artifactId}" />
+            </td>
+            <td>
+              <c:out value="${record.version}" />
+            </td>
               <%-- TODO: hits
             <td>
               <table border="1px" width="100%" cellspacing="0">



Mime
View raw message