aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-maven
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-07-19 19:29:01 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-07-19 19:29:01 +0200
commit8e4acdc82a875ca32e39eb216b879c002d228de3 (patch)
tree0c255f334dd886636ae1d1343430c89b7f1e630a /archiva-modules/archiva-maven
parentd599b89e3d259266373717897f8b7fd24fc7fb8e (diff)
downloadarchiva-8e4acdc82a875ca32e39eb216b879c002d228de3.tar.gz
archiva-8e4acdc82a875ca32e39eb216b879c002d228de3.zip
Migrating to storage API
Diffstat (limited to 'archiva-modules/archiva-maven')
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java28
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java9
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java44
3 files changed, 32 insertions, 49 deletions
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java
index b59d99835..9c383c37d 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java
@@ -28,6 +28,7 @@ import org.apache.archiva.proxy.ProxyException;
import org.apache.archiva.proxy.model.NetworkProxy;
import org.apache.archiva.proxy.model.ProxyConnector;
import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.content.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
@@ -101,9 +102,8 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
/**
* @param connector
* @param remoteRepository
- * @param tmpMd5
- * @param tmpSha1
* @param tmpResource
+ * @param checksumFiles
* @param url
* @param remotePath
* @param resource
@@ -112,9 +112,9 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @throws ProxyException
* @throws NotModifiedException
*/
- protected void transferResources(ProxyConnector connector, RemoteRepositoryContent remoteRepository, Path tmpMd5,
- Path tmpSha1, Path tmpResource, String url, String remotePath, Path resource,
- Path workingDirectory, ManagedRepositoryContent repository)
+ protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository,
+ Path tmpResource, Path[] checksumFiles, String url, String remotePath, StorageAsset resource,
+ Path workingDirectory, ManagedRepositoryContent repository )
throws ProxyException, NotModifiedException {
Wagon wagon = null;
try {
@@ -146,16 +146,17 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
boolean connected = connectToRepository(connector, wagon, remoteRepository);
if (connected) {
- transferArtifact(wagon, remoteRepository, remotePath, repository, resource, workingDirectory,
+ transferArtifact(wagon, remoteRepository, remotePath, repository, resource.getFilePath(), workingDirectory,
tmpResource);
// TODO: these should be used to validate the download based on the policies, not always downloaded
// to
// save on connections since md5 is rarely used
- transferChecksum(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".sha1",
- tmpSha1);
- transferChecksum(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".md5",
- tmpMd5);
+ for (int i=0; i<checksumFiles.length; i++) {
+ String ext = "."+StringUtils.substringAfterLast( checksumFiles[i].getFileName( ).toString( ), "." );
+ transferChecksum(wagon, remoteRepository, remotePath, repository, resource.getFilePath(), ext,
+ checksumFiles[i]);
+ }
}
} catch (NotFoundException e) {
urlFailureCache.cacheFailure(url);
@@ -196,13 +197,12 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @param remotePath the remote path to the resource to get.
* @param repository the managed repository that will hold the file
* @param resource the local file that should contain the downloaded contents
- * @param tmpDirectory the temporary directory to download to
* @param ext the type of checksum to transfer (example: ".md5" or ".sha1")
* @throws ProxyException if copying the downloaded file into place did not succeed.
*/
- protected void transferChecksum(Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
- ManagedRepositoryContent repository, Path resource, Path tmpDirectory, String ext,
- Path destFile)
+ protected void transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
+ ManagedRepositoryContent repository, Path resource, String ext,
+ Path destFile )
throws ProxyException {
String url = remoteRepository.getURL().getUrl() + remotePath + ext;
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
index 2f10b16b5..61ad3d3a0 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
@@ -27,19 +27,14 @@ import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.*;
-import org.apache.archiva.repository.content.PathParser;
import org.apache.archiva.repository.content.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -334,13 +329,13 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
@Override
- public Path toFile( ArtifactReference reference )
+ public StorageAsset toFile( ArtifactReference reference )
{
return Paths.get(getRepoRoot(), refs.get(reference));
}
@Override
- public Path toFile( ArchivaArtifact reference )
+ public StorageAsset toFile( ArchivaArtifact reference )
{
return null;
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
index 01e429e6d..9c36647d0 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
@@ -19,10 +19,7 @@ package org.apache.archiva.repository.content.maven2;
* under the License.
*/
-import org.apache.archiva.common.filelock.FileLockException;
import org.apache.archiva.common.filelock.FileLockManager;
-import org.apache.archiva.common.filelock.FileLockTimeoutException;
-import org.apache.archiva.common.filelock.Lock;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
@@ -37,15 +34,10 @@ import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryException;
-import org.apache.archiva.repository.content.FilesystemAsset;
-import org.apache.archiva.repository.content.FilesystemStorage;
import org.apache.archiva.repository.content.StorageAsset;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -55,7 +47,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
-import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -202,30 +193,30 @@ public class ManagedDefaultRepositoryContent
public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
throws ContentNotFoundException
{
- Path artifactFile = toFile( reference );
- Path repoBase = PathUtil.getPathFromUri(repository.getLocation()).toAbsolutePath();
- Path repoDir = artifactFile.getParent().toAbsolutePath();
+ StorageAsset artifactFile = toFile( reference );
+ StorageAsset repoBase = repository.getAsset( "" );
+ StorageAsset repoDir = artifactFile.getParent();
- if ( !Files.exists(repoDir))
+ if ( !repoDir.exists())
{
throw new ContentNotFoundException(
- "Unable to get related artifacts using a non-existant directory: " + repoDir.toAbsolutePath() );
+ "Unable to get related artifacts using a non-existant directory: " + repoDir.getPath() );
}
- if ( !Files.isDirectory( repoDir ) )
+ if ( !repoDir.isContainer() )
{
throw new ContentNotFoundException(
- "Unable to get related artifacts using a non-directory: " + repoDir.toAbsolutePath() );
+ "Unable to get related artifacts using a non-directory: " + repoDir.getPath() );
}
Set<ArtifactReference> foundArtifacts;
// First gather up the versions found as artifacts in the managed repository.
- try (Stream<Path> stream = Files.list(repoDir)) {
- foundArtifacts = stream.filter(Files::isRegularFile).map(path -> {
+ try (Stream<StorageAsset> stream = repoDir.list().stream() ) {
+ foundArtifacts = stream.filter(asset -> !asset.isContainer()).map(path -> {
try {
- ArtifactReference artifact = toArtifactReference(repoBase.relativize(path).toString());
+ ArtifactReference artifact = toArtifactReference(path.getPath());
if( artifact.getGroupId().equals( reference.getGroupId() ) && artifact.getArtifactId().equals(
reference.getArtifactId() ) && artifact.getVersion().equals( reference.getVersion() )) {
return artifact;
@@ -237,9 +228,6 @@ public class ManagedDefaultRepositoryContent
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toSet());
- } catch (IOException e) {
- log.error("Could not read directory {}: {}", repoDir, e.getMessage(), e);
- return Collections.emptySet();
}
return foundArtifacts;
}
@@ -379,8 +367,8 @@ public class ManagedDefaultRepositoryContent
@Override
public boolean hasContent( ArtifactReference reference )
{
- Path artifactFile = toFile( reference );
- return Files.exists(artifactFile) && Files.isRegularFile( artifactFile );
+ StorageAsset artifactFile = toFile( reference );
+ return artifactFile.exists() && !artifactFile.isContainer();
}
@Override
@@ -454,15 +442,15 @@ public class ManagedDefaultRepositoryContent
@Override
- public Path toFile( ArtifactReference reference )
+ public StorageAsset toFile( ArtifactReference reference )
{
- return PathUtil.getPathFromUri( repository.getLocation()).resolve( toPath( reference ) );
+ return repository.getAsset(toPath(reference));
}
@Override
- public Path toFile( ArchivaArtifact reference )
+ public StorageAsset toFile( ArchivaArtifact reference )
{
- return PathUtil.getPathFromUri( repository.getLocation()).resolve( toPath( reference ) );
+ return repository.getAsset( toPath( reference ) );
}
/**