use of org.apache.archiva.proxy.model.ProxyFetchResult in project archiva by apache.
the class DefaultRepositoryProxyConnectors method fetchMetadataFromProxies.
@Override
public ProxyFetchResult fetchMetadataFromProxies(ManagedRepositoryContent repository, String logicalPath) {
Path localFile = Paths.get(repository.getRepoRoot(), logicalPath);
Properties requestProperties = new Properties();
requestProperties.setProperty("filetype", "metadata");
boolean metadataNeedsUpdating = false;
long originalTimestamp = getLastModified(localFile);
List<ProxyConnector> connectors = new ArrayList<>(getProxyConnectors(repository));
for (ProxyConnector connector : connectors) {
if (connector.isDisabled()) {
continue;
}
RemoteRepositoryContent targetRepository = connector.getTargetRepository();
Path localRepoFile = toLocalRepoFile(repository, targetRepository, logicalPath);
long originalMetadataTimestamp = getLastModified(localRepoFile);
try {
transferFile(connector, targetRepository, logicalPath, repository, localRepoFile, requestProperties, true);
if (hasBeenUpdated(localRepoFile, originalMetadataTimestamp)) {
metadataNeedsUpdating = true;
}
} catch (NotFoundException e) {
log.debug("Metadata {} not found on remote repository '{}'.", logicalPath, targetRepository.getRepository().getId(), e);
} catch (NotModifiedException e) {
log.debug("Metadata {} not updated on remote repository '{}'.", logicalPath, targetRepository.getRepository().getId(), e);
} catch (ProxyException | RepositoryAdminException e) {
log.warn("Transfer error from repository {} for versioned Metadata {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), logicalPath, e.getMessage());
log.debug("Full stack trace", e);
}
}
if (hasBeenUpdated(localFile, originalTimestamp)) {
metadataNeedsUpdating = true;
}
if (metadataNeedsUpdating || !Files.exists(localFile)) {
try {
metadataTools.updateMetadata(repository, logicalPath);
} catch (RepositoryMetadataException e) {
log.warn("Unable to update metadata {}:{}", localFile.toAbsolutePath(), e.getMessage(), e);
}
}
if (fileExists(localFile)) {
return new ProxyFetchResult(localFile, metadataNeedsUpdating);
}
return new ProxyFetchResult(null, false);
}
Aggregations