Search in sources :

Example 36 with Artifact

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

the class ManagedDefaultRepositoryContentTest method testArtifactListWithArtifactSelector4.

@Test
public void testArtifactListWithArtifactSelector4() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("test").withVersion("1.0-SNAPSHOT").withClassifier("").build();
    List<? extends Artifact> results = repoContent.getArtifacts(selector);
    assertNotNull(results);
    assertEquals(5, results.size());
    Artifact artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("test-1.0-20050611.112233-1-javadoc.jar")).findFirst().get();
    assertNotNull(artifact);
    assertEquals("javadoc", artifact.getClassifier());
    assertEquals("javadoc", artifact.getType());
    artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("wrong-artifactId-1.0-20050611.112233-1.jar")).findFirst().get();
    assertNotNull(artifact);
    assertEquals("", artifact.getClassifier());
    assertEquals("wrong-artifactId", artifact.getId());
    artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("wrong-artifactId-1.0-20050611.1122x-1.jar")).findFirst().get();
    assertNotNull(artifact);
    assertEquals("", artifact.getClassifier());
    assertEquals("wrong-artifactId", artifact.getId());
    assertEquals("", artifact.getArtifactVersion());
    artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("test-1.0-20050611.1122x-1.jar")).findFirst().get();
    assertNotNull(artifact);
    assertEquals("", artifact.getClassifier());
    assertEquals("test", artifact.getId());
    assertEquals("1.0-20050611.1122x-1", artifact.getArtifactVersion());
}
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 Artifact

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

the class ManagedDefaultRepositoryContentTest method testArtifactListWithArtifactSelectorWrongArtifact.

@Test
public void testArtifactListWithArtifactSelectorWrongArtifact() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("test").withVersion("1.0-SNAPSHOT").withArtifactId("wrong-artifactId").withArtifactVersion("1.0-20050611.112233-1").build();
    List<? extends Artifact> results = repoContent.getArtifacts(selector);
    assertNotNull(results);
    assertEquals(1, results.size());
    Artifact artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("wrong-artifactId-1.0-20050611.112233-1.jar")).findFirst().get();
    assertNotNull(artifact);
}
Also used : 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 38 with Artifact

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

the class ManagedDefaultRepositoryContentTest method checkArtifactListWithArtifactSelector1.

private void checkArtifactListWithArtifactSelector1(List<? extends Artifact> results) {
    assertNotNull(results);
    assertEquals(1, results.size());
    Artifact artifact = results.get(0);
    assertEquals("pom", artifact.getExtension());
    assertEquals(BaseArtifactTypes.MAIN, artifact.getDataType());
}
Also used : Artifact(org.apache.archiva.repository.content.Artifact)

Example 39 with Artifact

use of org.apache.archiva.repository.content.Artifact 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 40 with Artifact

use of org.apache.archiva.repository.content.Artifact 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)

Aggregations

Artifact (org.apache.archiva.repository.content.Artifact)78 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)63 Test (org.junit.Test)60 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)59 Path (java.nio.file.Path)54 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)26 ItemSelector (org.apache.archiva.repository.content.ItemSelector)21 LayoutException (org.apache.archiva.repository.content.LayoutException)21 ContentItem (org.apache.archiva.repository.content.ContentItem)19 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)15 IOException (java.io.IOException)13 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 Project (org.apache.archiva.repository.content.Project)13 MavenMetadataReader (org.apache.archiva.maven.metadata.MavenMetadataReader)12 Version (org.apache.archiva.repository.content.Version)12 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)12 Reader (java.io.Reader)11 List (java.util.List)11 Collectors (java.util.stream.Collectors)11 Inject (javax.inject.Inject)11