diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-06-20 19:25:28 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-06-20 19:25:28 +0200 |
commit | 240292077ed8c622d3e3dbe43d01f738c6293bfc (patch) | |
tree | ea9ffd59107a377876a2fbb00a175f5bd423c143 /archiva-modules | |
parent | 42257e90337da35c472d87f65aab065a6ec6f07d (diff) | |
download | archiva-240292077ed8c622d3e3dbe43d01f738c6293bfc.tar.gz archiva-240292077ed8c622d3e3dbe43d01f738c6293bfc.zip |
Switching to asset API
Diffstat (limited to 'archiva-modules')
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<Path> mergedRepositoryContents = new ArrayList<>(); + List<StorageAsset> 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<Path> localResources; + private final List<StorageAsset> localResources; - public ArchivaVirtualDavResource( List<Path> localResources, String logicalResource, MimeTypes mimeTypes, - ArchivaDavResourceLocator locator, DavResourceFactory factory ) + public ArchivaVirtualDavResource(List<StorageAsset> 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<Path> localResourceFiles = new ArrayList<>(); - - for ( Path resourceFile : localResources ) - { - if ( Files.exists(resourceFile) ) - { - localResourceFiles.add( resourceFile ); - } - } + List<StorageAsset> 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<RepoAsset> repositoryAssets; + private final List<StorageAsset> 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<RepoAsset> localResources, String logicalResource ) + public IndexWriter( List<StorageAsset> 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<String, StorageAsset> uniqueChildFiles = new TreeMap<>(); - for ( RepoAsset resource : repositoryAssets ) + for ( StorageAsset resource : repositoryAssets ) { - List<StorageAsset> files = resource.getAsset().list(); + List<StorageAsset> files = resource.list(); for ( StorageAsset file : files ) { // the first entry wins |