CWM-632 vcs: decouple builtin-server from vcs
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Mon, 19 Oct 2020 12:20:01 +0000 (15:20 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Mon, 19 Oct 2020 16:31:23 +0000 (16:31 +0000)
GitOrigin-RevId: a516765eb53838a29e2b1cde540f50c931dbb3d2

platform/built-in-server/intellij.platform.builtInServer.impl.iml
platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt
platform/vcs-impl/intellij.platform.vcs.impl.iml
platform/vcs-impl/resources/META-INF/VcsExtensions.xml
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsRootWebServerRootsProvider.kt [new file with mode: 0644]

index b4b9d04069606b6e282f34d5502b5fc6205c301c..4e749b1cf12616a731a0a0455fb8720762b48b17 100644 (file)
@@ -22,7 +22,7 @@
     <orderEntry type="library" name="commons-imaging" level="project" />
     <orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
     <orderEntry type="module" module-name="intellij.platform.builtInServer" exported="" />
-    <orderEntry type="module" module-name="intellij.platform.vcs" />
+    <orderEntry type="module" module-name="intellij.platform.diff" />
     <orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
     <orderEntry type="library" name="netty-codec-http" level="project" />
     <orderEntry type="library" name="fastutil-min" level="project" />
index ac0248283e5077ee939e133b5d0863685161c332..c5e843a1af9105679b2069ecc6e36e5a1be808ee 100644 (file)
@@ -12,7 +12,6 @@ import com.intellij.openapi.project.guessProjectForContentFile
 import com.intellij.openapi.util.io.FileUtil
 import com.intellij.openapi.util.text.StringUtil
 import com.intellij.openapi.util.text.StringUtilRt
-import com.intellij.openapi.vcs.ProjectLevelVcsManager
 import com.intellij.openapi.vfs.LocalFileSystem
 import com.intellij.openapi.vfs.VirtualFile
 import com.intellij.openapi.vfs.newvfs.ManagingFS
@@ -219,18 +218,6 @@ private fun openRelativePath(path: String, request: OpenFileRequest): Boolean {
     }
   }
 
-  if (virtualFile == null) {
-    for (openedProject in projects) {
-      for (vcsRoot in ProjectLevelVcsManager.getInstance(openedProject).allVcsRoots) {
-        virtualFile = vcsRoot.path.findFileByRelativePath(path)
-        if (virtualFile != null) {
-          project = openedProject
-          break
-        }
-      }
-    }
-  }
-
   return virtualFile?.let {
     AppUIUtil.invokeLaterIfProjectAlive(project!!, Runnable { navigate(project, it, request) })
     true
index 79b14acfec64458858bee568d4403800537ae763..f6c0c5675eda6e2dd6cbe5fc95735e6c0e00d688 100644 (file)
@@ -31,5 +31,6 @@
     <orderEntry type="library" name="fastutil-min" level="project" />
     <orderEntry type="library" name="Trove4j" level="project" />
     <orderEntry type="module" module-name="intellij.platform.core.ui" />
+    <orderEntry type="module" module-name="intellij.platform.builtInServer.impl" />
   </component>
 </module>
\ No newline at end of file
index 4cbd409785addbc0ec9ff83edbabb392f87a918d..b5540784d184da549ac40a7f433cb8fefa2e9aeb 100644 (file)
     <statistics.projectUsagesCollector implementation="com.intellij.openapi.vcs.statistics.VcsUsagesCollector"/>
   </extensions>
 
+  <extensions defaultExtensionNs="org.jetbrains">
+    <webServerRootsProvider implementation="com.intellij.openapi.vcs.impl.VcsRootWebServerRootsProvider" order="last"/>
+  </extensions>
+
   <applicationListeners>
     <listener class="com.intellij.openapi.vcs.changes.patch.PatchClipboardListener"
               topic="com.intellij.openapi.application.ApplicationActivationListener"/>
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsRootWebServerRootsProvider.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsRootWebServerRootsProvider.kt
new file mode 100644 (file)
index 0000000..c02b130
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2000-2017 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.impl
+
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.vcs.ProjectLevelVcsManager
+import com.intellij.openapi.vfs.VfsUtilCore
+import com.intellij.openapi.vfs.VirtualFile
+import org.jetbrains.builtInWebServer.FileResolver
+import org.jetbrains.builtInWebServer.PathInfo
+import org.jetbrains.builtInWebServer.PathQuery
+import org.jetbrains.builtInWebServer.PrefixlessWebServerRootsProvider
+
+internal class VcsRootWebServerRootsProvider : PrefixlessWebServerRootsProvider() {
+  override fun resolve(path: String, project: Project, resolver: FileResolver, pathQuery: PathQuery): PathInfo? {
+    for (vcsRoot in ProjectLevelVcsManager.getInstance(project).allVcsRoots) {
+      val root = if (vcsRoot.vcs != null) vcsRoot.path else continue
+      val virtualFile = resolver.resolve(path, root, pathQuery = pathQuery)
+      if (virtualFile != null) return virtualFile
+    }
+    return null
+  }
+
+  override fun getPathInfo(file: VirtualFile, project: Project): PathInfo? {
+    for (vcsRoot in ProjectLevelVcsManager.getInstance(project).allVcsRoots) {
+      val root = if (vcsRoot.vcs != null) vcsRoot.path else continue
+      if (VfsUtilCore.isAncestor(root, file, true)) {
+        return PathInfo(null, file, root)
+      }
+    }
+    return null
+  }
+}
\ No newline at end of file