archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1140232 - in /archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing: ./ src/main/java/org/apache/archiva/scheduler/indexing/ src/main/resources/META-INF/plexus/ src/test/java/org/apache/archiva/scheduler/indexing/
Date Mon, 27 Jun 2011 16:45:58 GMT
Author: olamy
Date: Mon Jun 27 16:45:57 2011
New Revision: 1140232

URL: http://svn.apache.org/viewvc?rev=1140232&view=rev
Log:
fix unit tests by using NexusIndexer facade to manipulate index datas : adding/removing artifacts

Removed:
    archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/resources/META-INF/plexus/components.xml
Modified:
    archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml
    archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
    archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
    archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java

Modified: archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml?rev=1140232&r1=1140231&r2=1140232&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml (original)
+++ archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml Mon
Jun 27 16:45:57 2011
@@ -23,6 +23,10 @@
       <artifactId>indexer-core</artifactId>
     </dependency>
     <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+    <dependency>
       <groupId>javax.inject</groupId>
       <artifactId>javax.inject</artifactId>
     </dependency>
@@ -39,5 +43,6 @@
       <artifactId>slf4j-simple</artifactId>
       <scope>test</scope>
     </dependency>
+
   </dependencies>
 </project>

Modified: archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java?rev=1140232&r1=1140231&r2=1140232&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
(original)
+++ archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
Mon Jun 27 16:45:57 2011
@@ -21,20 +21,20 @@ package org.apache.archiva.scheduler.ind
 
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.index.ArtifactContext;
 import org.apache.maven.index.ArtifactContextProducer;
-import org.apache.maven.index.ArtifactInfo;
 import org.apache.maven.index.DefaultArtifactContextProducer;
-import org.apache.maven.index.IndexerEngine;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.MAVEN;
 import org.apache.maven.index.NexusIndexer;
 import org.apache.maven.index.artifact.IllegalArtifactCoordinateException;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
+import org.apache.maven.index.expr.SourcedSearchExpression;
 import org.apache.maven.index.packer.IndexPacker;
 import org.apache.maven.index.packer.IndexPackingRequest;
 import org.codehaus.plexus.taskqueue.Task;
@@ -66,11 +66,6 @@ public class ArchivaIndexingTaskExecutor
     /**
      * plexus.requirement
      */
-    private IndexerEngine indexerEngine;
-
-    /**
-     * plexus.requirement
-     */
     private IndexPacker indexPacker;
 
     private ArtifactContextProducer artifactContextProducer;
@@ -88,15 +83,15 @@ public class ArchivaIndexingTaskExecutor
 
         artifactContextProducer = new DefaultArtifactContextProducer();
 
-        indexerEngine = plexusSisuBridge.lookup( IndexerEngine.class, "default" );
-
         indexPacker = plexusSisuBridge.lookup( IndexPacker.class, "default" );
