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();
}
}
Aggregations