Search in sources :

Example 36 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method testArtifactListWithArtifactSelectorAndRelated.

@Test
public void testArtifactListWithArtifactSelectorAndRelated() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("samplejar").withVersion("1.0").withArtifactVersion("1.0").withArtifactId("samplejar").withExtension("jar").includeRelatedArtifacts().build();
    List<? extends Artifact> results = repoContent.getArtifacts(selector);
    assertNotNull(results);
    assertEquals(3, results.size());
    Artifact artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("samplejar-1.0.jar")).findFirst().get();
    assertNotNull(artifact);
    assertEquals(BaseArtifactTypes.MAIN, artifact.getDataType());
    artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("samplejar-1.0.jar.md5")).findFirst().get();
    assertNotNull(artifact);
    assertEquals(BaseArtifactTypes.RELATED, artifact.getDataType());
    assertEquals("md5", artifact.getExtension());
    artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("samplejar-1.0.jar.sha1")).findFirst().get();
    assertNotNull(artifact);
    assertEquals(BaseArtifactTypes.RELATED, artifact.getDataType());
    assertEquals("sha1", artifact.getExtension());
}
Also used : Artifact(org.apache.archiva.repository.content.Artifact) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ArtifactMappingProvider(org.apache.archiva.maven.repository.metadata.storage.ArtifactMappingProvider) RepositoryPathTranslator(org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator) MavenManagedRepository(org.apache.archiva.maven.repository.MavenManagedRepository) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) URISyntaxException(java.net.URISyntaxException) Namespace(org.apache.archiva.repository.content.Namespace) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) FileTime(java.nio.file.attribute.FileTime) Version(org.apache.archiva.repository.content.Version) FileType(org.apache.archiva.configuration.model.FileType) Inject(javax.inject.Inject) Charset(java.nio.charset.Charset) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Named(javax.inject.Named) VersionComparator(org.apache.archiva.common.utils.VersionComparator) Path(java.nio.file.Path) ContentItem(org.apache.archiva.repository.content.ContentItem) Before(org.junit.Before) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) OutputStream(java.io.OutputStream) FileTypes(org.apache.archiva.configuration.provider.FileTypes) Project(org.apache.archiva.repository.content.Project) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) BaseArtifactTypes(org.apache.archiva.repository.content.BaseArtifactTypes) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) IOException(java.io.IOException) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) ManagedRepository(org.apache.archiva.repository.ManagedRepository) DataItem(org.apache.archiva.repository.content.DataItem) List(java.util.List) RepositoryContent(org.apache.archiva.repository.RepositoryContent) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) LayoutException(org.apache.archiva.repository.content.LayoutException) Assert(org.junit.Assert) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ItemNotFoundException(org.apache.archiva.repository.content.ItemNotFoundException) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 37 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class AbstractRepositoryContentTest method assertLayoutCi.

private void assertLayoutCi(String path, String groupId, String artifactId, String version, String artifactVersion, String classifier, String type) throws LayoutException {
    ItemSelector expectedArtifact = createItemSelector(groupId, artifactId, version, artifactVersion, classifier, type);
    // --- Artifact Tests.
    // Artifact to Path
    assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(expectedArtifact));
    // --- Artifact Reference Tests
    // Path to Artifact Reference.
    ItemSelector testReference = toItemSelector(path);
    assertItemSelector(testReference, groupId, artifactId, version, artifactVersion, classifier, type);
    // And back again, using test Reference from previous step.
    assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(testReference));
    if (getManaged() != null) {
        Namespace ns = null;
        Project pr = null;
        Version ver = null;
        if (StringUtils.isNotEmpty(groupId)) {
            ns = getManaged().getLayout(BaseRepositoryContentLayout.class).getNamespace(expectedArtifact);
            assertNotNull(ns);
            assertEquals(groupId, ns.getId());
        }
        if (StringUtils.isNotEmpty(artifactId)) {
            pr = getManaged().getLayout(BaseRepositoryContentLayout.class).getProject(expectedArtifact);
            assertNotNull(pr);
            assertEquals(artifactId, pr.getId());
            assertEquals(ns, pr.getNamespace());
        }
        if (StringUtils.isNotEmpty(version)) {
            ver = getManaged().getLayout(BaseRepositoryContentLayout.class).getVersion(expectedArtifact);
            assertNotNull(ver);
            assertEquals(version, ver.getId());
            assertEquals(pr, ver.getProject());
        }
        Artifact artifact = getManaged().getLayout(BaseRepositoryContentLayout.class).getArtifact(expectedArtifact);
        assertNotNull(artifact);
        assertEquals(artifactId, artifact.getId());
        assertEquals(ver, artifact.getVersion());
    }
}
Also used : Project(org.apache.archiva.repository.content.Project) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Version(org.apache.archiva.repository.content.Version) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) Namespace(org.apache.archiva.repository.content.Namespace) Artifact(org.apache.archiva.repository.content.Artifact)

Example 38 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class AbstractRepositoryContentTest method testToPathOnNullItemSelector.