+
+        nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
     }
 
     public void executeTask( Task task )
         throws TaskExecutionException
     {
-        synchronized ( indexerEngine )
+        synchronized ( nexusIndexer )
         {
             ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task;
 
@@ -116,8 +111,8 @@ public class ArchivaIndexingTaskExecutor
                 {
                     try
                     {
-                        log.debug(
-                            "Creating indexing context on resource: {}", indexingTask.getResourceFile().getPath()
);
+                        log.debug( "Creating indexing context on resource: {}",
+                                   indexingTask.getResourceFile().getPath() );
                         context = ArtifactIndexingTask.createContext( repository, nexusIndexer
);
                     }
                     catch ( IOException e )
@@ -146,35 +141,61 @@ public class ArchivaIndexingTaskExecutor
                     {
                         if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD
) )
                         {
-                            IndexSearcher s = context.getIndexSearcher();
-                            String uinfo = ac.getArtifactInfo().getUinfo();
-                            TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO,
uinfo ) ), 1 );
-                            if ( d.totalHits == 0 )
+                            //IndexSearcher s = context.getIndexSearcher();
+                            //String uinfo = ac.getArtifactInfo().getUinfo();
+                            //TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO,
uinfo ) ), 1 );
+
+                            BooleanQuery q = new BooleanQuery();
+                            q.add( nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression(
+                                ac.getArtifactInfo().groupId ) ), BooleanClause.Occur.MUST
);
+                            q.add( nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression(
+                                ac.getArtifactInfo().artifactId ) ), BooleanClause.Occur.MUST
);
+                            q.add( nexusIndexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
+                                ac.getArtifactInfo().version ) ), BooleanClause.Occur.MUST
);
+                            if (ac.getArtifactInfo().classifier != null)
+                            {
+                                q.add( nexusIndexer.constructQuery( MAVEN.CLASSIFIER, new
SourcedSearchExpression(
+                                    ac.getArtifactInfo().classifier ) ), BooleanClause.Occur.MUST
);
+                            }
+                            if (ac.getArtifactInfo().packaging != null)
+                            {
+                                q.add( nexusIndexer.constructQuery( MAVEN.PACKAGING, new
SourcedSearchExpression(
+                                    ac.getArtifactInfo().packaging ) ), BooleanClause.Occur.MUST
);
+                            }
+                            FlatSearchRequest flatSearchRequest = new FlatSearchRequest(
q, context );
+                            FlatSearchResponse flatSearchResponse = nexusIndexer.searchFlat(
flatSearchRequest );
+                            if ( flatSearchResponse.getResults().isEmpty() )
+                            //if ( d.totalHits == 0 )
                             {
                                 log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo()
);
-                                indexerEngine.index( context, ac );
-                                context.getIndexWriter().commit();
+                                //indexerEngine.index( context, ac );
+                                //context.getIndexWriter().commit();
+                                nexusIndexer.addArtifactToIndex( ac, context );
                             }
                             else
                             {
                                 log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo()
);
-                                indexerEngine.update( context, ac );
-                                context.getIndexWriter().commit();
+                                // TODO check if update exists !!
+                                nexusIndexer.deleteArtifactFromIndex( ac, context );
+                                nexusIndexer.addArtifactToIndex( ac, context );
                             }
 
+                            //nexusIndexer.scan( context, true );
+
+                            context.updateTimestamp();
+
                             // close the context if not a repo scan request
                             if ( !indexingTask.isExecuteOnEntireRepo() )
                             {
                                 log.debug( "Finishing indexing task on resource file : {}",
-                                               indexingTask.getResourceFile().getPath() );
+                                           indexingTask.getResourceFile().getPath() );
                                 finishIndexingTask( indexingTask, repository, context );
                             }
                         }
                         else
                         {
                             log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo()
);
-                            indexerEngine.remove( context, ac );
-                            context.getIndexWriter().commit();
+                            nexusIndexer.deleteArtifactFromIndex( ac, context );
                         }
                     }
                 }
@@ -217,6 +238,8 @@ public class ArchivaIndexingTaskExecutor
         }
         finally
         {
+            /*
+            olamy don't close it anymore as it nullify IndexSearcher
             if ( context != null )
             {
                 try
@@ -229,16 +252,10 @@ public class ArchivaIndexingTaskExecutor
                     throw new TaskExecutionException( "Error occurred while closing context:
" + e.getMessage() );
                 }
             }
+            */
         }
     }
 
-
-
-    public void setIndexerEngine( IndexerEngine indexerEngine )
-    {
-        this.indexerEngine = indexerEngine;
-    }
-
     public void setIndexPacker( IndexPacker indexPacker )
     {
         this.indexPacker = indexPacker;

Modified: archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java?rev=1140232&r1=1140231&r2=1140232&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
(original)
+++ archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
Mon Jun 27 16:45:57 2011
@@ -184,9 +184,6 @@ public class ArtifactIndexingTask
                                         managedRepository.toURI().toURL().toString(),
                                         indexDirectory.toURI().toURL().toString(), ArchivaNexusIndexerUtil.FULL_INDEX
);
 
