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;
}
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);
}
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);
}
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());
}
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);
}
Aggregations