mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ProjectUtil.isSameProject check simplified and fixed to properly support directory-based projects, test added (IDEA-CR-15060)
This commit is contained in:
@@ -283,26 +283,26 @@ public class ProjectUtil {
|
||||
|
||||
public static boolean isSameProject(String projectFilePath, @NotNull Project project) {
|
||||
IProjectStore projectStore = ProjectKt.getStateStore(project);
|
||||
|
||||
String toOpen = FileUtil.toSystemIndependentName(projectFilePath);
|
||||
String existing = projectStore.getProjectFilePath();
|
||||
|
||||
String existingBaseDir = projectStore.getProjectBasePath();
|
||||
if (existingBaseDir == null) {
|
||||
String existingBaseDirPath = projectStore.getProjectBasePath();
|
||||
if (existingBaseDirPath == null) {
|
||||
// could be null if not yet initialized
|
||||
return false;
|
||||
}
|
||||
|
||||
final File openFile = new File(toOpen);
|
||||
if (openFile.isDirectory()) {
|
||||
return FileUtil.pathsEqual(toOpen, existingBaseDir);
|
||||
}
|
||||
if (StorageScheme.DIRECTORY_BASED == projectStore.getStorageScheme()) {
|
||||
// todo: check if IPR is located not under the project base dir
|
||||
return FileUtil.pathsEqual(FileUtil.toSystemIndependentName(openFile.getParentFile().getPath()), existingBaseDir);
|
||||
final File projectFile = new File(projectFilePath);
|
||||
if (projectFile.isDirectory()) {
|
||||
return FileUtil.pathsEqual(projectFilePath, existingBaseDirPath);
|
||||
}
|
||||
|
||||
return FileUtil.pathsEqual(toOpen, existing);
|
||||
if (projectStore.getStorageScheme() == StorageScheme.DEFAULT) {
|
||||
return FileUtil.pathsEqual(projectFilePath, projectStore.getProjectFilePath());
|
||||
}
|
||||
|
||||
File parent = projectFile.getParentFile();
|
||||
if (parent.getName().equals(Project.DIRECTORY_STORE_FOLDER)) {
|
||||
parent = parent.getParentFile();
|
||||
}
|
||||
return parent != null && FileUtil.pathsEqual(parent.getPath(), existingBaseDirPath);
|
||||
}
|
||||
|
||||
public static void focusProjectWindow(final Project p, boolean executeIfAppInactive) {
|
||||
|
||||
+27
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.project.impl;
|
||||
|
||||
import com.intellij.ide.impl.ProjectUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
@@ -29,6 +30,7 @@ import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.intellij.openapi.startup.StartupActivity.POST_STARTUP_ACTIVITY;
|
||||
|
||||
@@ -85,6 +87,31 @@ public class ProjectOpeningTest extends PlatformTestCase {
|
||||
|
||||
*/
|
||||
|
||||
public void testIsSameProjectForDirectoryBasedProject() throws IOException {
|
||||
File projectDir = createTempDir("project");
|
||||
Project dirBasedProject = ProjectManager.getInstance().createProject("project", projectDir.getAbsolutePath());
|
||||
disposeOnTearDown(dirBasedProject);
|
||||
|
||||
assertTrue(ProjectUtil.isSameProject(projectDir.getAbsolutePath(), dirBasedProject));
|
||||
assertFalse(ProjectUtil.isSameProject(createTempDir("project2").getAbsolutePath(), dirBasedProject));
|
||||
File iprFilePath = new File(projectDir, "project.ipr");
|
||||
assertTrue(ProjectUtil.isSameProject(iprFilePath.getAbsolutePath(), dirBasedProject));
|
||||
File miscXmlFilePath = new File(projectDir, ".idea/misc.xml");
|
||||
assertTrue(ProjectUtil.isSameProject(miscXmlFilePath.getAbsolutePath(), dirBasedProject));
|
||||
}
|
||||
|
||||
public void testIsSameProjectForFileBasedProject() throws IOException {
|
||||
File projectDir = createTempDir("project");
|
||||
File iprFilePath = new File(projectDir, "project.ipr");
|
||||
Project fileBasedProject = ProjectManager.getInstance().createProject(iprFilePath.getName(), iprFilePath.getAbsolutePath());
|
||||
disposeOnTearDown(fileBasedProject);
|
||||
|
||||
assertTrue(ProjectUtil.isSameProject(projectDir.getAbsolutePath(), fileBasedProject));
|
||||
assertFalse(ProjectUtil.isSameProject(createTempDir("project2").getAbsolutePath(), fileBasedProject));
|
||||
File iprFilePath2 = new File(projectDir, "project2.ipr");
|
||||
assertFalse(ProjectUtil.isSameProject(iprFilePath2.getAbsolutePath(), fileBasedProject));
|
||||
}
|
||||
|
||||
private static void closeProject(final Project project) {
|
||||
if (project != null && !project.isDisposed()) {
|
||||
ProjectManager.getInstance().closeProject(project);
|
||||
|
||||
Reference in New Issue
Block a user