aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-maven
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-07-28 15:24:13 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-07-28 15:24:13 +0200
commitbb3b074aaf5a2be0d81c950ecf1588fe8efa3316 (patch)
tree8f165780e4d81cfdb6ed4a73c40fbed3a6f39a69 /archiva-modules/archiva-maven
parent8e4acdc82a875ca32e39eb216b879c002d228de3 (diff)
downloadarchiva-bb3b074aaf5a2be0d81c950ecf1588fe8efa3316.tar.gz
archiva-bb3b074aaf5a2be0d81c950ecf1588fe8efa3316.zip
Refactoring to StorageAsset access
Diffstat (limited to 'archiva-modules/archiva-maven')
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java3
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java29
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java85
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java2
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-metadata/pom.xml4
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java32
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java12
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java13
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java75
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java17
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java11
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java57
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java17
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java37
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java21
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java20
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java9
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java175
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java29
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java2
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java4
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java2
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java3
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java17
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java10
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/ArchivaIndexManagerMock.java31
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java12
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/metadata/RepositoryMetadataReaderTest.java7
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java2
29 files changed, 384 insertions, 354 deletions
diff --git a/archiva-modules/archiva-maven/archiva-maven-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java b/archiva-modules/archiva-maven/archiva-maven-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java
index 25a3f9d64..93cc6ce81 100644
--- a/archiva-modules/archiva-maven/archiva-maven-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java
+++ b/archiva-modules/archiva-maven/archiva-maven-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java
@@ -28,12 +28,11 @@ import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.converter.RepositoryConversionException;
import org.apache.archiva.repository.BasicManagedRepository;
-import org.apache.archiva.repository.content.FilesystemStorage;
+import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
import org.apache.archiva.repository.scanner.RepositoryScanner;
import org.apache.archiva.repository.scanner.RepositoryScannerException;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.springframework.stereotype.Service;
diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java
index 47de4b72c..7f18ad185 100644
--- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java
+++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java
@@ -19,14 +19,21 @@ package org.apache.archiva.indexer.maven;
* under the License.
*/
+import org.apache.archiva.common.filelock.DefaultFileLockManager;
+import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.repository.Repository;
+import org.apache.archiva.repository.storage.FilesystemStorage;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.maven.index.context.IndexingContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
import java.sql.Date;
import java.time.ZonedDateTime;
import java.util.Set;
@@ -36,8 +43,11 @@ import java.util.Set;
*/
public class MavenIndexContext implements ArchivaIndexingContext {
+ private static final Logger log = LoggerFactory.getLogger(ArchivaIndexingContext.class);
+
private IndexingContext delegate;
private Repository repository;
+ private StorageAsset dir = null;
protected MavenIndexContext(Repository repository, IndexingContext delegate) {
this.delegate = delegate;
@@ -56,8 +66,23 @@ public class MavenIndexContext implements ArchivaIndexingContext {
}
@Override
- public URI getPath() {
- return delegate.getIndexDirectoryFile().toURI();
+ public StorageAsset getPath() {
+ if (dir==null) {
+ StorageAsset repositoryDirAsset = repository.getAsset("");
+ Path repositoryDir = repositoryDirAsset.getFilePath().toAbsolutePath();
+ Path indexDir = delegate.getIndexDirectoryFile().toPath();
+ if (indexDir.startsWith(repositoryDir)) {
+ dir = repository.getAsset(repositoryDir.relativize(indexDir).toString());
+ } else {
+ try {
+ FilesystemStorage storage = new FilesystemStorage(indexDir, new DefaultFileLockManager());
+ dir = storage.getAsset("");
+ } catch (IOException e) {
+ log.error("Error occured while creating storage for index dir");
+ }
+ }
+ }
+ return dir;
}
@Override
diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java
index d04911206..a621a5bc8 100644
--- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java
+++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java
@@ -19,7 +19,6 @@ package org.apache.archiva.indexer.maven;
* under the License.
*/
-import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.configuration.ArchivaConfiguration;
@@ -28,8 +27,6 @@ import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.indexer.IndexCreationFailedException;
import org.apache.archiva.indexer.IndexUpdateFailedException;
import org.apache.archiva.indexer.UnsupportedBaseContextException;
-import org.apache.archiva.indexer.merger.IndexMergerException;
-import org.apache.archiva.indexer.merger.TemporaryGroupIndex;
import org.apache.archiva.proxy.ProxyRegistry;
import org.apache.archiva.proxy.maven.WagonFactory;
import org.apache.archiva.proxy.maven.WagonFactoryException;
@@ -42,10 +39,12 @@ import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.UnsupportedRepositoryTypeException;
-import org.apache.archiva.repository.content.FilesystemAsset;
-import org.apache.archiva.repository.content.StorageAsset;
+import org.apache.archiva.repository.storage.FilesystemStorage;
+import org.apache.archiva.repository.storage.RepositoryStorage;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.RemoteIndexFeature;
+import org.apache.archiva.repository.storage.StorageUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactContextProducer;
@@ -142,7 +141,7 @@ public class MavenIndexManager implements ArchivaIndexManager {
private ProxyRegistry proxyRegistry;
- private ConcurrentSkipListSet<Path> activeContexts = new ConcurrentSkipListSet<>( );
+ private ConcurrentSkipListSet<StorageAsset> activeContexts = new ConcurrentSkipListSet<>( );
private static final int WAIT_TIME = 100;
private static final int MAX_WAIT = 10;
@@ -158,9 +157,9 @@ public class MavenIndexManager implements ArchivaIndexManager {
return context.getBaseContext( IndexingContext.class );
}
- private Path getIndexPath( ArchivaIndexingContext ctx )
+ private StorageAsset getIndexPath( ArchivaIndexingContext ctx )
{
- return PathUtil.getPathFromUri( ctx.getPath( ) );
+ return ctx.getPath( );
}
@FunctionalInterface
@@ -185,7 +184,7 @@ public class MavenIndexManager implements ArchivaIndexManager {
{
throw new IndexUpdateFailedException( "Maven index is not supported by this context", e );
}
- final Path ctxPath = getIndexPath( context );
+ final StorageAsset ctxPath = getIndexPath( context );
int loop = MAX_WAIT;
boolean active = false;
while ( loop-- > 0 && !active )
@@ -395,9 +394,9 @@ public class MavenIndexManager implements ArchivaIndexManager {
@Override
public void addArtifactsToIndex( final ArchivaIndexingContext context, final Collection<URI> artifactReference ) throws IndexUpdateFailedException
{
- final URI ctxUri = context.getPath();
+ final StorageAsset ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
- Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
+ Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.getFilePath().toUri().resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.addArtifactsToIndex(artifacts, indexingContext);
} catch (IOException e) {
@@ -411,9 +410,9 @@ public class MavenIndexManager implements ArchivaIndexManager {
@Override
public void removeArtifactsFromIndex( ArchivaIndexingContext context, Collection<URI> artifactReference ) throws IndexUpdateFailedException
{
- final URI ctxUri = context.getPath();
+ final StorageAsset ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
- Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
+ Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.getFilePath().toUri().resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.deleteArtifactsFromIndex(artifacts, indexingContext);
} catch (IOException e) {
@@ -457,9 +456,8 @@ public class MavenIndexManager implements ArchivaIndexManager {
throw new IndexCreationFailedException( "Could not create index context for repository " + repository.getId( )
+ ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e );
}
- MavenIndexContext context = new MavenIndexContext( repository, mvnCtx );
- return context;
+ return new MavenIndexContext( repository, mvnCtx );
}
@Override
@@ -472,7 +470,7 @@ public class MavenIndexManager implements ArchivaIndexManager {
log.warn("Index close failed");
}
try {
- FileUtils.deleteDirectory(Paths.get(context.getPath()));
+ StorageUtil.deleteRecursively(context.getPath());
} catch (IOException e) {
throw new IndexUpdateFailedException("Could not delete index files");
}
@@ -593,51 +591,57 @@ public class MavenIndexManager implements ArchivaIndexManager {
}
}
- private StorageAsset getIndexPath(URI indexDir, Path repoDir, String defaultDir) throws IOException
+ private StorageAsset getIndexPath(URI indexDirUri, RepositoryStorage storage, String defaultDir) throws IOException
{
- String indexPath = indexDir.getPath();
- Path indexDirectory = null;
- if ( ! StringUtils.isEmpty(indexDir.toString( ) ) )
+ Path indexDirectory;
+ Path repositoryPath = storage.getAsset("").getFilePath().toAbsolutePath();
+ StorageAsset indexDir;
+ if ( ! StringUtils.isEmpty(indexDirUri.toString( ) ) )
{
- indexDirectory = PathUtil.getPathFromUri( indexDir );
+ indexDirectory = PathUtil.getPathFromUri( indexDirUri );
// not absolute so create it in repository directory
- if ( indexDirectory.isAbsolute( ) )
+ if ( indexDirectory.isAbsolute( ) && !indexDirectory.startsWith(repositoryPath))
{
- indexPath = indexDirectory.getFileName().toString();
+ if (storage instanceof FilesystemStorage) {
+ FilesystemStorage fsStorage = (FilesystemStorage) storage;
+ FilesystemStorage indexStorage = new FilesystemStorage(indexDirectory.getParent(), fsStorage.getFileLockManager());
+ indexDir = indexStorage.getAsset(indexDirectory.getFileName().toString());
+ } else {
+ throw new IOException("The given storage is not file based.");
+ }
+ } else if (indexDirectory.isAbsolute()) {
+ indexDir = storage.getAsset(repositoryPath.relativize(indexDirectory).toString());
}
else
{
- indexDirectory = repoDir.resolve( indexDirectory );
+ indexDir = storage.getAsset(indexDirectory.toString());
}
}
else
{
- indexDirectory = repoDir.resolve( defaultDir );
- indexPath = defaultDir;
+ indexDir = storage.getAsset( defaultDir );
}
- if ( !Files.exists( indexDirectory ) )
+ if ( !indexDir.exists() )
{
- Files.createDirectories( indexDirectory );
+ indexDir.create();
}
- return new FilesystemAsset( indexPath, indexDirectory);
+ return indexDir;
}
private StorageAsset getIndexPath( Repository repo) throws IOException {
IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
- return getIndexPath( icf.getIndexPath(), repo.getAsset( "" ).getFilePath(), DEFAULT_INDEX_PATH);
+ return getIndexPath( icf.getIndexPath(), repo, DEFAULT_INDEX_PATH);
}
private StorageAsset getPackedIndexPath(Repository repo) throws IOException {
IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
- return getIndexPath(icf.getPackedIndexPath(), repo.getAsset( "" ).getFilePath(), DEFAULT_PACKED_INDEX_PATH);
+ return getIndexPath(icf.getPackedIndexPath(), repo, DEFAULT_PACKED_INDEX_PATH);
}
private IndexingContext createRemoteContext(RemoteRepository remoteRepository ) throws IOException
{
- Path appServerBase = archivaConfiguration.getAppServerBaseDir( );
-
String contextKey = "remote-" + remoteRepository.getId( );
@@ -648,7 +652,7 @@ public class MavenIndexManager implements ArchivaIndexManager {
Files.createDirectories( repoDir );
}
- StorageAsset indexDirectory = null;
+ StorageAsset indexDirectory;
// is there configured indexDirectory ?
if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) )
@@ -715,7 +719,7 @@ public class MavenIndexManager implements ArchivaIndexManager {
}
}
- StorageAsset indexDirectory = null;
+ StorageAsset indexDirectory;
if ( repository.supportsFeature( IndexCreationFeature.class ) )
{
@@ -837,23 +841,18 @@ public class MavenIndexManager implements ArchivaIndexManager {
}
@Override
- public void connect( String id, String url )
- throws IOException
- {
+ public void connect( String id, String url ) {
//no op
}
@Override
- public void disconnect( )
- throws IOException
- {
+ public void disconnect( ) {
// no op
}
@Override
public InputStream retrieve( String name )
- throws IOException, FileNotFoundException
- {
+ throws IOException {
try
{
log.info( "index update retrieve file, name:{}", name );
diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java
index 2698575db..5f73f27eb 100644
--- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java
@@ -208,7 +208,7 @@ public class MavenIndexManagerTest {
assertNotNull(ctx);
assertEquals(repository, ctx.getRepository());
assertEquals("test-repo", ctx.getId());
- assertEquals(indexPath.toAbsolutePath(), Paths.get(ctx.getPath()).toAbsolutePath());
+ assertEquals(indexPath.toAbsolutePath(), ctx.getPath().getFilePath().toAbsolutePath());
assertTrue(Files.exists(indexPath));
List<Path> li = Files.list(indexPath).collect(Collectors.toList());
assertTrue(li.size()>0);
diff --git a/archiva-modules/archiva-maven/archiva-maven-metadata/pom.xml b/archiva-modules/archiva-maven/archiva-maven-metadata/pom.xml
index aca1c7d4b..3448fe001 100644
--- a/archiva-modules/archiva-maven/archiva-maven-metadata/pom.xml
+++ b/archiva-modules/archiva-maven/archiva-maven-metadata/pom.xml
@@ -41,6 +41,10 @@
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-storage-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
<artifactId>archiva-xml-tools</artifactId>
</dependency>
<dependency>
diff --git a/archiva-modules/archiva-maven/archiva-maven-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java b/archiva-modules/archiva-maven/archiva-maven-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java
index 023b8eaa2..2c81bd994 100644
--- a/archiva-modules/archiva-maven/archiva-maven-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java
+++ b/archiva-modules/archiva-maven/archiva-maven-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java
@@ -21,6 +21,7 @@ package org.apache.archiva.maven2.metadata;
import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.model.Plugin;
import org.apache.archiva.model.SnapshotVersion;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.xml.XMLException;
import org.apache.archiva.xml.XMLReader;
import org.apache.commons.lang.math.NumberUtils;
@@ -64,6 +65,14 @@ public class MavenMetadataReader
private static final Logger log = LoggerFactory.getLogger( MavenMetadataReader.class );
+ public static ArchivaRepositoryMetadata read(StorageAsset metadataFile) throws XMLException, IOException {
+ if (metadataFile.isFileBased()) {
+ return read(metadataFile.getFilePath());
+ } else {
+ throw new IOException("StorageAsset is not file based");
+ }
+ }
+
/**
* Read and return the {@link org.apache.archiva.model.ArchivaRepositoryMetadata} object from the provided xml file.
*
@@ -72,8 +81,7 @@ public class MavenMetadataReader
* @throws XMLException
*/
public static ArchivaRepositoryMetadata read( Path metadataFile )
- throws XMLException
- {
+ throws XMLException, IOException {
XMLReader xml = new XMLReader( "metadata", metadataFile );
// invoke this to remove namespaces, see MRM-1136
@@ -85,25 +93,9 @@ public class MavenMetadataReader
metadata.setArtifactId( xml.getElementText( "//metadata/artifactId" ) );
metadata.setVersion( xml.getElementText( "//metadata/version" ) );
Date modTime;
- try
- {
- modTime = new Date(Files.getLastModifiedTime( metadataFile ).toMillis( ));
- }
- catch ( IOException e )
- {
- modTime = new Date();
- log.error("Could not read modification time of {}", metadataFile);
- }
+ modTime = new Date(Files.getLastModifiedTime(metadataFile).toMillis());
metadata.setFileLastModified( modTime );
- try
- {
- metadata.setFileSize( Files.size( metadataFile ) );
- }
- catch ( IOException e )
- {
- metadata.setFileSize( 0 );
- log.error("Could not read file size of {}", metadataFile);
- }
+ metadata.setFileSize( Files.size(metadataFile) );
metadata.setLastUpdated( xml.getElementText( "//metadata/versioning/lastUpdated" ) );
metadata.setLatestVersion( xml.getElementText( "//metadata/versioning/latest" ) );
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 9c383c37d..7119c9613 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,7 +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.archiva.repository.storage.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
@@ -113,7 +113,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @throws NotModifiedException
*/
protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository,
- Path tmpResource, Path[] checksumFiles, String url, String remotePath, StorageAsset resource,
+ StorageAsset tmpResource, StorageAsset[] checksumFiles, String url, String remotePath, StorageAsset resource,
Path workingDirectory, ManagedRepositoryContent repository )
throws ProxyException, NotModifiedException {
Wagon wagon = null;
@@ -153,9 +153,9 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
// to
// save on connections since md5 is rarely used
for (int i=0; i<checksumFiles.length; i++) {
- String ext = "."+StringUtils.substringAfterLast( checksumFiles[i].getFileName( ).toString( ), "." );
+ String ext = "."+StringUtils.substringAfterLast(checksumFiles[i].getName( ), "." );
transferChecksum(wagon, remoteRepository, remotePath, repository, resource.getFilePath(), ext,
- checksumFiles[i]);
+ checksumFiles[i].getFilePath());
}
}
} catch (NotFoundException e) {
@@ -182,9 +182,9 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
protected void transferArtifact(Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, Path resource, Path tmpDirectory,
- Path destFile)
+ StorageAsset destFile)
throws ProxyException {
- transferSimpleFile(wagon, remoteRepository, remotePath, repository, resource, destFile);
+ transferSimpleFile(wagon, remoteRepository, remotePath, repository, resource, destFile.getFilePath());
}
/**
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java
index 0061fa732..3a9c16bba 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java
@@ -26,6 +26,7 @@ import org.apache.archiva.policies.ChecksumPolicy;
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.policies.urlcache.UrlFailureCache;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.easymock.EasyMock;
import org.junit.Test;
@@ -82,7 +83,7 @@ public class CacheFailuresTransferTest
wagonMockControl.replay();
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify();
@@ -92,7 +93,7 @@ public class CacheFailuresTransferTest
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify();
- assertNotDownloaded( downloadedFile);
+ assertNotDownloaded( downloadedFile.getFilePath());
assertNoTempFiles( expectedFile );
}
@@ -124,7 +125,7 @@ public class CacheFailuresTransferTest
wagonMockControl.replay();
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify();
@@ -140,7 +141,7 @@ public class CacheFailuresTransferTest
wagonMockControl.verify();
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertNoTempFiles( expectedFile );
}
@@ -168,11 +169,11 @@ public class CacheFailuresTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
// Validate that file actually came from proxied2 (as intended).
Path proxied2File = Paths.get( REPOPATH_PROXIED2, path );
- assertFileEquals( expectedFile, downloadedFile, proxied2File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied2File );
assertNoTempFiles( expectedFile );
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java
index e9ade0479..2bf77d2ec 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java
@@ -25,6 +25,7 @@ import org.apache.archiva.policies.CachedFailuresPolicy;
import org.apache.archiva.policies.ChecksumPolicy;
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.easymock.EasyMock;
import org.junit.Test;
@@ -63,7 +64,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNull( downloadedFile );
}
@@ -85,10 +86,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar",
"e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar" );
@@ -111,10 +112,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
null );
@@ -137,10 +138,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
}
@@ -162,10 +163,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, null, null );
}
@@ -187,10 +188,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
}
@@ -212,9 +213,9 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertChecksums( expectedFile, null, null );
}
@@ -235,10 +236,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "4ec20a12dc91557330bd0b39d1805be5e329ae56 get-checksum-both-bad-1.0.jar",
"a292491a35925465e693a44809a078b5 get-checksum-both-bad-1.0.jar" );
@@ -261,9 +262,9 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertChecksums( expectedFile, null, null );
}
@@ -284,11 +285,11 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
// This is a success situation. No SHA1 with a Good MD5.
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
}
@@ -310,9 +311,9 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertChecksums( expectedFile, null, null );
}
@@ -333,10 +334,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
"invalid checksum file" );
@@ -360,10 +361,10 @@ public class ChecksumTransferTest
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
"c35f3b76268b73a4ba617f6f275c49ab get-checksum-sha1-bad-md5-1.0.jar" );
@@ -386,10 +387,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "71f7dc3f72053a3f2d9fdd6fef9db055ef957ffb get-checksum-md5-only-1.0.jar",
"f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
@@ -412,10 +413,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "1f12821c5e43e1a0b76b9564a6ddb0548ccb9486 get-default-layout-1.0.jar",
"3f7341545f21226b6f49a3c2704cb9be get-default-layout-1.0.jar" );
@@ -452,7 +453,7 @@ public class ChecksumTransferTest
wagonMockControl.replay();
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify();
@@ -465,7 +466,7 @@ public class ChecksumTransferTest
// Test results.
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
null );
@@ -489,10 +490,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
// There are no hashcodes on the proxy side to download, hence the local ones should remain invalid.
assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
@@ -516,9 +517,9 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertNoTempFiles( expectedFile );
// There are no hashcodes on the proxy side to download.
// The FAIL policy will delete the checksums as bad.
@@ -544,10 +545,10 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4 get-bad-local-checksum-1.0.jar",
"46fdd6ca55bf1d7a7eb0c858f41e0ccd get-bad-local-checksum-1.0.jar" );
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java
index cef7501b4..511ea16da 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java
@@ -27,6 +27,7 @@ import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.repository.LayoutException;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.authorization.AuthorizationException;
@@ -598,7 +599,7 @@ public class ErrorHandlingTest
wagonMockControl.replay();
// Attempt the proxy fetch.
- Path downloadedFile = null;
+ StorageAsset downloadedFile = null;
try
{
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
@@ -616,33 +617,33 @@ public class ErrorHandlingTest
wagonMockControl.verify();
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
}
private void confirmSuccess( String path, Path expectedFile, String basedir )
throws Exception
{
- Path downloadedFile = performDownload( path );
+ StorageAsset downloadedFile = performDownload( path );
Path proxied1File = Paths.get( basedir, path );
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
}
private void confirmNotDownloadedNoError( String path )
throws Exception
{
- Path downloadedFile = performDownload( path );
+ StorageAsset downloadedFile = performDownload( path );
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
}
- private Path performDownload( String path )
+ private StorageAsset performDownload( String path )
throws ProxyDownloadException, LayoutException
{
wagonMockControl.replay();
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
managedDefaultRepository.toArtifactReference( path ) );
wagonMockControl.verify();
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java
index 5d2c93b4f..3df014c1c 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java
@@ -32,6 +32,7 @@ import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.io.FileUtils;
import org.assertj.core.api.Assertions;
@@ -208,18 +209,18 @@ public class HttpProxyTransferTest
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path sourceFile = Paths.get( PROXIED_BASEDIR, path );
assertNotNull( "Expected File should not be null.", expectedFile );
assertNotNull( "Actual File should not be null.", downloadedFile );
- assertTrue( "Check actual file exists.", Files.exists(downloadedFile));
- assertTrue( "Check filename path is appropriate.", Files.isSameFile( expectedFile, downloadedFile));
- assertTrue( "Check file path matches.", Files.isSameFile( expectedFile, downloadedFile));
+ assertTrue( "Check actual file exists.", Files.exists(downloadedFile.getFilePath()));
+ assertTrue( "Check filename path is appropriate.", Files.isSameFile( expectedFile, downloadedFile.getFilePath()));
+ assertTrue( "Check file path matches.", Files.isSameFile( expectedFile, downloadedFile.getFilePath()));
String expectedContents = FileUtils.readFileToString( sourceFile.toFile(), Charset.defaultCharset() );
- String actualContents = FileUtils.readFileToString( downloadedFile.toFile(), Charset.defaultCharset() );
+ String actualContents = FileUtils.readFileToString( downloadedFile.getFilePath().toFile(), Charset.defaultCharset() );
assertEquals( "Check file contents.", expectedContents, actualContents );
Assertions.assertThat( System.getProperty( "http.proxyHost" , "") ).isEmpty();
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java
index 017594374..03bfbceaf 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java
@@ -24,6 +24,7 @@ import org.apache.archiva.policies.CachedFailuresPolicy;
import org.apache.archiva.policies.ChecksumPolicy;
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.wagon.ResourceDoesNotExistException;
@@ -64,7 +65,7 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, true );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNull( "File should not have been downloaded", downloadedFile );
}
@@ -86,10 +87,10 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path sourceFile = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, sourceFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), sourceFile );
assertNoTempFiles( expectedFile );
}
@@ -110,13 +111,13 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
Path sourceFile = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, sourceFile );
- assertFalse( Files.exists( downloadedFile.getParent().resolve(downloadedFile.getFileName() + ".sha1" )) );
- assertFalse( Files.exists(downloadedFile.getParent().resolve(downloadedFile.getFileName() + ".md5" ) ));
- assertFalse( Files.exists( downloadedFile.getParent().resolve(downloadedFile.getFileName() + ".asc" ) ));
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), sourceFile );
+ assertFalse( Files.exists( downloadedFile.getParent().getFilePath().resolve(downloadedFile.getName() + ".sha1" )) );
+ assertFalse( Files.exists(downloadedFile.getParent().getFilePath().resolve(downloadedFile.getName() + ".md5" ) ));
+ assertFalse( Files.exists( downloadedFile.getParent().getFilePath().resolve(downloadedFile.getName() + ".asc" ) ));
assertNoTempFiles( expectedFile );
}
@@ -145,9 +146,9 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertFileEquals( expectedFile, downloadedFile, expectedFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), expectedFile );
assertNoTempFiles( expectedFile );
}
@@ -179,9 +180,9 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertNotModified( expectedFile, originalModificationTime );
assertNoTempFiles( expectedFile );
}
@@ -225,9 +226,9 @@ public class ManagedDefaultTransferTest
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertNotModified( expectedFile, originalModificationTime );
assertNoTempFiles( expectedFile );
}
@@ -270,10 +271,10 @@ public class ManagedDefaultTransferTest
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
@@ -302,10 +303,10 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
@@ -326,15 +327,15 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
- assertFileEquals( expectedFile, downloadedFile, proxied1File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
assertNoTempFiles( expectedFile );
// TODO: is this check even needed if it passes above?
- String actualContents = FileUtils.readFileToString( downloadedFile.toFile(), Charset.defaultCharset() );
+ String actualContents = FileUtils.readFileToString( downloadedFile.getFilePath().toFile(), Charset.defaultCharset() );
String badContents = FileUtils.readFileToString( proxied2File.toFile(), Charset.defaultCharset() );
assertFalse( "Downloaded file contents should not be that of proxy 2",
StringUtils.equals( actualContents, badContents ) );
@@ -357,10 +358,10 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
- assertFileEquals( expectedFile, downloadedFile, proxied2File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied2File );
assertNoTempFiles( expectedFile );
}
@@ -381,7 +382,7 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception",
downloadedFile );
@@ -412,12 +413,12 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify();
Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
- assertFileEquals( expectedFile, downloadedFile, proxied2File );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied2File );
assertNoTempFiles( expectedFile );
}
@@ -451,9 +452,9 @@ public class ManagedDefaultTransferTest
wagonMockControl.replay();
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
wagonMockControl.verify();
assertNoTempFiles( expectedFile );
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java
index 23bfb8503..dc3681aaa 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java
@@ -19,6 +19,7 @@ package org.apache.archiva.proxy;
* under the License.
*/
+import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
@@ -34,6 +35,8 @@ import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.repository.metadata.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
+import org.apache.archiva.repository.storage.FilesystemStorage;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.wagon.TransferFailedException;
import org.custommonkey.xmlunit.DetailedDiff;
@@ -125,7 +128,7 @@ public class MetadataTransferTest
ProjectReference metadata = createProjectReference( requestedResource );
- Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
+ StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();
@@ -988,7 +991,7 @@ public class MetadataTransferTest
ProjectReference metadata = createProjectReference( requestedResource );
- Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
+ StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();
@@ -1014,7 +1017,7 @@ public class MetadataTransferTest
Path expectedFile = managedDefaultDir.resolve(requestedResource);
ProjectReference metadata = createProjectReference( requestedResource );
- Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
+ StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();
@@ -1035,7 +1038,7 @@ public class MetadataTransferTest
VersionedReference metadata = createVersionedReference( requestedResource );
- Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
+ StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();
@@ -1061,7 +1064,7 @@ public class MetadataTransferTest
Path expectedFile = managedDefaultDir.resolve(requestedResource);
VersionedReference metadata = createVersionedReference( requestedResource );
- Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
+ StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();
@@ -1090,7 +1093,9 @@ public class MetadataTransferTest
assertTrue( "Actual file exists.", Files.exists(actualFile) );
StringWriter actualContents = new StringWriter();
- ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile );
+ FilesystemStorage fsStorage = new FilesystemStorage(actualFile.getParent(), new DefaultFileLockManager());
+ StorageAsset actualFileAsset = fsStorage.getAsset(actualFile.getFileName().toString());
+ ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFileAsset );
RepositoryMetadataWriter.write( metadata, actualContents );
DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java
index 9ab0585bf..ace9e584a 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java
@@ -24,6 +24,7 @@ import org.apache.archiva.policies.CachedFailuresPolicy;
import org.apache.archiva.policies.ChecksumPolicy;
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.junit.Test;
import java.nio.file.Files;
@@ -59,8 +60,8 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertNotDownloaded( downloadedFile );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertNoTempFiles( expectedFile );
}
@@ -80,10 +81,10 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
@@ -103,10 +104,10 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
@@ -128,10 +129,10 @@ public class SnapshotTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
// Attempt to download.
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
// Should not have downloaded as managed is newer than remote.
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertNoTempFiles( expectedFile );
}
@@ -220,9 +221,9 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
@@ -244,9 +245,9 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertNotDownloaded( downloadedFile );
+ assertNotDownloaded( downloadedFile.getFilePath() );
assertNotModified( expectedFile, expectedTimestamp );
assertNoTempFiles( expectedFile );
}
@@ -270,10 +271,10 @@ public class SnapshotTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
@@ -293,10 +294,10 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
@@ -320,10 +321,10 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
- Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
}
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 61ad3d3a0..706511c68 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
@@ -19,6 +19,7 @@ package org.apache.archiva.repository.mock;
* under the License.
*/
+import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
@@ -27,10 +28,12 @@ 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.StorageAsset;
+import org.apache.archiva.repository.storage.FilesystemStorage;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
+import java.io.IOException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
@@ -50,6 +53,7 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
private ManagedRepository repository;
+ private FilesystemStorage fsStorage;
ManagedRepositoryContentMock(ManagedRepository repo) {
this.repository = repo;
@@ -94,7 +98,18 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
@Override
public String getRepoRoot( )
{
- return Paths.get("", "target", "test-repository", "managed").toString();
+ return getRepoRootAsset().getFilePath().toString();
+ }
+
+ private StorageAsset getRepoRootAsset() {
+ if (fsStorage==null) {
+ try {
+ fsStorage = new FilesystemStorage(Paths.get("", "target", "test-repository", "managed"), new DefaultFileLockManager());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return fsStorage.getAsset("");
}
@Override
@@ -331,7 +346,7 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
@Override
public StorageAsset toFile( ArtifactReference reference )
{
- return Paths.get(getRepoRoot(), refs.get(reference));
+ return getRepoRootAsset().resolve( refs.get(reference));
}
@Override
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java
index 4fee9ee60..05ad9a011 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java
@@ -36,6 +36,7 @@ import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.maven2.MavenSystemManager;
import org.apache.archiva.repository.metadata.MetadataTools;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.xml.XMLException;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
@@ -55,8 +56,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
-import java.nio.file.Files;
-import java.nio.file.Path;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -233,22 +233,22 @@ public class Maven3DependencyTreeBuilder
for ( String repoId : repositoryIds )
{
ManagedRepository managedRepo = repositoryRegistry.getManagedRepository(repoId);
- Path repoDir = managedRepo.getAsset("").getFilePath();
+ StorageAsset repoDir = managedRepo.getAsset("");
- Path file = pathTranslator.toFile( repoDir, projectArtifact.getGroupId(), projectArtifact.getArtifactId(),
+ StorageAsset file = pathTranslator.toFile( repoDir, projectArtifact.getGroupId(), projectArtifact.getArtifactId(),
projectArtifact.getBaseVersion(),
projectArtifact.getArtifactId() + "-" + projectArtifact.getVersion()
+ ".pom" );
- if ( Files.exists(file) )
+ if ( file.exists() )
{
return managedRepo;
}
// try with snapshot version
if ( StringUtils.endsWith( projectArtifact.getBaseVersion(), VersionUtil.SNAPSHOT ) )
{
- Path metadataFile = file.getParent().resolve( MetadataTools.MAVEN_METADATA );
- if ( Files.exists(metadataFile) )
+ StorageAsset metadataFile = file.getParent().resolve( MetadataTools.MAVEN_METADATA );
+ if ( metadataFile.exists() )
{
try
{
@@ -262,14 +262,14 @@ public class Maven3DependencyTreeBuilder
"-" + VersionUtil.SNAPSHOT ) ).append( '-' ).append(
timeStamp ).append( '-' ).append( Integer.toString( buildNumber ) ).append(
".pom" ).toString();
- Path timeStampFile = file.getParent().resolve( timeStampFileName );
+ StorageAsset timeStampFile = file.getParent().resolve( timeStampFileName );
log.debug( "try to find timestamped snapshot version file: {}", timeStampFile);
- if ( Files.exists(timeStampFile) )
+ if ( timeStampFile.exists() )
{
return managedRepo;
}
}
- catch ( XMLException e )
+ catch (XMLException | IOException e )
{
log.warn( "skip fail to find timestamped snapshot pom: {}", e.getMessage() );
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java
index b91036809..7d728f9fc 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java
@@ -23,6 +23,7 @@ import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -78,13 +79,13 @@ public class Maven2RepositoryPathTranslator
}
@Override
- public Path toFile(Path basedir, String namespace, String projectId, String projectVersion, String filename )
+ public StorageAsset toFile(StorageAsset basedir, String namespace, String projectId, String projectVersion, String filename )
{
return basedir.resolve( toPath( namespace, projectId, projectVersion, filename ) );
}
@Override
- public Path toFile( Path basedir, String namespace, String projectId, String projectVersion )
+ public StorageAsset toFile( StorageAsset basedir, String namespace, String projectId, String projectVersion )
{
return basedir.resolve( toPath( namespace, projectId, projectVersion ) );
}
@@ -148,13 +149,13 @@ public class Maven2RepositoryPathTranslator
}
@Override
- public Path toFile( Path basedir, String namespace, String projectId )
+ public StorageAsset toFile( StorageAsset basedir, String namespace, String projectId )
{
return basedir.resolve( toPath( namespace, projectId ) );
}
@Override
- public Path toFile( Path basedir, String namespace )
+ public StorageAsset toFile( StorageAsset basedir, String namespace )
{
return basedir.resolve( toPath( namespace ) );
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
index e754a72cf..6d788c06a 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
@@ -48,6 +48,7 @@ import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.repository.*;
import org.apache.archiva.repository.content.PathParser;
import org.apache.archiva.repository.maven2.MavenSystemManager;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.xml.XMLException;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
@@ -80,11 +81,9 @@ import javax.inject.Named;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
+import java.nio.channels.Channels;
import java.nio.charset.Charset;
-import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -95,7 +94,6 @@ import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
// import java.io.FileNotFoundException;
@@ -187,9 +185,9 @@ public class Maven2RepositoryStorage
}
}
}
- Path basedir = Paths.get(managedRepository.getLocation());
+ StorageAsset basedir = managedRepository.getAsset("");
if (VersionUtil.isSnapshot(artifactVersion)) {
- Path metadataFile = pathTranslator.toFile(basedir, readMetadataRequest.getNamespace(),
+ StorageAsset metadataFile = pathTranslator.toFile(basedir, readMetadataRequest.getNamespace(),
readMetadataRequest.getProjectId(), artifactVersion,
METADATA_FILENAME);
try {
@@ -203,7 +201,7 @@ public class Maven2RepositoryStorage
artifactVersion =
artifactVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
}
- } catch (XMLException e) {
+ } catch (XMLException | IOException e) {
// unable to parse metadata - LOGGER it, and continue with the version as the original SNAPSHOT version
LOGGER.warn("Invalid metadata: {} - {}", metadataFile, e.getMessage());
}
@@ -211,14 +209,14 @@ public class Maven2RepositoryStorage
// TODO: won't work well with some other layouts, might need to convert artifact parts to ID by path translator
String id = readMetadataRequest.getProjectId() + "-" + artifactVersion + ".pom";
- Path file =
+ StorageAsset file =
pathTranslator.toFile(basedir, readMetadataRequest.getNamespace(), readMetadataRequest.getProjectId(),
readMetadataRequest.getProjectVersion(), id);
- if (!Files.exists(file)) {
+ if (!file.exists()) {
// metadata could not be resolved
throw new RepositoryStorageMetadataNotFoundException(
- "The artifact's POM file '" + file.toAbsolutePath() + "' was missing");
+ "The artifact's POM file '" + file.getPath() + "' was missing");
}
// TODO: this is a workaround until we can properly resolve using proxies as well - this doesn't cache
@@ -254,7 +252,7 @@ public class Maven2RepositoryStorage
}
ModelBuildingRequest req =
- new DefaultModelBuildingRequest().setProcessPlugins(false).setPomFile(file.toFile()).setTwoPhaseBuilding(
+ new DefaultModelBuildingRequest().setProcessPlugins(false).setPomFile(file.getFilePath().toFile()).setTwoPhaseBuilding(
false).setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
//MRM-1607. olamy this will resolve jdk profiles on the current running archiva jvm
@@ -460,67 +458,52 @@ public class Maven2RepositoryStorage
@Override
public Collection<String> listRootNamespaces(String repoId, Filter<String> filter)
throws RepositoryStorageRuntimeException {
- Path dir = getRepositoryBasedir(repoId);
+ StorageAsset dir = getRepositoryBasedir(repoId);
return getSortedFiles(dir, filter);
}
- private static Collection<String> getSortedFiles(Path dir, Filter<String> filter) {
+ private static Collection<String> getSortedFiles(StorageAsset dir, Filter<String> filter) {
- try (Stream<Path> stream = Files.list(dir)) {
- final Predicate<Path> dFilter = new DirectoryFilter(filter);
- return stream.filter(Files::isDirectory)
+ final Predicate<StorageAsset> dFilter = new DirectoryFilter(filter);
+ return dir.list().stream().filter(f -> f.isContainer())
.filter(dFilter)
- .map(path -> path.getFileName().toString())
+ .map(path -> path.getName().toString())
.sorted().collect(Collectors.toList());
- } catch (IOException e) {
- LOGGER.error("Could not read directory list {}: {}", dir, e.getMessage(), e);
- return Collections.emptyList();
- }
}
- private Path getRepositoryBasedir(String repoId)
+ private StorageAsset getRepositoryBasedir(String repoId)
throws RepositoryStorageRuntimeException {
ManagedRepository repositoryConfiguration = repositoryRegistry.getManagedRepository(repoId);
- return Paths.get(repositoryConfiguration.getLocation());
+ return repositoryConfiguration.getAsset("");
}
@Override
public Collection<String> listNamespaces(String repoId, String namespace, Filter<String> filter)
throws RepositoryStorageRuntimeException {
- Path dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace);
- if (!(Files.exists(dir) && Files.isDirectory(dir))) {
+ StorageAsset dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace);
+ if (!(dir.exists()) && !dir.isContainer()) {
return Collections.emptyList();
}
// scan all the directories which are potential namespaces. Any directories known to be projects are excluded
- Predicate<Path> dFilter = new DirectoryFilter(filter);
- try (Stream<Path> stream = Files.list(dir)) {
- return stream.filter(dFilter).filter(path -> !isProject(path, filter)).map(path -> path.getFileName().toString())
+ Predicate<StorageAsset> dFilter = new DirectoryFilter(filter);
+ return dir.list().stream().filter(dFilter).filter(path -> !isProject(path, filter)).map(path -> path.getName().toString())
.sorted().collect(Collectors.toList());
- } catch (IOException e) {
- LOGGER.error("Could not read directory {}: {}", dir, e.getMessage(), e);
- return Collections.emptyList();
- }
}
@Override
public Collection<String> listProjects(String repoId, String namespace, Filter<String> filter)
throws RepositoryStorageRuntimeException {
- Path dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace);
- if (!(Files.exists(dir) && Files.isDirectory(dir))) {
+ StorageAsset dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace);
+ if (!(dir.exists() && dir.isContainer())) {
return Collections.emptyList();
}
// scan all directories in the namespace, and only include those that are known to be projects
- final Predicate<Path> dFilter = new DirectoryFilter(filter);
- try (Stream<Path> stream = Files.list(dir)) {
- return stream.filter(dFilter).filter(path -> isProject(path, filter)).map(path -> path.getFileName().toString())
+ final Predicate<StorageAsset> dFilter = new DirectoryFilter(filter);
+ return dir.list().stream().filter(dFilter).filter(path -> isProject(path, filter)).map(path -> path.getName().toString())
.sorted().collect(Collectors.toList());
- } catch (IOException e) {
- LOGGER.error("Could not read directory {}: {}", dir, e.getMessage(), e);
- return Collections.emptyList();
- }
}
@@ -528,8 +511,8 @@ public class Maven2RepositoryStorage
public Collection<String> listProjectVersions(String repoId, String namespace, String projectId,
Filter<String> filter)
throws RepositoryStorageRuntimeException {
- Path dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace, projectId);
- if (!(Files.exists(dir) && Files.isDirectory(dir))) {
+ StorageAsset dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace, projectId);
+ if (!(dir.exists() && dir.isContainer())) {
return Collections.emptyList();
}
@@ -540,18 +523,17 @@ public class Maven2RepositoryStorage
@Override
public Collection<ArtifactMetadata> readArtifactsMetadata(ReadMetadataRequest readMetadataRequest)
throws RepositoryStorageRuntimeException {
- Path dir = pathTranslator.toFile(getRepositoryBasedir(readMetadataRequest.getRepositoryId()),
+ StorageAsset dir = pathTranslator.toFile(getRepositoryBasedir(readMetadataRequest.getRepositoryId()),
readMetadataRequest.getNamespace(), readMetadataRequest.getProjectId(),
readMetadataRequest.getProjectVersion());
- if (!(Files.exists(dir) && Files.isDirectory(dir))) {
+ if (!(dir.exists() && dir.isContainer())) {
return Collections.emptyList();
}
// all files that are not metadata and not a checksum / signature are considered artifacts
- final Predicate<Path> dFilter = new ArtifactDirectoryFilter(readMetadataRequest.getFilter());
- try (Stream<Path> stream = Files.list(dir)) {
+ final Predicate<StorageAsset> dFilter = new ArtifactDirectoryFilter(readMetadataRequest.getFilter());
// Returns a map TRUE -> (success values), FALSE -> (Exceptions)
- Map<Boolean, List<Try<ArtifactMetadata>>> result = stream.filter(dFilter).map(path -> {
+ Map<Boolean, List<Try<ArtifactMetadata>>> result = dir.list().stream().filter(dFilter).map(path -> {
try {
return Try.success(getArtifactFromFile(readMetadataRequest.getRepositoryId(), readMetadataRequest.getNamespace(),
readMetadataRequest.getProjectId(), readMetadataRequest.getProjectVersion(),
@@ -573,10 +555,6 @@ public class Maven2RepositoryStorage
}
return result.get(Boolean.TRUE).stream().map(tr -> tr.get()).collect(Collectors.toList());
}
- } catch (IOException e) {
- LOGGER.error("Could not read directory {}: {}", dir, e.getMessage(), e);
- }
- return Collections.emptyList();
}
@@ -595,9 +573,9 @@ public class Maven2RepositoryStorage
}
private ArtifactMetadata getArtifactFromFile(String repoId, String namespace, String projectId,
- String projectVersion, Path file) throws IOException {
+ String projectVersion, StorageAsset file) throws IOException {
ArtifactMetadata metadata =
- pathTranslator.getArtifactFromId(repoId, namespace, projectId, projectVersion, file.getFileName().toString());
+ pathTranslator.getArtifactFromId(repoId, namespace, projectId, projectVersion, file.getName());
populateArtifactMetadataFromFile(metadata, file);
@@ -629,17 +607,17 @@ public class Maven2RepositoryStorage
proxyHandler.fetchFromProxies(managedRepository, pomReference);
// Open and read the POM from the managed repo
- Path pom = managedRepository.toFile(pomReference);
+ StorageAsset pom = managedRepository.toFile(pomReference);
- if (!Files.exists(pom)) {
+ if (!pom.exists()) {
return;
}
try {
// MavenXpp3Reader leaves the file open, so we need to close it ourselves.
- Model model = null;
- try (Reader reader = Files.newBufferedReader(pom, Charset.defaultCharset())) {
+ Model model;
+ try (Reader reader = Channels.newReader(pom.getReadChannel(), Charset.defaultCharset().name())) {
model = MAVEN_XPP_3_READER.read(reader);
}
@@ -708,7 +686,7 @@ public class Maven2RepositoryStorage
@Override
public String getFilePathWithVersion(final String requestPath, ManagedRepositoryContent managedRepositoryContent)
- throws XMLException, RelocationException {
+ throws RelocationException, XMLException, IOException {
if (StringUtils.endsWith(requestPath, METADATA_FILENAME)) {
return getFilePath(requestPath, managedRepositoryContent.getRepository());
@@ -725,12 +703,12 @@ public class Maven2RepositoryStorage
if (StringUtils.endsWith(artifactReference.getVersion(), VersionUtil.SNAPSHOT)) {
// read maven metadata to get last timestamp
- Path metadataDir = Paths.get(managedRepositoryContent.getRepoRoot(), filePath).getParent();
- if (!Files.exists(metadataDir)) {
+ StorageAsset metadataDir = managedRepositoryContent.getRepository().getAsset( filePath).getParent();
+ if (!metadataDir.exists()) {
return filePath;
}
- Path metadataFile = metadataDir.resolve(METADATA_FILENAME);
- if (!Files.exists(metadataFile)) {
+ StorageAsset metadataFile = metadataDir.resolve(METADATA_FILENAME);
+ if (!metadataFile.exists()) {
return filePath;
}
ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read(metadataFile);
@@ -788,10 +766,10 @@ public class Maven2RepositoryStorage
return joinedString;
}
- private static void populateArtifactMetadataFromFile(ArtifactMetadata metadata, Path file) throws IOException {
+ private static void populateArtifactMetadataFromFile(ArtifactMetadata metadata, StorageAsset file) throws IOException {
metadata.setWhenGathered(new Date());
- metadata.setFileLastModified(Files.getLastModifiedTime(file).toMillis());
- ChecksummedFile checksummedFile = new ChecksummedFile(file);
+ metadata.setFileLastModified(file.getModificationTime().toEpochMilli());
+ ChecksummedFile checksummedFile = new ChecksummedFile(file.getFilePath());
try {
metadata.setMd5(checksummedFile.calculateChecksum(ChecksumAlgorithm.MD5));
} catch (IOException e) {
@@ -802,52 +780,43 @@ public class Maven2RepositoryStorage
} catch (IOException e) {
LOGGER.error("Unable to checksum file {}: {},SHA1", file, e.getMessage());
}
- metadata.setSize(Files.size(file));
+ metadata.setSize(file.getSize());
}
- private boolean isProject(Path dir, Filter<String> filter) {
+ private boolean isProject(StorageAsset dir, Filter<String> filter) {
// scan directories for a valid project version subdirectory, meaning this must be a project directory
- final Predicate<Path> dFilter = new DirectoryFilter(filter);
- try (Stream<Path> stream = Files.list(dir)) {
- boolean projFound = stream.filter(dFilter)
+ final Predicate<StorageAsset> dFilter = new DirectoryFilter(filter);
+ boolean projFound = dir.list().stream().filter(dFilter)
.anyMatch(path -> isProjectVersion(path));
if (projFound) {
return true;
}
- } catch (IOException e) {
- LOGGER.error("Could not read directory list {}: {}", dir, e.getMessage(), e);
- }
// if a metadata file is present, check if this is the "artifactId" directory, marking it as a project
ArchivaRepositoryMetadata metadata = readMetadata(dir);
- if (metadata != null && dir.getFileName().toString().equals(metadata.getArtifactId())) {
+ if (metadata != null && dir.getName().toString().equals(metadata.getArtifactId())) {
return true;
}
return false;
}
- private boolean isProjectVersion(Path dir) {
- final String artifactId = dir.getParent().getFileName().toString();
- final String projectVersion = dir.getFileName().toString();
+ private boolean isProjectVersion(StorageAsset dir) {
+ final String artifactId = dir.getParent().getName();
+ final String projectVersion = dir.getName();
// check if there is a POM artifact file to ensure it is a version directory
- Predicate<Path> filter;
+ Predicate<StorageAsset> filter;
if (VersionUtil.isSnapshot(projectVersion)) {
filter = new PomFilenameFilter(artifactId, projectVersion);
} else {
final String pomFile = artifactId + "-" + projectVersion + ".pom";
filter = new PomFileFilter(pomFile);
}
- try (Stream<Path> stream = Files.list(dir)) {
- if (stream.filter(Files::isRegularFile).anyMatch(filter)) {
+ if (dir.list().stream().filter(f -> !f.isContainer()).anyMatch(filter)) {
return true;
}
- } catch (IOException e) {
- LOGGER.error("Could not list directory {}: {}", dir, e.getMessage(), e);
- }
-
// if a metadata file is present, check if this is the "version" directory, marking it as a project version
ArchivaRepositoryMetadata metadata = readMetadata(dir);
if (metadata != null && projectVersion.equals(metadata.getVersion())) {
@@ -857,13 +826,13 @@ public class Maven2RepositoryStorage
return false;
}
- private ArchivaRepositoryMetadata readMetadata(Path directory) {
+ private ArchivaRepositoryMetadata readMetadata(StorageAsset directory) {
ArchivaRepositoryMetadata metadata = null;
- Path metadataFile = directory.resolve(METADATA_FILENAME);
- if (Files.exists(metadataFile)) {
+ StorageAsset metadataFile = directory.resolve(METADATA_FILENAME);
+ if (metadataFile.exists()) {
try {
metadata = MavenMetadataReader.read(metadataFile);
- } catch (XMLException e) {
+ } catch (XMLException | IOException e) {
// ignore missing or invalid metadata
}
}
@@ -871,7 +840,7 @@ public class Maven2RepositoryStorage
}
private static class DirectoryFilter
- implements Predicate<Path> {
+ implements Predicate<StorageAsset> {
private final Filter<String> filter;
public DirectoryFilter(Filter<String> filter) {
@@ -879,13 +848,13 @@ public class Maven2RepositoryStorage
}
@Override
- public boolean test(Path dir) {
- final String name = dir.getFileName().toString();
+ public boolean test(StorageAsset dir) {
+ final String name = dir.getName();
if (!filter.accept(name)) {
return false;
} else if (name.startsWith(".")) {
return false;
- } else if (!Files.isDirectory(dir)) {
+ } else if (!dir.isContainer()) {
return false;
}
return true;
@@ -893,7 +862,7 @@ public class Maven2RepositoryStorage
}
private static class ArtifactDirectoryFilter
- implements Predicate<Path> {
+ implements Predicate<StorageAsset> {
private final Filter<String> filter;
private ArtifactDirectoryFilter(Filter<String> filter) {
@@ -901,8 +870,8 @@ public class Maven2RepositoryStorage
}
@Override
- public boolean test(Path dir) {
- final String name = dir.getFileName().toString();
+ public boolean test(StorageAsset dir) {
+ final String name = dir.getName().toString();
// TODO compare to logic in maven-repository-layer
if (!filter.accept(name)) {
return false;
@@ -912,7 +881,7 @@ public class Maven2RepositoryStorage
return false;
} else if (Arrays.binarySearch(IGNORED_FILES, name) >= 0) {
return false;
- } else if (Files.isDirectory(dir)) {
+ } else if (dir.isContainer()) {
return false;
}
// some files from remote repositories can have name like maven-metadata-archiva-vm-all-public.xml
@@ -927,7 +896,7 @@ public class Maven2RepositoryStorage
private static final class PomFilenameFilter
- implements Predicate<Path> {
+ implements Predicate<StorageAsset> {
private final String artifactId, projectVersion;
@@ -937,8 +906,8 @@ public class Maven2RepositoryStorage
}
@Override
- public boolean test(Path dir) {
- final String name = dir.getFileName().toString();
+ public boolean test(StorageAsset dir) {
+ final String name = dir.getName();
if (name.startsWith(artifactId + "-") && name.endsWith(".pom")) {
String v = name.substring(artifactId.length() + 1, name.length() - 4);
v = VersionUtil.getBaseVersion(v);
@@ -952,7 +921,7 @@ public class Maven2RepositoryStorage
}
private static class PomFileFilter
- implements Predicate<Path> {
+ implements Predicate<StorageAsset> {
private final String pomFile;
private PomFileFilter(String pomFile) {
@@ -960,8 +929,8 @@ public class Maven2RepositoryStorage
}
@Override
- public boolean test(Path dir) {
- return pomFile.equals(dir.getFileName().toString());
+ public boolean test(StorageAsset dir) {
+ return pomFile.equals(dir.getName());
}
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java
index f978d554f..b03beed9f 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java
@@ -32,6 +32,7 @@ import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RepositoryCredentials;
import org.apache.archiva.repository.maven2.MavenSystemManager;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.xml.XMLException;
import org.apache.commons.lang.StringUtils;
import org.apache.http.auth.UsernamePasswordCredentials;
@@ -78,7 +79,7 @@ public class RepositoryModelResolver
private RepositorySystemSession session;
private VersionRangeResolver versionRangeResolver;
- private Path basedir;
+ private StorageAsset basedir;
private RepositoryPathTranslator pathTranslator;
@@ -98,7 +99,7 @@ public class RepositoryModelResolver
private ManagedRepository managedRepository;
- public RepositoryModelResolver( Path basedir, RepositoryPathTranslator pathTranslator )
+ public RepositoryModelResolver(StorageAsset basedir, RepositoryPathTranslator pathTranslator )
{
this.basedir = basedir;
@@ -110,7 +111,7 @@ public class RepositoryModelResolver
Map<String, NetworkProxy> networkProxiesMap, ManagedRepository targetRepository,
MavenSystemManager mavenSystemManager)
{
- this( Paths.get( managedRepository.getLocation() ), pathTranslator );
+ this( managedRepository.getAsset(""), pathTranslator );
this.managedRepository = managedRepository;
@@ -138,9 +139,9 @@ public class RepositoryModelResolver
String filename = artifactId + "-" + version + ".pom";
// TODO: we need to convert 1.0-20091120.112233-1 type paths to baseVersion for the below call - add a test
- Path model = pathTranslator.toFile( basedir, groupId, artifactId, version, filename );
+ StorageAsset model = pathTranslator.toFile( basedir, groupId, artifactId, version, filename );
- if ( !Files.exists(model) )
+ if ( !model.exists() )
{
/**
*
@@ -161,10 +162,10 @@ public class RepositoryModelResolver
try
{
boolean success = getModelFromProxy( remoteRepository, groupId, artifactId, version, filename );
- if ( success && Files.exists(model) )
+ if ( success && model.exists() )
{
log.info( "Model '{}' successfully retrieved from remote repository '{}'",
- model.toAbsolutePath(), remoteRepository.getId() );
+ model.getPath(), remoteRepository.getId() );
break;
}
}
@@ -172,20 +173,20 @@ public class RepositoryModelResolver
{
log.info(
"An exception was caught while attempting to retrieve model '{}' from remote repository '{}'.Reason:{}",
- model.toAbsolutePath(), remoteRepository.getId(), e.getMessage() );
+ model.getPath(), remoteRepository.getId(), e.getMessage() );
}
catch ( Exception e )
{
log.warn(
"An exception was caught while attempting to retrieve model '{}' from remote repository '{}'.Reason:{}",
- model.toAbsolutePath(), remoteRepository.getId(), e.getMessage() );
+ model.getPath(), remoteRepository.getId(), e.getMessage() );
continue;
}
}
}
- return new FileModelSource( model.toFile() );
+ return new FileModelSource( model.getFilePath().toFile() );
}
public ModelSource resolveModel(Parent parent) throws UnresolvableModelException {
@@ -249,15 +250,15 @@ public class RepositoryModelResolver
log.debug( "use snapshot path {} for maven coordinate {}:{}:{}", snapshotPath, groupId, artifactId,
version );
- Path model = basedir.resolve( snapshotPath );
+ StorageAsset model = basedir.resolve( snapshotPath );
//model = pathTranslator.toFile( basedir, groupId, artifactId, lastVersion, filename );
- if ( Files.exists(model) )
+ if ( model.exists() )
{
- return model;
+ return model.getFilePath();
}
}
}
- catch ( XMLException e )
+ catch (XMLException | IOException e )
{
log.warn( "fail to read {}, {}", mavenMetadata.toAbsolutePath(), e.getCause() );
}
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 9c36647d0..266a84105 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
@@ -34,7 +34,7 @@ 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.StorageAsset;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.commons.lang.StringUtils;
import java.io.IOException;
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java
index 026990e87..f8e171dac 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java
@@ -23,8 +23,7 @@ import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.repository.*;
-import org.apache.archiva.repository.content.FilesystemStorage;
-import org.apache.archiva.repository.content.RepositoryStorage;
+import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo;
import org.apache.archiva.repository.features.ArtifactCleanupFeature;
import org.apache.archiva.repository.features.IndexCreationFeature;
@@ -38,7 +37,6 @@ import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
-import java.util.function.Function;
/**
* Maven2 managed repository implementation.
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java
index f3380c0ec..e89321704 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java
@@ -9,7 +9,7 @@ import org.apache.archiva.repository.RepositoryCapabilities;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.StandardCapabilities;
import org.apache.archiva.repository.UnsupportedFeatureException;
-import org.apache.archiva.repository.content.FilesystemStorage;
+import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.RemoteIndexFeature;
import org.apache.archiva.repository.features.RepositoryFeature;
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java
index 56e65a2bd..60c91ac71 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java
@@ -22,13 +22,12 @@ package org.apache.archiva.repository.maven2;
import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.repository.*;
-import org.apache.archiva.repository.content.FilesystemStorage;
+import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
index bbcb6585d..75b2117a2 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
@@ -22,8 +22,7 @@ package org.apache.archiva.repository.maven2;
import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.configuration.*;
import org.apache.archiva.repository.*;
-import org.apache.archiva.repository.content.FilesystemAsset;
-import org.apache.archiva.repository.content.FilesystemStorage;
+import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.features.ArtifactCleanupFeature;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.RemoteIndexFeature;
@@ -298,11 +297,19 @@ public class MavenRepositoryProvider implements RepositoryProvider {
IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get();
indexCreationFeature.setIndexPath( getURIFromString(configuration.getMergedIndexPath()) );
Path localPath = Paths.get(configuration.getMergedIndexPath());
- if (localPath.isAbsolute()) {
- indexCreationFeature.setLocalIndexPath( new FilesystemAsset(localPath.getFileName().toString(), localPath) );
+ Path repoGroupPath = repositoryGroup.getAsset("").getFilePath().toAbsolutePath();
+ if (localPath.isAbsolute() && !localPath.startsWith(repoGroupPath)) {
+ try {
+ FilesystemStorage storage = new FilesystemStorage(localPath.getParent(), fileLockManager);
+ indexCreationFeature.setLocalIndexPath(storage.getAsset(localPath.getFileName().toString()));
+ } catch (IOException e) {
+ throw new RepositoryException("Could not initialize storage for index path "+localPath);
+ }
+ } else if (localPath.isAbsolute()) {
+ indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(repoGroupPath.relativize(localPath).toString()));
} else
{
- indexCreationFeature.setLocalIndexPath( new FilesystemAsset(localPath.toString(), archivaConfiguration.getRepositoryGroupBaseDir( ).resolve( localPath )));
+ indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(localPath.toString()));
}
}
// References to other repositories are set filled by the registry
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java
index e2fec5010..769be5ef9 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java
@@ -29,6 +29,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
@@ -46,8 +47,7 @@ public class MavenRepositoryMetadataReaderTest
@Test
public void testGroupMetadata()
- throws XMLException
- {
+ throws XMLException, IOException {
Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/plugins/maven-metadata.xml" );
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
@@ -81,8 +81,7 @@ public class MavenRepositoryMetadataReaderTest
@Test
public void testProjectMetadata()
- throws XMLException
- {
+ throws XMLException, IOException {
Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile);
@@ -99,8 +98,7 @@ public class MavenRepositoryMetadataReaderTest
@Test
public void testProjectVersionMetadata()
- throws XMLException
- {
+ throws XMLException, IOException {
Path metadataFile = defaultRepoDir.resolve( "org/apache/apache/5-SNAPSHOT/maven-metadata.xml" );
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/ArchivaIndexManagerMock.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/ArchivaIndexManagerMock.java
index 171563add..53bb59308 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/ArchivaIndexManagerMock.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/ArchivaIndexManagerMock.java
@@ -19,7 +19,7 @@ package org.apache.archiva.repository.index.mock;
* under the License.
*/
-import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.configuration.ArchivaConfiguration;
@@ -40,8 +40,9 @@ import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.UnsupportedRepositoryTypeException;
-import org.apache.archiva.repository.content.FilesystemAsset;
-import org.apache.archiva.repository.content.StorageAsset;
+import org.apache.archiva.repository.storage.FilesystemAsset;
+import org.apache.archiva.repository.storage.FilesystemStorage;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.RemoteIndexFeature;
import org.apache.commons.lang.StringUtils;
@@ -145,7 +146,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
private Path getIndexPath( ArchivaIndexingContext ctx )
{
- return PathUtil.getPathFromUri( ctx.getPath( ) );
+ return ctx.getPath( ).getFilePath();
}
@FunctionalInterface
@@ -380,9 +381,9 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
@Override
public void addArtifactsToIndex( final ArchivaIndexingContext context, final Collection<URI> artifactReference ) throws IndexUpdateFailedException
{
- final URI ctxUri = context.getPath();
+ final StorageAsset ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
- Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
+ Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.getFilePath().toUri().resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.addArtifactsToIndex(artifacts, indexingContext);
} catch (IOException e) {
@@ -396,9 +397,9 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
@Override
public void removeArtifactsFromIndex( ArchivaIndexingContext context, Collection<URI> artifactReference ) throws IndexUpdateFailedException
{
- final URI ctxUri = context.getPath();
+ final StorageAsset ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
- Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
+ Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.getFilePath().toUri().resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.deleteArtifactsFromIndex(artifacts, indexingContext);
} catch (IOException e) {
@@ -442,7 +443,12 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
throw new IndexCreationFailedException( "Could not create index context for repository " + repository.getId( )
+ ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e );
}
- MavenIndexContextMock context = new MavenIndexContextMock( repository, mvnCtx );
+ MavenIndexContextMock context = null;
+ try {
+ context = new MavenIndexContextMock( repository, mvnCtx );
+ } catch (IOException e) {
+ throw new IndexCreationFailedException(e);
+ }
return context;
}
@@ -457,7 +463,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
log.warn("Index close failed");
}
try {
- FileUtils.deleteDirectory(Paths.get(context.getPath()));
+ FileUtils.deleteDirectory(context.getPath().getFilePath());
} catch (IOException e) {
throw new IndexUpdateFailedException("Could not delete index files");
}
@@ -527,12 +533,14 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
}
+
private StorageAsset getIndexPath( Repository repo) throws IOException {
IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
Path repoDir = repo.getAsset( "" ).getFilePath();
URI indexDir = icf.getIndexPath();
String indexPath = indexDir.getPath();
Path indexDirectory = null;
+ FilesystemStorage fsStorage = (FilesystemStorage) repo.getAsset("").getStorage();
if ( ! StringUtils.isEmpty(indexDir.toString( ) ) )
{
@@ -541,6 +549,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
if ( indexDirectory.isAbsolute( ) )
{
indexPath = indexDirectory.getFileName().toString();
+ fsStorage = new FilesystemStorage(indexDirectory.getParent(), new DefaultFileLockManager());
}
else
{
@@ -557,7 +566,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
{
Files.createDirectories( indexDirectory );
}
- return new FilesystemAsset( indexPath, indexDirectory );
+ return new FilesystemAsset( fsStorage, indexPath, indexDirectory );
}
private IndexingContext createRemoteContext(RemoteRepository remoteRepository ) throws IOException
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java
index e0db09597..a6dddae4e 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java
@@ -19,12 +19,14 @@ package org.apache.archiva.repository.index.mock;
* under the License.
*/
+import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.repository.Repository;
+import org.apache.archiva.repository.storage.FilesystemStorage;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.maven.index.context.IndexingContext;
import java.io.IOException;
-import java.net.URI;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.sql.Date;
@@ -38,10 +40,12 @@ public class MavenIndexContextMock implements ArchivaIndexingContext {
private IndexingContext delegate;
private Repository repository;
+ private FilesystemStorage indexStorage;
- MavenIndexContextMock(Repository repository, IndexingContext delegate) {
+ MavenIndexContextMock(Repository repository, IndexingContext delegate) throws IOException {
this.delegate = delegate;
this.repository = repository;
+ indexStorage = new FilesystemStorage(delegate.getIndexDirectoryFile().toPath(), new DefaultFileLockManager());
}
@@ -56,8 +60,8 @@ public class MavenIndexContextMock implements ArchivaIndexingContext {
}
@Override
- public URI getPath() {
- return delegate.getIndexDirectoryFile().toURI();
+ public StorageAsset getPath() {
+ return indexStorage.getAsset("");
}
@Override
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/metadata/RepositoryMetadataReaderTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/metadata/RepositoryMetadataReaderTest.java
index 7c7da49cf..a02814042 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/metadata/RepositoryMetadataReaderTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/metadata/RepositoryMetadataReaderTest.java
@@ -27,6 +27,7 @@ import org.apache.archiva.xml.XMLException;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -41,8 +42,7 @@ public class RepositoryMetadataReaderTest
{
@Test
public void testLoadSimple()
- throws XMLException
- {
+ throws XMLException, IOException {
Path defaultRepoDir = Paths.get( "src/test/repositories/default-repository" );
Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
@@ -59,8 +59,7 @@ public class RepositoryMetadataReaderTest
@Test
public void testLoadComplex()
- throws XMLException
- {
+ throws XMLException, IOException {
Path defaultRepoDir = Paths.get( "src/test/repositories/default-repository" );
Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/samplejar/maven-metadata.xml" );
diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java
index a890ca4f6..b4a8e05ce 100644
--- a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java
@@ -26,7 +26,7 @@ import org.apache.archiva.repository.BasicManagedRepository;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.content.StorageAsset;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;