use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.
the class MavenResolver method findUniqueSnapshotVersion.
@Nullable
private MavenUniqueSnapshotModuleSource findUniqueSnapshotVersion(ModuleComponentIdentifier module, ResourceAwareResolveResult result) {
M2ResourcePattern wholePattern = getWholePattern();
if (!wholePattern.isComplete(module)) {
// do not attempt to download maven-metadata.xml for incomplete identifiers
return null;
}
ExternalResourceName metadataLocation = wholePattern.toModuleVersionPath(module).resolve("maven-metadata.xml");
result.attempted(metadataLocation);
MavenMetadata mavenMetadata = parseMavenMetadata(metadataLocation);
if (mavenMetadata.timestamp != null) {
// we have found a timestamp, so this is a snapshot unique version
String timestamp = mavenMetadata.timestamp + "-" + mavenMetadata.buildNumber;
return new MavenUniqueSnapshotModuleSource(timestamp);
}
return null;
}
use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.
the class DefaultExternalResourceArtifactResolver method downloadByCoords.
private LocallyAvailableExternalResource downloadByCoords(List<ResourcePattern> patternList, final ModuleComponentArtifactMetadata artifact, ResourceAwareResolveResult result) {
for (ResourcePattern resourcePattern : patternList) {
if (isIncomplete(resourcePattern, artifact)) {
continue;
}
ExternalResourceName location = resourcePattern.getLocation(artifact);
result.attempted(location);
LOGGER.debug("Loading {}", location);
LocallyAvailableResourceCandidates localCandidates = locallyAvailableResourceFinder.findCandidates(artifact);
try {
LocallyAvailableExternalResource resource = resourceAccessor.getResource(location, null, getFileStore(artifact), localCandidates);
if (resource != null) {
return resource;
}
} catch (Exception e) {
throw ResourceExceptions.getFailed(location.getUri(), e);
}
}
return null;
}
use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.
the class DefaultExternalResourceArtifactResolver method downloadByUrl.
private LocallyAvailableExternalResource downloadByUrl(List<ResourcePattern> patternList, final UrlBackedArtifactMetadata artifact, ResourceAwareResolveResult result) {
for (ResourcePattern resourcePattern : patternList) {
if (isIncomplete(resourcePattern, artifact)) {
continue;
}
ExternalResourceName moduleDir = resourcePattern.toModuleVersionPath(normalizeComponentId(artifact));
ExternalResourceName location = moduleDir.resolve(artifact.getRelativeUrl());
result.attempted(location);
LOGGER.debug("Loading {}", location);
LocallyAvailableResourceCandidates localCandidates = locallyAvailableResourceFinder.findCandidates(artifact);
try {
LocallyAvailableExternalResource resource = resourceAccessor.getResource(location, artifact.getId().getFileName(), getFileStore(artifact), localCandidates);
if (resource != null) {
return resource;
}
} catch (Exception e) {
throw ResourceExceptions.getFailed(location.getUri(), e);
}
}
return null;
}
use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.
the class ExternalResourceResolver method publishChecksum.
private void publishChecksum(ExternalResourceName destination, File content, String algorithm, int length) {
byte[] checksum = createChecksumFile(content, algorithm.toUpperCase(), length);
ExternalResourceName checksumDestination = destination.append("." + algorithm.replaceAll("-", ""));
repository.resource(checksumDestination).put(new ByteArrayReadableContent(checksum));
}
use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.
the class DefaultCacheAwareExternalResourceAccessor method getResourceSha1.
@Nullable
private HashCode getResourceSha1(ExternalResourceName location, boolean revalidate) {
try {
ExternalResourceName sha1Location = location.append(".sha1");
ExternalResource resource = delegate.resource(sha1Location, revalidate);
ExternalResourceReadResult<HashCode> result = resource.withContentIfPresent(inputStream -> {
String sha = IOUtils.toString(inputStream, StandardCharsets.US_ASCII);
// Servers may return SHA-1 with leading zeros stripped
sha = StringUtils.leftPad(sha, Hashing.sha1().getHexDigits(), '0');
return HashCode.fromString(sha);
});
return result == null ? null : result.getResult();
} catch (Exception e) {
LOGGER.debug(String.format("Failed to download SHA1 for resource '%s'.", location), e);
return null;
}
}
Aggregations