Search in sources :

Example 16 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class MockStorage method getAsset.

@Override
public StorageAsset getAsset(final String requestedPath) {
    String path = requestedPath.startsWith("/") ? requestedPath : "/" + requestedPath;
    if (assets.containsKey(path)) {
        return assets.get(path);
    }
    String[] pathArr = splitPath(path);
    StorageAsset parent = root;
    for (String pathElement : pathArr) {
        Optional<? extends StorageAsset> next = parent.list().stream().filter(a -> a.getName().equals(pathElement)).findFirst();
        if (next.isPresent()) {
            parent = next.get();
        } else {
            MockAsset asset = new MockAsset((MockAsset) parent, pathElement);
            assets.put(asset.getPath(), asset);
            parent = asset;
        }
    }
    return parent;
}
Also used : OutputStream(java.io.OutputStream) ReadableByteChannel(java.nio.channels.ReadableByteChannel) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) IOException(java.io.IOException) VisitStatus(org.apache.archiva.repository.storage.util.VisitStatus) LinkedHashMap(java.util.LinkedHashMap) Consumer(java.util.function.Consumer) AssetType(org.apache.archiva.repository.storage.AssetType) WritableByteChannel(java.nio.channels.WritableByteChannel) Optional(java.util.Optional) URI(java.net.URI) RepositoryStorage(org.apache.archiva.repository.storage.RepositoryStorage) InputStream(java.io.InputStream) CopyOption(java.nio.file.CopyOption) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Example 17 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class MockStorage method addAsset.

@Override
public StorageAsset addAsset(String path, boolean container) {
    String[] pathArr = splitPath(path);
    StorageAsset parent = root;
    for (String pathElement : pathArr) {
        Optional<? extends StorageAsset> next = parent.list().stream().filter(a -> a.getName().equals(pathElement)).findFirst();
        if (next.isPresent()) {
            parent = next.get();
        } else {
            MockAsset asset = new MockAsset((MockAsset) parent, pathElement);
            assets.put(asset.getPath(), asset);
            parent = asset;
        }
    }
    status.add(ADD, parent);
    return parent;
}
Also used : OutputStream(java.io.OutputStream) ReadableByteChannel(java.nio.channels.ReadableByteChannel) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) IOException(java.io.IOException) VisitStatus(org.apache.archiva.repository.storage.util.VisitStatus) LinkedHashMap(java.util.LinkedHashMap) Consumer(java.util.function.Consumer) AssetType(org.apache.archiva.repository.storage.AssetType) WritableByteChannel(java.nio.channels.WritableByteChannel) Optional(java.util.Optional) URI(java.net.URI) RepositoryStorage(org.apache.archiva.repository.storage.RepositoryStorage) InputStream(java.io.InputStream) CopyOption(java.nio.file.CopyOption) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Example 18 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class AssetSpliteratorTest method forEachRemaining3.

@Test
void forEachRemaining3() {
    StorageAsset root = createTree();
    StorageAsset testRoot = root.list().get(1);
    AssetSpliterator spliterator = new AssetSpliterator(testRoot);
    final ConsumeVisitStatus status = new ConsumeVisitStatus();
    spliterator.forEachRemaining(status);
    int expected = LEVEL2 * LEVEL3 + LEVEL2 + 1;
    assertEquals(expected, status.size());
    assertEquals(testRoot, status.getLast());
}
Also used : StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Test(org.junit.jupiter.api.Test)

Example 19 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class AssetSpliteratorTest method forEachRemaining.

@Test
void forEachRemaining() {
    StorageAsset root = createTree();
    AssetSpliterator spliterator = new AssetSpliterator(root);
    final ConsumeVisitStatus status = new ConsumeVisitStatus();
    spliterator.forEachRemaining(status);
    // 10 * 15 * 5 + 10 * 15 + 10 + 1
    assertEquals(LEVEL1 * LEVEL2 * LEVEL3 + LEVEL1 * LEVEL2 + LEVEL1 + 1, status.size());
    assertEquals(root, status.getLast());
}
Also used : StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Test(org.junit.jupiter.api.Test)

Example 20 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class AssetSpliteratorTest method forEachRemaining2.

@Test
void forEachRemaining2() {
    StorageAsset root = createTree();
    AssetSpliterator spliterator = new AssetSpliterator(root);
    final ConsumeVisitStatus status = new ConsumeVisitStatus();
    spliterator.tryAdvance(a -> {
    });
    spliterator.tryAdvance(a -> {
    });
    spliterator.tryAdvance(a -> {
    });
    spliterator.tryAdvance(a -> {
    });
    spliterator.forEachRemaining(status);
    int expected = LEVEL1 * LEVEL2 * LEVEL3 + LEVEL1 * LEVEL2 + LEVEL1 + 1;
    expected = expected - 4;
    assertEquals(expected, status.size());
    assertEquals(root, status.getLast());
}
Also used : StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Test(org.junit.jupiter.api.Test)

Aggregations

StorageAsset (org.apache.archiva.repository.storage.StorageAsset)191 Path (java.nio.file.Path)91 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)61 IOException (java.io.IOException)59 Test (org.junit.Test)59 Artifact (org.apache.archiva.repository.content.Artifact)54 ManagedRepository (org.apache.archiva.repository.ManagedRepository)27 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)22 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)22 List (java.util.List)20 Inject (javax.inject.Inject)20 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)20 Collectors (java.util.stream.Collectors)19 RemoteRepository (org.apache.archiva.repository.RemoteRepository)19 IndexingContext (org.apache.maven.index.context.IndexingContext)19 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)18 StringUtils (org.apache.commons.lang3.StringUtils)18 Logger (org.slf4j.Logger)18 LoggerFactory (org.slf4j.LoggerFactory)18 Map (java.util.Map)17