From 240292077ed8c622d3e3dbe43d01f738c6293bfc Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Thu, 20 Jun 2019 19:25:28 +0200 Subject: [PATCH] Switching to asset API --- .../webdav/ArchivaDavResourceFactory.java | 13 ++++--- .../webdav/ArchivaVirtualDavResource.java | 32 ++++++---------- .../archiva/webdav/util/IndexWriter.java | 38 ++++--------------- 3 files changed, 28 insertions(+), 55 deletions(-) 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 d51b47f61..238cedb84 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 @@ -1022,7 +1022,7 @@ public class ArchivaDavResourceFactory throw new DavException(500, e); } } - List mergedRepositoryContents = new ArrayList<>(); + List mergedRepositoryContents = new ArrayList<>(); ManagedRepository firstRepo = repositories.get( 0 ); @@ -1050,8 +1050,9 @@ public class ArchivaDavResourceFactory if ( StringUtils.endsWith( pathInfo, repositoryGroup.getMergedIndexPath().getPath() ) ) { - Path mergedRepoDir = + Path mergedRepoDirPath = buildMergedIndexDirectory( activePrincipal, request, repositoryGroup ); + FilesystemAsset mergedRepoDir = new FilesystemAsset(pathInfo, mergedRepoDirPath); mergedRepositoryContents.add( mergedRepoDir ); } else @@ -1078,7 +1079,8 @@ public class ArchivaDavResourceFactory } } } - mergedRepositoryContents.add( tmpDirectory.getParent() ); + FilesystemAsset parentDir = new FilesystemAsset(pathInfo, tmpDirectory.getParent()); + mergedRepositoryContents.add( parentDir ); } for ( ManagedRepository repo : repositories ) { @@ -1093,8 +1095,9 @@ public class ArchivaDavResourceFactory throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid managed repository <" + repo.getId() + ">"); } - Path resourceFile = Paths.get( managedRepository.getRepoRoot(), logicalResource.getPath() ); - if ( Files.exists(resourceFile) ) + // Path resourceFile = Paths.get( managedRepository.getRepoRoot(), logicalResource.getPath() ); + StorageAsset resourceFile = managedRepository.getAsset(logicalResource.getPath()); + if ( resourceFile.exists() ) { // in case of group displaying index directory doesn't have sense !! IndexCreationFeature idf = managedRepository.getRepository().getFeature(IndexCreationFeature.class).get(); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaVirtualDavResource.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaVirtualDavResource.java index a74e80d4d..586eebc88 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaVirtualDavResource.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaVirtualDavResource.java @@ -19,6 +19,8 @@ package org.apache.archiva.webdav; * under the License. */ +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.content.StorageAsset; import org.apache.archiva.webdav.util.IndexWriter; import org.apache.archiva.webdav.util.MimeTypes; import org.apache.jackrabbit.util.Text; @@ -49,9 +51,8 @@ import org.joda.time.format.ISODateTimeFormat; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; /** * DavResource for virtual repositories @@ -73,10 +74,10 @@ public class ArchivaVirtualDavResource private static final String METHODS = "OPTIONS, GET, HEAD, POST, TRACE, PROPFIND, PROPPATCH, MKCOL"; - private final List localResources; + private final List localResources; - public ArchivaVirtualDavResource( List localResources, String logicalResource, MimeTypes mimeTypes, - ArchivaDavResourceLocator locator, DavResourceFactory factory ) + public ArchivaVirtualDavResource(List localResources, String logicalResource, MimeTypes mimeTypes, + ArchivaDavResourceLocator locator, DavResourceFactory factory ) { this.localResources = localResources; this.logicalResource = logicalResource; @@ -86,23 +87,14 @@ public class ArchivaVirtualDavResource } @Override - public void spool( OutputContext outputContext ) - throws IOException - { + public void spool( OutputContext outputContext ) { if ( outputContext.hasStream() ) { - Collections.sort( localResources ); - List localResourceFiles = new ArrayList<>(); - - for ( Path resourceFile : localResources ) - { - if ( Files.exists(resourceFile) ) - { - localResourceFiles.add( resourceFile ); - } - } + List localResourceFiles = localResources.stream().filter(Objects::nonNull) + .filter(repoAsset -> repoAsset.exists()) + .sorted(Comparator.comparing(o -> o.getName())).collect(Collectors.toList()); - IndexWriter writer = new IndexWriter( this, localResourceFiles, logicalResource ); + IndexWriter writer = new IndexWriter(localResourceFiles, logicalResource ); writer.write( outputContext ); } } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java index 284633156..3aa9b387b 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java @@ -50,42 +50,20 @@ public class IndexWriter private final String logicalResource; - private final List repositoryAssets; + private final List repositoryAssets; private final boolean isVirtual; - public class RepoAsset - { - private ManagedRepositoryContent repo; - private StorageAsset asset; - - public RepoAsset( ManagedRepositoryContent repo, StorageAsset asset) { - this.repo = repo; - this.asset = asset; - } - - public ManagedRepositoryContent getRepo( ) - { - return repo; - } - - public StorageAsset getAsset( ) - { - return asset; - } - - } - - public IndexWriter( ManagedRepositoryContent repo, StorageAsset reference, String logicalResource ) + public IndexWriter( StorageAsset reference, String logicalResource ) { this.repositoryAssets = new ArrayList<>( ); - this.repositoryAssets.add(new RepoAsset( repo, reference)); + this.repositoryAssets.add(reference); this.logicalResource = logicalResource; this.isVirtual = false; } - public IndexWriter( List localResources, String logicalResource ) + public IndexWriter( List localResources, String logicalResource ) { this.logicalResource = logicalResource; this.repositoryAssets = localResources; @@ -176,9 +154,9 @@ public class IndexWriter { if ( !isVirtual ) { - for ( RepoAsset localResource : repositoryAssets ) + for ( StorageAsset localResource : repositoryAssets ) { - localResource.getAsset().list().stream().sorted( + localResource.list().stream().sorted( Comparator.comparing( StorageAsset::getName ) ).forEach( asset -> { writeHyperlink( writer, asset.getName(), asset.getModificationTime().toEpochMilli(), asset.getSize(), @@ -190,9 +168,9 @@ public class IndexWriter { // virtual repository - filter unique directories SortedMap uniqueChildFiles = new TreeMap<>(); - for ( RepoAsset resource : repositoryAssets ) + for ( StorageAsset resource : repositoryAssets ) { - List files = resource.getAsset().list(); + List files = resource.list(); for ( StorageAsset file : files ) { // the first entry wins -- 2.39.5