From 8e36162963f829b75497699f29966d22fdfba38b Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 2 Nov 2011 22:33:09 +0000 Subject: [PATCH] [MRM-815] aggregate indices for repository groups. pack index for download. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1196845 13f79535-47bb-0310-9956-ffa450edef68 --- .../indexer/merger/DefaultIndexMerger.java | 19 ++++++++++++++++--- .../archiva/indexer/merger/IndexMerger.java | 3 ++- .../webdav/ArchivaDavResourceFactory.java | 4 ++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java index 2a3411a16..7a29fb76f 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java @@ -27,6 +27,8 @@ import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; import org.apache.maven.index.NexusIndexer; 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.packer.IndexPackingRequest; import org.springframework.stereotype.Service; import java.io.File; @@ -49,15 +51,18 @@ public class DefaultIndexMerger private NexusIndexer indexer; + private IndexPacker indexPacker; + @javax.inject.Inject public DefaultIndexMerger( PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils ) throws PlexusSisuBridgeException { this.indexer = plexusSisuBridge.lookup( NexusIndexer.class ); this.mavenIndexerUtils = mavenIndexerUtils; + indexPacker = plexusSisuBridge.lookup( IndexPacker.class, "default" ); } - public File buildMergedIndex( Collection repositoriesIds ) + public File buildMergedIndex( Collection repositoriesIds, boolean packIndex ) throws IndexMergerException { File tempRepoFile = Files.createTempDir(); @@ -67,9 +72,10 @@ public class DefaultIndexMerger try { + File indexLocation = new File( tempRepoFile, ".indexer" ); IndexingContext indexingContext = - indexer.addIndexingContext( tempRepoId, tempRepoId, tempRepoFile, new File( tempRepoFile, ".indexer" ), - null, null, mavenIndexerUtils.getAllIndexCreators() ); + indexer.addIndexingContext( tempRepoId, tempRepoId, tempRepoFile, indexLocation, null, null, + mavenIndexerUtils.getAllIndexCreators() ); for ( String repoId : repositoriesIds ) { @@ -80,6 +86,13 @@ public class DefaultIndexMerger } } + indexingContext.optimize(); + + if ( packIndex ) + { + IndexPackingRequest request = new IndexPackingRequest( indexingContext, indexLocation ); + indexPacker.packIndex( request ); + } return indexingContext.getIndexDirectoryFile(); } catch ( IOException e ) diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMerger.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMerger.java index 7f6333f37..89e2c7d6f 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMerger.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMerger.java @@ -29,9 +29,10 @@ public interface IndexMerger { /** * @param repositoriesIds repositories Ids to merge content + * @param packIndex will generate a downloadable index * @return a temporary directory with a merge index (directory marked deleteOnExit) * @throws IndexMergerException */ - File buildMergedIndex( Collection repositoriesIds ) + File buildMergedIndex( Collection repositoriesIds, boolean packIndex ) throws IndexMergerException; } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index 03cf17dfc..0dbe1f350 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -1033,7 +1033,7 @@ public class ArchivaDavResourceFactory } } // remove last / - String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" ); + String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" ); if ( StringUtils.endsWith( path, ".indexer" ) ) { try @@ -1063,7 +1063,7 @@ public class ArchivaDavResourceFactory } } - File mergedRepoDir = indexMerger.buildMergedIndex( authzRepos ); + File mergedRepoDir = indexMerger.buildMergedIndex( authzRepos, true ); mergedRepositoryContents.add( mergedRepoDir ); } -- 2.39.5