From 7f112483691fa27f51f79e2ac850b489fdfd5e8c Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Tue, 7 Mar 2017 14:22:16 +0100 Subject: [PATCH] ability to introduce custom roots --- .../vfs/impl/local/LocalFileSystemBase.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java index 82c8337c59be..0387ca2b2d58 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.vfs.impl.local; +import com.google.common.annotations.VisibleForTesting; import com.intellij.ide.GeneralSettings; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; @@ -39,10 +40,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; +import java.util.*; /** * @author Dmitry Avdeev @@ -643,6 +641,24 @@ public abstract class LocalFileSystemBase extends LocalFileSystem { } } + private static final List ourRootPaths = new ArrayList<>(); + + { + List persistentFsRoots = StringUtil.split(System.getProperty("idea.persistentfs.roots", ""), File.pathSeparator); + sortRootsLongestFirst(persistentFsRoots); + for(String persistentFsRoot:persistentFsRoots) ourRootPaths.add(persistentFsRoot); + } + + private static void sortRootsLongestFirst(List persistentFsRoots) { + Collections.sort(persistentFsRoots, (o1, o2) -> o2.length() - o1.length()); + } + + @VisibleForTesting + public void registerCustomRootPath(@NotNull String path) { + ourRootPaths.add(path); + sortRootsLongestFirst(ourRootPaths); + } + @NotNull @Override protected String extractRootPath(@NotNull final String path) { @@ -655,6 +671,10 @@ public abstract class LocalFileSystemBase extends LocalFileSystem { } } + for(String customRootPath:ourRootPaths) { + if (path.startsWith(customRootPath)) return customRootPath; + } + if (SystemInfo.isWindows) { if (path.length() >= 2 && path.charAt(1) == ':') { // Drive letter