use of org.apache.archiva.repository.content.Artifact 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.Artifact in project archiva by apache.
the class ManagedDefaultRepositoryContent method applyCharacteristic.
@Override
public <T extends ContentItem> T applyCharacteristic(Class<T> clazz, ContentItem item) throws LayoutException {
if (item.getAsset().isLeaf()) {
if (clazz.isAssignableFrom(Artifact.class)) {
Artifact artifact = getArtifactFromPath(item.getAsset());
item.setCharacteristic(Artifact.class, artifact);
return (T) artifact;
} else {
throw new LayoutException("Could not adapt file to clazz " + clazz);
}
} else {
if (clazz.isAssignableFrom(Version.class)) {
Version version = getVersionFromPath(item.getAsset());
item.setCharacteristic(Version.class, version);
return (T) version;
} else if (clazz.isAssignableFrom(Project.class)) {
Project project = getProjectFromPath(item.getAsset());
item.setCharacteristic(Project.class, project);
return (T) project;
} else if (clazz.isAssignableFrom(Namespace.class)) {
Namespace ns = getNamespaceFromPath(item.getAsset());
item.setCharacteristic(Namespace.class, ns);
return (T) ns;
} else {
throw new LayoutException("Cannot adapt directory to clazz " + clazz);
}
}
}
use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class ChecksumTransferTest method testGetWithNoChecksumsUsingFailSetting.
@Test
public void testGetWithNoChecksumsUsingFailSetting() throws Exception {
String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(path);
FileUtils.deleteDirectory(expectedFile.getParent());
assertFalse(Files.exists(expectedFile));
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
assertNotDownloaded(downloadedFile);
assertChecksums(expectedFile, null, null);
}
use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class ChecksumTransferTest method testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting.
@Test
public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting() throws Exception {
String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
setManagedOlderThanRemote(expectedFile, remoteFile);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(path);
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
assertNoTempFiles(expectedFile);
assertChecksums(expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4 get-bad-local-checksum-1.0.jar", "46fdd6ca55bf1d7a7eb0c858f41e0ccd get-bad-local-checksum-1.0.jar");
}
use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class ChecksumTransferTest method testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting.
@Test
public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting() throws Exception {
String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
setManagedOlderThanRemote(expectedFile, remoteFile);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(path);
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
assertNoTempFiles(expectedFile);
// There are no hashcodes on the proxy side to download, hence the local ones should remain invalid.
assertChecksums(expectedFile, "invalid checksum file", "invalid checksum file");
}
Aggregations