Search in sources :

Example 1 with DataItem

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

the class ManagedDefaultRepositoryContent method toItem.

@Override
public ContentItem toItem(String path) throws LayoutException {
    StorageAsset asset = getRepository().getAsset(path);
    ContentItem item = getItemFromPath(asset);
    if (item instanceof DataItem) {
        Artifact artifact = adaptItem(Artifact.class, item);
        if (asset.getParent() == null) {
            throw new LayoutException("Path too short for maven artifact " + path);
        }
        String version = asset.getParent().getName();
        if (asset.getParent().getParent() == null) {
            throw new LayoutException("Path too short for maven artifact " + path);
        }
        String project = item.getAsset().getParent().getParent().getName();
        DataItem dataItem = (DataItem) item;
        if (StringUtils.isEmpty(dataItem.getExtension())) {
            throw new LayoutException("Missing type on maven artifact");
        }
        if (!project.equals(artifact.getId())) {
            throw new LayoutException("The maven artifact id " + artifact.getId() + " does not match the project id: " + project);
        }
        boolean versionIsGenericSnapshot = VersionUtil.isGenericSnapshot(version);
        boolean artifactVersionIsSnapshot = VersionUtil.isSnapshot(artifact.getArtifactVersion());
        if (versionIsGenericSnapshot && !artifactVersionIsSnapshot) {
            throw new LayoutException("The maven artifact has no snapshot version in snapshot directory " + dataItem);
        }
        if (!versionIsGenericSnapshot && artifactVersionIsSnapshot) {
            throw new LayoutException("The maven artifact version " + artifact.getArtifactVersion() + " is a snapshot version but inside a non snapshot directory " + version);
        }
        if (!versionIsGenericSnapshot && !version.equals(artifact.getArtifactVersion())) {
            throw new LayoutException("The maven artifact version " + artifact.getArtifactVersion() + " does not match the version directory " + version);
        }
    }
    return item;
}
Also used : DataItem(org.apache.archiva.repository.content.DataItem) LayoutException(org.apache.archiva.repository.content.LayoutException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Artifact(org.apache.archiva.repository.content.Artifact)

Example 2 with DataItem

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

the class MetadataTransferTest method assertFetchVersioned.

/**
 * Transfer the metadata file.
 *
 * @param requestedResource the requested resource
 * @throws Exception
 */
private void assertFetchVersioned(String requestedResource) throws Exception {
    Path expectedFile = managedDefaultDir.resolve(requestedResource);
    ContentItem item = managedDefaultRepository.toItem(requestedResource);
    if (item instanceof DataItem) {
        item = managedDefaultRepository.getParent(item);
    }
    assertNotNull(item);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Version version = layout.adaptItem(Version.class, item);
    assertNotNull(version);
    String metaPath = managedDefaultRepository.toPath(layout.getMetadataItem(version));
    StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies(managedDefaultRepository.getRepository(), metaPath).getFile();
    assertNotNull("Should have downloaded a file.", downloadedFile);
    assertNoTempFiles(expectedFile);
}
Also used : Path(java.nio.file.Path) DataItem(org.apache.archiva.repository.content.DataItem) Version(org.apache.archiva.repository.content.Version) SnapshotVersion(org.apache.archiva.model.SnapshotVersion) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ContentItem(org.apache.archiva.repository.content.ContentItem)

Example 3 with DataItem

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

the class ManagedDefaultRepositoryContentTest method testToItemFromPath.

@Test
public void testToItemFromPath() throws LayoutException {
    String path = "/org/apache/maven/shared";
    ContentItem item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = "/org/apache/maven/shared/maven-downloader";
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = "/org/apache/maven/shared/maven-downloader/1.1";
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = "/org/apache/maven/shared/maven-downloader/1.1/maven-downloader-1.1.jar";
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof DataItem);
}
Also used : ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) DataItem(org.apache.archiva.repository.content.DataItem) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Test(org.junit.Test)

Example 4 with DataItem

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

the class ManagedDefaultRepositoryContentTest method getNonExistingMetadataItem.

@Test
public void getNonExistingMetadataItem() {
    // org/apache/maven/some-ejb/1.0
    ArchivaItemSelector versionSelector = ArchivaItemSelector.builder().withNamespace("javax.sql").withProjectId("jdbc").withVersion("2.0").build();
    Version version = repoContent.getVersion(versionSelector);
    DataItem metaData = repoContent.getMetadataItem(version);
    assertFalse(metaData.exists());
    assertEquals("/javax/sql/jdbc/2.0/maven-metadata.xml", metaData.getAsset().getPath());
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) Version(org.apache.archiva.repository.content.Version) DataItem(org.apache.archiva.repository.content.DataItem) Test(org.junit.Test)

Example 5 with DataItem

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

the class ManagedDefaultRepositoryContentTest method testToItemFromAssetPath.

@Test
public void testToItemFromAssetPath() throws LayoutException {
    StorageAsset path = repoContent.getRepository().getAsset("/org/apache/maven/shared");
    ContentItem item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = repoContent.getRepository().getAsset("/org/apache/maven/shared/maven-downloader");
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = repoContent.getRepository().getAsset("/org/apache/maven/shared/maven-downloader/1.1");
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = repoContent.getRepository().getAsset("/org/apache/maven/shared/maven-downloader/1.1/maven-downloader-1.1.jar");
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof DataItem);
}
Also used : ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) DataItem(org.apache.archiva.repository.content.DataItem) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Test(org.junit.Test)

Aggregations

DataItem (org.apache.archiva.repository.content.DataItem)7 Test (org.junit.Test)5 ContentItem (org.apache.archiva.repository.content.ContentItem)4 Version (org.apache.archiva.repository.content.Version)3 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)3 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)3 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)3 Path (java.nio.file.Path)1 SnapshotVersion (org.apache.archiva.model.SnapshotVersion)1 Artifact (org.apache.archiva.repository.content.Artifact)1 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)1 ItemSelector (org.apache.archiva.repository.content.ItemSelector)1 LayoutException (org.apache.archiva.repository.content.LayoutException)1