-        //IndexingContext context =
-        //    new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository,
indexDirectory,
-        //                                null, null, ArchivaNexusIndexerUtil.FULL_INDEX,
false );
         context.setSearchable( repository.isScanned() );
         return context;
     }

Modified: archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java?rev=1140232&r1=1140231&r2=1140232&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
Mon Jun 27 16:45:57 2011
@@ -32,12 +32,11 @@ import org.apache.maven.archiva.configur
 import org.apache.maven.index.ArtifactInfo;
 import org.apache.maven.index.FlatSearchRequest;
 import org.apache.maven.index.FlatSearchResponse;
-import org.apache.maven.index.IndexerEngine;
 import org.apache.maven.index.MAVEN;
 import org.apache.maven.index.NexusIndexer;
 import org.apache.maven.index.context.IndexingContext;
+import org.apache.maven.index.expr.SourcedSearchExpression;
 import org.apache.maven.index.expr.StringSearchExpression;
-import org.apache.maven.index.packer.IndexPacker;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -68,18 +67,12 @@ public class ArchivaIndexingTaskExecutor
     @Inject
     private ArchivaIndexingTaskExecutor indexingExecutor;
 
-    private IndexerEngine indexerEngine;
-
-    private IndexPacker indexPacker;
-
     private ManagedRepositoryConfiguration repositoryConfig;
 
     private Configuration configuration;
 
     private NexusIndexer indexer;
 
-    private IndexingContext context;
-
     @Inject
     PlexusSisuBridge plexusSisuBridge;
 
@@ -89,10 +82,6 @@ public class ArchivaIndexingTaskExecutor
     {
         super.setUp();
 
-        //indexingExecutor = new ArchivaIndexingTaskExecutor();
-        //indexingExecutor.setPlexusSisuBridge( plexusSisuBridge );
-        indexingExecutor.initialize();
-
         repositoryConfig = new ManagedRepositoryConfiguration();
         repositoryConfig.setId( "test-repo" );
         repositoryConfig.setLocation( "target/test-classes/test-repo" );
@@ -106,25 +95,16 @@ public class ArchivaIndexingTaskExecutor
         configuration.addManagedRepository( repositoryConfig );
 
         indexer = plexusSisuBridge.lookup( NexusIndexer.class );
-        indexerEngine = plexusSisuBridge.lookup( IndexerEngine.class );
-        indexPacker = plexusSisuBridge.lookup( IndexPacker.class );
-
-        indexingExecutor.setIndexerEngine( indexerEngine );
-        indexingExecutor.setIndexPacker( indexPacker );
-
-        context = ArtifactIndexingTask.createContext( repositoryConfig, indexer );
-
 
+        ArtifactIndexingTask.createContext( repositoryConfig, indexer );
     }
 
     @After
     public void tearDown()
         throws Exception
     {
-        //context.close( true );
-        //indexer.removeIndexingContext( context, true );
 
-        for (IndexingContext indexingContext : indexer.getIndexingContexts().values())
+        for ( IndexingContext indexingContext : indexer.getIndexingContexts().values() )
         {
             indexer.removeIndexingContext( indexingContext, true );
         }
@@ -141,6 +121,11 @@ public class ArchivaIndexingTaskExecutor
         super.tearDown();
     }
 
+    protected IndexingContext getIndexingContext()
+    {
+        return indexer.getIndexingContexts().get( repositoryConfig.getId() );
+    }
+
     @Test
     public void testAddArtifactToIndex()
         throws Exception
@@ -149,7 +134,8 @@ public class ArchivaIndexingTaskExecutor
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar"
);
 
         ArtifactIndexingTask task =
-            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
context );
+            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+                                      getIndexingContext() );
 
         indexingExecutor.executeTask( task );
 
@@ -160,16 +146,16 @@ public class ArchivaIndexingTaskExecutor
             indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test"
) ),
             Occur.SHOULD );
 