public void testToPathOnNullItemSelector() {
    try {
        ItemSelector selector = null;
        toPath(selector);
        fail("Should have failed due to null artifact reference.");
    } catch (IllegalArgumentException e) {
    /* expected path */
    }
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector)

Example 39 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class AbstractRepositoryContentTest method testToPathOnNullArtifactReference.

@Test
public void testToPathOnNullArtifactReference() {
    try {
        ItemSelector reference = null;
        toPath(reference);
        fail("Should have failed due to null artifact reference.");
    } catch (IllegalArgumentException e) {
    /* expected path */
    }
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Test(org.junit.Test)

Example 40 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class ManagedDefaultRepositoryContent method newItemStream.

@Override
public Stream<? extends ContentItem> newItemStream(ItemSelector selector, boolean parallel) throws ContentAccessException, IllegalArgumentException {
    final Predicate<StorageAsset> filter = getItemFileFilterFromSelector(selector);
    StorageAsset startDir;
    if (selector.getNamespace().contains("*")) {
        startDir = getAsset("");
    } else if (selector.hasProjectId() && selector.getProjectId().contains("*")) {
        startDir = getAsset(selector.getNamespace());
    } else if (selector.hasProjectId() && selector.hasVersion() && selector.getVersion().contains("*")) {
        startDir = getAsset(selector.getNamespace(), selector.getProjectId());
    } else if (selector.hasProjectId() && selector.hasVersion()) {
        startDir = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion());
    } else if (selector.hasProjectId()) {
        startDir = getAsset(selector.getNamespace(), selector.getProjectId());
    } else {
        startDir = getAsset(selector.getNamespace());
        if (!selector.recurse()) {
            // We descend into 2 subdirectories (project and version)
            return startDir.list().stream().flatMap(a -> getChildrenDF(a, 1)).map(this::getItemFromPath);
        }
    }
    return StorageUtil.newAssetStream(startDir, parallel).filter(filter).map(this::getItemFromPath);
}
Also used : Arrays(java.util.Arrays) ArchivaNamespace(org.apache.archiva.repository.content.base.ArchivaNamespace) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Namespace(org.apache.archiva.repository.content.Namespace) StringUtils(org.apache.commons.lang3.StringUtils) LayoutRuntimeException(org.apache.archiva.repository.content.LayoutRuntimeException) Matcher(java.util.regex.Matcher) FileUtils(org.apache.archiva.common.utils.FileUtils) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Path(java.nio.file.Path) ContentItem(org.apache.archiva.repository.content.ContentItem) RepositoryStorage(org.apache.archiva.repository.storage.RepositoryStorage) FileTypes(org.apache.archiva.configuration.provider.FileTypes) ArtifactOptBuilder(org.apache.archiva.repository.content.base.builder.ArtifactOptBuilder) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Predicate(java.util.function.Predicate) BaseArtifactTypes(org.apache.archiva.repository.content.BaseArtifactTypes) Collectors(java.util.stream.Collectors) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) Pattern(java.util.regex.Pattern) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) Artifact(org.apache.archiva.repository.content.Artifact) ItemDeleteStatus(org.apache.archiva.repository.ItemDeleteStatus) ArchivaProject(org.apache.archiva.repository.content.base.ArchivaProject) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) Version(org.apache.archiva.repository.content.Version) ReferenceMap(org.apache.commons.collections4.map.ReferenceMap) Inject(javax.inject.Inject) Named(javax.inject.Named) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ContentAccessException(org.apache.archiva.repository.content.ContentAccessException) Project(org.apache.archiva.repository.content.Project) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) VersionUtil(org.apache.archiva.common.utils.VersionUtil) ManagedRepositoryContentLayout(org.apache.archiva.repository.content.ManagedRepositoryContentLayout) IOException(java.io.IOException) DataItem(org.apache.archiva.repository.content.DataItem) Consumer(java.util.function.Consumer) StorageUtil(org.apache.archiva.repository.storage.util.StorageUtil) ArchivaVersion(org.apache.archiva.repository.content.base.ArchivaVersion) LayoutException(org.apache.archiva.repository.content.LayoutException) Collections(java.util.Collections) ItemNotFoundException(org.apache.archiva.repository.content.ItemNotFoundException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Aggregations

ItemSelector (org.apache.archiva.repository.content.ItemSelector)76 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)74 Test (org.junit.Test)41 Path (java.nio.file.Path)16 Artifact (org.apache.archiva.repository.content.Artifact)16 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)13 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)12 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)12 LayoutException (org.apache.archiva.repository.content.LayoutException)12 IOException (java.io.IOException)11 ContentItem (org.apache.archiva.repository.content.ContentItem)11 Project (org.apache.archiva.repository.content.Project)11 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)10 Namespace (org.apache.archiva.repository.content.Namespace)9 Version (org.apache.archiva.repository.content.Version)9 VersionComparator (org.apache.archiva.common.utils.VersionComparator)8 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)6