Search in sources :

Example 21 with ExternalResourceName

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;
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) MavenMetadata(org.gradle.api.internal.artifacts.repositories.maven.MavenMetadata) Nullable(javax.annotation.Nullable)

Example 22 with ExternalResourceName

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;
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) LocallyAvailableResourceCandidates(org.gradle.internal.resource.local.LocallyAvailableResourceCandidates) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource)

Example 23 with ExternalResourceName

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;
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) LocallyAvailableResourceCandidates(org.gradle.internal.resource.local.LocallyAvailableResourceCandidates) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource)

Example 24 with ExternalResourceName

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));
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) ByteArrayReadableContent(org.gradle.internal.resource.local.ByteArrayReadableContent)

Example 25 with ExternalResourceName

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;
    }
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) HashCode(org.gradle.internal.hash.HashCode) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource) ExternalResource(org.gradle.internal.resource.ExternalResource) CachedExternalResource(org.gradle.internal.resource.cached.CachedExternalResource) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Aggregations

ExternalResourceName (org.gradle.internal.resource.ExternalResourceName)25 LocallyAvailableExternalResource (org.gradle.internal.resource.local.LocallyAvailableExternalResource)6 Pattern (java.util.regex.Pattern)4 URI (java.net.URI)3 Nullable (javax.annotation.Nullable)3 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)3 LocallyAvailableResourceCandidates (org.gradle.internal.resource.local.LocallyAvailableResourceCandidates)3 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Matcher (java.util.regex.Matcher)2 ExternalResource (org.gradle.internal.resource.ExternalResource)2 ByteArrayReadableContent (org.gradle.internal.resource.local.ByteArrayReadableContent)2 Lists (com.google.common.collect.Lists)1 File (java.io.File)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1