/*
- * 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.
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;
@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;
}
}
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;
semaphore.down();
final ErrorReportingCallback callback = new ErrorReportingCallback(semaphore);
- UIUtil.invokeAndWaitIfNeeded(new Runnable() {
+ EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() {
@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);
}
});
/*
- * 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.
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;
}
protected String getRootFiles() {
- return " " + myModule.getModuleFile().getName() + "\n";
+ return " " + PathUtil.getFileName(myModule.getModuleFilePath()) + "\n";
}
}
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)
}
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
}
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.
VirtualFile getBaseDir();
/**
- * Returns a system-dependent path to a project base directory (see {@linkplain #getBaseDir()}).<br/>
+ * Returns a system-independent path to a project base directory (see {@linkplain #getBaseDir()}).<br/>
* Returns <code>null</code> for default project.
*
* @return a path to a project base directory, or <code>null</code> for default project
/*
- * 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.
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;
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,
VirtualFile getProjectBaseDir();
@Nullable
+ /**
+ * System-independent path.
+ */
String getProjectBasePath();
@NotNull
VirtualFile getProjectFile();
@NotNull
+ /**
+ * System-independent path.
+ */
String getProjectFilePath();
@Nullable
VirtualFile getWorkspaceFile();
@Nullable
+ /**
+ * System-independent path.
+ */
String getWorkspaceFilePath();
void loadProjectFromTemplate(@NotNull Project project);
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;
}
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;
+ }
}
}
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;
}
}
+ 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 {
/**
*