]> source.dussan.org Git - archiva.git/commitdiff
Cleaning up indexing task
authorMartin Stockhammer <martin_s@apache.org>
Fri, 30 Mar 2018 15:33:03 +0000 (17:33 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Fri, 30 Mar 2018 15:33:54 +0000 (17:33 +0200)
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultIndexUpdateSideEffect.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTaskRequest.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/IndexingArchivaTaskScheduler.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTaskTest.java

index 03a95be75db1c8c982d98351c0e7c38e29b137a0..9a2babf04382ca35f505abd80d69b30ae9c9a4ee 100644 (file)
@@ -20,8 +20,6 @@ package org.apache.archiva.scheduler.indexing;
  * under the License.
  */
 
-import org.apache.archiva.admin.model.RepositoryAdminException;
-import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
 import org.apache.archiva.indexer.ArchivaIndexingContext;
 import org.apache.archiva.indexer.UnsupportedBaseContextException;
 import org.apache.archiva.redback.components.taskqueue.Task;
@@ -31,10 +29,15 @@ import org.apache.archiva.repository.ManagedRepository;
 import org.apache.archiva.repository.features.IndexCreationFeature;
 import org.apache.maven.index.ArtifactContext;
 import org.apache.maven.index.ArtifactContextProducer;
+import org.apache.maven.index.DefaultScannerListener;
 import org.apache.maven.index.FlatSearchRequest;
 import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.Indexer;
+import org.apache.maven.index.IndexerEngine;
 import org.apache.maven.index.MAVEN;
-import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.Scanner;
+import org.apache.maven.index.ScanningRequest;
+import org.apache.maven.index.ScanningResult;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index.expr.SourcedSearchExpression;
 import org.apache.maven.index.packer.IndexPacker;
@@ -67,8 +70,13 @@ public class ArchivaIndexingTaskExecutor
     private ArtifactContextProducer artifactContextProducer;
 
     @Inject
-    private NexusIndexer nexusIndexer;
+    private Indexer indexer;
 
+    @Inject
+    private Scanner scanner;
+
+    @Inject
+    IndexerEngine indexerEngine;
 
     /**
      * depending on current {@link Task} you have.
@@ -87,30 +95,40 @@ public class ArchivaIndexingTaskExecutor
         ManagedRepository repository = indexingTask.getRepository( );
         ArchivaIndexingContext archivaContext = indexingTask.getContext( );
         IndexingContext context = null;
-        try {
-            context = archivaContext.getBaseContext(IndexingContext.class);
-        } catch (UnsupportedBaseContextException e) {
-            throw new TaskExecutionException("Bad repository type.", e);
+        try
+        {
+            context = archivaContext.getBaseContext( IndexingContext.class );
         }
-        if (!nexusIndexer.getIndexingContexts().containsKey(context.getId())) {
-            nexusIndexer.addIndexingContext(context);
+        catch ( UnsupportedBaseContextException e )
+        {
+            throw new TaskExecutionException( "Bad repository type.", e );
         }
 
         if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction( ) )
             && indexingTask.isExecuteOnEntireRepo( ) )
         {
+            long start = System.currentTimeMillis( );
             try
             {
-                long start = System.currentTimeMillis( );
-                nexusIndexer.scan( context, null, indexingTask.isOnlyUpdate( ) );
-                long end = System.currentTimeMillis( );
-                log.info( "indexed maven repository: {}, onlyUpdate: {}, time {} ms", repository.getId( ),
-                    indexingTask.isOnlyUpdate( ), ( end - start ) );
+                context.updateTimestamp( );
+                DefaultScannerListener listener = new DefaultScannerListener( context, indexerEngine, true, null );
+                ScanningRequest request = new ScanningRequest( context, listener );
+                ScanningResult result = scanner.scan( request );
+                if ( result.hasExceptions( ) )
+                {
+                    log.error( "Exceptions occured during index scan of " + context.getId( ) );
+                    result.getExceptions( ).stream( ).map( e -> e.getMessage( ) ).distinct( ).limit( 5 ).forEach(
+                        s -> log.error( "Message: " + s )
+                    );
+                }
             }
             catch ( IOException e )
             {
-                throw new TaskExecutionException( "Error scan repository " + repository, e );
+                log.error( "Error during context scan {}: {}", context.getId( ), context.getIndexDirectory( ) );
             }
+            long end = System.currentTimeMillis( );
+            log.info( "indexed maven repository: {}, onlyUpdate: {}, time {} ms", repository.getId( ),
+                indexingTask.isOnlyUpdate( ), ( end - start ) );
             log.debug( "Finishing indexing task on repo: {}", repository.getId( ) );
             finishIndexingTask( indexingTask, repository, context );
         }
@@ -125,8 +143,8 @@ public class ArchivaIndexingTaskExecutor
                         ( indexingTask.getResourceFile( ) == null
                             ? "none"
                             : indexingTask.getResourceFile( ) ) );
-                    archivaContext = repository.getIndexingContext();
-                    context = archivaContext.getBaseContext(IndexingContext.class);
+                    archivaContext = repository.getIndexingContext( );
+                    context = archivaContext.getBaseContext( IndexingContext.class );
                 }
                 catch ( UnsupportedBaseContextException e )
                 {
@@ -167,36 +185,35 @@ public class ArchivaIndexingTaskExecutor
                             //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(
+                            BooleanQuery.Builder qb = new BooleanQuery.Builder();
+                            qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression(
                                 ac.getArtifactInfo( ).getGroupId( ) ) ), BooleanClause.Occur.MUST );
-                            q.add( nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression(
+                            qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression(
                                 ac.getArtifactInfo( ).getArtifactId( ) ) ), BooleanClause.Occur.MUST );
-                            q.add( nexusIndexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
+                            qb.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
                                 ac.getArtifactInfo( ).getVersion( ) ) ), BooleanClause.Occur.MUST );
                             if ( ac.getArtifactInfo( ).getClassifier( ) != null )
                             {
-                                q.add( nexusIndexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression(
+                                qb.add( indexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression(
                                     ac.getArtifactInfo( ).getClassifier( ) ) ), BooleanClause.Occur.MUST );
                             }
                             if ( ac.getArtifactInfo( ).getPackaging( ) != null )
                             {
-                                q.add( nexusIndexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression(
+                                qb.add( indexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression(
                                     ac.getArtifactInfo( ).getPackaging( ) ) ), BooleanClause.Occur.MUST );
                             }
-                            FlatSearchRequest flatSearchRequest = new FlatSearchRequest( q, context );
-                            FlatSearchResponse flatSearchResponse = nexusIndexer.searchFlat( flatSearchRequest );
+                            FlatSearchRequest flatSearchRequest = new FlatSearchRequest( qb.build(), context );
+                            FlatSearchResponse flatSearchResponse = indexer.searchFlat( flatSearchRequest );
                             if ( flatSearchResponse.getResults( ).isEmpty( ) )
                             {
                                 log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo( ) );
-                                nexusIndexer.addArtifactToIndex( ac, context );
+                                indexerEngine.index( context, ac );
                             }
                             else
                             {
                                 log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo( ) );
                                 // TODO check if update exists !!
-                                nexusIndexer.deleteArtifactFromIndex( ac, context );
-                                nexusIndexer.addArtifactToIndex( ac, context );
+                                indexerEngine.update( context, ac );
                             }
 
                             context.updateTimestamp( );
@@ -207,7 +224,7 @@ public class ArchivaIndexingTaskExecutor
                         else
                         {
                             log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo( ) );
-                            nexusIndexer.deleteArtifactFromIndex( ac, context );
+                            indexerEngine.remove( context, ac );
                         }
                     }
                 }
@@ -238,26 +255,28 @@ public class ArchivaIndexingTaskExecutor
         try
         {
 
-            log.debug("Finishing indexing");
+            log.debug( "Finishing indexing" );
             context.optimize( );
 
             if ( repository.supportsFeature( IndexCreationFeature.class ) )
             {
                 IndexCreationFeature icf = repository.getFeature( IndexCreationFeature.class ).get( );
-                if ( !icf.isSkipPackedIndexCreation( ) && icf.getLocalPackedIndexPath()!=null)
+                if ( !icf.isSkipPackedIndexCreation( ) && icf.getLocalPackedIndexPath( ) != null )
                 {
 
-                    log.debug("Creating packed index from {} on {}", context.getIndexDirectoryFile(), icf.getLocalPackedIndexPath());
+                    log.debug( "Creating packed index from {} on {}", context.getIndexDirectoryFile( ), icf.getLocalPackedIndexPath( ) );
                     IndexPackingRequest request = new IndexPackingRequest( context, //
                         context.acquireIndexSearcher( ).getIndexReader( ),
                         //
-                        icf.getLocalPackedIndexPath().toFile() );
+                        icf.getLocalPackedIndexPath( ).toFile( ) );
 
                     indexPacker.packIndex( request );
                     context.updateTimestamp( true );
 
-                    log.debug( "Index file packed at '{}'.", icf.getLocalPackedIndexPath() );
-                } else {
+                    log.debug( "Index file packed at '{}'.", icf.getLocalPackedIndexPath( ) );
+                }
+                else
+                {
                     log.debug( "skip packed index creation" );
                 }
             }
index d5da807d9ef116a8a8dd7a53a6e7679437b0d8e8..4bf089196ac2379018123b217446d2b5641bbf0d 100644 (file)
@@ -21,8 +21,6 @@ package org.apache.archiva.scheduler.indexing;
 import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.NetworkProxy;
 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
-import org.apache.archiva.common.ArchivaException;
-import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.configuration.ConfigurationEvent;
 import org.apache.archiva.configuration.ConfigurationListener;
@@ -32,7 +30,6 @@ import org.apache.archiva.repository.RepositoryRegistry;
 import org.apache.archiva.repository.features.RemoteIndexFeature;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.index.context.IndexingContext;
-import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
 import org.apache.maven.index.packer.IndexPacker;
 import org.apache.maven.index.updater.IndexUpdater;
 import org.slf4j.Logger;
@@ -44,7 +41,6 @@ import org.springframework.stereotype.Service;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.io.IOException;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
index 0dcadd9d78dac65740f7a86ab92dda36de7847a3..e1e28517cbe1067323ef48db9902e38dbb365d97 100644 (file)
@@ -20,8 +20,8 @@ package org.apache.archiva.scheduler.indexing;
  */
 
 import org.apache.maven.index.context.IndexingContext;
-import org.apache.maven.index_shaded.lucene.store.Directory;
 import org.apache.maven.index.updater.IndexUpdateSideEffect;
+import org.apache.maven.index_shaded.lucene.store.Directory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
index 63c8b5e0d73d293d0044b76de8065edde3604b9d..1563e127be4c58724399a05873fd12e1b47dbfbc 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.scheduler.indexing;
  */
 
 import org.apache.archiva.admin.model.beans.NetworkProxy;
-import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
 import org.apache.archiva.proxy.common.WagonFactory;
 import org.apache.archiva.proxy.common.WagonFactoryRequest;
 import org.apache.archiva.repository.PasswordCredentials;
@@ -28,7 +27,6 @@ import org.apache.archiva.repository.RepositoryException;
 import org.apache.archiva.repository.RepositoryType;
 import org.apache.archiva.repository.features.RemoteIndexFeature;
 import org.apache.commons.lang.time.StopWatch;
-import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index.updater.IndexUpdateRequest;
 import org.apache.maven.index.updater.IndexUpdateResult;
@@ -54,7 +52,6 @@ import org.slf4j.LoggerFactory;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
index 9c5223c7a51181e93fc4b90a9f8f5777e7f8f308..dce7215d80f0c24360dcbb18942a65ca8a26082f 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.scheduler.indexing;
  */
 
 import org.apache.archiva.admin.model.beans.NetworkProxy;
-import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
 import org.apache.archiva.proxy.common.WagonFactory;
 import org.apache.archiva.repository.RemoteRepository;
 import org.apache.maven.index.packer.IndexPacker;
index c53410aa0825aac097e6aeaaa1f8429d5d013b58..3d658107b9002f3e1761b7a61fd1de344e41b5e6 100644 (file)
@@ -19,9 +19,9 @@ package org.apache.archiva.scheduler.indexing;
  * under the License.
  */
 
-import org.apache.archiva.scheduler.ArchivaTaskScheduler;
 import org.apache.archiva.redback.components.taskqueue.TaskQueue;
 import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
+import org.apache.archiva.scheduler.ArchivaTaskScheduler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
index aba76b7ae8d50aa0175606651ee028307e4984ef..674d09783684b60842f90fc6659b4e16d85efebb 100644 (file)
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
-       xmlns:task="http://www.springframework.org/schema/task"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context
-           http://www.springframework.org/schema/context/spring-context-3.0.xsd
-           http://www.springframework.org/schema/task
-           http://www.springframework.org/schema/task/spring-task-3.0.xsd"
+           http://www.springframework.org/schema/context/spring-context-3.0.xsd"
        default-lazy-init="false">
 
   <context:annotation-config/>
-  <context:component-scan base-package="org.apache.archiva.scheduler.indexing"/>
-
-  <bean id="logger" class="org.apache.archiva.common.utils.Slf4JPlexusLogger">
-    <constructor-arg type="java.lang.Class">
-      <value>org.apache.maven.index.DefaultNexusIndexer</value>
-    </constructor-arg>
-  </bean>
+  <context:component-scan base-package="org.apache.archiva.scheduler.indexing,org.apache.maven.index"/>
 
   <bean name="taskQueue#indexing" class="org.apache.archiva.redback.components.taskqueue.DefaultTaskQueue"/>
 
index 2cc9af6fa324e2a75b20c84e9e29eadf4ddd60c5..719a19aa12f870127cc428b7458b1b911409d454 100644 (file)
@@ -20,19 +20,19 @@ package org.apache.archiva.scheduler.indexing;
  */
 
 import junit.framework.TestCase;
-import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
-import org.apache.archiva.common.utils.PathUtil;
 import org.apache.archiva.indexer.ArchivaIndexingContext;
 import org.apache.archiva.indexer.UnsupportedBaseContextException;
-import org.apache.archiva.repository.*;
-import org.apache.archiva.repository.features.ArtifactCleanupFeature;
+import org.apache.archiva.repository.BasicManagedRepository;
+import org.apache.archiva.repository.ManagedRepository;
+import org.apache.archiva.repository.ReleaseScheme;
+import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.features.IndexCreationFeature;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.maven.index.ArtifactInfo;
 import org.apache.maven.index.FlatSearchRequest;
 import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.Indexer;
 import org.apache.maven.index.MAVEN;
-import org.apache.maven.index.NexusIndexer;
-import org.apache.maven.index.context.IndexCreator;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index.expr.SourcedSearchExpression;
 import org.apache.maven.index.expr.StringSearchExpression;
@@ -55,9 +55,6 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
 import java.util.Set;
 
 /**
@@ -71,17 +68,17 @@ public class ArchivaIndexingTaskExecutorTest
     @Inject
     private ArchivaIndexingTaskExecutor indexingExecutor;
 
-    private BasicManagedRepository repositoryConfig;
-
-    @Inject
-    private NexusIndexer indexer;
-
     @Inject
     RepositoryRegistry repositoryRegistry;
 
     @Inject
     private IndexUpdater indexUpdater;
 
+    private ManagedRepository repo;
+
+    @Inject
+    private Indexer indexer;
+
     @Before
     @Override
     public void setUp()
@@ -90,7 +87,7 @@ public class ArchivaIndexingTaskExecutorTest
         super.setUp();
 
         Path baseDir = Paths.get(System.getProperty("basedir"), "target/test-classes").toAbsolutePath();
-        repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", baseDir);
+        BasicManagedRepository repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", baseDir);
         Path repoLocation = baseDir.resolve("test-repo" );
         repositoryConfig.setLocation(repoLocation.toUri() );
         repositoryConfig.setLayout( "default" );
@@ -98,6 +95,7 @@ public class ArchivaIndexingTaskExecutorTest
         repositoryConfig.addActiveReleaseScheme( ReleaseScheme.RELEASE );
         repositoryConfig.removeActiveReleaseScheme( ReleaseScheme.SNAPSHOT );
         repositoryRegistry.putRepository(repositoryConfig);
+        repo = repositoryRegistry.getManagedRepository( repositoryConfig.getId() );
     }
 
     @After
@@ -106,10 +104,6 @@ public class ArchivaIndexingTaskExecutorTest
         throws Exception
     {
 
-        for ( IndexingContext indexingContext : indexer.getIndexingContexts().values() )
-        {
-            indexer.removeIndexingContext( indexingContext, true );
-        }
         repositoryRegistry.destroy();
         /*
         removeIndexingContext with true cleanup files.
@@ -126,7 +120,6 @@ public class ArchivaIndexingTaskExecutorTest
     }
 
     protected IndexingContext getIndexingContext() throws UnsupportedBaseContextException {
-        Repository repo = repositoryRegistry.getRepository(repositoryConfig.getId());
         assert repo != null;
         ArchivaIndexingContext ctx = repo.getIndexingContext();
         assert ctx != null;
@@ -137,26 +130,29 @@ public class ArchivaIndexingTaskExecutorTest
     public void testAddArtifactToIndex()
         throws Exception
     {
-        Path basePath = PathUtil.getPathFromUri( repositoryConfig.getLocation() );
+        Path basePath = repo.getLocalPath();
         Path artifactFile = basePath.resolve(
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
 
-        ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryConfig.getId());
         ArtifactIndexingTask task =
-            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+            new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.ADD,
                                       repo.getIndexingContext());
 
         indexingExecutor.executeTask( task );
 
-        Map<String, IndexingContext> ctxs = indexer.getIndexingContexts();
-        BooleanQuery q = new BooleanQuery();
-        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
+        task = new ArtifactIndexingTask( repo, null, ArtifactIndexingTask.Action.FINISH,
+            repo.getIndexingContext() );
+        indexingExecutor.executeTask( task );
+
+        BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder( );
+        queryBuilder.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
                BooleanClause.Occur.SHOULD );
-        q.add(
+        queryBuilder.add(
             indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
             BooleanClause.Occur.SHOULD );
+        BooleanQuery q = queryBuilder.build();
 
-        FlatSearchRequest request = new FlatSearchRequest( q );
+        FlatSearchRequest request = new FlatSearchRequest( q , getIndexingContext());
         FlatSearchResponse response = indexer.searchFlat( request );
 
         assertTrue( Files.exists(basePath.resolve( ".indexer" )) );
@@ -176,29 +172,28 @@ public class ArchivaIndexingTaskExecutorTest
     public void testUpdateArtifactInIndex()
         throws Exception
     {
-        Path basePath = PathUtil.getPathFromUri( repositoryConfig.getLocation( ) );
+        Path basePath = repo.getLocalPath();
         Path artifactFile = basePath.resolve(
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
 
-        ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryConfig.getId());
         ArtifactIndexingTask task =
-            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+            new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.ADD,
                                       repo.getIndexingContext() );
 
         indexingExecutor.executeTask( task );
         indexingExecutor.executeTask( task );
 
-        BooleanQuery q = new BooleanQuery();
-        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
+        BooleanQuery.Builder qb = new BooleanQuery.Builder();
+        qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
                BooleanClause.Occur.SHOULD );
-        q.add(
+        qb.add(
             indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
             BooleanClause.Occur.SHOULD );
 
         IndexingContext ctx = getIndexingContext();
 
         IndexSearcher searcher = ctx.acquireIndexSearcher();
-        TopDocs topDocs = searcher.search( q, null, 10 );
+        TopDocs topDocs = searcher.search( qb.build(), 10 );
 
         //searcher.close();
         ctx.releaseIndexSearcher( searcher );
@@ -214,27 +209,27 @@ public class ArchivaIndexingTaskExecutorTest
     public void testRemoveArtifactFromIndex()
         throws Exception
     {
-        Path basePath = PathUtil.getPathFromUri( repositoryConfig.getLocation( ) );
+        Path basePath = repo.getLocalPath();
         Path artifactFile = basePath.resolve(
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
 
-        ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryConfig.getId());
         ArtifactIndexingTask task =
-            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+            new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.ADD,
                                       repo.getIndexingContext() );
 
         // add artifact to index
         indexingExecutor.executeTask( task );
 
-        BooleanQuery q = new BooleanQuery();
-        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva" ) ),
+        BooleanQuery.Builder qb = new BooleanQuery.Builder();
+        qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva" ) ),
                BooleanClause.Occur.SHOULD );
         //q.add(
         //    indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ),
         //    Occur.SHOULD );
 
+        IndexingContext ctx = repo.getIndexingContext( ).getBaseContext( IndexingContext.class );
         FlatSearchRequest flatSearchRequest =
-            new FlatSearchRequest( q, indexer.getIndexingContexts().get( repositoryConfig.getId() ) );
+            new FlatSearchRequest( qb.build(), ctx );
 
         FlatSearchResponse response = indexer.searchFlat( flatSearchRequest );
 
@@ -245,25 +240,25 @@ public class ArchivaIndexingTaskExecutorTest
         assertEquals( 1, response.getTotalHitsCount() );
 
         // remove added artifact from index
-        task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE,
+        task = new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.DELETE,
                         repo.getIndexingContext());
         indexingExecutor.executeTask( task );
 
-        task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
+        task = new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.FINISH,
                                          repo.getIndexingContext() );
         indexingExecutor.executeTask( task );
 
-        q = new BooleanQuery();
-        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva" ) ),
+        qb = new BooleanQuery.Builder();
+        qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva" ) ),
                BooleanClause.Occur.SHOULD );
-        q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID,
+        qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID,
                                        new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ),
                BooleanClause.Occur.SHOULD );
 
         assertTrue( Files.exists(basePath.resolve( ".indexer" )) );
         assertTrue( Files.exists(basePath.resolve(".index" )) );
 
-        flatSearchRequest = new FlatSearchRequest( q, getIndexingContext() );
+        flatSearchRequest = new FlatSearchRequest( qb.build(), getIndexingContext() );
 
         response = indexer.searchFlat( flatSearchRequest );
         // artifact should have been removed from the index!
@@ -277,14 +272,17 @@ public class ArchivaIndexingTaskExecutorTest
         throws Exception
     {
 
-        Path basePath = PathUtil.getPathFromUri( repositoryConfig.getLocation());
-        Path indexDirectory = basePath.resolve(".index");
+        Path basePath = repo.getLocalPath();
+        IndexCreationFeature icf = repo.getFeature( IndexCreationFeature.class ).get();
+        Path packedIndexDirectory = icf.getLocalPackedIndexPath();
+        Path indexerDirectory = icf.getLocalIndexPath();
 
-        Files.list(indexDirectory).filter( path -> path.getFileName().toString().startsWith("nexus-maven-repository-index") )
+        Files.list(packedIndexDirectory).filter( path -> path.getFileName().toString().startsWith("nexus-maven-repository-index") )
             .forEach( path ->
             {
                 try
                 {
+                    System.err.println("Deleting "+path);
                     Files.delete( path );
                 }
                 catch ( IOException e )
@@ -296,48 +294,49 @@ public class ArchivaIndexingTaskExecutorTest
 
         Path artifactFile = basePath.resolve(
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
-        ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryConfig.getId());
         ArtifactIndexingTask task =
-            new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+            new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.ADD,
                                       repo.getIndexingContext() );
         task.setExecuteOnEntireRepo( false );
 
         indexingExecutor.executeTask( task );
 
-        task = new ArtifactIndexingTask( repositoryConfig, null, ArtifactIndexingTask.Action.FINISH,
+        task = new ArtifactIndexingTask( repo, null, ArtifactIndexingTask.Action.FINISH,
                                          repo.getIndexingContext() );
 
         task.setExecuteOnEntireRepo( false );
 
         indexingExecutor.executeTask( task );
 
-        assertTrue( Files.exists(indexDirectory) );
+        assertTrue( Files.exists(packedIndexDirectory) );
+        assertTrue( Files.exists(indexerDirectory) );
 
         // test packed index file creation
         //no more zip
         //Assertions.assertThat(new File( indexerDirectory, "nexus-maven-repository-index.zip" )).exists();
-        Assertions.assertThat( Files.exists(indexDirectory.resolve("nexus-maven-repository-index.properties" ) ));
-        Assertions.assertThat( Files.exists(indexDirectory.resolve("nexus-maven-repository-index.gz" ) ));
+        Assertions.assertThat( Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.properties" ) ));
+        Assertions.assertThat( Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.gz" ) ));
+        assertFalse( Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.1.gz" )  ));
 
         // unpack .zip index
-        Path destDir = basePath.resolve( ".index/tmp" );
         //unzipIndex( indexerDirectory.getPath(), destDir.getPath() );
 
-        DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher( indexDirectory.toFile() );
+        DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher( packedIndexDirectory.toFile() );
         IndexUpdateRequest updateRequest = new IndexUpdateRequest( getIndexingContext(), fetcher );
         //updateRequest.setLocalIndexCacheDir( indexerDirectory );
         indexUpdater.fetchAndUpdateIndex( updateRequest );
 
-        BooleanQuery q = new BooleanQuery();
-        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
+        BooleanQuery.Builder qb = new BooleanQuery.Builder();
+        qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
                BooleanClause.Occur.SHOULD );
-        q.add(
+        qb.add(
             indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
             BooleanClause.Occur.SHOULD );
 
-        FlatSearchRequest request = new FlatSearchRequest( q, getIndexingContext() );
+        FlatSearchRequest request = new FlatSearchRequest( qb.build(), getIndexingContext() );
         FlatSearchResponse response = indexer.searchFlat( request );
 
+        assertEquals( 1, response.getTotalHitsCount() );
         Set<ArtifactInfo> results = response.getResults();
 
         ArtifactInfo artifactInfo = results.iterator().next();
@@ -345,7 +344,7 @@ public class ArchivaIndexingTaskExecutorTest
         assertEquals( "archiva-index-methods-jar-test", artifactInfo.getArtifactId() );
         assertEquals( "test-repo", artifactInfo.getRepository() );
 
-        assertEquals( 1, response.getTotalHits() );
+
     }
 
 }
index aeeaa6788f13c3c0aa373910bc7e9a0d23df576a..c4d7d936f1fab72667607d99886357c6752e2e84 100644 (file)
@@ -23,7 +23,10 @@ import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
 import org.apache.archiva.common.utils.FileUtils;
 import org.apache.archiva.repository.RepositoryRegistry;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
-import org.apache.maven.index.*;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.Indexer;
+import org.apache.maven.index.MAVEN;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index.expr.StringSearchExpression;
 import org.apache.maven.index_shaded.lucene.search.BooleanClause;
@@ -81,9 +84,6 @@ public class DownloadRemoteIndexTaskTest
     @Inject
     RepositoryRegistry repositoryRegistry;
 
-    @Inject
-    NexusIndexer nexusIndexer;
-
     @Before
     public void initialize()
         throws Exception
@@ -149,12 +149,12 @@ public class DownloadRemoteIndexTaskTest
         remoteRepositoryAdmin.deleteRemoteRepository( "test-repo-re", null );
 
         // search
-        BooleanQuery iQuery = new BooleanQuery();
+        BooleanQuery.Builder iQuery = new BooleanQuery.Builder();
         iQuery.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "commons-logging" ) ),
                     BooleanClause.Occur.SHOULD );
 
         remoteRepositoryAdmin.addRemoteRepository(remoteRepository,  null);
-        FlatSearchRequest rq = new FlatSearchRequest( iQuery );
+        FlatSearchRequest rq = new FlatSearchRequest( iQuery.build() );
         rq.setContexts(
             Arrays.asList( repositoryRegistry.getRemoteRepository(remoteRepository.getId()).getIndexingContext().getBaseContext(IndexingContext.class) ) );