From 7f2fbd20e045c8bf20f1f16d7c328b0bdf2278a1 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 15 Oct 2012 12:12:43 +0000 Subject: [PATCH] [MRM-1693] exposing index downloaded from remote repositories git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1398262 13f79535-47bb-0310-9956-ffa450edef68 --- .../remote/DefaultRemoteRepositoryAdmin.java | 27 ++++++++++++-- .../webdav/ArchivaDavResourceFactory.java | 35 +++++++++++++++++-- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java index 9086903da..28e189e12 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java @@ -52,7 +52,7 @@ import java.util.Map; * @author Olivier Lamy * @since 1.4-M1 */ -@Service( "remoteRepositoryAdmin#default" ) +@Service ( "remoteRepositoryAdmin#default" ) public class DefaultRemoteRepositoryAdmin extends AbstractRepositoryAdmin implements RemoteRepositoryAdmin @@ -268,13 +268,34 @@ public class DefaultRemoteRepositoryAdmin { return indexingContext; } - // create path + // create remote repository path File repoDir = new File( appServerBase, "data/remotes/" + remoteRepository.getId() ); if ( !repoDir.exists() ) { repoDir.mkdirs(); } - File indexDirectory = new File( repoDir, ".index" ); + + File indexDirectory = null; + + // is there configured indexDirectory ? + String indexDirectoryPath = remoteRepository.getIndexDirectory(); + + if ( StringUtils.isNotBlank( indexDirectoryPath ) ) + { + if ( new File( indexDirectoryPath ).isAbsolute() ) + { + indexDirectory = new File( indexDirectoryPath ); + } + else + { + indexDirectory = new File( repoDir, indexDirectoryPath ); + } + } + // if not configured use a default value + if ( indexDirectory == null ) + { + indexDirectory = new File( repoDir, ".index" ); + } if ( !indexDirectory.exists() ) { indexDirectory.mkdirs(); 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 974e09861..a7c9bc0b8 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 @@ -20,6 +20,8 @@ package org.apache.archiva.webdav; */ import org.apache.archiva.admin.model.RepositoryAdminException; +import org.apache.archiva.admin.model.beans.RemoteRepository; +import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; import org.apache.archiva.audit.Auditable; @@ -178,6 +180,9 @@ public class ArchivaDavResourceFactory @Named ( value = "httpAuthenticator#basic" ) private HttpAuthenticator httpAuth; + @Inject + private RemoteRepositoryAdmin remoteRepositoryAdmin; + @Inject private IndexMerger indexMerger; @@ -277,6 +282,32 @@ public class ArchivaDavResourceFactory } else { + + try + { + RemoteRepository remoteRepository = + remoteRepositoryAdmin.getRemoteRepository( archivaLocator.getRepositoryId() ); + + if ( remoteRepository != null ) + { + String logicalResource = RepositoryPathUtil.getLogicalResource( locator.getResourcePath() ); + IndexingContext indexingContext = remoteRepositoryAdmin.createIndexContext( remoteRepository ); + File resourceFile = StringUtils.equals( logicalResource, "/" ) + ? new File( indexingContext.getIndexDirectoryFile().getParent() ) + : new File( indexingContext.getIndexDirectoryFile().getParent(), logicalResource ); + resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), locator.getResourcePath(), null, + request.getRemoteAddr(), activePrincipal, + request.getDavSession(), archivaLocator, this, mimeTypes, + auditListeners, scheduler ); + return resource; + } + } + catch ( RepositoryAdminException e ) + { + log.debug( "RepositoryException remote repository with d'{}' not found, msg: {}", + archivaLocator.getRepositoryId(), e.getMessage() ); + } + ManagedRepositoryContent managedRepository = null; try @@ -592,8 +623,8 @@ public class ArchivaDavResourceFactory if ( managedRepository.hasContent( artifact ) && managedRepository.getRepository().isBlockRedeployments() ) { - log.warn( "Overwriting released artifacts in repository '" + managedRepository.getId() - + "' is not allowed." ); + log.warn( "Overwriting released artifacts in repository '{}' is not allowed.", + managedRepository.getId() ); throw new DavException( HttpServletResponse.SC_CONFLICT, "Overwriting released artifacts is not allowed." ); }