use of org.apache.archiva.repository.content.BaseRepositoryContentLayout in project archiva by apache.
the class MetadataTools method updateProjectMetadata.
/**
* Update the metadata to represent the all versions/plugins of
* the provided groupId:artifactId project or group reference,
* based off of information present in the repository,
* the maven-metadata.xml files, and the proxy/repository specific
* metadata file contents.
* <p>
* We must treat this as a group or a project metadata file as there is no way to know in advance
*
* @param managedRepository the managed repository where the metadata is kept.
* @param reference the reference to update.
* @throws LayoutException
* @throws RepositoryMetadataException
* @throws IOException
* @throws ContentNotFoundException
* @deprecated
*/
public void updateProjectMetadata(ManagedRepositoryContent managedRepository, ItemSelector reference) throws LayoutException, RepositoryMetadataException, IOException, ContentNotFoundException {
StorageAsset metadataFile = managedRepository.getRepository().getAsset(toPath(reference));
ArchivaRepositoryMetadata existingMetadata = readMetadataFile(managedRepository, metadataFile);
BaseRepositoryContentLayout layout = managedRepository.getLayout(BaseRepositoryContentLayout.class);
long lastUpdated = getExistingLastUpdated(existingMetadata);
ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
metadata.setGroupId(reference.getNamespace());
metadata.setArtifactId(reference.getProjectId());
// Gather up all versions found in the managed repository.
ItemSelector selector = ArchivaItemSelector.builder().withNamespace(reference.getNamespace()).withProjectId(reference.getProjectId()).build();
Set<String> allVersions = null;
try {
Project project = layout.getProject(selector);
allVersions = layout.getVersions(project).stream().map(v -> v.getId()).collect(Collectors.toSet());
} catch (ContentAccessException e) {
log.error("Error while accessing repository: {}", e.getMessage(), e);
throw new RepositoryMetadataException("Error while accessing repository " + e.getMessage(), e);
}
// Gather up all plugins found in the managed repository.
// TODO: do we know this information instead?
// Set<Plugin> allPlugins = managedRepository.getPlugins( reference );
Set<Plugin> allPlugins;
if (existingMetadata != null) {
allPlugins = new LinkedHashSet<Plugin>(existingMetadata.getPlugins());
} else {
allPlugins = new LinkedHashSet<Plugin>();
}
// Does this repository have a set of remote proxied repositories?
Set<String> proxiedRepoIds = this.proxies.get(managedRepository.getId());
if (CollectionUtils.isNotEmpty(proxiedRepoIds)) {
// Add in the proxied repo version ids too.
Iterator<String> it = proxiedRepoIds.iterator();
while (it.hasNext()) {
String proxyId = it.next();
ArchivaRepositoryMetadata proxyMetadata = readProxyMetadata(managedRepository, reference, proxyId);
if (proxyMetadata != null) {
allVersions.addAll(proxyMetadata.getAvailableVersions());
allPlugins.addAll(proxyMetadata.getPlugins());
long proxyLastUpdated = getLastUpdated(proxyMetadata);
lastUpdated = Math.max(lastUpdated, proxyLastUpdated);
}
}
}
if (!allVersions.isEmpty()) {
updateMetadataVersions(allVersions, metadata);
} else {
// Add the plugins to the metadata model.
metadata.setPlugins(new ArrayList<>(allPlugins));
// artifact ID was actually the last part of the group
metadata.setGroupId(metadata.getGroupId() + "." + metadata.getArtifactId());
metadata.setArtifactId(null);
}
if (lastUpdated > 0) {
metadata.setLastUpdatedTimestamp(toLastUpdatedDate(lastUpdated));
}
// Save the metadata model to disk.
RepositoryMetadataWriter.write(metadata, metadataFile);
ChecksummedFile checksum = new ChecksummedFile(metadataFile.getFilePath());
checksum.fixChecksums(algorithms);
}
use of org.apache.archiva.repository.content.BaseRepositoryContentLayout in project archiva by apache.
the class ChecksumTransferTest method testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting.
@Test
public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting() 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, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
assertNotDownloaded(downloadedFile);
assertNoTempFiles(expectedFile);
// There are no hashcodes on the proxy side to download.
// The FAIL policy will delete the checksums as bad.
assertChecksums(expectedFile, "invalid checksum file", "invalid checksum file");
}
use of org.apache.archiva.repository.content.BaseRepositoryContentLayout in project archiva by apache.
the class ChecksumTransferTest method testGetChecksumCorrectSha1BadMd5UsingFixSetting.
@Test
public void testGetChecksumCorrectSha1BadMd5UsingFixSetting() throws Exception {
String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-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.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, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar", "c35f3b76268b73a4ba617f6f275c49ab get-checksum-sha1-bad-md5-1.0.jar");
}
use of org.apache.archiva.repository.content.BaseRepositoryContentLayout in project archiva by apache.
the class ChecksumTransferTest method testGetChecksumWhenConnectorIsDisabled.
@Test
public void testGetChecksumWhenConnectorIsDisabled() throws Exception {
String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(path);
org.apache.archiva.common.utils.FileUtils.deleteDirectory(expectedFile.getParent());
assertFalse(Files.exists(expectedFile));
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
assertNull(downloadedFile);
}
use of org.apache.archiva.repository.content.BaseRepositoryContentLayout in project archiva by apache.
the class ChecksumTransferTest method testGetWithNoChecksumsUsingIgnoredSetting.
@Test
public void testGetWithNoChecksumsUsingIgnoredSetting() 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.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);
assertChecksums(expectedFile, null, null);
}
Aggregations