Search in sources :

Example 1 with ExternalResourceName

use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.

the class DefaultExternalResourceArtifactResolver method downloadStaticResource.

private LocallyAvailableExternalResource downloadStaticResource(List<ResourcePattern> patternList, final ModuleComponentArtifactMetadata artifact, ResourceAwareResolveResult result) {
    for (ResourcePattern resourcePattern : patternList) {
        ExternalResourceName location = resourcePattern.getLocation(artifact);
        result.attempted(location);
        LOGGER.debug("Loading {}", location);
        LocallyAvailableResourceCandidates localCandidates = locallyAvailableResourceFinder.findCandidates(artifact);
        try {
            LocallyAvailableExternalResource resource = resourceAccessor.getResource(location.getUri(), new CacheAwareExternalResourceAccessor.ResourceFileStore() {

                public LocallyAvailableResource moveIntoCache(File downloadedResource) {
                    return fileStore.move(artifact.getId(), downloadedResource);
                }
            }, 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) LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource) LocallyAvailableResourceCandidates(org.gradle.internal.resource.local.LocallyAvailableResourceCandidates) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource) CacheAwareExternalResourceAccessor(org.gradle.internal.resource.transfer.CacheAwareExternalResourceAccessor) File(java.io.File)

Example 2 with ExternalResourceName

use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.

the class MavenVersionLister method newVisitor.

public VersionPatternVisitor newVisitor(final ModuleIdentifier module, final Collection<String> dest, final ResourceAwareResolveResult result) {
    return new VersionPatternVisitor() {

        final Set<ExternalResourceName> searched = new HashSet<ExternalResourceName>();

        public void visit(ResourcePattern pattern, IvyArtifactName artifact) throws ResourceException {
            ExternalResourceName metadataLocation = pattern.toModulePath(module).resolve("maven-metadata.xml");
            if (!searched.add(metadataLocation)) {
                return;
            }
            result.attempted(metadataLocation);
            MavenMetadata mavenMetaData = mavenMetadataLoader.load(metadataLocation.getUri());
            for (String version : mavenMetaData.versions) {
                dest.add(version);
            }
        }
    };
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) HashSet(java.util.HashSet) Set(java.util.Set) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName)

Example 3 with ExternalResourceName

use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.

the class ResourceVersionLister method visit.

private void visit(ResourcePattern pattern, IvyArtifactName artifact, ModuleIdentifier module, List<String> collector, BuildableModuleVersionListingResolveResult result) {
    ExternalResourceName versionListPattern = pattern.toVersionListPattern(module, artifact);
    LOGGER.debug("Listing all in {}", versionListPattern);
    try {
        List<String> versionStrings = listRevisionToken(versionListPattern, result);
        for (String versionString : versionStrings) {
            collector.add(versionString);
        }
    } catch (Exception e) {
        throw ResourceExceptions.failure(versionListPattern.getUri(), String.format("Could not list versions using %s.", pattern), e);
    }
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName)

Example 4 with ExternalResourceName

use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.

the class ResourceVersionLister method filterOutMatchesWithOverlappingPatterns.

private List<String> filterOutMatchesWithOverlappingPatterns(List<String> listedVersions, ExternalResourceName currentVersionListPattern, Collection<ExternalResourceName> versionListPatterns) {
    List<String> remaining = Lists.newArrayList(listedVersions);
    for (ExternalResourceName otherVersionListPattern : versionListPatterns) {
        if (otherVersionListPattern != currentVersionListPattern) {
            String patternPath = otherVersionListPattern.getPath();
            Pattern regexPattern = toControlRegexPattern(patternPath);
            List<String> matching = listedVersions.stream().filter(version -> regexPattern.matcher(currentVersionListPattern.getPath().replace(REVISION_TOKEN, version)).matches()).collect(Collectors.toList());
            if (!matching.isEmpty()) {
                LOGGER.debug("Filtered out {} from results for overlapping match with {}", matching, otherVersionListPattern);
                remaining.removeAll(matching);
            }
        }
    }
    return remaining;
}
Also used : Logger(org.slf4j.Logger) ExternalResourceRepository(org.gradle.internal.resource.ExternalResourceRepository) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) Matcher(java.util.regex.Matcher) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) Map(java.util.Map) ResourceExceptions(org.gradle.internal.resource.ResourceExceptions) BuildableModuleVersionListingResolveResult(org.gradle.internal.resolve.result.BuildableModuleVersionListingResolveResult) IvyPatternHelper(org.apache.ivy.core.IvyPatternHelper) Pattern(java.util.regex.Pattern) ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) Pattern(java.util.regex.Pattern) ExternalResourceName(org.gradle.internal.resource.ExternalResourceName)

Example 5 with ExternalResourceName

use of org.gradle.internal.resource.ExternalResourceName in project gradle by gradle.

the class ResourceVersionLister method visit.

private void visit(ResourcePattern pattern, Map<ResourcePattern, ExternalResourceName> versionListPatterns, List<String> collector, BuildableModuleVersionListingResolveResult result) {
    ExternalResourceName versionListPattern = versionListPatterns.get(pattern);
    LOGGER.debug("Listing all in {}", versionListPattern);
    try {
        collector.addAll(listRevisionToken(versionListPattern, result, versionListPatterns));
    } catch (Exception e) {
        throw ResourceExceptions.failure(versionListPattern.getUri(), String.format("Could not list versions using %s.", pattern), e);
    }
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName)

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