* 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;
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;
private ArtifactContextProducer artifactContextProducer;
@Inject
- private NexusIndexer nexusIndexer;
+ private Indexer indexer;
+ @Inject
+ private Scanner scanner;
+
+ @Inject
+ IndexerEngine indexerEngine;
/**
* depending on current {@link Task} you have.
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 );
}
( 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 )
{
//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( );
else
{
log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo( ) );
- nexusIndexer.deleteArtifactFromIndex( ac, context );
+ indexerEngine.remove( context, ac );
}
}
}
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" );
}
}
*/
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;
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;
/**
@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()
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" );
repositoryConfig.addActiveReleaseScheme( ReleaseScheme.RELEASE );
repositoryConfig.removeActiveReleaseScheme( ReleaseScheme.SNAPSHOT );
repositoryRegistry.putRepository(repositoryConfig);
+ repo = repositoryRegistry.getManagedRepository( repositoryConfig.getId() );
}
@After
throws Exception
{
- for ( IndexingContext indexingContext : indexer.getIndexingContexts().values() )
- {
- indexer.removeIndexingContext( indexingContext, true );
- }
repositoryRegistry.destroy();
/*
removeIndexingContext with true cleanup files.
}
protected IndexingContext getIndexingContext() throws UnsupportedBaseContextException {
- Repository repo = repositoryRegistry.getRepository(repositoryConfig.getId());
assert repo != null;
ArchivaIndexingContext ctx = repo.getIndexingContext();
assert ctx != null;
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" )) );
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 );
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 );
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!
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 )
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();
assertEquals( "archiva-index-methods-jar-test", artifactInfo.getArtifactId() );
assertEquals( "test-repo", artifactInfo.getRepository() );
- assertEquals( 1, response.getTotalHits() );
+
}
}