mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: improve debug logging for content root detection
GitOrigin-RevId: 7bc09c079cf97e49857e1aac6270bb7714250ce9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
79d4635709
commit
6b52116a24
@@ -6,6 +6,7 @@ import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager
|
||||
import com.intellij.openapi.vcs.VcsDirectoryMapping
|
||||
import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.platform.ModuleAttachListener
|
||||
@@ -27,6 +28,7 @@ class VcsModuleAttachListener : ModuleAttachListener {
|
||||
}
|
||||
|
||||
private fun addVcsMapping(primaryModule: Module, addedModuleContentRoot: VirtualFile) {
|
||||
MAPPING_DETECTION_LOG.debug("VcsModuleAttachListener.addVcsMapping", primaryModule, addedModuleContentRoot)
|
||||
val project = primaryModule.project
|
||||
val vcsManager = ProjectLevelVcsManager.getInstance(project)
|
||||
val mappings = vcsManager.directoryMappings
|
||||
@@ -53,6 +55,7 @@ class VcsModuleAttachListener : ModuleAttachListener {
|
||||
}
|
||||
|
||||
private fun removeVcsMapping(module: Module) {
|
||||
MAPPING_DETECTION_LOG.debug("VcsModuleAttachListener.removeVcsMapping", module)
|
||||
val project = module.project
|
||||
val vcsManager = ProjectLevelVcsManager.getInstance(project)
|
||||
val mappings = vcsManager.directoryMappings
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.vcs.ex;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsConfiguration;
|
||||
import com.intellij.openapi.vcs.impl.projectlevelman.NewMappings;
|
||||
import com.intellij.openapi.vcs.impl.projectlevelman.PersistentVcsShowConfirmationOption;
|
||||
import com.intellij.openapi.vcs.impl.projectlevelman.PersistentVcsShowSettingOption;
|
||||
import com.intellij.openapi.vcs.update.ActionInfo;
|
||||
@@ -20,6 +22,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ProjectLevelVcsManagerEx extends ProjectLevelVcsManager {
|
||||
@SuppressWarnings("LoggerInitializedWithForeignClass")
|
||||
public static final Logger MAPPING_DETECTION_LOG = Logger.getInstance(NewMappings.class);
|
||||
|
||||
@Topic.ProjectLevel
|
||||
public static final Topic<VcsActivationListener> VCS_ACTIVATED =
|
||||
new Topic<>(VcsActivationListener.class, Topic.BroadcastDirection.NONE);
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.startup.StartupActivity
|
||||
import com.intellij.openapi.vcs.AbstractVcs
|
||||
import com.intellij.openapi.vcs.VcsDirectoryMapping
|
||||
import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.Alarm
|
||||
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
|
||||
@@ -23,6 +24,7 @@ internal class ModuleVcsDetector(private val project: Project) {
|
||||
}
|
||||
|
||||
private fun startDetection() {
|
||||
MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.startDetection")
|
||||
val busConnection = project.messageBus.connect()
|
||||
|
||||
WorkspaceModelTopics.getInstance(project).subscribeAfterModuleLoading(busConnection, MyWorkspaceModelChangeListener())
|
||||
@@ -35,12 +37,15 @@ internal class ModuleVcsDetector(private val project: Project) {
|
||||
|
||||
@RequiresBackgroundThread
|
||||
private fun autoDetectDefaultRoots() {
|
||||
MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectDefaultRoots")
|
||||
if (vcsManager.haveDefaultMapping() != null) return
|
||||
|
||||
val contentRoots = DefaultVcsRootPolicy.getInstance(project).defaultVcsRoots
|
||||
MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectDefaultRoots - contentRoots", contentRoots)
|
||||
|
||||
val usedVcses = mutableSetOf<AbstractVcs>()
|
||||
val detectedRoots = mutableSetOf<Pair<VirtualFile, AbstractVcs>>()
|
||||
|
||||
val contentRoots = DefaultVcsRootPolicy.getInstance(project).defaultVcsRoots
|
||||
contentRoots
|
||||
.forEach { root ->
|
||||
val foundVcs = vcsManager.findVersioningVcs(root)
|
||||
@@ -50,6 +55,7 @@ internal class ModuleVcsDetector(private val project: Project) {
|
||||
}
|
||||
}
|
||||
if (detectedRoots.isEmpty()) return
|
||||
MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectDefaultRoots - detectedRoots", detectedRoots)
|
||||
|
||||
val commonVcs = usedVcses.singleOrNull()
|
||||
if (commonVcs != null) {
|
||||
@@ -65,6 +71,7 @@ internal class ModuleVcsDetector(private val project: Project) {
|
||||
|
||||
@RequiresBackgroundThread
|
||||
private fun autoDetectForContentRoots(contentRoots: List<VirtualFile>) {
|
||||
MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectForContentRoots - contentRoots", contentRoots)
|
||||
if (vcsManager.haveDefaultMapping() != null) return
|
||||
|
||||
val usedVcses = mutableSetOf<AbstractVcs>()
|
||||
@@ -81,6 +88,7 @@ internal class ModuleVcsDetector(private val project: Project) {
|
||||
}
|
||||
}
|
||||
if (detectedRoots.isEmpty()) return
|
||||
MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectForContentRoots - detectedRoots", detectedRoots)
|
||||
|
||||
val commonVcs = usedVcses.singleOrNull()
|
||||
if (commonVcs != null && !vcsManager.hasAnyMappings()) {
|
||||
@@ -104,15 +112,19 @@ internal class ModuleVcsDetector(private val project: Project) {
|
||||
private val dirtyContentRoots = mutableSetOf<VirtualFile>()
|
||||
|
||||
override fun contentRootsChanged(removed: List<VirtualFile>, added: List<VirtualFile>) {
|
||||
if (added.isNotEmpty() && vcsManager.haveDefaultMapping() == null) {
|
||||
synchronized(dirtyContentRoots) {
|
||||
dirtyContentRoots.addAll(added)
|
||||
dirtyContentRoots.removeAll(removed.toSet())
|
||||
if (added.isNotEmpty()) {
|
||||
MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.contentRootsChanged - roots added", added)
|
||||
if (vcsManager.haveDefaultMapping() == null) {
|
||||
synchronized(dirtyContentRoots) {
|
||||
dirtyContentRoots.addAll(added)
|
||||
dirtyContentRoots.removeAll(removed.toSet())
|
||||
}
|
||||
queue.queue(Update.create("modules scan") { runScanForNewContentRoots() })
|
||||
}
|
||||
queue.queue(Update.create("content root scan") { runScanForNewContentRoots() })
|
||||
}
|
||||
|
||||
if (removed.isNotEmpty()) {
|
||||
MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.contentRootsChanged - roots removed", removed)
|
||||
val remotedPaths = removed.map { it.path }.toSet()
|
||||
val removedMappings = vcsManager.directoryMappings.filter { it.directory in remotedPaths }
|
||||
removedMappings.forEach { mapping -> vcsManager.removeDirectoryMapping(mapping) }
|
||||
|
||||
@@ -596,6 +596,10 @@ public final class NewMappings implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("NewMappings.cleanupMappings", getDirectoryMappings(), filteredMappings);
|
||||
}
|
||||
|
||||
updateVcsMappings(filteredMappings);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG;
|
||||
import static com.intellij.openapi.vfs.VirtualFileVisitor.CONTINUE;
|
||||
import static com.intellij.openapi.vfs.VirtualFileVisitor.SKIP_CHILDREN;
|
||||
|
||||
@@ -37,6 +38,7 @@ final class VcsRootDetectorImpl implements VcsRootDetector {
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<VcsRoot> detect() {
|
||||
MAPPING_DETECTION_LOG.debug("VcsRootDetectorImpl.detect");
|
||||
synchronized (LOCK) {
|
||||
Collection<VcsRoot> roots = scanForRootsInContentRoots();
|
||||
myDetectedRoots = ContainerUtil.map(roots, DetectedVcsRoot::new);
|
||||
@@ -47,12 +49,14 @@ final class VcsRootDetectorImpl implements VcsRootDetector {
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<VcsRoot> detect(@Nullable VirtualFile startDir) {
|
||||
MAPPING_DETECTION_LOG.debug("VcsRootDetectorImpl.detect root", startDir);
|
||||
if (startDir == null || !startDir.isInLocalFileSystem()) return Collections.emptyList();
|
||||
return Collections.unmodifiableSet(scanForDirectory(startDir));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<VcsRoot> getOrDetect() {
|
||||
MAPPING_DETECTION_LOG.debug("VcsRootDetectorImpl.getOrDetect");
|
||||
synchronized (LOCK) {
|
||||
if (myDetectedRoots != null) {
|
||||
return ContainerUtil.mapNotNull(myDetectedRoots, it -> it.toVcsRoot(myProject));
|
||||
@@ -83,6 +87,7 @@ final class VcsRootDetectorImpl implements VcsRootDetector {
|
||||
|
||||
List<VirtualFile> contentRoots = ContainerUtil.filter(ProjectRootManager.getInstance(myProject).getContentRoots(),
|
||||
file -> file.isInLocalFileSystem());
|
||||
MAPPING_DETECTION_LOG.debug("VcsRootDetectorImpl.scanForRootsInContentRoots - contentRoots", contentRoots);
|
||||
|
||||
VirtualFile baseDir = myProject.getBaseDir();
|
||||
if (baseDir != null && !contentRoots.contains(baseDir)) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import static com.intellij.openapi.util.text.StringUtil.escapeXmlEntities;
|
||||
import static com.intellij.openapi.vcs.VcsNotificationIdsHolder.ROOTS_INVALID;
|
||||
import static com.intellij.openapi.vcs.VcsNotificationIdsHolder.ROOTS_REGISTERED;
|
||||
import static com.intellij.openapi.vcs.VcsRootError.Type.UNREGISTERED_ROOT;
|
||||
import static com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG;
|
||||
import static com.intellij.util.containers.ContainerUtil.*;
|
||||
import static com.intellij.util.ui.UIUtil.BR;
|
||||
|
||||
@@ -77,7 +78,7 @@ public final class VcsRootProblemNotifier {
|
||||
}
|
||||
return;
|
||||
}
|
||||
LOG.debug("Following errors detected: " + errors);
|
||||
MAPPING_DETECTION_LOG.debug("Following errors detected: " + errors);
|
||||
|
||||
Collection<VcsRootError> importantUnregisteredRoots = getImportantUnregisteredMappings(errors);
|
||||
Collection<VcsRootError> invalidRoots = getInvalidRoots(errors);
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import static com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG;
|
||||
import static com.intellij.openapi.vfs.VirtualFileVisitor.*;
|
||||
|
||||
@Service
|
||||
@@ -135,6 +136,7 @@ public final class VcsRootScanner implements Disposable {
|
||||
if (myAlarm.isDisposed()) return;
|
||||
if (VcsRootChecker.EXTENSION_POINT_NAME.getExtensionList().isEmpty()) return;
|
||||
|
||||
MAPPING_DETECTION_LOG.debug("VcsRootScanner.scheduleScan");
|
||||
myAlarm.cancelAllRequests(); // one scan is enough, no need to queue, they all do the same
|
||||
myAlarm.addRequest(() -> BackgroundTaskUtil.runUnderDisposeAwareIndicator(myAlarm, () -> {
|
||||
myRootProblemNotifier.rescanAndNotifyIfNeeded();
|
||||
@@ -179,6 +181,7 @@ public final class VcsRootScanner implements Disposable {
|
||||
public void runActivity(@NotNull Project project) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
if (!TrustedProjects.isTrusted(project)) return; // vcs is disabled
|
||||
MAPPING_DETECTION_LOG.debug("VcsRootScanner.start activity");
|
||||
getInstance(project).scheduleScan();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user