Moved "ThreadLocalDefendedInvoker" logic to "SvnFileUrlMappingImpl"
authorKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Wed, 9 Nov 2016 11:52:55 +0000 (14:52 +0300)
committerKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Wed, 16 Nov 2016 18:01:56 +0000 (21:01 +0300)
Removed "ThreadLocalDefendedInvoker"

platform/vcs-api/src/com/intellij/openapi/vcs/ThreadLocalDefendedInvoker.java [deleted file]
plugins/svn4idea/src/org/jetbrains/idea/svn/SvnFileUrlMappingImpl.java

diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/ThreadLocalDefendedInvoker.java b/platform/vcs-api/src/com/intellij/openapi/vcs/ThreadLocalDefendedInvoker.java
deleted file mode 100644 (file)
index 9fef491..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * 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.intellij.openapi.vcs;
-
-import com.intellij.openapi.project.Project;
-
-public abstract class ThreadLocalDefendedInvoker<T> {
-  protected final static ThreadLocal<Boolean> myThreadLocal = new ThreadLocal<Boolean>() {
-    @Override
-    protected Boolean initialValue() {
-      return Boolean.TRUE;
-    }
-  };
-
-  protected abstract T execute(Project project);
-
-  public static boolean isInside() {
-    return ! Boolean.TRUE.equals(myThreadLocal.get());
-  }
-
-  public static boolean isOutside() {
-    return ! isInside();
-  }
-
-  public T executeDefended(Project project) {
-    try {
-      myThreadLocal.set(Boolean.FALSE);
-      return execute(project);
-    } finally {
-      myThreadLocal.set(Boolean.TRUE);
-    }
-  }
-}
index 4a0cb90817870dd246aa630f88e4bef7667c0480..6f4a46aa26487de860c0e8ec734624db333f7529 100644 (file)
@@ -24,7 +24,6 @@ import com.intellij.openapi.project.DumbAwareRunnable;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vcs.ProjectLevelVcsManager;
-import com.intellij.openapi.vcs.ThreadLocalDefendedInvoker;
 import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl;
 import com.intellij.openapi.vcs.impl.VcsInitObject;
 import com.intellij.openapi.vfs.LocalFileSystem;
@@ -53,21 +52,35 @@ public class SvnFileUrlMappingImpl implements SvnFileUrlMapping, PersistentState
   // grouped; if there are several mappings one under another, will return the upmost
   private final SvnMapping myMoreRealMapping;
   private final List<RootUrlInfo> myErrorRoots;
-  private final MyRootsHelper myHelper;
+  @NotNull private final MyRootsHelper myRootsHelper;
   private final Project myProject;
   private final NestedCopiesHolder myNestedCopiesHolder;
   private boolean myInitialized;
   private boolean myInitedReloaded;
 
-  private static class MyRootsHelper extends ThreadLocalDefendedInvoker<VirtualFile[]> {
-    private final ProjectLevelVcsManager myPlVcsManager;
+  private static class MyRootsHelper {
+    @NotNull private final static ThreadLocal<Boolean> ourInProgress = ThreadLocal.withInitial(() -> Boolean.FALSE);
+    @NotNull private final Project myProject;
+    @NotNull private final ProjectLevelVcsManager myVcsManager;
 
-    private MyRootsHelper(final ProjectLevelVcsManager vcsManager) {
-      myPlVcsManager = vcsManager;
+    private MyRootsHelper(@NotNull Project project, @NotNull ProjectLevelVcsManager vcsManager) {
+      myProject = project;
+      myVcsManager = vcsManager;
     }
 
-    protected VirtualFile[] execute(Project project) {
-      return myPlVcsManager.getRootsUnderVcs(SvnVcs.getInstance(project));
+    @NotNull
+    public VirtualFile[] execute() {
+      try {
+        ourInProgress.set(Boolean.TRUE);
+        return myVcsManager.getRootsUnderVcs(SvnVcs.getInstance(myProject));
+      }
+      finally {
+        ourInProgress.set(Boolean.FALSE);
+      }
+    }
+
+    public static boolean isInProgress() {
+      return ourInProgress.get();
     }
   }
 
@@ -81,7 +94,7 @@ public class SvnFileUrlMappingImpl implements SvnFileUrlMapping, PersistentState
     myMapping = new SvnMapping();
     myMoreRealMapping = new SvnMapping();
     myErrorRoots = ContainerUtil.newArrayList();
-    myHelper = new MyRootsHelper(vcsManager);
+    myRootsHelper = new MyRootsHelper(project, vcsManager);
     myChecker = new SvnCompatibilityChecker(project);
     myNestedCopiesHolder = new NestedCopiesHolder();
   }
@@ -183,7 +196,7 @@ public class SvnFileUrlMappingImpl implements SvnFileUrlMapping, PersistentState
 
   @NotNull
   public List<VirtualFile> convertRoots(@NotNull List<VirtualFile> result) {
-    if (ThreadLocalDefendedInvoker.isInside()) return ContainerUtil.newArrayList(result);
+    if (MyRootsHelper.isInProgress()) return ContainerUtil.newArrayList(result);
 
     synchronized (myMonitor) {
       final List<VirtualFile> cachedRoots = myMoreRealMapping.getUnderVcsRoots();
@@ -214,7 +227,7 @@ public class SvnFileUrlMappingImpl implements SvnFileUrlMapping, PersistentState
     }
     else {
       final SvnVcs vcs = SvnVcs.getInstance(myProject);
-      final VirtualFile[] roots = myHelper.executeDefended(myProject);
+      final VirtualFile[] roots = myRootsHelper.execute();
       final SvnRootsDetector rootsDetector = new SvnRootsDetector(vcs, this, myNestedCopiesHolder);
       // do not send additional request for nested copies when in init state
       rootsDetector.detectCopyRoots(roots, init(), afterRefreshCallback);
@@ -306,8 +319,9 @@ public class SvnFileUrlMappingImpl implements SvnFileUrlMapping, PersistentState
     }
   }
 
+  @NotNull
   public VirtualFile[] getNotFilteredRoots() {
-    return myHelper.executeDefended(myProject);
+    return myRootsHelper.execute();
   }
 
   public boolean isEmpty() {