Java 类com.intellij.openapi.project.ex.ProjectManagerEx 实例源码

项目:intellij-ce-playground    文件:OrderEntryTest.java   
@Override
protected void setUpProject() throws Exception {
  final String root = PathManagerEx.getTestDataPath() + BASE_PATH;

  VirtualFile tempProjectRootDir =
    PsiTestUtil.createTestProjectStructure(getTestName(true), null, FileUtil.toSystemIndependentName(root), myFilesToDelete, false);

  VirtualFile projectFile = tempProjectRootDir.findChild("orderEntry.ipr");

  myProject = ProjectManagerEx.getInstanceEx().loadProject(projectFile.getPath());
  ProjectManagerEx.getInstanceEx().openTestProject(myProject);
  UIUtil.dispatchAllInvocationEvents(); // startup activities

  setUpJdk();
  myModule = ModuleManager.getInstance(getProject()).getModules()[0];
}
项目:intellij-ce-playground    文件:TemplateModuleBuilder.java   
@Nullable
@Override
public Project createProject(String name, final String path) {
  myProjectMode = true;
  unzip(name, path, false);
  return ApplicationManager.getApplication().runWriteAction(new NullableComputable<Project>() {
    @Nullable
    @Override
    public Project compute() {
      try {
        return ProjectManagerEx.getInstanceEx().convertAndLoadProject(path);
      }
      catch (IOException e) {
        LOG.error(e);
        return null;
      }
    }
  });
}
项目:intellij-ce-playground    文件:HeavyIdeaTestFixtureImpl.java   
private void setUpProject() throws IOException {
  File tempDirectory = FileUtil.createTempDirectory(myName, "");
  PlatformTestCase.synchronizeTempDirVfs(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory));
  myFilesToDelete.add(tempDirectory);

  String projectPath = FileUtil.toSystemIndependentName(tempDirectory.getPath()) + "/" + myName + ProjectFileType.DOT_DEFAULT_EXTENSION;
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  new Throwable(projectPath).printStackTrace(new PrintStream(buffer));
  myProject = PlatformTestCase.createProject(projectPath, buffer.toString());

  EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() {
    @SuppressWarnings("TestOnlyProblems")
    @Override
    public void run() throws Throwable {
      ProjectManagerEx.getInstanceEx().openTestProject(myProject);

      for (ModuleFixtureBuilder moduleFixtureBuilder : myModuleFixtureBuilders) {
        moduleFixtureBuilder.getFixture().setUp();
      }

      LightPlatformTestCase.clearUncommittedDocuments(myProject);
      ((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue();
    }
  });
}
项目:intellij-ce-playground    文件:ApplicationImpl.java   
private boolean canExit() {
  for (ApplicationListener applicationListener : myDispatcher.getListeners()) {
    if (!applicationListener.canExitApplication()) {
      return false;
    }
  }

  ProjectManagerEx projectManager = (ProjectManagerEx)ProjectManager.getInstance();
  Project[] projects = projectManager.getOpenProjects();
  for (Project project : projects) {
    if (!projectManager.canClose(project)) {
      return false;
    }
  }

  return true;
}
项目:intellij-ce-playground    文件:MergeVersion.java   
@Nullable
public static Runnable prepareToReportChangedProjectFiles(@NotNull final Project project, @NotNull Collection<VirtualFile> files) {
  final Set<VirtualFile> vfs = new THashSet<VirtualFile>();
  for (VirtualFile file : files) {
    if (file != null && !file.isDirectory()) {
      if (ProjectCoreUtil.isProjectOrWorkspaceFile(file) || isProjectFile(file)) {
        vfs.add(file);
      }
    }
  }
  return vfs.isEmpty() ? null : new Runnable() {
    @Override
    public void run() {
      ProjectManagerEx ex = ProjectManagerEx.getInstanceEx();
      for (VirtualFile vf : vfs) {
        ex.saveChangedProjectFile(vf, project);
      }
    }
  };
}
项目:intellij-ce-playground    文件:Template.java   
private void doRender(@NotNull File outputRootPath,
                      @NotNull File moduleRootPath,
                      @NotNull Map<String, Object> args,
                      @Nullable Project project,
                      boolean gradleSyncIfNeeded) {
  myFilesToOpen.clear();
  if (project == null) {
    // Project creation: no current project to read code style settings from yet, so use defaults
    project = ProjectManagerEx.getInstanceEx().getDefaultProject();
  }
  myProject = project;

  Map<String, Object> paramMap = createParameterMap(args);
  enforceParameterTypes(getMetadata(), args);
  Configuration freemarker = new FreemarkerConfiguration();
  freemarker.setTemplateLoader(myLoader);

  processFile(freemarker, new File(TEMPLATE_XML_NAME), paramMap, outputRootPath, moduleRootPath, gradleSyncIfNeeded);
}
项目:intellij-ce-playground    文件:ThemeEditorVirtualFileTest.java   
/**
 * 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).closeProject(otherProject, false, true, false);
    }
  }
}
项目:intellij-ce-playground    文件:GradleSyncTest.java   
@Test @IdeGuiTest
public void testJavaModelSerialization() throws IOException {
  IdeFrameFixture projectFrame = importProjectAndWaitForProjectSyncToFinish("MultipleModuleTypes");
  final File projectPath = projectFrame.getProjectPath();

  projectFrame.requestProjectSync()
              .waitForGradleProjectSyncToFinish();
  projectFrame.closeProject();

  execute(new GuiTask() {
    @Override
    protected void executeInEDT() throws Throwable {
      ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
      projectManager.loadAndOpenProject(projectPath.getPath());
    }
  });

  projectFrame = findIdeFrame(projectPath);
  LibraryTable libraryTable = ProjectLibraryTable.getInstance(projectFrame.getProject());
  // When serialization of Java model fails, libraries are not set up.
  // Here we confirm that serialization works, because the Java module has the dependency declared in its build.gradle file.
  assertThat(libraryTable.getLibraries()).hasSize(1);
}
项目:r2m-plugin-android    文件:AsyncHelper.java   
private void performFileOperation() {
    project.save();
    FileDocumentManager.getInstance().saveAllDocuments();
    ProjectManagerEx.getInstanceEx().blockReloadingProjectOnExternalChanges();
    ProgressManager.getInstance().run(new Task.Backgroundable(project, MESSAGE_GENERATING_SERVICE, false) {
        public void run(@NotNull ProgressIndicator progressIndicator) {
            getGenerator().makeFilePerformance(progressIndicator);
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    onActionSuccess(GenerateActions.FILE_OPERATION_SUCCESS);
                }
            });
        }
    });
}
项目:r2m-plugin-android    文件:AddControllerForm.java   
@Override
public void onGenerateFinished(boolean result, File file) {
    SaveAndSyncHandlerImpl.refreshOpenFiles();
    VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
    ProjectManagerEx.getInstanceEx().unblockReloadingProjectOnExternalChanges();
    project.getBaseDir().refresh(false, true);

    if (null == JavaPsiFacade.getInstance(project).findPackage("com.magnet.android.mms.async")) {
        showMissingDependencies();
    }

    if (!result) {
        showCloseDialog(file);
    } else {
        getThis().setVisible(true);
    }
}
项目:tools-idea    文件:OrderEntryTest.java   
@Override
protected void setUpProject() throws Exception {
  final String root = PathManagerEx.getTestDataPath() + BASE_PATH;

  VirtualFile tempProjectRootDir =
    PsiTestUtil.createTestProjectStructure(getTestName(true), null, FileUtil.toSystemIndependentName(root), myFilesToDelete, false);

  VirtualFile projectFile = tempProjectRootDir.findChild("orderEntry.ipr");

  myProject = ProjectManagerEx.getInstanceEx().loadProject(projectFile.getPath());
  ProjectManagerEx.getInstanceEx().openTestProject(myProject);
  ModuleManagerImpl mm = (ModuleManagerImpl)ModuleManager.getInstance(myProject);
  mm.projectOpened();
  setUpJdk();
  myModule = ModuleManager.getInstance(getProject()).getModules()[0];
}
项目:tools-idea    文件:TemplateModuleBuilder.java   
@Nullable
@Override
public Project createProject(String name, final String path) {
  myProjectMode = true;
  unzip(name, path, false);
  return ApplicationManager.getApplication().runWriteAction(new NullableComputable<Project>() {
    @Nullable
    @Override
    public Project compute() {
      try {
        return ProjectManagerEx.getInstanceEx().convertAndLoadProject(path);
      }
      catch (IOException e) {
        LOG.error(e);
        return null;
      }
    }
  });
}
项目:tools-idea    文件:ApplicationImpl.java   
private boolean canExit() {
  for (ApplicationListener applicationListener : myDispatcher.getListeners()) {
    if (!applicationListener.canExitApplication()) {
      return false;
    }
  }

  ProjectManagerEx projectManager = (ProjectManagerEx)ProjectManager.getInstance();
  Project[] projects = projectManager.getOpenProjects();
  for (Project project : projects) {
    if (!projectManager.canClose(project)) {
      return false;
    }
  }

  return true;
}
项目:tools-idea    文件:SaveAndSyncHandlerImpl.java   
public void saveProjectsAndDocuments() {
  if (LOG.isDebugEnabled()) {
    LOG.debug("enter: save()");
  }
  if (ApplicationManager.getApplication().isDisposed()) return;

  if (myBlockSaveOnFrameDeactivationCount.get() == 0 && GeneralSettings.getInstance().isSaveOnFrameDeactivation()) {
    FileDocumentManager.getInstance().saveAllDocuments();

    Project[] openProjects = ProjectManagerEx.getInstanceEx().getOpenProjects();
    for (Project project : openProjects) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("save project: " + project);
      }
      project.save();
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("save application settings");
    }
    ApplicationManagerEx.getApplicationEx().saveSettings();
    if (LOG.isDebugEnabled()) {
      LOG.debug("exit: save()");
    }
  }
}
项目:tools-idea    文件:FileTemplateUtil.java   
private static String mergeTemplate(String templateContent, final VelocityContext context, boolean useSystemLineSeparators) throws IOException {
  final StringWriter stringWriter = new StringWriter();
  try {
    Velocity.evaluate(context, stringWriter, "", templateContent);
  }
  catch (final VelocityException e) {
    LOG.error("Error evaluating template:\n"+templateContent,e);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        Messages.showErrorDialog(IdeBundle.message("error.parsing.file.template", e.getMessage()),
                                 IdeBundle.message("title.velocity.error"));
      }
    });
  }
  final String result = stringWriter.toString();

  if (useSystemLineSeparators) {
    final String newSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
    if (!"\n".equals(newSeparator)) {
      return StringUtil.convertLineSeparators(result, newSeparator);
    }
  }

  return result;
}
项目:consulo    文件:GwtTransportServiceImpl.java   
private Project getProject() {
  String path = "R:/_github.com/consulo/mssdw";

  try {
    final Project project;
    ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
    Project[] openProjects = projectManager.getOpenProjects();
    if (openProjects.length > 0) {
      project = openProjects[0];
    }
    else {
      project = projectManager.loadProject(path);
      projectManager.openTestProject(project);
      final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project);
      startupManager.runStartupActivities();
      startupManager.startCacheUpdate();
    }
    return project;
  }
  catch (Exception e) {
    e.getMessage();
  }
  return null;
}
项目:consulo    文件:ApplicationImpl.java   
@RequiredDispatchThread
private boolean disposeSelf(final boolean checkCanCloseProject) {
  final ProjectManagerImpl manager = (ProjectManagerImpl)ProjectManagerEx.getInstanceEx();
  if (manager != null) {
    final boolean[] canClose = {true};
    for (final Project project : manager.getOpenProjects()) {
      try {
        CommandProcessor.getInstance().executeCommand(project, () -> {
          if (!manager.closeProject(project, true, true, checkCanCloseProject)) {
            canClose[0] = false;
          }
        }, ApplicationBundle.message("command.exit"), null);
      }
      catch (Throwable e) {
        LOG.error(e);
      }
      if (!canClose[0]) {
        return false;
      }
    }
  }
  runWriteAction(() -> Disposer.dispose(ApplicationImpl.this));

  Disposer.assertIsEmpty();
  return true;
}
项目:consulo    文件:ApplicationImpl.java   
private boolean canExit() {
  for (ApplicationListener applicationListener : myDispatcher.getListeners()) {
    if (!applicationListener.canExitApplication()) {
      return false;
    }
  }

  ProjectManagerEx projectManager = (ProjectManagerEx)ProjectManager.getInstance();
  Project[] projects = projectManager.getOpenProjects();
  for (Project project : projects) {
    if (!projectManager.canClose(project)) {
      return false;
    }
  }

  return true;
}
项目:consulo    文件:FileTemplateUtil.java   
private static String mergeTemplate(String templateContent, final VelocityContext context, boolean useSystemLineSeparators) throws IOException {
  final StringWriter stringWriter = new StringWriter();
  try {
    VelocityWrapper.evaluate(null, context, stringWriter, templateContent);
  }
  catch (final VelocityException e) {
    LOG.error("Error evaluating template:\n" + templateContent, e);
    ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(IdeBundle.message("error.parsing.file.template", e.getMessage()), IdeBundle.message("title.velocity.error")));
  }
  final String result = stringWriter.toString();

  if (useSystemLineSeparators) {
    final String newSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
    if (!"\n".equals(newSeparator)) {
      return StringUtil.convertLineSeparators(result, newSeparator);
    }
  }

  return result;
}
项目:consulo-java    文件:OrderEntryTest.java   
@Override
protected void setUpProject() throws Exception {
  final String root = BASE_PATH;

  VirtualFile tempProjectRootDir =
    PsiTestUtil.createTestProjectStructure(getTestName(true), null, FileUtil.toSystemIndependentName(root), myFilesToDelete, false);

  VirtualFile projectFile = tempProjectRootDir.findChild("orderEntry.ipr");

  myProject = ProjectManagerEx.getInstanceEx().loadProject(projectFile.getPath());
  ProjectManagerEx.getInstanceEx().openTestProject(myProject);
  ModuleManagerImpl mm = (ModuleManagerImpl)ModuleManager.getInstance(myProject);
  mm.projectOpened();
  setUpJdk();
  myModule = ModuleManager.getInstance(getProject()).getModules()[0];
}
项目:TearDownGenerator    文件:ImportProjectTestFixture.java   
@Override
public void setUp() throws Exception {
  String tempDirectory = tempDirTestFixture.getTempDirPath();
  copyFolder(new File(projectDirectoryPath), new File(tempDirectory));
  project = ProjectUtil.openOrImport(tempDirectory + "/" + projectFileName, null, true);
  ProjectManagerEx.getInstanceEx().openTestProject(getProject());
}
项目:TearDownGenerator    文件:ImportProjectTestFixture.java   
@Override
public void tearDown() throws Exception {
  if (getProject() != null) {
    ProjectManagerEx.getInstanceEx().closeTestProject(getProject());
    ProjectUtil.closeAndDispose(getProject());
    project = null;
  }
}
项目:educational-plugin    文件:PyStudyInitialConfigurator.java   
/**
 * @noinspection UnusedParameters
 */