-        if (!indexer.getIndexingContexts().containsKey( repositoryConfig.getId() ))
+        if ( !indexer.getIndexingContexts().containsKey( repositoryConfig.getId() ) )
         {
             IndexingContext context = indexer.addIndexingContext( repositoryConfig.getId(),
repositoryConfig.getId(),
-                                                              new File( repositoryConfig.getLocation()
),
-                                                              new File( repositoryConfig.getLocation(),
".indexer" ),
-                                                              null, null, ArchivaNexusIndexerUtil.FULL_INDEX
);
+                                                                  new File( repositoryConfig.getLocation()
),
+                                                                  new File( repositoryConfig.getLocation(),
+                                                                            ".indexer" ),
null, null,
+                                                                  ArchivaNexusIndexerUtil.FULL_INDEX
);
             context.setSearchable( true );
         }
 
-
         FlatSearchRequest request = new FlatSearchRequest( q );
         FlatSearchResponse response = indexer.searchFlat( request );
 
@@ -194,7 +180,8 @@ public class ArchivaIndexingTaskExecutor
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar"
);
 
         ArtifactIndexingTask task =
-            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
context );
+            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+                                      getIndexingContext() );
 
         indexingExecutor.executeTask( task );
         indexingExecutor.executeTask( task );
@@ -226,60 +213,55 @@ public class ArchivaIndexingTaskExecutor
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar"
);
 
         ArtifactIndexingTask task =
-            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
context );
+            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+                                      getIndexingContext() );
 
-        // remove artifact from index
+        // add artifact to index
         indexingExecutor.executeTask( task );
 
         BooleanQuery q = new BooleanQuery();
-        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva"
) ),
+        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva"
) ),
                Occur.SHOULD );
-        q.add(
-            indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test"
) ),
-            Occur.SHOULD );
+        //q.add(
+        //    indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( "archiva-index-methods-jar-test"
) ),
+        //    Occur.SHOULD );
 
-        IndexSearcher searcher = indexer.getIndexingContexts().get( repositoryConfig.getId()
).getIndexSearcher();
+        FlatSearchRequest flatSearchRequest =
+            new FlatSearchRequest( q, indexer.getIndexingContexts().get( repositoryConfig.getId()
) );
 
-        TopDocs topDocs = searcher.search( q, null, 10 );
-
-        searcher.close();
+        FlatSearchResponse response = indexer.searchFlat( flatSearchRequest );
 
         assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
         assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
 
         // should return 1 hit
-        assertEquals( 1, topDocs.totalHits );
-
-        searcher.close();
-
-        context = ArtifactIndexingTask.createContext( repositoryConfig, indexer );
+        assertEquals( 1, response.getTotalHitsCount() );
 
         // remove added artifact from index
-        task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE,
context );
+        task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE,
+                                         getIndexingContext() );
         indexingExecutor.executeTask( task );
 
-        task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
context );
+        task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
+                                         getIndexingContext() );
         indexingExecutor.executeTask( task );
 
         q = new BooleanQuery();
-        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva"
) ),
+        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva"
) ),
+               Occur.SHOULD );
+        q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID,
+                                       new SourcedSearchExpression( "archiva-index-methods-jar-test"
) ),
                Occur.SHOULD );
-        q.add(
-            indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test"
) ),
-            Occur.SHOULD );
-
-        searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher();
-
-        topDocs = searcher.search( q, null, 10 );
 
         assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
         assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
 
+        flatSearchRequest = new FlatSearchRequest( q, getIndexingContext() );
+
+        response = indexer.searchFlat( flatSearchRequest );
         // artifact should have been removed from the index!
-        assertEquals( 0, topDocs.totalHits );
+        assertEquals( 0, response.getTotalHitsCount() );//.totalHits );
 
-        context.close( true );
-        searcher.close();
         // TODO: test it was removed from the packaged index also
     }
 
@@ -291,11 +273,13 @@ public class ArchivaIndexingTaskExecutor
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar"
);
 
         ArtifactIndexingTask task =
-            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
context );
+            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+                                      getIndexingContext() );
 
         indexingExecutor.executeTask( task );
 
-        task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
context );
+        task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
+                                         getIndexingContext() );
 
         indexingExecutor.executeTask( task );
 



Mime
View raw message