From 0da207565c4cb4a789ea7cf581d8ede9e4143e99 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sun, 21 Apr 2013 23:35:17 +0000 Subject: [PATCH] fix handling of dynamic mergedIndexPath git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1470363 13f79535-47bb-0310-9956-ffa450edef68 --- .../indexer/merger/DefaultIndexMerger.java | 7 +-- .../indexer/merger/IndexMergerRequest.java | 30 ++++++++++-- .../webdav/ArchivaDavResourceFactory.java | 47 ++++++++++--------- 3 files changed, 55 insertions(+), 29 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 1d4bfecfd..77618be8b 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 @@ -47,7 +47,7 @@ import java.util.concurrent.CopyOnWriteArrayList; * @author Olivier Lamy * @since 1.4-M2 */ -@Service( "indexMerger#default" ) +@Service("indexMerger#default") public class DefaultIndexMerger implements IndexMerger { @@ -100,7 +100,7 @@ public class DefaultIndexMerger try { - File indexLocation = new File( tempRepoFile, ".indexer" ); + File indexLocation = new File( tempRepoFile, indexMergerRequest.getMergedIndexPath() ); IndexingContext indexingContext = indexer.addIndexingContext( tempRepoId, tempRepoId, tempRepoFile, indexLocation, null, null, mavenIndexerUtils.getAllIndexCreators() ); @@ -124,7 +124,8 @@ public class DefaultIndexMerger temporaryGroupIndexes.add( new TemporaryGroupIndex( tempRepoFile, tempRepoId, indexMergerRequest.getGroupId() ) ); stopWatch.stop(); - log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), stopWatch.getTime() ); + log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), + stopWatch.getTime() ); return indexingContext; } catch ( IOException e ) diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java index d6836061e..76d238fd2 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java @@ -40,6 +40,8 @@ public class IndexMergerRequest */ private String groupId; + private String mergedIndexPath = "/.indexer"; + public IndexMergerRequest( Collection repositoriesIds, boolean packIndex, String groupId ) { this.repositoriesIds = repositoriesIds; @@ -47,6 +49,18 @@ public class IndexMergerRequest this.groupId = groupId; } + /** + * @since 1.4-M4 + */ + public IndexMergerRequest( Collection repositoriesIds, boolean packIndex, String groupId, + String mergedIndexPath ) + { + this.repositoriesIds = repositoriesIds; + this.packIndex = packIndex; + this.groupId = groupId; + this.mergedIndexPath = mergedIndexPath; + } + public Collection getRepositoriesIds() { return repositoriesIds; @@ -77,14 +91,24 @@ public class IndexMergerRequest this.groupId = groupId; } + public String getMergedIndexPath() + { + return mergedIndexPath; + } + + public void setMergedIndexPath( String mergedIndexPath ) + { + this.mergedIndexPath = mergedIndexPath; + } + @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append( "IndexMergerRequest" ); - sb.append( "{repositoriesIds=" ).append( repositoriesIds ); + final StringBuilder sb = new StringBuilder( "IndexMergerRequest{" ); + sb.append( "repositoriesIds=" ).append( repositoriesIds ); sb.append( ", packIndex=" ).append( packIndex ); sb.append( ", groupId='" ).append( groupId ).append( '\'' ); + sb.append( ", mergedIndexPath='" ).append( mergedIndexPath ).append( '\'' ); sb.append( '}' ); return sb.toString(); } 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 bc72bccce..3d99333d0 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 @@ -110,7 +110,7 @@ import java.util.Set; /** * */ -@Service( "davResourceFactory#archiva" ) +@Service("davResourceFactory#archiva") public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable { @@ -141,7 +141,7 @@ public class ArchivaDavResourceFactory * */ @Inject - @Named( value = "repositoryProxyConnectors#default" ) + @Named(value = "repositoryProxyConnectors#default") private RepositoryProxyConnectors connectors; /** @@ -171,7 +171,7 @@ public class ArchivaDavResourceFactory * */ @Inject - @Named( value = "httpAuthenticator#basic" ) + @Named(value = "httpAuthenticator#basic") private HttpAuthenticator httpAuth; @Inject @@ -207,7 +207,7 @@ public class ArchivaDavResourceFactory * */ @Inject - @Named( value = "archivaTaskScheduler#repository" ) + @Named(value = "archivaTaskScheduler#repository") private RepositoryArchivaTaskScheduler scheduler; private ApplicationContext applicationContext; @@ -272,7 +272,7 @@ public class ArchivaDavResourceFactory // infrequent List repositories = new ArrayList( repoGroupConfig.getRepositories() ); resource = processRepositoryGroup( request, archivaLocator, repositories, activePrincipal, - resourcesInAbsolutePath, archivaLocator.getRepositoryId() ); + resourcesInAbsolutePath, repoGroupConfig ); } } else @@ -435,7 +435,7 @@ public class ArchivaDavResourceFactory private DavResource processRepositoryGroup( final DavServletRequest request, ArchivaDavResourceLocator archivaLocator, List repositories, String activePrincipal, List resourcesInAbsolutePath, - String repositoryGroupId ) + RepositoryGroupConfiguration repoGroupConfig ) throws DavException { DavResource resource = null; @@ -450,7 +450,7 @@ public class ArchivaDavResourceFactory // we are in the case of index file request String requestedFileName = StringUtils.substringAfterLast( pathInfo, "/" ); File temporaryIndexDirectory = - buildMergedIndexDirectory( repositories, activePrincipal, request, repositoryGroupId ); + buildMergedIndexDirectory( repositories, activePrincipal, request, repoGroupConfig ); File resourceFile = new File( temporaryIndexDirectory, requestedFileName ); resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), requestedFileName, null, @@ -931,11 +931,10 @@ public class ArchivaDavResourceFactory // remove last / String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" ); - if ( StringUtils.endsWith( pathInfo, "/" + repositoryGroupConfiguration.getMergedIndexPath() ) - || StringUtils.endsWith( pathInfo, "/" + repositoryGroupConfiguration.getMergedIndexPath() + "/" ) ) + if ( StringUtils.endsWith( pathInfo, repositoryGroupConfiguration.getMergedIndexPath() ) ) { - File mergedRepoDir = buildMergedIndexDirectory( repositories, activePrincipal, request, - repositoryGroupConfiguration.getId() ); + File mergedRepoDir = + buildMergedIndexDirectory( repositories, activePrincipal, request, repositoryGroupConfiguration ); mergedRepositoryContents.add( mergedRepoDir ); } else @@ -1163,7 +1162,8 @@ public class ArchivaDavResourceFactory } protected File buildMergedIndexDirectory( List repositories, String activePrincipal, - DavServletRequest request, String groupId ) + DavServletRequest request, + RepositoryGroupConfiguration repositoryGroupConfiguration ) throws DavException { @@ -1179,7 +1179,7 @@ public class ArchivaDavResourceFactory temporaryGroupIndexMap = new HashMap(); } - TemporaryGroupIndex tmp = temporaryGroupIndexMap.get( groupId ); + TemporaryGroupIndex tmp = temporaryGroupIndexMap.get( repositoryGroupConfiguration.getId() ); if ( tmp != null && tmp.getDirectory() != null && tmp.getDirectory().exists() ) { @@ -1187,13 +1187,13 @@ public class ArchivaDavResourceFactory * 1000 ) ) { log.debug( MarkerFactory.getMarker( "group.merged.index" ), - "tmp group index '{}' is too old so delete it", groupId ); + "tmp group index '{}' is too old so delete it", repositoryGroupConfiguration.getId() ); indexMerger.cleanTemporaryGroupIndex( tmp ); } else { log.debug( MarkerFactory.getMarker( "group.merged.index" ), - "merged index for group '{}' found in cache", groupId ); + "merged index for group '{}' found in cache", repositoryGroupConfiguration.getId() ); return tmp.getDirectory(); } } @@ -1218,15 +1218,16 @@ public class ArchivaDavResourceFactory e.getMessage() ); } } - log.info( "generate temporary merged index for repository group '{}' for repositories '{}'", groupId, - authzRepos ); - IndexingContext indexingContext = - indexMerger.buildMergedIndex( new IndexMergerRequest( authzRepos, true, groupId ) ); + log.info( "generate temporary merged index for repository group '{}' for repositories '{}'", + repositoryGroupConfiguration.getId(), authzRepos ); + IndexingContext indexingContext = indexMerger.buildMergedIndex( + new IndexMergerRequest( authzRepos, true, repositoryGroupConfiguration.getId(), + repositoryGroupConfiguration.getMergedIndexPath() ) ); File mergedRepoDir = indexingContext.getIndexDirectoryFile(); - TemporaryGroupIndex temporaryGroupIndex = - new TemporaryGroupIndex( mergedRepoDir, indexingContext.getId(), groupId ).setCreationTime( - new Date().getTime() ); - temporaryGroupIndexMap.put( groupId, temporaryGroupIndex ); + TemporaryGroupIndex temporaryGroupIndex = new TemporaryGroupIndex( mergedRepoDir, indexingContext.getId(), + repositoryGroupConfiguration.getId() ).setCreationTime( + new Date().getTime() ); + temporaryGroupIndexMap.put( repositoryGroupConfiguration.getId(), temporaryGroupIndex ); session.setAttribute( TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY, temporaryGroupIndexMap ); return mergedRepoDir;