diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt index 5c43675221fe..951f0138f9ed 100644 --- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt @@ -33,6 +33,7 @@ import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.project.Project import com.intellij.openapi.project.ProjectCoreUtil +import com.intellij.openapi.project.ex.ProjectEx.NAME_PROVIDER_EP import com.intellij.openapi.project.impl.ProjectImpl import com.intellij.openapi.project.impl.ProjectManagerImpl.UnableToSaveProjectNotification import com.intellij.openapi.project.impl.ProjectStoreClassProvider @@ -48,6 +49,7 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.PathUtilRt import com.intellij.util.SmartList import com.intellij.util.attribute +import com.intellij.util.containers.computeOrNull import com.intellij.util.containers.forEachGuaranteed import com.intellij.util.containers.isNullOrEmpty import com.intellij.util.io.* @@ -303,25 +305,24 @@ private open class ProjectStoreImpl(project: ProjectImpl, private val pathMacroM } override fun getProjectName(): String { - if (isDirectoryBased) { - val baseDir = projectBasePath - val nameFile = nameFile - if (nameFile.exists()) { - try { - nameFile.inputStream().reader().useLines { it.firstOrNull { !it.isEmpty() }?.trim() }?.let { - lastSavedProjectName = it - return it - } - } - catch (ignored: IOException) { - } - } - - return PathUtilRt.getFileName(baseDir).replace(":", "") - } - else { + if (!isDirectoryBased) { return PathUtilRt.getFileName(projectFilePath).removeSuffix(ProjectFileType.DOT_DEFAULT_EXTENSION) } + + val baseDir = projectBasePath + val nameFile = nameFile + if (nameFile.exists()) { + LOG.catchAndLog { + nameFile.inputStream().reader().useLines { it.firstOrNull { !it.isEmpty() }?.trim() }?.let { + lastSavedProjectName = it + return it + } + } + } + + return NAME_PROVIDER_EP.extensions.computeOrNull { + LOG.catchAndLog { it.getName(project) } + } ?: PathUtilRt.getFileName(baseDir).replace(":", "") } private fun saveProjectName() { diff --git a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java index da3255d0f931..d6b1e7fa3550 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.project.ex; +import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.project.Project; import com.intellij.util.messages.Topic; import org.jetbrains.annotations.NotNull; @@ -26,6 +27,8 @@ public interface ProjectEx extends Project { void saved(@NotNull final Project project); } + ExtensionPointName NAME_PROVIDER_EP = ExtensionPointName.create("com.intellij.projectNameProvider"); + void init(); void setProjectName(@NotNull String name); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectNameProvider.java b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectNameProvider.java new file mode 100644 index 000000000000..580e48e137c0 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectNameProvider.java @@ -0,0 +1,25 @@ +/* + * 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.project.ex; + +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface ProjectNameProvider { + @Nullable + String getName(@NotNull Project project); +} diff --git a/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml b/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml index b2d740f89352..1b1bb8942cef 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml @@ -282,5 +282,6 @@ +