use of com.google.idea.blaze.base.sync.SyncMode in project intellij by bazelbuild.
the class AutoSyncHandler method combineSyncParams.
@Nullable
private static BlazeSyncParams combineSyncParams(@Nullable BlazeSyncParams params1, @Nullable BlazeSyncParams params2) {
if (params1 == null || params2 == null) {
return params1 == null ? params2 : params1;
}
SyncMode mode = combineModes(params1.syncMode(), params2.syncMode());
String origin = params1.syncOrigin().equals(params2.syncOrigin()) ? params1.syncOrigin() : AutoSyncProvider.AUTO_SYNC_REASON + ".Combined";
return BlazeSyncParams.builder().setTitle(AutoSyncProvider.AUTO_SYNC_TITLE).setSyncMode(mode).setSyncOrigin(origin).setBackgroundSync(params1.backgroundSync() && params2.backgroundSync()).addTargetExpressions(params1.targetExpressions()).addTargetExpressions(params2.targetExpressions()).setAddWorkingSet(params1.addWorkingSet() || params2.addWorkingSet()).setAddProjectViewTargets(params1.addProjectViewTargets() || params2.addProjectViewTargets()).build();
}
use of com.google.idea.blaze.base.sync.SyncMode in project intellij by bazelbuild.
the class JdepsFileReader method doLoadJdepsFiles.
@Nullable
private JdepsState doLoadJdepsFiles(Project project, BlazeContext context, ArtifactLocationDecoder decoder, @Nullable JdepsState oldState, Collection<TargetIdeInfo> targetsToLoad, SyncMode syncMode) throws InterruptedException, ExecutionException {
Map<OutputArtifact, TargetKey> fileToTargetMap = Maps.newHashMap();
for (TargetIdeInfo target : targetsToLoad) {
BlazeArtifact output = resolveJdepsOutput(decoder, target);
if (output instanceof OutputArtifact) {
fileToTargetMap.put((OutputArtifact) output, target.getKey());
}
}
ArtifactsDiff diff = ArtifactsDiff.diffArtifacts(oldState != null ? oldState.getArtifactState() : null, fileToTargetMap.keySet());
// TODO: handle prefetching for arbitrary OutputArtifacts
List<OutputArtifact> outputArtifacts = diff.getUpdatedOutputs();
// already. Additional logging to identify what is going wrong.
if (!outputArtifacts.isEmpty() && !SyncMode.involvesBlazeBuild(syncMode)) {
logger.warn("ArtifactDiff: " + outputArtifacts.size() + " outputs need to be updated during SyncMode.NO_BUILD ");
if (oldState == null) {
logger.warn("ArtifactDiff: oldState == null, we failed to load prior JdepsState.");
} else {
// Do not list all artifacts since it may be pretty long.
if (oldState.getArtifactState().size() != fileToTargetMap.size()) {
logger.warn("Existing artifact state does not match with target map." + " [oldState.getArtifactState().size() = " + oldState.getArtifactState().size() + ", fileToTargetMap.size() = " + fileToTargetMap.size() + "]");
}
}
}
ListenableFuture<?> downloadArtifactsFuture = RemoteArtifactPrefetcher.getInstance().downloadArtifacts(/* projectName= */
project.getName(), /* outputArtifacts= */
BlazeArtifact.getRemoteArtifacts(outputArtifacts));
ListenableFuture<?> fetchLocalFilesFuture = PrefetchService.getInstance().prefetchFiles(BlazeArtifact.getLocalFiles(outputArtifacts), true, false);
if (!FutureUtil.waitForFuture(context, Futures.allAsList(downloadArtifactsFuture, fetchLocalFilesFuture)).timed("FetchJdeps", EventType.Prefetching).withProgressMessage("Reading jdeps files...").run().success()) {
return null;
}
AtomicLong totalSizeLoaded = new AtomicLong(0);
List<ListenableFuture<Result>> futures = Lists.newArrayList();
for (OutputArtifact updatedFile : outputArtifacts) {
futures.add(FetchExecutor.EXECUTOR.submit(() -> {
totalSizeLoaded.addAndGet(updatedFile.getLength());
try (InputStream inputStream = updatedFile.getInputStream()) {
Deps.Dependencies dependencies = Deps.Dependencies.parseFrom(inputStream);
if (dependencies == null) {
return null;
}
List<String> deps = dependencies.getDependencyList().stream().filter(dep -> relevantDep(dep)).map(Dependency::getPath).collect(toImmutableList());
TargetKey targetKey = fileToTargetMap.get(updatedFile);
return new Result(updatedFile, targetKey, deps);
} catch (IOException e) {
logger.info("Could not read jdeps file: " + updatedFile);
return null;
}
}));
}
JdepsState.Builder state = JdepsState.builder();
if (oldState != null) {
state.list.addAll(oldState.data);
}
state.removeArtifacts(diff.getUpdatedOutputs().stream().map(OutputArtifact::toArtifactState).collect(toImmutableList()));
state.removeArtifacts(diff.getRemovedOutputs());
for (Result result : Futures.allAsList(futures).get()) {
if (result != null) {
state.list.add(JdepsData.create(result.targetKey, result.dependencies, result.output.toArtifactState()));
}
}
context.output(PrintOutput.log(String.format("Loaded %d jdeps files, total size %dkB", diff.getUpdatedOutputs().size(), totalSizeLoaded.get() / 1024)));
return state.build();
}
Aggregations