Search in sources :

Example 11 with ProjectManagerEx

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);
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(com.intellij.openapi.project.Project) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull) Test(org.junit.Test)

Example 12 with ProjectManagerEx

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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) ProjectManagerImpl(com.intellij.openapi.project.impl.ProjectManagerImpl)

Example 13 with ProjectManagerEx

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();
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProjectBuilder(com.intellij.ide.util.projectWizard.ProjectBuilder) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) IOException(java.io.IOException) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) File(java.io.File) IdeFrameEx(com.intellij.openapi.wm.ex.IdeFrameEx)

Example 14 with ProjectManagerEx

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;
}
Also used : Project(com.intellij.openapi.project.Project) InvalidDataException(com.intellij.openapi.util.InvalidDataException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with ProjectManagerEx

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();
}
Also used : Project(com.intellij.openapi.project.Project) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) ProjectManagerImpl(com.intellij.openapi.project.impl.ProjectManagerImpl)

Aggregations

ProjectManagerEx (com.intellij.openapi.project.ex.ProjectManagerEx)18 Project (com.intellij.openapi.project.Project)17 File (java.io.File)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 IOException (java.io.IOException)6 ProjectManagerImpl (com.intellij.openapi.project.impl.ProjectManagerImpl)3 ProjectBuilder (com.intellij.ide.util.projectWizard.ProjectBuilder)2 Module (com.intellij.openapi.module.Module)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1 AndroidGradleProjectComponent (com.android.tools.idea.gradle.project.AndroidGradleProjectComponent)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 Projects.canImportAsGradleProject (com.android.tools.idea.gradle.util.Projects.canImportAsGradleProject)1 Projects.isLegacyIdeaAndroidProject (com.android.tools.idea.gradle.util.Projects.isLegacyIdeaAndroidProject)1 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 FileDocumentManagerImpl (com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl)1 FileTypeManagerImpl (com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1