diff --git a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java index 1691cd71f7ef..77d1ded95d82 100644 --- a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java +++ b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java @@ -16,9 +16,11 @@ package com.intellij.ide; import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.ex.ApplicationInfoEx; +import com.intellij.openapi.components.PathMacroManager; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; @@ -99,35 +101,54 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im // TODO Should be removed later (required to convert the already saved system-dependent paths). private void makePathsSystemIndependent() { - makeSystemIndependent(recentPaths); + ApplicationInfo appInfo = ApplicationInfo.getInstance(); + String version = appInfo.getMajorVersion() + "." + appInfo.getMinorVersion(); + PathMacroManager pathMacroManager = PathMacroManager.getInstance(ApplicationManager.getApplication()); + Function convert = depPath -> { + String result = PathUtil.toSystemIndependentName(depPath); + if (!result.startsWith("$APP") && result.contains("2017.1")) { + String migrated = result.replace("2017.1", version); + // check for possible PathMacroUtil.APPLICATION_* + if (pathMacroManager.collapsePath(migrated).startsWith("$APP")) { + return migrated; + } + } + return result; + }; + Consumer> convertList = o -> { + for (ListIterator it = o.listIterator(); it.hasNext(); ) { + it.set(convert.fun(it.next())); + } + }; - makeSystemIndependent(openPaths); + convertList.consume(recentPaths); + convertList.consume(openPaths); Map namesCopy = new HashMap<>(names); names.clear(); for (Map.Entry entry : namesCopy.entrySet()) { - names.put(PathUtil.toSystemIndependentName(entry.getKey()), entry.getValue()); + names.put(convert.fun(entry.getKey()), entry.getValue()); } for (ProjectGroup group : groups) { List paths = new ArrayList<>(group.getProjects()); - makeSystemIndependent(paths); + convertList.consume(paths); group.save(paths); } if (lastPath != null) { - lastPath = PathUtil.toSystemIndependentName(lastPath); + lastPath = convert.fun(lastPath); } Map additionalInfoCopy = new HashMap<>(additionalInfo); additionalInfo.clear(); for (Map.Entry entry : additionalInfoCopy.entrySet()) { - entry.getValue().binFolder = PathUtil.toSystemIndependentName(entry.getValue().binFolder); - additionalInfo.put(PathUtil.toSystemIndependentName(entry.getKey()), entry.getValue()); + entry.getValue().binFolder = convert.fun(entry.getValue().binFolder); + additionalInfo.put(convert.fun(entry.getKey()), entry.getValue()); } if (lastProjectLocation != null) { - lastProjectLocation = PathUtil.toSystemIndependentName(lastProjectLocation); + lastProjectLocation = convert.fun(lastProjectLocation); } } @@ -140,14 +161,6 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im } } } - - private static void makeSystemIndependent(List paths) { - List copy = new ArrayList<>(paths); - paths.clear(); - for (String path : copy) { - paths.add(PathUtil.toSystemIndependentName(path)); - } - } } private final Object myStateLock = new Object();