use of com.intellij.openapi.project.ex.ProjectManagerEx in project android by JetBrains.
the class GradleSyncTest method gradleModelCache.
@Test
public void gradleModelCache() throws IOException {
guiTest.importSimpleApplication();
IdeFrameFixture ideFrameFixture = guiTest.ideFrame();
File projectPath = ideFrameFixture.getProjectPath();
ideFrameFixture.closeProject();
AtomicBoolean syncSkipped = new AtomicBoolean(false);
// Reopen project and verify that sync was skipped (i.e. model loaded from cache)
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
Project project = projectManager.convertAndLoadProject(projectPath.getPath());
GradleSyncState.subscribe(project, new GradleSyncListener.Adapter() {
@Override
public void syncSkipped(@NotNull Project project) {
syncSkipped.set(true);
}
});
projectManager.openProject(project);
}
});
Wait.seconds(5).expecting("sync to be skipped").until(syncSkipped::get);
}
use of com.intellij.openapi.project.ex.ProjectManagerEx in project android by JetBrains.
the class ThemeEditorVirtualFileTest method testRightProject.
/**
* Tests that the theme editor works with the right virtual file
* when there are several projects with the same name open.
*/
public void testRightProject() throws IOException {
ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
Project otherProject = projectManager.newProject(getProject().getName(), FileUtilRt.generateRandomTemporaryPath().getPath(), true, true);
try {
assertNotNull(otherProject);
projectManager.openProject(otherProject);
ThemeEditorVirtualFile themeEditorVirtualFile = ThemeEditorVirtualFile.getThemeEditorFile(myModule.getProject());
VirtualFile virtualFile = themeEditorVirtualFile.getFileSystem().findFileByPath(themeEditorVirtualFile.getPath());
assertEquals(themeEditorVirtualFile, virtualFile);
} finally {
if (otherProject != null) {
((ProjectManagerImpl) projectManager).forceCloseProject(otherProject, true);
}
}
}
use of com.intellij.openapi.project.ex.ProjectManagerEx in project intellij-community by JetBrains.
the class NewProjectUtil method doCreate.
private static Project doCreate(final AbstractProjectWizard dialog, @Nullable Project projectToClose) throws IOException {
final ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
final String projectFilePath = dialog.getNewProjectFilePath();
for (Project p : ProjectManager.getInstance().getOpenProjects()) {
if (ProjectUtil.isSameProject(projectFilePath, p)) {
ProjectUtil.focusProjectWindow(p, false);
return null;
}
}
final ProjectBuilder projectBuilder = dialog.getProjectBuilder();
try {
File projectDir = new File(projectFilePath).getParentFile();
LOG.assertTrue(projectDir != null, "Cannot create project in '" + projectFilePath + "': no parent file exists");
FileUtil.ensureExists(projectDir);
if (StorageScheme.DIRECTORY_BASED == dialog.getStorageScheme()) {
FileUtil.ensureExists(new File(projectFilePath, Project.DIRECTORY_STORE_FOLDER));
}
final Project newProject;
if (projectBuilder == null || !projectBuilder.isUpdate()) {
String name = dialog.getProjectName();
newProject = projectBuilder == null ? projectManager.newProject(name, projectFilePath, true, false) : projectBuilder.createProject(name, projectFilePath);
} else {
newProject = projectToClose;
}
if (newProject == null)
return projectToClose;
final Sdk jdk = dialog.getNewProjectJdk();
if (jdk != null) {
CommandProcessor.getInstance().executeCommand(newProject, () -> ApplicationManager.getApplication().runWriteAction(() -> applyJdkToProject(newProject, jdk)), null, null);
}
final String compileOutput = dialog.getNewCompileOutput();
CommandProcessor.getInstance().executeCommand(newProject, () -> ApplicationManager.getApplication().runWriteAction(() -> {
String canonicalPath = compileOutput;
try {
canonicalPath = FileUtil.resolveShortWindowsName(compileOutput);
} catch (IOException e) {
//file doesn't exist
}
canonicalPath = FileUtil.toSystemIndependentName(canonicalPath);
CompilerProjectExtension.getInstance(newProject).setCompilerOutputUrl(VfsUtilCore.pathToUrl(canonicalPath));
}), null, null);
if (!ApplicationManager.getApplication().isUnitTestMode()) {
newProject.save();
}
if (projectBuilder != null && !projectBuilder.validate(projectToClose, newProject)) {
return projectToClose;
}
if (newProject != projectToClose && !ApplicationManager.getApplication().isUnitTestMode()) {
closePreviousProject(projectToClose);
}
if (projectBuilder != null) {
projectBuilder.commit(newProject, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
}
final boolean need2OpenProjectStructure = projectBuilder == null || projectBuilder.isOpenProjectSettingsAfter();
StartupManager.getInstance(newProject).registerPostStartupActivity(() -> {
// ensure the dialog is shown after all startup activities are done
ApplicationManager.getApplication().invokeLater(() -> {
if (newProject.isDisposed() || ApplicationManager.getApplication().isUnitTestMode())
return;
if (need2OpenProjectStructure) {
ModulesConfigurator.showDialog(newProject, null, null);
}
ApplicationManager.getApplication().invokeLater(() -> {
if (newProject.isDisposed())
return;
final ToolWindow toolWindow = ToolWindowManager.getInstance(newProject).getToolWindow(ToolWindowId.PROJECT_VIEW);
if (toolWindow != null) {
toolWindow.activate(null);
}
}, ModalityState.NON_MODAL);
}, ModalityState.NON_MODAL);
});
if (newProject != projectToClose) {
ProjectUtil.updateLastProjectLocation(projectFilePath);
if (WindowManager.getInstance().isFullScreenSupportedInCurrentOS()) {
IdeFocusManager instance = IdeFocusManager.findInstance();
IdeFrame lastFocusedFrame = instance.getLastFocusedFrame();
if (lastFocusedFrame instanceof IdeFrameEx) {
boolean fullScreen = ((IdeFrameEx) lastFocusedFrame).isInFullScreen();
if (fullScreen) {
newProject.putUserData(IdeFrameImpl.SHOULD_OPEN_IN_FULL_SCREEN, Boolean.TRUE);
}
}
}
projectManager.openProject(newProject);
}
if (!ApplicationManager.getApplication().isUnitTestMode()) {
newProject.save();
}
return newProject;
} finally {
if (projectBuilder != null) {
projectBuilder.cleanup();
}
}
}
use of com.intellij.openapi.project.ex.ProjectManagerEx in project intellij-community by JetBrains.
the class ProjectUtil method openProject.
@Nullable
public static Project openProject(final String path, @Nullable Project projectToClose, boolean forceOpenInNewFrame) {
File file = new File(path);
if (!file.exists()) {
Messages.showErrorDialog(IdeBundle.message("error.project.file.does.not.exist", path), CommonBundle.getErrorTitle());
return null;
}
if (file.isDirectory()) {
File dir = new File(file, Project.DIRECTORY_STORE_FOLDER);
if (!dir.exists()) {
String message = IdeBundle.message("error.project.file.does.not.exist", dir.getPath());
Messages.showErrorDialog(message, CommonBundle.getErrorTitle());
return null;
}
}
Project existing = findAndFocusExistingProjectForPath(path);
if (existing != null)
return existing;
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
if (!forceOpenInNewFrame && openProjects.length > 0) {
int exitCode = confirmOpenNewProject(false);
if (exitCode == GeneralSettings.OPEN_PROJECT_SAME_WINDOW) {
final Project toClose = projectToClose != null ? projectToClose : openProjects[openProjects.length - 1];
if (!closeAndDispose(toClose))
return null;
} else if (exitCode != GeneralSettings.OPEN_PROJECT_NEW_WINDOW) {
return null;
}
}
if (isRemotePath(path) && !RecentProjectsManager.getInstance().hasPath(path)) {
if (!confirmLoadingFromRemotePath(path, "warning.load.project.from.share", "title.load.project.from.share")) {
return null;
}
}
ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
Project project = null;
try {
project = projectManager.loadAndOpenProject(path);
} catch (IOException e) {
Messages.showMessageDialog(IdeBundle.message("error.cannot.load.project", e.getMessage()), IdeBundle.message("title.cannot.load.project"), Messages.getErrorIcon());
} catch (JDOMException | InvalidDataException e) {
LOG.info(e);
Messages.showMessageDialog(IdeBundle.message("error.project.file.is.corrupted"), IdeBundle.message("title.cannot.load.project"), Messages.getErrorIcon());
}
return project;
}
use of com.intellij.openapi.project.ex.ProjectManagerEx in project intellij-community by JetBrains.
the class PlatformTestCase method closeAndDisposeProjectAndCheckThatNoOpenProjects.
public static void closeAndDisposeProjectAndCheckThatNoOpenProjects(@NotNull final Project projectToClose) {
RunAll runAll = new RunAll();
ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
if (projectManager instanceof ProjectManagerImpl) {
for (Project project : projectManager.closeTestProject(projectToClose)) {
runAll = runAll.append(() -> {
throw new IllegalStateException("Test project is not disposed: " + project + ";\n created in: " + getCreationPlace(project));
}).append(() -> ((ProjectManagerImpl) projectManager).closeProject(project, false, true, false));
}
}
runAll.append(() -> WriteAction.run(() -> Disposer.dispose(projectToClose))).run();
}
Aggregations