Search in sources :

Example 1 with BuildCacheServiceRole

use of org.gradle.caching.internal.controller.service.BuildCacheServiceRole in project gradle by gradle.

the class DefaultBuildCacheController method load.

@Nullable
@Override
public <T> T load(final BuildCacheLoadCommand<T> command) {
    final Unpack<T> unpack = new Unpack<T>(command);
    if (local.canLoad()) {
        try {
            local.load(command.getKey(), unpack);
        } catch (Exception e) {
            throw new GradleException("Build cache entry " + command.getKey() + " from local build cache is invalid", e);
        }
        if (unpack.result != null) {
            return unpack.result.getMetadata();
        }
    }
    if (legacyLocal.canLoad() || remote.canLoad()) {
        tmp.withTempFile(command.getKey(), new Action<File>() {

            @Override
            public void execute(File file) {
                LoadTarget loadTarget = new LoadTarget(file);
                BuildCacheServiceRole loadedRole = null;
                if (legacyLocal.canLoad()) {
                    loadedRole = BuildCacheServiceRole.LOCAL;
                    legacyLocal.load(command.getKey(), loadTarget);
                }
                if (remote.canLoad() && !loadTarget.isLoaded()) {
                    loadedRole = BuildCacheServiceRole.REMOTE;
                    remote.load(command.getKey(), loadTarget);
                }
                if (loadTarget.isLoaded()) {
                    try {
                        unpack.execute(file);
                    } catch (Exception e) {
                        @SuppressWarnings("ConstantConditions") String roleDisplayName = loadedRole.getDisplayName();
                        throw new GradleException("Build cache entry " + command.getKey() + " from " + roleDisplayName + " build cache is invalid", e);
                    }
                    if (local.canStore()) {
                        local.store(command.getKey(), file);
                    }
                }
            }
        });
    }
    BuildCacheLoadCommand.Result<T> result = unpack.result;
    if (result == null) {
        return null;
    } else {
        return result.getMetadata();
    }
}
Also used : LoadTarget(org.gradle.caching.internal.controller.service.LoadTarget) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedException(org.gradle.internal.UncheckedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) GradleException(org.gradle.api.GradleException) GradleException(org.gradle.api.GradleException) BuildCacheServiceRole(org.gradle.caching.internal.controller.service.BuildCacheServiceRole) File(java.io.File) Nullable(javax.annotation.Nullable)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1 GradleException (org.gradle.api.GradleException)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 BuildCacheServiceRole (org.gradle.caching.internal.controller.service.BuildCacheServiceRole)1 LoadTarget (org.gradle.caching.internal.controller.service.LoadTarget)1 UncheckedException (org.gradle.internal.UncheckedException)1