Skip to content

Commit

Permalink
WIP - Enable QuerySyncManager to track sync status
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 588569078
  • Loading branch information
Googler authored and copybara-github committed Dec 7, 2023
1 parent 5c531ff commit 28c296a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 10 deletions.
18 changes: 9 additions & 9 deletions base/src/com/google/idea/blaze/base/qsync/QuerySyncManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
import com.google.idea.blaze.base.scope.scopes.ProgressIndicatorScope;
import com.google.idea.blaze.base.scope.scopes.ToolWindowScope;
import com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior;
import com.google.idea.blaze.base.sync.SyncMode;
import com.google.idea.blaze.base.sync.SyncResult;
import com.google.idea.blaze.base.sync.status.BlazeSyncStatus;
import com.google.idea.blaze.base.targetmaps.SourceToTargetMap;
import com.google.idea.blaze.base.toolwindow.Task;
import com.google.idea.blaze.base.util.SaveUtil;
Expand Down Expand Up @@ -96,6 +93,8 @@ public class QuerySyncManager implements Disposable {
private final ProjectLoader loader;
private volatile QuerySyncProject loadedProject;

private final QuerySyncStatus syncStatus = new QuerySyncStatus();

private static final BoolExperiment showWindowOnAutomaticSyncErrors =
new BoolExperiment("querysync.autosync.show.console.on.error", true);

Expand Down Expand Up @@ -257,23 +256,20 @@ private ListenableFuture<Boolean> run(
ThrowingScopedOperation operation,
TaskOrigin taskOrigin) {
SettableFuture<Boolean> result = SettableFuture.create();
BlazeSyncStatus syncStatus = BlazeSyncStatus.getInstance(project);
syncStatus.syncStarted();
Futures.addCallback(
result,
new FutureCallback<Boolean>() {
@Override
public void onSuccess(Boolean success) {
syncStatus.syncEnded(SyncMode.FULL, success ? SyncResult.SUCCESS : SyncResult.FAILURE);
syncStatus.syncStarted();
}

@Override
public void onFailure(Throwable throwable) {
if (result.isCancelled()) {
syncStatus.syncEnded(SyncMode.FULL, SyncResult.CANCELLED);
} else {
syncStatus.syncEnded();
if (!result.isCancelled()) {
logger.error("Sync failed", throwable);
syncStatus.syncEnded(SyncMode.FULL, SyncResult.FAILURE);
}
}
},
Expand Down Expand Up @@ -393,6 +389,10 @@ public boolean canEnableAnalysisFor(Path workspaceRelativePath) {
return loadedProject.canEnableAnalysisFor(workspaceRelativePath);
}

public boolean syncInProgress() {
return syncStatus.syncInProgress();
}

@CanIgnoreReturnValue
public ListenableFuture<Boolean> generateRenderJar(
PsiFile psiFile, QuerySyncActionStatsScope querySyncActionStats, TaskOrigin taskOrigin) {
Expand Down
36 changes: 36 additions & 0 deletions base/src/com/google/idea/blaze/base/qsync/QuerySyncStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.base.qsync;

import java.util.concurrent.atomic.AtomicBoolean;

/** Class that keeps track of query sync operations. */
public class QuerySyncStatus {

private final AtomicBoolean syncInProgress = new AtomicBoolean(false);

public boolean syncInProgress() {
return syncInProgress.get();
}

public void syncStarted() {
syncInProgress.set(true);
}

public void syncEnded() {
syncInProgress.set(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ enum SyncStatus {

SyncStatus getStatus();


static BlazeSyncStatus getInstance(Project project) {
return project.getService(BlazeSyncStatus.class);
}
Expand All @@ -40,6 +39,11 @@ static BlazeSyncStatus getInstance(Project project) {

void syncEnded(SyncMode syncMode, SyncResult syncResult);

/**
* @deprecated For query sync, use {@link
* com.google.idea.blaze.base.qsync.QuerySyncManager#syncInProgress}
*/
@Deprecated
boolean syncInProgress();

void setDirty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.google.idea.blaze.base.sync.status;

import com.google.idea.blaze.base.qsync.QuerySyncManager;
import com.google.idea.blaze.base.settings.Blaze;
import com.google.idea.blaze.base.settings.BlazeImportSettings.ProjectType;
import com.google.idea.blaze.base.sync.SyncMode;
import com.google.idea.blaze.base.sync.SyncResult;
import com.intellij.openapi.project.Project;
Expand All @@ -25,6 +28,8 @@
*/
public class BlazeSyncStatusImpl implements BlazeSyncStatus {

private final Project project;

public static BlazeSyncStatusImpl getImpl(Project project) {
return (BlazeSyncStatusImpl) BlazeSyncStatus.getInstance(project);
}
Expand All @@ -34,6 +39,7 @@ public static BlazeSyncStatusImpl getImpl(Project project) {

public BlazeSyncStatusImpl(Project project) {
this.stateManager = BlazeSyncStatusStateManager.getInstance(project);
this.project = project;
}

@Override
Expand All @@ -46,6 +52,9 @@ public SyncStatus getStatus() {

@Override
public boolean syncInProgress() {
if (Blaze.getProjectType(project).equals(ProjectType.QUERY_SYNC)) {
return QuerySyncManager.getInstance(project).syncInProgress();
}
return syncInProgress.get();
}

Expand Down

0 comments on commit 28c296a

Please sign in to comment.