public PyStudyInitialConfigurator(MessageBus bus,
                                  CodeInsightSettings codeInsightSettings,
                                  final PropertiesComponent propertiesComponent,
                                  FileTypeManager fileTypeManager,
                                  final ProjectManagerEx projectManager) {
  if (!propertiesComponent.getBoolean(CONFIGURED_V40)) {
    final File courses = new File(PathManager.getConfigPath(), "courses");
    FileUtil.delete(courses);
    propertiesComponent.setValue(CONFIGURED_V40, "true");
  }
}
项目:intellij-ce-playground    文件:LoadProjectTest.java   
public void testLoadProject() throws Exception {
  VirtualFile src = ProjectRootManager.getInstance(getProject()).getContentSourceRoots()[0];

  VirtualFile a = src.findFileByRelativePath("/x/AClass.java");
  assertNotNull(a);
  PsiFile fileA = getPsiManager().findFile(a);
  assertNotNull(fileA);
  fileA.navigate(true);
  Editor editorA = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), a), true);
  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

  assertNotNull(editorA);
  CodeInsightTestFixtureImpl.instantiateAndRun(fileA, editorA, new int[0], false);

  VirtualFile b = src.findFileByRelativePath("/x/BClass.java");
  assertNotNull(b);
  PsiFile fileB = getPsiManager().findFile(b);
  assertNotNull(fileB);
  fileB.navigate(true);
  Editor editorB = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), b), true);
  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

  assertNotNull(editorB);
  CodeInsightTestFixtureImpl.instantiateAndRun(fileB, editorB, new int[0], false);

  FileEditor[] allEditors = FileEditorManager.getInstance(getProject()).getAllEditors();
  assertEquals(2, allEditors.length);

  FileEditorManager.getInstance(getProject()).closeFile(a);
  FileEditorManager.getInstance(getProject()).closeFile(b);
  ProjectManagerEx.getInstanceEx().closeAndDispose(getProject());

  LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiFileImpl.class, new Processor<PsiFileImpl>() {
    @Override
    public boolean process(PsiFileImpl psiFile) {
      return  psiFile.getViewProvider().getVirtualFile().getFileSystem() instanceof LocalFileSystem;
    }
  });
}
项目:intellij-ce-playground    文件:GotoImplementationTest.java   
@Override
protected void setUpProject() throws Exception {
  final String root = JavaTestUtil.getJavaTestDataPath() + "/codeInsight/navigation/alexProject";
  VirtualFile vfsRoot = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(root));

  VirtualFile projectFile = vfsRoot.findChild("test.ipr");
  myProject = ProjectManagerEx.getInstanceEx().loadProject(projectFile.getPath());

  ProjectManagerEx.getInstanceEx().openTestProject(myProject);
  UIUtil.dispatchAllInvocationEvents(); // startup activities
}
项目:intellij-ce-playground    文件:UpdateCacheTest.java   
@Override
protected void setUpProject() throws Exception {
  myProjectManager = ProjectManagerEx.getInstanceEx();
  LOG.assertTrue(myProjectManager != null, "Cannot instantiate ProjectManager component");

  File projectFile = getIprFile();
  loadAndSetupProject(projectFile.getPath());
}
项目:intellij-ce-playground    文件:ProjectJdkForModuleStep.java   
@Nullable
private static Sdk getDefaultJdk(WizardContext context) {
  Project defaultProject = ProjectManagerEx.getInstanceEx().getDefaultProject();
  final Sdk sdk = ProjectRootManagerEx.getInstanceEx(defaultProject).getProjectSdk();
  if (sdk == null) {
    return AddModuleWizard.getMostRecentSuitableSdk(context);
  }
  return sdk;
}
项目:intellij-ce-playground    文件:LightPlatformTestCase.java   
@SuppressWarnings("NonPrivateFieldAccessedInSynchronizedContext")
public static synchronized void closeAndDeleteProject() {
  if (ourProject != null) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();

    if (!ourProject.isDisposed()) {
      File ioFile = new File(ourProject.getProjectFilePath());
      Disposer.dispose(ourProject);
      if (ioFile.exists()) {
        File dir = ioFile.getParentFile();
        if (dir.getName().startsWith(UsefulTestCase.TEMP_DIR_MARKER)) {
          FileUtil.delete(dir);
        }
        else {
          FileUtil.delete(ioFile);
        }
      }
    }

    ProjectManagerEx.getInstanceEx().closeAndDispose(ourProject);

    // project may be disposed but empty folder may still be there
    if (ourPathToKeep != null) {
      File parent = new File(ourPathToKeep).getParentFile();
      if (parent.getName().startsWith(UsefulTestCase.TEMP_DIR_MARKER)) {
        parent.delete(); // delete only empty folders
      }
    }

    ourProject = null;
    ourPathToKeep = null;
  }
}
项目:intellij-ce-playground    文件:PlatformTestCase.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  if (ourTestCase != null) {
    String message = "Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call.";
    ourTestCase = null;
    fail(message);
  }
  IdeaLogger.ourErrorsOccurred = null;

  LOG.info(getClass().getName() + ".setUp()");

  initApplication();

  myEditorListenerTracker = new EditorListenerTracker();
  myThreadTracker = new ThreadTracker();

  setUpProject();

  storeSettings();
  ourTestCase = this;
  if (myProject != null) {
    ProjectManagerEx.getInstanceEx().openTestProject(myProject);
    CodeStyleSettingsManager.getInstance(myProject).setTemporarySettings(new CodeStyleSettings());
    InjectedLanguageManagerImpl.pushInjectors(getProject());
  }

  DocumentCommitThread.getInstance().clearQueue();
  UIUtil.dispatchAllInvocationEvents();
}
项目:intellij-ce-playground    文件:ApplicationImpl.java   
private boolean disposeSelf(final boolean checkCanCloseProject) {
  final ProjectManagerImpl manager = (ProjectManagerImpl)ProjectManagerEx.getInstanceEx();
  if (manager != null) {
    final boolean[] canClose = {true};
    for (final Project project : manager.getOpenProjects()) {
      try {
        CommandProcessor.getInstance().executeCommand(project, new Runnable() {
          @Override
          public void run() {
            if (!manager.closeProject(project, true, true, checkCanCloseProject)) {
              canClose[0] = false;
            }
          }
        }, ApplicationBundle.message("command.exit"), null);
      }
      catch (Throwable e) {
        LOG.error(e);
      }
      if (!canClose[0]) {
        return false;
      }
    }
  }
  runWriteAction(new Runnable() {
    @Override
    public void run() {
      Disposer.dispose(ApplicationImpl.this);
    }
  });

  Disposer.assertIsEmpty();
  return true;
}
项目:intellij-ce-playground    文件:SaveAndSyncHandlerImpl.java   
public static void doSaveDocumentsAndProjectsAndApp() {
  LOG.debug("saving documents");
  FileDocumentManager.getInstance().saveAllDocuments();

  for (Project project : ProjectManagerEx.getInstanceEx().getOpenProjects()) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("saving project: " + project);
    }
    project.save();
  }

  LOG.debug("saving application settings");
  ApplicationManager.getApplication().saveSettings();
}
项目:intellij-ce-playground    文件:NonProjectFileAccessTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  EditorNotifications notifications = new EditorNotificationsImpl(getProject());
  ((ComponentManagerImpl)getProject()).registerComponentInstance(EditorNotifications.class, notifications);
  NonProjectFileWritingAccessProvider.enableChecksInTests(getProject(), true);
  ProjectManagerEx.getInstanceEx().blockReloadingProjectOnExternalChanges();
}
项目:intellij-ce-playground    文件:NonProjectFileAccessTest.java   
@Override
protected void tearDown() throws Exception {
  NonProjectFileWritingAccessProvider.setCustomUnlocker(null);
  NonProjectFileWritingAccessProvider.enableChecksInTests(getProject(), false);
  super.tearDown();
  ProjectManagerEx.getInstanceEx().unblockReloadingProjectOnExternalChanges(); // unblock only after project is disposed
}
项目:intellij-ce-playground    文件:ModuleAttachProcessor.java   
@Override
public boolean attachToProject(Project project, File projectDir, @Nullable ProjectOpenedCallback callback) {
  if (!projectDir.exists()) {
    Project newProject = ((ProjectManagerEx)ProjectManager.getInstance())
      .newProject(projectDir.getParentFile().getName(), projectDir.getParent(), true, false);
    if (newProject == null) {
      return false;
    }
    final VirtualFile baseDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(projectDir.getParent());
    PlatformProjectOpenProcessor.runDirectoryProjectConfigurators(baseDir, newProject);
    newProject.save();
    AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(null);
    try {
      Disposer.dispose(newProject);
    }
    finally {
      token.finish();
    }
  }
  final String[] files = projectDir.list();
  if (files != null) {
    for (String file : files) {
      if (FileUtilRt.extensionEquals(file, "iml")) {
        VirtualFile imlFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(projectDir, file));
        if (imlFile != null) {
          attachModule(project, imlFile, callback);
          return true;
        }
      }
    }
  }
  int rc = Messages.showYesNoDialog(project, "The project at " +
                                             FileUtil.toSystemDependentName(projectDir.getPath()) +
                                             " uses a non-standard layout and cannot be attached to this project. Would you like to open it in a new window?",
                                    "Open Project", Messages.getQuestionIcon());

  return rc != Messages.YES;
}
项目:intellij-ce-playground    文件:Projects.java   
/**
 * Opens the given project in the IDE.
 *
 * @param project the project to open.
 */
