@Test public void testUpdateArtifactInIndex() throws Exception { Path basePath = repo.getRoot().getFilePath(); Path artifactFile = basePath.resolve( "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ); ArtifactIndexingTask task = new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.ADD, repo.getIndexingContext() ); indexingExecutor.executeTask( task ); indexingExecutor.executeTask( task ); BooleanQuery.Builder qb = new BooleanQuery.Builder(); qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ), BooleanClause.Occur.SHOULD ); 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( qb.build(), 10 ); ctx.releaseIndexSearcher( searcher ); assertTrue( Files.exists(basePath.resolve(".indexer" )) ); assertTrue( Files.exists(basePath.resolve(".index" )) ); assertEquals( 1, topDocs.totalHits ); }
@Override public void executeTask( Task task ) throws TaskExecutionException { ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task; 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 ); } if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction( ) ) && indexingTask.isExecuteOnEntireRepo( ) ) { long start = System.currentTimeMillis( ); try { 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 ) { 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 ); } else { if ( !indexingTask.isExecuteOnEntireRepo( ) ) { try { log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile( ) == null ? "none" : indexingTask.getResourceFile( ) ) ); archivaContext = repository.getIndexingContext( ); context = archivaContext.getBaseContext( IndexingContext.class ); } catch ( UnsupportedBaseContextException e ) { log.error( "Error occurred while creating context: {}", e.getMessage( ) ); throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage( ), e ); } } if ( context == null || context.getIndexDirectory( ) == null ) { throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" ); } try { Path artifactFile = indexingTask.getResourceFile( ); if ( artifactFile == null ) { log.debug( "no artifact pass in indexing task so skip it" ); } else { ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile.toFile( ) ); if ( ac != null ) { if ( artifactFile.getFileName( ).toString( ).endsWith( ".pom" ) ) { ac.getArtifactInfo( ).setFileExtension( "pom" ); ac.getArtifactInfo( ).setPackaging( "pom" ); ac.getArtifactInfo( ).setClassifier( "pom" ); } if ( indexingTask.getAction( ).equals( ArtifactIndexingTask.Action.ADD ) ) { BooleanQuery.Builder qb = new BooleanQuery.Builder(); qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getGroupId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getArtifactId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression( ac.getArtifactInfo( ).getVersion( ) ) ), BooleanClause.Occur.MUST ); if ( ac.getArtifactInfo( ).getClassifier( ) != null ) { qb.add( indexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression( ac.getArtifactInfo( ).getClassifier( ) ) ), BooleanClause.Occur.MUST ); } if ( ac.getArtifactInfo( ).getPackaging( ) != null ) { qb.add( indexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression( ac.getArtifactInfo( ).getPackaging( ) ) ), BooleanClause.Occur.MUST ); } FlatSearchRequest flatSearchRequest = new FlatSearchRequest( qb.build(), context ); FlatSearchResponse flatSearchResponse = indexer.searchFlat( flatSearchRequest ); if ( flatSearchResponse.getResults( ).isEmpty( ) ) { log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo( ) ); indexerEngine.index( context, ac ); } else { log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo( ) ); indexerEngine.update( context, ac ); } context.updateTimestamp( ); context.commit( ); } else { log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo( ) ); indexerEngine.remove( context, ac ); } } } if ( !indexingTask.isExecuteOnEntireRepo( ) ) { log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile( ) != null ? indexingTask.getResourceFile( ) : " none " ); finishIndexingTask( indexingTask, repository, context ); } } catch ( IOException e ) { log.error( "Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage( ), e ); throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'", e ); } } }
ArchivaIndexingTaskExecutor implements TaskExecutor { @Override public void executeTask( Task task ) throws TaskExecutionException { ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task; 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 ); } if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction( ) ) && indexingTask.isExecuteOnEntireRepo( ) ) { long start = System.currentTimeMillis( ); try { 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 ) { 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 ); } else { if ( !indexingTask.isExecuteOnEntireRepo( ) ) { try { log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile( ) == null ? "none" : indexingTask.getResourceFile( ) ) ); archivaContext = repository.getIndexingContext( ); context = archivaContext.getBaseContext( IndexingContext.class ); } catch ( UnsupportedBaseContextException e ) { log.error( "Error occurred while creating context: {}", e.getMessage( ) ); throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage( ), e ); } } if ( context == null || context.getIndexDirectory( ) == null ) { throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" ); } try { Path artifactFile = indexingTask.getResourceFile( ); if ( artifactFile == null ) { log.debug( "no artifact pass in indexing task so skip it" ); } else { ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile.toFile( ) ); if ( ac != null ) { if ( artifactFile.getFileName( ).toString( ).endsWith( ".pom" ) ) { ac.getArtifactInfo( ).setFileExtension( "pom" ); ac.getArtifactInfo( ).setPackaging( "pom" ); ac.getArtifactInfo( ).setClassifier( "pom" ); } if ( indexingTask.getAction( ).equals( ArtifactIndexingTask.Action.ADD ) ) { BooleanQuery.Builder qb = new BooleanQuery.Builder(); qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getGroupId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getArtifactId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression( ac.getArtifactInfo( ).getVersion( ) ) ), BooleanClause.Occur.MUST ); if ( ac.getArtifactInfo( ).getClassifier( ) != null ) { qb.add( indexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression( ac.getArtifactInfo( ).getClassifier( ) ) ), BooleanClause.Occur.MUST ); } if ( ac.getArtifactInfo( ).getPackaging( ) != null ) { qb.add( indexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression( ac.getArtifactInfo( ).getPackaging( ) ) ), BooleanClause.Occur.MUST ); } FlatSearchRequest flatSearchRequest = new FlatSearchRequest( qb.build(), context ); FlatSearchResponse flatSearchResponse = indexer.searchFlat( flatSearchRequest ); if ( flatSearchResponse.getResults( ).isEmpty( ) ) { log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo( ) ); indexerEngine.index( context, ac ); } else { log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo( ) ); indexerEngine.update( context, ac ); } context.updateTimestamp( ); context.commit( ); } else { log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo( ) ); indexerEngine.remove( context, ac ); } } } if ( !indexingTask.isExecuteOnEntireRepo( ) ) { log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile( ) != null ? indexingTask.getResourceFile( ) : " none " ); finishIndexingTask( indexingTask, repository, context ); } } catch ( IOException e ) { log.error( "Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage( ), e ); throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'", e ); } } } }
ArchivaIndexingTaskExecutor implements TaskExecutor { @Override public void executeTask( Task task ) throws TaskExecutionException { ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task; 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 ); } if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction( ) ) && indexingTask.isExecuteOnEntireRepo( ) ) { long start = System.currentTimeMillis( ); try { 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 ) { 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 ); } else { if ( !indexingTask.isExecuteOnEntireRepo( ) ) { try { log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile( ) == null ? "none" : indexingTask.getResourceFile( ) ) ); archivaContext = repository.getIndexingContext( ); context = archivaContext.getBaseContext( IndexingContext.class ); } catch ( UnsupportedBaseContextException e ) { log.error( "Error occurred while creating context: {}", e.getMessage( ) ); throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage( ), e ); } } if ( context == null || context.getIndexDirectory( ) == null ) { throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" ); } try { Path artifactFile = indexingTask.getResourceFile( ); if ( artifactFile == null ) { log.debug( "no artifact pass in indexing task so skip it" ); } else { ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile.toFile( ) ); if ( ac != null ) { if ( artifactFile.getFileName( ).toString( ).endsWith( ".pom" ) ) { ac.getArtifactInfo( ).setFileExtension( "pom" ); ac.getArtifactInfo( ).setPackaging( "pom" ); ac.getArtifactInfo( ).setClassifier( "pom" ); } if ( indexingTask.getAction( ).equals( ArtifactIndexingTask.Action.ADD ) ) { BooleanQuery.Builder qb = new BooleanQuery.Builder(); qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getGroupId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getArtifactId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression( ac.getArtifactInfo( ).getVersion( ) ) ), BooleanClause.Occur.MUST ); if ( ac.getArtifactInfo( ).getClassifier( ) != null ) { qb.add( indexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression( ac.getArtifactInfo( ).getClassifier( ) ) ), BooleanClause.Occur.MUST ); } if ( ac.getArtifactInfo( ).getPackaging( ) != null ) { qb.add( indexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression( ac.getArtifactInfo( ).getPackaging( ) ) ), BooleanClause.Occur.MUST ); } FlatSearchRequest flatSearchRequest = new FlatSearchRequest( qb.build(), context ); FlatSearchResponse flatSearchResponse = indexer.searchFlat( flatSearchRequest ); if ( flatSearchResponse.getResults( ).isEmpty( ) ) { log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo( ) ); indexerEngine.index( context, ac ); } else { log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo( ) ); indexerEngine.update( context, ac ); } context.updateTimestamp( ); context.commit( ); } else { log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo( ) ); indexerEngine.remove( context, ac ); } } } if ( !indexingTask.isExecuteOnEntireRepo( ) ) { log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile( ) != null ? indexingTask.getResourceFile( ) : " none " ); finishIndexingTask( indexingTask, repository, context ); } } catch ( IOException e ) { log.error( "Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage( ), e ); throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'", e ); } } }  }
ArchivaIndexingTaskExecutor implements TaskExecutor { @Override public void executeTask( Task task ) throws TaskExecutionException { ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task; 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 ); } if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction( ) ) && indexingTask.isExecuteOnEntireRepo( ) ) { long start = System.currentTimeMillis( ); try { 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 ) { 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 ); } else { if ( !indexingTask.isExecuteOnEntireRepo( ) ) { try { log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile( ) == null ? "none" : indexingTask.getResourceFile( ) ) ); archivaContext = repository.getIndexingContext( ); context = archivaContext.getBaseContext( IndexingContext.class ); } catch ( UnsupportedBaseContextException e ) { log.error( "Error occurred while creating context: {}", e.getMessage( ) ); throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage( ), e ); } } if ( context == null || context.getIndexDirectory( ) == null ) { throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" ); } try { Path artifactFile = indexingTask.getResourceFile( ); if ( artifactFile == null ) { log.debug( "no artifact pass in indexing task so skip it" ); } else { ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile.toFile( ) ); if ( ac != null ) { if ( artifactFile.getFileName( ).toString( ).endsWith( ".pom" ) ) { ac.getArtifactInfo( ).setFileExtension( "pom" ); ac.getArtifactInfo( ).setPackaging( "pom" ); ac.getArtifactInfo( ).setClassifier( "pom" ); } if ( indexingTask.getAction( ).equals( ArtifactIndexingTask.Action.ADD ) ) { BooleanQuery.Builder qb = new BooleanQuery.Builder(); qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getGroupId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getArtifactId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression( ac.getArtifactInfo( ).getVersion( ) ) ), BooleanClause.Occur.MUST ); if ( ac.getArtifactInfo( ).getClassifier( ) != null ) { qb.add( indexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression( ac.getArtifactInfo( ).getClassifier( ) ) ), BooleanClause.Occur.MUST ); } if ( ac.getArtifactInfo( ).getPackaging( ) != null ) { qb.add( indexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression( ac.getArtifactInfo( ).getPackaging( ) ) ), BooleanClause.Occur.MUST ); } FlatSearchRequest flatSearchRequest = new FlatSearchRequest( qb.build(), context ); FlatSearchResponse flatSearchResponse = indexer.searchFlat( flatSearchRequest ); if ( flatSearchResponse.getResults( ).isEmpty( ) ) { log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo( ) ); indexerEngine.index( context, ac ); } else { log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo( ) ); indexerEngine.update( context, ac ); } context.updateTimestamp( ); context.commit( ); } else { log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo( ) ); indexerEngine.remove( context, ac ); } } } if ( !indexingTask.isExecuteOnEntireRepo( ) ) { log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile( ) != null ? indexingTask.getResourceFile( ) : " none " ); finishIndexingTask( indexingTask, repository, context ); } } catch ( IOException e ) { log.error( "Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage( ), e ); throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'", e ); } } }  @Override void executeTask( Task task ); void setIndexPacker( IndexPacker indexPacker ); }
ArchivaIndexingTaskExecutor implements TaskExecutor { @Override public void executeTask( Task task ) throws TaskExecutionException { ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task; 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 ); } if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction( ) ) && indexingTask.isExecuteOnEntireRepo( ) ) { long start = System.currentTimeMillis( ); try { 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 ) { 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 ); } else { if ( !indexingTask.isExecuteOnEntireRepo( ) ) { try { log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile( ) == null ? "none" : indexingTask.getResourceFile( ) ) ); archivaContext = repository.getIndexingContext( ); context = archivaContext.getBaseContext( IndexingContext.class ); } catch ( UnsupportedBaseContextException e ) { log.error( "Error occurred while creating context: {}", e.getMessage( ) ); throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage( ), e ); } } if ( context == null || context.getIndexDirectory( ) == null ) { throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" ); } try { Path artifactFile = indexingTask.getResourceFile( ); if ( artifactFile == null ) { log.debug( "no artifact pass in indexing task so skip it" ); } else { ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile.toFile( ) ); if ( ac != null ) { if ( artifactFile.getFileName( ).toString( ).endsWith( ".pom" ) ) { ac.getArtifactInfo( ).setFileExtension( "pom" ); ac.getArtifactInfo( ).setPackaging( "pom" ); ac.getArtifactInfo( ).setClassifier( "pom" ); } if ( indexingTask.getAction( ).equals( ArtifactIndexingTask.Action.ADD ) ) { BooleanQuery.Builder qb = new BooleanQuery.Builder(); qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getGroupId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( ac.getArtifactInfo( ).getArtifactId( ) ) ), BooleanClause.Occur.MUST ); qb.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression( ac.getArtifactInfo( ).getVersion( ) ) ), BooleanClause.Occur.MUST ); if ( ac.getArtifactInfo( ).getClassifier( ) != null ) { qb.add( indexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression( ac.getArtifactInfo( ).getClassifier( ) ) ), BooleanClause.Occur.MUST ); } if ( ac.getArtifactInfo( ).getPackaging( ) != null ) { qb.add( indexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression( ac.getArtifactInfo( ).getPackaging( ) ) ), BooleanClause.Occur.MUST ); } FlatSearchRequest flatSearchRequest = new FlatSearchRequest( qb.build(), context ); FlatSearchResponse flatSearchResponse = indexer.searchFlat( flatSearchRequest ); if ( flatSearchResponse.getResults( ).isEmpty( ) ) { log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo( ) ); indexerEngine.index( context, ac ); } else { log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo( ) ); indexerEngine.update( context, ac ); } context.updateTimestamp( ); context.commit( ); } else { log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo( ) ); indexerEngine.remove( context, ac ); } } } if ( !indexingTask.isExecuteOnEntireRepo( ) ) { log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile( ) != null ? indexingTask.getResourceFile( ) : " none " ); finishIndexingTask( indexingTask, repository, context ); } } catch ( IOException e ) { log.error( "Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage( ), e ); throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'", e ); } } }  @Override void executeTask( Task task ); void setIndexPacker( IndexPacker indexPacker );  }