IDEA-355463 [ExternalSystem|Sync] new: enter the incomplete project state during the sync

GitOrigin-RevId: 69e591301f6146c232933603ff45dc21a866f6ab
This commit is contained in:
Sergei Vorobyov
2024-06-25 21:20:54 +02:00
committed by intellij-monorepo-bot
parent 07f7cdaf55
commit 056c2edf93
2 changed files with 33 additions and 8 deletions

View File

@@ -74,6 +74,8 @@
description="Provide assignment of groupId/artifactId/version for JPS modules"/>
<registryKey key="external.system.pause.indexing.during.sync" defaultValue="false"
description="Suspend indexing and scanning during sync with external build system"/>
<registryKey key="external.system.incomplete.dependencies.state.during.sync" defaultValue="true"
description="Indicates project state as incomplete during sync with external build system"/>
<externalProjectDataService implementation="com.intellij.openapi.externalSystem.service.project.manage.ProjectDataServiceImpl"/>
<externalProjectDataService implementation="com.intellij.openapi.externalSystem.service.project.manage.LibraryDataService"/>

View File

@@ -26,6 +26,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.TransactionGuard;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.application.ex.ApplicationEx;
import com.intellij.openapi.diagnostic.ControlFlowException;
import com.intellij.openapi.diagnostic.Logger;
@@ -67,12 +68,14 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.IncompleteDependenciesService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.NaturalComparator;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -468,14 +471,34 @@ public final class ExternalSystemUtil {
}
};
LOG.info("External project [" + externalProjectPath + "] resolution task started");
var startTS = System.currentTimeMillis();
resolveProjectTask.execute(indicator, taskListener);
var endTS = System.currentTimeMillis();
LOG.info("External project [" + externalProjectPath + "] resolution task executed in " + (endTS - startTS) + " ms.");
ExternalSystemTelemetryUtil.runWithSpan(externalSystemId, "ExternalSystemSyncResultProcessing",
(ignore) -> handleSyncResult(externalProjectPath, importSpec, resolveProjectTask,
eventDispatcher, finishSyncEventSupplier));
incompleteDependenciesState(project, resolveProjectTask, () -> {
LOG.info("External project [" + externalProjectPath + "] resolution task started");
var startTS = System.currentTimeMillis();
resolveProjectTask.execute(indicator, taskListener);
var endTS = System.currentTimeMillis();
LOG.info("External project [" + externalProjectPath + "] resolution task executed in " + (endTS - startTS) + " ms.");
ExternalSystemTelemetryUtil.runWithSpan(externalSystemId, "ExternalSystemSyncResultProcessing",
(ignore) -> handleSyncResult(externalProjectPath, importSpec, resolveProjectTask,
eventDispatcher, finishSyncEventSupplier));
});
}
}
private static void incompleteDependenciesState(@NotNull Project project, @NotNull Object requestor, @NotNull Runnable runnable) {
if (!Registry.is("external.system.incomplete.dependencies.state.during.sync")) {
runnable.run();
}
var incompleteDependenciesService = project.getService(IncompleteDependenciesService.class);
var incompleteDependenciesAccessToken = WriteAction.computeAndWait(() -> {
return incompleteDependenciesService.enterIncompleteState(requestor);
});
try {
runnable.run();
}
finally {
WriteAction.runAndWait(() -> {
incompleteDependenciesAccessToken.finish();
});
}
}