Search in sources :

Example 6 with ExternalResourceName

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

the class ResourceVersionLister method listRevisionToken.

// lists all the values a revision token listed by a given url lister
private List<String> listRevisionToken(ExternalResourceName versionListPattern, BuildableModuleVersionListingResolveResult result, Map<ResourcePattern, ExternalResourceName> versionListPatterns) {
    String pattern = versionListPattern.getPath();
    if (!pattern.contains(REVISION_TOKEN)) {
        LOGGER.debug("revision token not defined in pattern {}.", pattern);
        return Collections.emptyList();
    }
    String prefix = pattern.substring(0, pattern.indexOf(REVISION_TOKEN));
    List<String> listedVersions;
    if (revisionMatchesDirectoryName(pattern)) {
        ExternalResourceName parent = versionListPattern.getRoot().resolve(prefix);
        listedVersions = listAll(parent, result);
    } else {
        int parentFolderSlashIndex = prefix.lastIndexOf(fileSeparator);
        String revisionParentFolder = parentFolderSlashIndex == -1 ? "" : prefix.substring(0, parentFolderSlashIndex + 1);
        ExternalResourceName parent = versionListPattern.getRoot().resolve(revisionParentFolder);
        LOGGER.debug("using {} to list all in {} ", repository, revisionParentFolder);
        result.attempted(parent);
        List<String> all = listWithCache(parent);
        if (all == null) {
            return Collections.emptyList();
        }
        LOGGER.debug("found {} urls", all.size());
        Pattern regexPattern = createRegexPattern(pattern, parentFolderSlashIndex);
        listedVersions = filterMatchedValues(all, regexPattern);
        LOGGER.debug("{} matched {}", listedVersions.size(), pattern);
    }
    if (versionListPatterns.size() > 1) {
        // Verify that none of the listed "versions" do match another pattern
        return filterOutMatchesWithOverlappingPatterns(listedVersions, versionListPattern, versionListPatterns.values());
    }
    return listedVersions;
}
Also used : Pattern(java.util.regex.Pattern) ExternalResourceName(org.gradle.internal.resource.ExternalResourceName)

Example 7 with ExternalResourceName

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

the class DefaultExternalResourceArtifactResolver method staticResourceExists.

private boolean staticResourceExists(List<ResourcePattern> patternList, 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);
        try {
            if (repository.resource(location, true).getMetaData() != null) {
                return true;
            }
        } catch (Exception e) {
            throw ResourceExceptions.getFailed(location.getUri(), e);
        }
    }
    return false;
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName)

Example 8 with ExternalResourceName

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

the class ExternalResourceResolver method publish.

public void publish(ModuleComponentArtifactMetadata artifact, File src) {
    ResourcePattern destinationPattern;
    if ("ivy".equals(artifact.getName().getType()) && !ivyPatterns.isEmpty()) {
        destinationPattern = ivyPatterns.get(0);
    } else if (!artifactPatterns.isEmpty()) {
        destinationPattern = artifactPatterns.get(0);
    } else {
        throw new IllegalStateException("impossible to publish " + artifact + " using " + this + ": no artifact pattern defined");
    }
    ExternalResourceName destination = destinationPattern.getLocation(artifact);
    put(src, destination);
    LOGGER.info("Published {} to {}", artifact, destination);
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName)

Example 9 with ExternalResourceName

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

the class ExternalRepositoryResourceAccessor method isUpToDate.

@Override
public boolean isUpToDate(String resource, @Nullable Long oldValue) {
    String[] parts = resource.split(";");
    if (!rootUriAsString.equals(parts[0])) {
        // not the same provider
        return false;
    }
    ExternalResourceName externalResourceName = new ExternalResourceName(rootUri, parts[1]);
    LocallyAvailableExternalResource locallyAvailableExternalResource = resourceResolver.resolveResource(externalResourceName);
    return Objects.equal(oldValue, hashFor(locallyAvailableExternalResource));
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource)

Example 10 with ExternalResourceName

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

the class ExternalRepositoryResourceAccessor method withResource.

@Override
public void withResource(String relativePath, Action<? super InputStream> action) {
    ExternalResourceName location = new ExternalResourceName(rootUri, relativePath);
    LocallyAvailableExternalResource resource = resourceResolver.resolveResource(location);
    if (resource != null) {
        resource.withContent(action);
    }
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource)

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