public static void open(@NotNull Project project) {
  updateLastProjectLocation(project.getBasePath());
  if (WindowManager.getInstance().isFullScreenSupportedInCurrentOS()) {
    IdeFocusManager instance = IdeFocusManager.findInstance();
    IdeFrame lastFocusedFrame = instance.getLastFocusedFrame();
    if (lastFocusedFrame instanceof IdeFrameEx) {
      boolean fullScreen = ((IdeFrameEx)lastFocusedFrame).isInFullScreen();
      if (fullScreen) {
        project.putUserData(SHOULD_OPEN_IN_FULL_SCREEN, TRUE);
      }
    }
  }
  ProjectManagerEx.getInstanceEx().openProject(project);
}
项目:intellij-ce-playground    文件:AndroidImportProjectAction.java   
private static void doCreate(@NotNull AddModuleWizard wizard) throws IOException {
  // TODO: Now we need to add as module if file does not exist
  ProjectBuilder projectBuilder = wizard.getProjectBuilder();

  try {
    File projectFilePath = new File(wizard.getNewProjectFilePath());
    File projectDirPath = projectFilePath.isDirectory() ? projectFilePath : projectFilePath.getParentFile();
    LOG.assertTrue(projectDirPath != null, "Cannot create project in '" + projectFilePath + "': no parent file exists");
    ensureExists(projectDirPath);

    if (StorageScheme.DIRECTORY_BASED == wizard.getStorageScheme()) {
      File ideaDirPath = new File(projectDirPath, DIRECTORY_STORE_FOLDER);
      ensureExists(ideaDirPath);
    }

    boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode();
    ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
    Project project = projectManager.newProject(wizard.getProjectName(), projectDirPath.getPath(), true, false);
    if (project == null) {
      return;
    }
    if (!unitTestMode) {
      project.save();
    }
    if (projectBuilder != null) {
      if (!projectBuilder.validate(null, project)) {
        return;
      }
      projectBuilder.commit(project, null, EMPTY_MODULES_PROVIDER);
    }
    if (!unitTestMode) {
      project.save();
    }
  }
  finally {
    if (projectBuilder != null) {
      projectBuilder.cleanup();
    }
  }
}
项目:intellij-ce-playground    文件:GuiTestCase.java   
@NotNull
private IdeFrameFixture openProject(@NotNull final File projectPath) {
  VirtualFile toSelect = findFileByIoFile(projectPath, true);
  assertNotNull(toSelect);

  GuiTestSuiteState state = getGuiTestSuiteState();
  if (!state.isOpenProjectWizardAlreadyTested()) {
    state.setOpenProjectWizardAlreadyTested(true);

    findWelcomeFrame().clickOpenProjectButton();

    FileChooserDialogFixture openProjectDialog = FileChooserDialogFixture.findOpenProjectDialog(myRobot);
    return openProjectAndWaitUntilOpened(toSelect, openProjectDialog);
  }

  execute(new GuiTask() {
    @Override
    protected void executeInEDT() throws Throwable {
      ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
      projectManager.loadAndOpenProject(projectPath.getPath());
    }
  });

  IdeFrameFixture projectFrame = findIdeFrame(projectPath);
  projectFrame.waitForGradleProjectSyncToFinish();

  return projectFrame;
}
项目:intellij-ce-playground    文件:GradleModuleBuilder.java   
public static void appendToFile(@NotNull VirtualFile file, @NotNull String text) throws IOException {
  String lineSeparator = LoadTextUtil.detectLineSeparator(file, true);
  if (lineSeparator == null) {
    lineSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
  }
  final String existingText = StringUtil.trimTrailing(VfsUtilCore.loadText(file));
  String content = (StringUtil.isNotEmpty(existingText) ? existingText + lineSeparator : "") +
                   StringUtil.convertLineSeparators(text, lineSeparator);
  VfsUtil.saveText(file, content);
}
项目:intellij-ce-playground    文件:MavenNotManagedProjectInspectionsTest.java   
public void testEnablingInspectionForNonMavenProjectsAfterImport() throws Throwable {
  if (ignore()) return;
  // can not reproduce in tests because of StartupManager.runWhenProjectIsInitialized
  // relies on ProjectManager.isProjectOpen. In tests the project is never being opened.

  ProjectManagerEx.getInstanceEx().openProject(myProject);
  UIUtil.dispatchAllInvocationEvents(); // startup activities

  Module m = createModule("module");
  PsiTestUtil.addContentRoot(m, myProjectRoot);

  createProjectPom("<groupId>test</groupId>" +
                   "<artifactId>project</artifactId>" +
                   "<version>1</version>" +

                   "<modules>" +
                   "  <module>m1</module>" +
                   "  <module>m2</module>" +
                   "</modules>" +

                   "<dependencies>" +
                   "  <dependency>" +
                   "    <groupId>xxx</groupId>" +
                   "    <artifactId>yyy</artifactId>" +
                   "    <version>zzz</version>" +
                   "  </dependency>" +
                   "</dependencies>");

  checkHighlighting(); // should not fail nor highlight errors

  importProject();

  checkHighlighting(); // should not fail nor highlight errors
}
项目:intellij-ce-playground    文件:SvnIntegrateChangesTask.java   
public void run(@NotNull final ProgressIndicator indicator) {
  myHandler.setProgressIndicator(ProgressManager.getInstance().getProgressIndicator());
  myResolveWorker = new ResolveWorker(myInfo.isUnderProjectRoot(), myProject);

  ProjectManagerEx.getInstanceEx().blockReloadingProjectOnExternalChanges();
  myProjectLevelVcsManager.startBackgroundVcsOperation();

  try {
    myRecentlyUpdatedFiles = UpdatedFiles.create();
    myHandler.setUpdatedFiles(myRecentlyUpdatedFiles);

    indicatorOnStart();

    // try to do multiple under single progress
    while (true) {
      doMerge();

      RefreshVFsSynchronously.updateAllChanged(myRecentlyUpdatedFiles);
      indicator.setText(VcsBundle.message("progress.text.updating.done"));

      if (myResolveWorker.needsInteraction(myRecentlyUpdatedFiles) || (! myMerger.hasNext()) ||
          (! myExceptions.isEmpty()) || UpdatedFilesReverseSide.containErrors(myRecentlyUpdatedFiles)) {
        break;
      }
      accumulate();
    }
  } finally {
    myProjectLevelVcsManager.stopBackgroundVcsOperation();
  }
}