diff --git a/platform/core-api/src/com/intellij/openapi/project/Project.java b/platform/core-api/src/com/intellij/openapi/project/Project.java
index 1c0146e48b57..bfb181e7bfdb 100644
--- a/platform/core-api/src/com/intellij/openapi/project/Project.java
+++ b/platform/core-api/src/com/intellij/openapi/project/Project.java
@@ -35,6 +35,7 @@ public interface Project extends ComponentManager, AreaInstance {
* Returns a project base directory - a parent directory of a {@code .ipr} file or {@code .idea} directory.
* Returns {@code null} for default project.
*
+ * @see com.intellij.openapi.project.ProjectUtil#guessProjectDir
* @deprecated Use {@link #getBasePath()}
*/
@Deprecated
diff --git a/platform/platform-api/src/com/intellij/openapi/project/ProjectUtil.kt b/platform/platform-api/src/com/intellij/openapi/project/ProjectUtil.kt
index 9a5e54a36d1e..10ac0a43ed0b 100644
--- a/platform/platform-api/src/com/intellij/openapi/project/ProjectUtil.kt
+++ b/platform/platform-api/src/com/intellij/openapi/project/ProjectUtil.kt
@@ -1,18 +1,4 @@
-/*
- * 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
@file:JvmName("ProjectUtil")
package com.intellij.openapi.project
@@ -31,6 +17,7 @@ import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.io.FileUtil
+import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFilePathWrapper
import com.intellij.openapi.wm.WindowManager
@@ -129,7 +116,7 @@ fun isProjectDirectoryExistsUsingIo(parent: VirtualFile): Boolean {
*
* @throws IllegalStateException if called on the default project, since there is no sense in "project dir" in that case.
*/
-fun Project.guessProjectDir() : VirtualFile {
+fun Project.guessProjectDir() : VirtualFile? {
if (isDefault) {
throw IllegalStateException("Not applicable for default project")
}
@@ -139,7 +126,7 @@ fun Project.guessProjectDir() : VirtualFile {
module?.rootManager?.contentRoots?.firstOrNull()?.let {
return it
}
- return this.baseDir!!
+ return LocalFileSystem.getInstance().findFileByPath(basePath!!)
}
fun Project.getProjectCacheFileName(forceNameUse: Boolean, hashSeparator: String): String {
diff --git a/platform/usageView/src/com/intellij/usages/impl/rules/DirectoryGroupingRule.java b/platform/usageView/src/com/intellij/usages/impl/rules/DirectoryGroupingRule.java
index 36e7ef540123..be1d9d046274 100644
--- a/platform/usageView/src/com/intellij/usages/impl/rules/DirectoryGroupingRule.java
+++ b/platform/usageView/src/com/intellij/usages/impl/rules/DirectoryGroupingRule.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2013 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.usages.impl.rules;
import com.intellij.injected.editor.VirtualFileWindow;
@@ -23,6 +9,7 @@ import com.intellij.openapi.actionSystem.TypeSafeDataProvider;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.openapi.vcs.FileStatusManager;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -87,7 +74,7 @@ public class DirectoryGroupingRule extends SingleParentUsageGroupingRule impleme
private Icon myIcon;
private DirectoryGroup(@NotNull VirtualFile dir) {
- myDir = dir;
+ myDir = dir;
update();
}
@@ -106,7 +93,7 @@ public class DirectoryGroupingRule extends SingleParentUsageGroupingRule impleme
@Override
@NotNull
public String getText(UsageView view) {
- VirtualFile baseDir = myProject.getBaseDir();
+ VirtualFile baseDir = ProjectUtil.guessProjectDir(myProject);
String relativePath = baseDir == null ? null : VfsUtilCore.getRelativePath(myDir, baseDir, File.separatorChar);
return relativePath == null ? myDir.getPresentableUrl() : relativePath;
}
diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalProjectOptionsProvider.kt b/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalProjectOptionsProvider.kt
index 6428b4437f71..f49b02aa7fc2 100644
--- a/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalProjectOptionsProvider.kt
+++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalProjectOptionsProvider.kt
@@ -7,7 +7,7 @@ import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
-import com.intellij.openapi.roots.ProjectRootManager
+import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.util.SystemInfo
import java.io.File
import kotlin.reflect.KMutableProperty1
@@ -54,16 +54,7 @@ class TerminalProjectOptionsProvider(val project: Project) : PersistentStateComp
}
- private fun currentProjectFolder(): String? {
- val projectRootManager = ProjectRootManager.getInstance(project)
-
- val roots = projectRootManager.contentRoots
- if (roots.size == 1) {
- roots[0].canonicalPath
- }
- val baseDir = project.baseDir
- return baseDir?.canonicalPath
- }
+ private fun currentProjectFolder() = project.guessProjectDir()?.canonicalPath
val defaultShellPath: String
get() {
@@ -97,7 +88,7 @@ class TerminalProjectOptionsProvider(val project: Project) : PersistentStateComp
}
-// TODO: In Kotlin 1.1 it will be possible to pass references to instance properties. Until then we need 'state' argument as a reciever for
+// TODO: In Kotlin 1.1 it will be possible to pass references to instance properties. Until then we need 'state' argument as a receiver for
// to property to apply
class ValueWithDefault(val prop: KMutableProperty1, val state: S, val default: () -> String?) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String? {
diff --git a/xml/impl/src/com/intellij/xml/actions/xmlbeans/UIUtils.java b/xml/impl/src/com/intellij/xml/actions/xmlbeans/UIUtils.java
index 8372111de8ac..1ed0e11570d2 100644
--- a/xml/impl/src/com/intellij/xml/actions/xmlbeans/UIUtils.java
+++ b/xml/impl/src/com/intellij/xml/actions/xmlbeans/UIUtils.java
@@ -1,24 +1,11 @@
-/*
- * Copyright 2000-2014 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xml.actions.xmlbeans;
import com.intellij.javaee.ExternalResourceManager;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -62,7 +49,7 @@ public class UIUtils {
fileChooserDescriptor.setTitle(selectFileDialogTitle);
- VirtualFile initialFile = myProject.getBaseDir();
+ VirtualFile initialFile = ProjectUtil.guessProjectDir(myProject);
String selectedItem = wsdlUrl.getTextField().getText();
if (selectedItem != null && selectedItem.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) {
VirtualFile fileByPath = VfsUtilCore