Search in sources :

Example 1 with LocallyAvailableResource

use of org.gradle.internal.resource.local.LocallyAvailableResource in project gradle by gradle.

the class AbstractModuleDescriptorParser method parseMetaData.

public T parseMetaData(DescriptorParseContext ivySettings, File descriptorFile, boolean validate) throws MetaDataParseException {
    LocallyAvailableResource localResource = new DefaultLocallyAvailableResource(descriptorFile);
    LocallyAvailableExternalResource resource = new DefaultLocallyAvailableExternalResource(descriptorFile.toURI(), localResource);
    return parseDescriptor(ivySettings, resource, validate);
}
Also used : LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource) DefaultLocallyAvailableResource(org.gradle.internal.resource.local.DefaultLocallyAvailableResource) DefaultLocallyAvailableExternalResource(org.gradle.internal.resource.local.DefaultLocallyAvailableExternalResource) DefaultLocallyAvailableResource(org.gradle.internal.resource.local.DefaultLocallyAvailableResource) DefaultLocallyAvailableExternalResource(org.gradle.internal.resource.local.DefaultLocallyAvailableExternalResource) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource)

Example 2 with LocallyAvailableResource

use of org.gradle.internal.resource.local.LocallyAvailableResource in project gradle by gradle.

the class DefaultModuleMetaDataCache method cacheMetaData.

public CachedMetaData cacheMetaData(ModuleComponentRepository repository, ModuleComponentResolveMetadata metadata) {
    LOGGER.debug("Recording module descriptor in cache: {} [changing = {}]", metadata.getComponentId(), metadata.isChanging());
    ModuleComponentAtRepositoryKey key = createKey(repository, metadata.getComponentId());
    LocallyAvailableResource resource = moduleMetadataStore.putModuleDescriptor(key, metadata);
    ModuleMetadataCacheEntry entry = createEntry(metadata, resource.getSha1());
    getCache().put(key, entry);
    return new DefaultCachedMetaData(entry, null, timeProvider);
}
Also used : LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource)

Example 3 with LocallyAvailableResource

use of org.gradle.internal.resource.local.LocallyAvailableResource in project gradle by gradle.

the class ModuleMetadataStore method getModuleDescriptor.

public MutableModuleComponentResolveMetadata getModuleDescriptor(ModuleComponentAtRepositoryKey component) {
    String filePath = getFilePath(component);
    final LocallyAvailableResource resource = metaDataStore.get(filePath);
    if (resource != null) {
        try {
            KryoBackedDecoder decoder = new KryoBackedDecoder(new FileInputStream(resource.getFile()));
            try {
                return moduleMetadataSerializer.read(decoder, moduleIdentifierFactory, moduleExclusions);
            } finally {
                decoder.close();
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not load module metadata from " + resource.getDisplayName(), e);
        }
    }
    return null;
}
Also used : KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource) FileInputStream(java.io.FileInputStream) UncheckedException(org.gradle.internal.UncheckedException)

Example 4 with LocallyAvailableResource

use of org.gradle.internal.resource.local.LocallyAvailableResource 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 5 with LocallyAvailableResource

use of org.gradle.internal.resource.local.LocallyAvailableResource in project gradle by gradle.

the class ExternalRepositoryResourceAccessor method withResource.

@Override
public void withResource(String relativePath, Action<? super InputStream> action) {
    try {
        String scheme = rootUri.getScheme();
        String host = rootUri.getHost();
        String path = makePath(rootUri.getPath());
        int port = rootUri.getPort();
        String userInfo = rootUri.getUserInfo();
        URI uri = new URI(scheme, userInfo, host, port, path + relativePath, null, null);
        Hasher hasher = Hashing.sha1().newHasher().putString(uri.toASCIIString(), Charsets.UTF_8);
        final String key = hasher.hash().toString();
        LocallyAvailableExternalResource resource = resourceAccessor.getResource(uri, new CacheAwareExternalResourceAccessor.ResourceFileStore() {

            @Override
            public LocallyAvailableResource moveIntoCache(File downloadedResource) {
                return fileStore.move(key, downloadedResource);
            }
        }, null);
        if (resource != null) {
            resource.withContent(action);
        }
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : Hasher(com.google.common.hash.Hasher) LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource) URI(java.net.URI) CacheAwareExternalResourceAccessor(org.gradle.internal.resource.transfer.CacheAwareExternalResourceAccessor) File(java.io.File) UncheckedException(org.gradle.internal.UncheckedException)

Aggregations

LocallyAvailableResource (org.gradle.internal.resource.local.LocallyAvailableResource)7 File (java.io.File)4 LocallyAvailableExternalResource (org.gradle.internal.resource.local.LocallyAvailableExternalResource)3 UncheckedException (org.gradle.internal.UncheckedException)2 DefaultLocallyAvailableExternalResource (org.gradle.internal.resource.local.DefaultLocallyAvailableExternalResource)2 DefaultLocallyAvailableResource (org.gradle.internal.resource.local.DefaultLocallyAvailableResource)2 CacheAwareExternalResourceAccessor (org.gradle.internal.resource.transfer.CacheAwareExternalResourceAccessor)2 Hasher (com.google.common.hash.Hasher)1 FileInputStream (java.io.FileInputStream)1 URI (java.net.URI)1 BuildOutcome (org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome)1 GeneratedArchiveBuildOutcome (org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcome)1 UnknownBuildOutcome (org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcome)1 ExternalResourceName (org.gradle.internal.resource.ExternalResourceName)1 LocallyAvailableResourceCandidates (org.gradle.internal.resource.local.LocallyAvailableResourceCandidates)1 KryoBackedDecoder (org.gradle.internal.serialize.kryo.KryoBackedDecoder)1 GradleBuildOutcome (org.gradle.tooling.model.internal.outcomes.GradleBuildOutcome)1 GradleFileBuildOutcome (org.gradle.tooling.model.internal.outcomes.GradleFileBuildOutcome)1