diff --git a/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java b/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java index 70457eb6bdf3..dc178a2b75e2 100644 --- a/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java +++ b/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -21,6 +21,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderEntry; @@ -100,7 +101,7 @@ public class ProjectStructureSelectInTarget extends SelectInTargetBase implement @Nullable private static Module findModuleByModuleFile(@NotNull Project project, @NotNull VirtualFile file) { for (Module module : ModuleManager.getInstance(project).getModules()) { - if (file.equals(module.getModuleFile())) { + if (ModuleUtilCore.isModuleFile(module, file)) { return module; } } diff --git a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java index ab85a3fabbee..c6cdc0fe3c49 100644 --- a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java +++ b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java @@ -38,6 +38,7 @@ import com.intellij.testFramework.fixtures.TempDirTestFixture; import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl; import com.intellij.util.Consumer; import com.intellij.util.ObjectUtils; +import com.intellij.util.ThrowableRunnable; import com.intellij.util.concurrency.Semaphore; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -203,26 +204,19 @@ public class CompilerTester { semaphore.down(); final ErrorReportingCallback callback = new ErrorReportingCallback(semaphore); - UIUtil.invokeAndWaitIfNeeded(new Runnable() { + EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { @Override - public void run() { - try { - getProject().save(); - CompilerTestUtil.saveApplicationSettings(); - for (Module module : myModules) { - VirtualFile moduleFile = module.getModuleFile(); - assert moduleFile != null; - File ioFile = VfsUtilCore.virtualToIoFile(moduleFile); - if (!ioFile.exists()) { - getProject().save(); - assert ioFile.exists() : "File does not exist: " + ioFile.getPath(); - } + public void run() throws Throwable { + getProject().save(); + CompilerTestUtil.saveApplicationSettings(); + for (Module module : myModules) { + File ioFile = new File(module.getModuleFilePath()); + if (!ioFile.exists()) { + getProject().save(); + assert ioFile.exists() : "File does not exist: " + ioFile.getPath(); } - runnable.consume(callback); - } - catch (Exception e) { - throw new RuntimeException(e); } + runnable.consume(callback); } }); diff --git a/java/testFramework/src/com/intellij/testFramework/TestSourceBasedTestCase.java b/java/testFramework/src/com/intellij/testFramework/TestSourceBasedTestCase.java index 0f4c5a1f53ef..774b9df5b96a 100644 --- a/java/testFramework/src/com/intellij/testFramework/TestSourceBasedTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/TestSourceBasedTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -22,6 +22,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; +import com.intellij.util.PathUtil; import org.jetbrains.annotations.NonNls; import java.io.File; @@ -100,6 +101,6 @@ import java.io.File; } protected String getRootFiles() { - return " " + myModule.getModuleFile().getName() + "\n"; + return " " + PathUtil.getFileName(myModule.getModuleFilePath()) + "\n"; } } diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt index 5ca7c61f9f6c..0ec530a25f79 100644 --- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt @@ -102,12 +102,9 @@ open class ProjectStoreImpl(override val project: ProjectImpl, private val pathM storageManager.clearStorages() } - override fun getProjectBaseDir(): VirtualFile? { - val path = getProjectBasePath() ?: return null - return LocalFileSystem.getInstance().findFileByPath(path) - } + override fun getProjectBaseDir() = LocalFileSystem.getInstance().findFileByPath(getProjectBasePath()) - override fun getProjectBasePath(): String? { + override fun getProjectBasePath(): String { val path = PathUtilRt.getParentPath(getProjectFilePath()) return if (scheme == StorageScheme.DEFAULT) path else PathUtilRt.getParentPath(path) } @@ -159,10 +156,7 @@ open class ProjectStoreImpl(override val project: ProjectImpl, private val pathM override fun getPresentableUrl(): String? { if (presentableUrl == null) { - val url = if (scheme == StorageScheme.DIRECTORY_BASED) getProjectBasePath() else getProjectFilePath() - if (url != null) { - presentableUrl = FileUtil.toSystemDependentName(url) - } + presentableUrl = FileUtil.toSystemDependentName(if (scheme == StorageScheme.DIRECTORY_BASED) getProjectBasePath() else getProjectFilePath()) } return presentableUrl } diff --git a/platform/core-api/src/com/intellij/openapi/module/Module.java b/platform/core-api/src/com/intellij/openapi/module/Module.java index 9900d384e367..36c9bef94dc9 100644 --- a/platform/core-api/src/com/intellij/openapi/module/Module.java +++ b/platform/core-api/src/com/intellij/openapi/module/Module.java @@ -48,11 +48,10 @@ public interface Module extends ComponentManager, AreaInstance, Disposable { VirtualFile getModuleFile(); /** - * Returns the path to the module .iml file. - * - * @return the path to the .iml file. + * System-independent path to the .iml file. */ - @NotNull String getModuleFilePath(); + @NotNull + String getModuleFilePath(); /** * Returns the project to which this module belongs. 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 1e0b2894412d..83fa78028fc7 100644 --- a/platform/core-api/src/com/intellij/openapi/project/Project.java +++ b/platform/core-api/src/com/intellij/openapi/project/Project.java @@ -54,7 +54,7 @@ public interface Project extends ComponentManager, AreaInstance { VirtualFile getBaseDir(); /** - * Returns a system-dependent path to a project base directory (see {@linkplain #getBaseDir()}).
+ * Returns a system-independent path to a project base directory (see {@linkplain #getBaseDir()}).
* Returns null for default project. * * @return a path to a project base directory, or null for default project diff --git a/platform/editor-ui-ex/src/com/intellij/codeStyle/AbstractConvertLineSeparatorsAction.java b/platform/editor-ui-ex/src/com/intellij/codeStyle/AbstractConvertLineSeparatorsAction.java index 1f96eb1aa9a8..d9872d2e56b4 100644 --- a/platform/editor-ui-ex/src/com/intellij/codeStyle/AbstractConvertLineSeparatorsAction.java +++ b/platform/editor-ui-ex/src/com/intellij/codeStyle/AbstractConvertLineSeparatorsAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -24,6 +24,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.impl.LoadTextUtil; import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.FileIndexFacade; import com.intellij.openapi.util.text.StringUtil; @@ -133,7 +134,7 @@ public abstract class AbstractConvertLineSeparatorsAction extends AnAction { return false; } Module module = FileIndexFacade.getInstance(project).getModuleForFile(file); - return module == null || !file.equals(module.getModuleFile()); + return module == null || !ModuleUtilCore.isModuleFile(module, file); } public static void changeLineSeparators(@NotNull final Project project, diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/IProjectStore.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/IProjectStore.java index 05e10b5cbacc..66c346e7d103 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/IProjectStore.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/IProjectStore.java @@ -29,6 +29,9 @@ public interface IProjectStore extends IComponentStore { VirtualFile getProjectBaseDir(); @Nullable + /** + * System-independent path. + */ String getProjectBasePath(); @NotNull @@ -47,12 +50,18 @@ public interface IProjectStore extends IComponentStore { VirtualFile getProjectFile(); @NotNull + /** + * System-independent path. + */ String getProjectFilePath(); @Nullable VirtualFile getWorkspaceFile(); @Nullable + /** + * System-independent path. + */ String getWorkspaceFilePath(); void loadProjectFromTemplate(@NotNull Project project); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/NonProjectFileWritingAccessProvider.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/NonProjectFileWritingAccessProvider.java index dfa210fab040..fce25b569185 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/NonProjectFileWritingAccessProvider.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/NonProjectFileWritingAccessProvider.java @@ -30,6 +30,7 @@ import com.intellij.openapi.roots.ModuleRootEvent; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.NotNullLazyKey; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.*; import com.intellij.util.NotNullFunction; @@ -162,9 +163,14 @@ public class NonProjectFileWritingAccessProvider extends WritingAccessProvider { } IProjectStore store = (IProjectStore)ComponentsPackage.getStateStore(project); - if (file.equals(store.getWorkspaceFile()) || file.equals(store.getProjectFile())) return true; - for (Module each : ModuleManager.getInstance(project).getModules()) { - if (file.equals(each.getModuleFile())) return true; + String filePath = file.getPath(); + if (FileUtil.namesEqual(filePath, store.getWorkspaceFilePath()) || FileUtil.namesEqual(filePath, store.getProjectFilePath())) { + return true; + } + for (Module module : ModuleManager.getInstance(project).getModules()) { + if (FileUtil.namesEqual(filePath, module.getModuleFilePath())) { + return true; + } } } diff --git a/platform/projectModel-api/src/com/intellij/openapi/module/ModuleUtilCore.java b/platform/projectModel-api/src/com/intellij/openapi/module/ModuleUtilCore.java index db65e295ba03..6e9b4fda363c 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/module/ModuleUtilCore.java +++ b/platform/projectModel-api/src/com/intellij/openapi/module/ModuleUtilCore.java @@ -20,10 +20,12 @@ import com.intellij.openapi.application.Result; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.*; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileSystemItem; +import com.intellij.util.PathUtilRt; import com.intellij.util.containers.HashSet; import com.intellij.util.graph.Graph; import org.jetbrains.annotations.NotNull; @@ -214,6 +216,19 @@ public class ModuleUtilCore { } } + public static boolean isModuleFile(@NotNull Module module, @NotNull VirtualFile file) { + return FileUtil.namesEqual(file.getPath(), module.getModuleFilePath()); + } + + public static boolean isModuleDir(@NotNull Module module, @NotNull VirtualFile dir) { + return FileUtil.namesEqual(dir.getPath(), getModuleDirPath(module)); + } + + @NotNull + public static String getModuleDirPath(@NotNull Module module) { + return PathUtilRt.getParentPath(module.getModuleFilePath()); + } + public interface ModuleVisitor { /** *