use of org.apache.archiva.repository.RemoteRepositoryContent in project archiva by apache.
the class DefaultRepositoryProxyConnectors method fetchFromProxies.
@Override
public Path fetchFromProxies(ManagedRepositoryContent repository, ArtifactReference artifact) throws ProxyDownloadException {
Path localFile = toLocalFile(repository, artifact);
Properties requestProperties = new Properties();
requestProperties.setProperty("filetype", "artifact");
requestProperties.setProperty("version", artifact.getVersion());
requestProperties.setProperty("managedRepositoryId", repository.getId());
List<ProxyConnector> connectors = getProxyConnectors(repository);
Map<String, Exception> previousExceptions = new LinkedHashMap<>();
for (ProxyConnector connector : connectors) {
if (connector.isDisabled()) {
continue;
}
RemoteRepositoryContent targetRepository = connector.getTargetRepository();
requestProperties.setProperty("remoteRepositoryId", targetRepository.getId());
String targetPath = targetRepository.toPath(artifact);
if (SystemUtils.IS_OS_WINDOWS) {
// toPath use system PATH_SEPARATOR so on windows url are \ which doesn't work very well :-)
targetPath = FilenameUtils.separatorsToUnix(targetPath);
}
try {
Path downloadedFile = transferFile(connector, targetRepository, targetPath, repository, localFile, requestProperties, true);
if (fileExists(downloadedFile)) {
log.debug("Successfully transferred: {}", downloadedFile.toAbsolutePath());
return downloadedFile;
}
} catch (NotFoundException e) {
log.debug("Artifact {} not found on repository \"{}\".", Keys.toKey(artifact), targetRepository.getRepository().getId());
} catch (NotModifiedException e) {
log.debug("Artifact {} not updated on repository \"{}\".", Keys.toKey(artifact), targetRepository.getRepository().getId());
} catch (ProxyException | RepositoryAdminException e) {
validatePolicies(this.downloadErrorPolicies, connector.getPolicies(), requestProperties, artifact, targetRepository, localFile, e, previousExceptions);
}
}
if (!previousExceptions.isEmpty()) {
throw new ProxyDownloadException("Failures occurred downloading from some remote repositories", previousExceptions);
}
log.debug("Exhausted all target repositories, artifact {} not found.", Keys.toKey(artifact));
return null;
}
use of org.apache.archiva.repository.RemoteRepositoryContent 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);
}
use of org.apache.archiva.repository.RemoteRepositoryContent in project archiva by apache.
the class DefaultRepositoryProxyConnectors method fetchFromProxies.
@Override
public Path fetchFromProxies(ManagedRepositoryContent repository, String path) {
Path localFile = Paths.get(repository.getRepoRoot(), path);
// no update policies for these paths
if (Files.exists(localFile)) {
return null;
}
Properties requestProperties = new Properties();
requestProperties.setProperty("filetype", "resource");
requestProperties.setProperty("managedRepositoryId", repository.getId());
List<ProxyConnector> connectors = getProxyConnectors(repository);
for (ProxyConnector connector : connectors) {
if (connector.isDisabled()) {
continue;
}
RemoteRepositoryContent targetRepository = connector.getTargetRepository();
requestProperties.setProperty("remoteRepositoryId", targetRepository.getId());
String targetPath = path;
try {
Path downloadedFile = transferFile(connector, targetRepository, targetPath, repository, localFile, requestProperties, false);
if (fileExists(downloadedFile)) {
log.debug("Successfully transferred: {}", downloadedFile.toAbsolutePath());
return downloadedFile;
}
} catch (NotFoundException e) {
log.debug("Resource {} not found on repository \"{}\".", path, targetRepository.getRepository().getId());
} catch (NotModifiedException e) {
log.debug("Resource {} not updated on repository \"{}\".", path, targetRepository.getRepository().getId());
} catch (ProxyException e) {
log.warn("Transfer error from repository {} for resource {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), path, e.getMessage());
log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Transfer error from repository \"{}" + "\" for resource {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), path, e.getMessage(), e);
} catch (RepositoryAdminException e) {
log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Transfer error from repository {} for resource {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), path, e.getMessage(), e);
log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Full stack trace", e);
}
}
log.debug("Exhausted all target repositories, resource {} not found.", path);
return null;
}
use of org.apache.archiva.repository.RemoteRepositoryContent in project archiva by apache.
the class MetadataToolsTest method testGetRepositorySpecificName.
@Test
public void testGetRepositorySpecificName() throws Exception {
RemoteRepositoryContent repoJavaNet = createRemoteRepositoryContent("maven2-repository.dev.java.net", "Java.net Repository for Maven 2", "http://download.java.net/maven/2/", "default");
RemoteRepositoryContent repoCentral = createRemoteRepositoryContent("central", "Central Global Repository", "http://repo1.maven.org/maven2/", "default");
String convertedName = tools.getRepositorySpecificName(repoJavaNet, "commons-lang/commons-lang/maven-metadata.xml");
assertMetadataPath("commons-lang/commons-lang/maven-metadata-maven2-repository.dev.java.net.xml", convertedName);
convertedName = tools.getRepositorySpecificName(repoCentral, "commons-lang/commons-lang/maven-metadata.xml");
assertMetadataPath("commons-lang/commons-lang/maven-metadata-central.xml", convertedName);
}
Aggregations