Search in sources :

Example 6 with LocallyAvailableResource

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

the class DirectoryBuildCacheService method loadInsideLock.

private void loadInsideLock(BuildCacheKey key, Action<? super File> reader) {
    LocallyAvailableResource resource = fileStore.get(key.getHashCode());
    if (resource == null) {
        return;
    }
    File file = resource.getFile();
    touch(file);
    try {
        reader.execute(file);
    } catch (Exception e) {
        // Try to move the file out of the way in case its permanently corrupt
        // Don't delete, so that it can be potentially used for debugging
        File failedFile = new File(file.getAbsolutePath() + failedFileSuffix);
        GFileUtils.deleteQuietly(failedFile);
        // noinspection ResultOfMethodCallIgnored
        file.renameTo(failedFile);
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource) File(java.io.File) BuildCacheException(org.gradle.caching.BuildCacheException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedException(org.gradle.internal.UncheckedException)

Example 7 with LocallyAvailableResource

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

the class ExternalResourceResolverDescriptorParseContext method getMetaDataArtifact.

public LocallyAvailableExternalResource getMetaDataArtifact(ModuleComponentIdentifier moduleComponentIdentifier, ArtifactType artifactType) {
    File resolvedArtifactFile = resolveMetaDataArtifactFile(moduleComponentIdentifier, mainResolvers.getComponentResolver(), mainResolvers.getArtifactResolver(), artifactType);
    LocallyAvailableResource localResource = new DefaultLocallyAvailableResource(resolvedArtifactFile);
    return new DefaultLocallyAvailableExternalResource(resolvedArtifactFile.toURI(), localResource);
}
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) File(java.io.File)

Example 8 with LocallyAvailableResource

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

use of org.gradle.internal.resource.local.LocallyAvailableResource 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(artifact.getComponentId());
        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(), 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 10 with LocallyAvailableResource

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

the class GradleBuildOutcomeSetTransformer method addFileBuildOutcome.

private void addFileBuildOutcome(GradleFileBuildOutcome outcome, ProjectOutcomes rootProject, Set<BuildOutcome> translatedOutcomes) {
    if (zipArchiveTypes.contains(outcome.getTypeIdentifier())) {
        File originalFile = outcome.getFile();
        String relativePath = RelativePathUtil.relativePath(rootProject.getProjectDirectory(), originalFile);
        LocallyAvailableResource resource = null;
        if (originalFile.exists()) {
            String filestoreDestination = fileStorePrefix + "/" + outcome.getTaskPath() + "/" + originalFile.getName();
            resource = fileStore.move(filestoreDestination, originalFile);
        }
        BuildOutcome buildOutcome = new GeneratedArchiveBuildOutcome(outcome.getTaskPath(), outcome.getDescription(), resource, relativePath);
        translatedOutcomes.add(buildOutcome);
    } else {
        String outcomeName = outcome.getTaskPath();
        if (isEmpty(outcomeName)) {
            outcomeName = RelativePathUtil.relativePath(rootProject.getProjectDirectory(), outcome.getFile());
        }
        translatedOutcomes.add(new UnknownBuildOutcome(outcomeName, outcome.getDescription()));
    }
}
Also used : LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource) GeneratedArchiveBuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcome) UnknownBuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcome) File(java.io.File) GeneratedArchiveBuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcome) GradleBuildOutcome(org.gradle.tooling.model.internal.outcomes.GradleBuildOutcome) UnknownBuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcome) BuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome) GradleFileBuildOutcome(org.gradle.tooling.model.internal.outcomes.GradleFileBuildOutcome)

Aggregations

LocallyAvailableResource (org.gradle.internal.resource.local.LocallyAvailableResource)10 File (java.io.File)7 LocallyAvailableExternalResource (org.gradle.internal.resource.local.LocallyAvailableExternalResource)4 CacheAwareExternalResourceAccessor (org.gradle.internal.resource.transfer.CacheAwareExternalResourceAccessor)4 ExternalResourceName (org.gradle.internal.resource.ExternalResourceName)3 LocallyAvailableResourceCandidates (org.gradle.internal.resource.local.LocallyAvailableResourceCandidates)3 UncheckedException (org.gradle.internal.UncheckedException)2 DefaultLocallyAvailableExternalResource (org.gradle.internal.resource.local.DefaultLocallyAvailableExternalResource)2 DefaultLocallyAvailableResource (org.gradle.internal.resource.local.DefaultLocallyAvailableResource)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 UncheckedIOException (org.gradle.api.UncheckedIOException)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 MissingResourceException (org.gradle.api.resources.MissingResourceException)1 BuildCacheException (org.gradle.caching.BuildCacheException)1 ExternalResource (org.gradle.internal.resource.ExternalResource)1 KryoBackedDecoder (org.gradle.internal.serialize.kryo.KryoBackedDecoder)1 GradleBuildOutcome (org.gradle.tooling.model.internal.outcomes.GradleBuildOutcome)1