Search in sources :

Example 1 with ContextMemberProvider

use of org.apache.maven.index.context.ContextMemberProvider in project archiva by apache.

the class DefaultIndexMerger method buildMergedIndex.

@Override
public IndexingContext buildMergedIndex(IndexMergerRequest indexMergerRequest) throws IndexMergerException {
    String groupId = indexMergerRequest.getGroupId();
    if (runningGroups.contains(groupId)) {
        log.info("skip build merge remote indexes for id: '{}' as already running", groupId);
        return null;
    }
    runningGroups.add(groupId);
    StopWatch stopWatch = new StopWatch();
    stopWatch.reset();
    stopWatch.start();
    Path mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();
    String tempRepoId = mergedIndexDirectory.getFileName().toString();
    try {
        Path indexLocation = mergedIndexDirectory.resolve(indexMergerRequest.getMergedIndexPath());
        List<IndexingContext> members = indexMergerRequest.getRepositoriesIds().stream().map(id -> repositoryRegistry.getRepository(id)).filter(repo -> repo.getType().equals(RepositoryType.MAVEN)).map(repo -> {
            try {
                return repo.getIndexingContext().getBaseContext(IndexingContext.class);
            } catch (UnsupportedBaseContextException e) {
                return null;
            // Ignore
            }
        }).filter(Objects::nonNull).collect(Collectors.toList());
        ContextMemberProvider memberProvider = new StaticContextMemberProvider(members);
        IndexingContext mergedCtx = indexer.createMergedIndexingContext(tempRepoId, tempRepoId, mergedIndexDirectory.toFile(), indexLocation.toFile(), true, memberProvider);
        mergedCtx.optimize();
        if (indexMergerRequest.isPackIndex()) {
            IndexPackingRequest request = new // 
            IndexPackingRequest(// 
            mergedCtx, // 
            mergedCtx.acquireIndexSearcher().getIndexReader(), indexLocation.toFile());
            indexPacker.packIndex(request);
        }
        if (indexMergerRequest.isTemporary()) {
            temporaryGroupIndexes.add(new TemporaryGroupIndex(mergedIndexDirectory, tempRepoId, groupId, indexMergerRequest.getMergedIndexTtl()));
            temporaryContextes.add(mergedCtx);
        }
        stopWatch.stop();
        log.info("merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), stopWatch.getTime());
        return mergedCtx;
    } catch (IOException e) {
        throw new IndexMergerException(e.getMessage(), e);
    } finally {
        runningGroups.remove(groupId);
    }
}
Also used : Path(java.nio.file.Path) Async(org.springframework.scheduling.annotation.Async) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) StaticContextMemberProvider(org.apache.maven.index.context.StaticContextMemberProvider) LoggerFactory(org.slf4j.LoggerFactory) IndexCreator(org.apache.maven.index.context.IndexCreator) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) FileUtils(org.apache.archiva.common.utils.FileUtils) IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) Path(java.nio.file.Path) Logger(org.slf4j.Logger) IndexPacker(org.apache.maven.index.packer.IndexPacker) Files(java.nio.file.Files) ContextMemberProvider(org.apache.maven.index.context.ContextMemberProvider) Collection(java.util.Collection) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) IOException(java.io.IOException) TemporaryGroupIndex(org.apache.archiva.indexer.merger.TemporaryGroupIndex) RepositoryType(org.apache.archiva.repository.RepositoryType) Collectors(java.util.stream.Collectors) IndexMerger(org.apache.archiva.indexer.merger.IndexMerger) IndexMergerException(org.apache.archiva.indexer.merger.IndexMergerException) Indexer(org.apache.maven.index.Indexer) Objects(java.util.Objects) List(java.util.List) IndexingContext(org.apache.maven.index.context.IndexingContext) IndexMergerRequest(org.apache.archiva.indexer.merger.IndexMergerRequest) StopWatch(org.apache.commons.lang.time.StopWatch) Optional(java.util.Optional) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TemporaryGroupIndex(org.apache.archiva.indexer.merger.TemporaryGroupIndex) StaticContextMemberProvider(org.apache.maven.index.context.StaticContextMemberProvider) ContextMemberProvider(org.apache.maven.index.context.ContextMemberProvider) IOException(java.io.IOException) StopWatch(org.apache.commons.lang.time.StopWatch) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) IndexingContext(org.apache.maven.index.context.IndexingContext) StaticContextMemberProvider(org.apache.maven.index.context.StaticContextMemberProvider) IndexMergerException(org.apache.archiva.indexer.merger.IndexMergerException)

Aggregations

IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 FileUtils (org.apache.archiva.common.utils.FileUtils)1 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)1 IndexMerger (org.apache.archiva.indexer.merger.IndexMerger)1 IndexMergerException (org.apache.archiva.indexer.merger.IndexMergerException)1 IndexMergerRequest (org.apache.archiva.indexer.merger.IndexMergerRequest)1 TemporaryGroupIndex (org.apache.archiva.indexer.merger.TemporaryGroupIndex)1 RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)1 RepositoryType (org.apache.archiva.repository.RepositoryType)1 StopWatch (org.apache.commons.lang.time.StopWatch)1 Indexer (org.apache.maven.index.Indexer)1