[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
This commit is contained in:
Olivier Lamy 2011-11-02 22:33:09 +00:00
parent a635f44ace
commit 8e36162963
3 changed files with 20 additions and 6 deletions

View File

@ -27,6 +27,8 @@ import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; 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 org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
@ -49,15 +51,18 @@ public class DefaultIndexMerger
private NexusIndexer indexer; private NexusIndexer indexer;
private IndexPacker indexPacker;
@javax.inject.Inject @javax.inject.Inject
public DefaultIndexMerger( PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils ) public DefaultIndexMerger( PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils )
throws PlexusSisuBridgeException throws PlexusSisuBridgeException
{ {
this.indexer = plexusSisuBridge.lookup( NexusIndexer.class ); this.indexer = plexusSisuBridge.lookup( NexusIndexer.class );
this.mavenIndexerUtils = mavenIndexerUtils; this.mavenIndexerUtils = mavenIndexerUtils;
indexPacker = plexusSisuBridge.lookup( IndexPacker.class, "default" );
} }
public File buildMergedIndex( Collection<String> repositoriesIds ) public File buildMergedIndex( Collection<String> repositoriesIds, boolean packIndex )
throws IndexMergerException throws IndexMergerException
{ {
File tempRepoFile = Files.createTempDir(); File tempRepoFile = Files.createTempDir();
@ -67,9 +72,10 @@ public class DefaultIndexMerger
try try
{ {
File indexLocation = new File( tempRepoFile, ".indexer" );
IndexingContext indexingContext = IndexingContext indexingContext =
indexer.addIndexingContext( tempRepoId, tempRepoId, tempRepoFile, new File( tempRepoFile, ".indexer" ), indexer.addIndexingContext( tempRepoId, tempRepoId, tempRepoFile, indexLocation, null, null,
null, null, mavenIndexerUtils.getAllIndexCreators() ); mavenIndexerUtils.getAllIndexCreators() );
for ( String repoId : repositoriesIds ) 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(); return indexingContext.getIndexDirectoryFile();
} }
catch ( IOException e ) catch ( IOException e )

View File

@ -29,9 +29,10 @@ public interface IndexMerger
{ {
/** /**
* @param repositoriesIds repositories Ids to merge content * @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) * @return a temporary directory with a merge index (directory marked deleteOnExit)
* @throws IndexMergerException * @throws IndexMergerException
*/ */
File buildMergedIndex( Collection<String> repositoriesIds ) File buildMergedIndex( Collection<String> repositoriesIds, boolean packIndex )
throws IndexMergerException; throws IndexMergerException;
} }

View File

@ -1033,7 +1033,7 @@ public class ArchivaDavResourceFactory
} }
} }
// remove last / // remove last /
String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" ); String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" );
if ( StringUtils.endsWith( path, ".indexer" ) ) if ( StringUtils.endsWith( path, ".indexer" ) )
{ {
try try
@ -1063,7 +1063,7 @@ public class ArchivaDavResourceFactory
} }
} }
File mergedRepoDir = indexMerger.buildMergedIndex( authzRepos ); File mergedRepoDir = indexMerger.buildMergedIndex( authzRepos, true );
mergedRepositoryContents.add( mergedRepoDir ); mergedRepositoryContents.add( mergedRepoDir );
} }