com.intellij.openapi.project.impl.ProjectImpl Java Examples

The following examples show how to use com.intellij.openapi.project.impl.ProjectImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
public void init41(@Nullable ProgressIndicator indicator) {
  boolean finished = false;
  try {
    //ProjectManagerImpl.initProject(path, this, true, null, null);
    Method method = ReflectionUtil
      .getDeclaredMethod(ProjectManagerImpl.class, "initProject", Path.class, ProjectImpl.class, boolean.class, Project.class,
                         ProgressIndicator.class);
    assert (method != null);
    try {
      method.invoke(null, path, this, true, null, null);
    }
    catch (IllegalAccessException | InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    finished = true;
  }
  finally {
    if (!finished) {
      TransactionGuard.submitTransaction(this, () -> WriteAction.run(() -> Disposer.dispose(this)));
    }
  }
}
 
Example #2
public void initPre41(@Nullable ProgressIndicator indicator) {
  boolean finished = false;
  try {
    //registerComponents();
    Method method = ReflectionUtil.getDeclaredMethod(ProjectImpl.class, "registerComponents");
    assert (method != null);
    try {
      method.invoke(this);
    }
    catch (IllegalAccessException | InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    getStateStore().setPath(path, true, null);
    super.init(indicator);
    finished = true;
  }
  finally {
    if (!finished) {
      TransactionGuard.submitTransaction(this, () -> WriteAction.run(() -> Disposer.dispose(this)));
    }
  }
}
 
Example #3
public void init41(@Nullable ProgressIndicator indicator) {
  boolean finished = false;
  try {
    //ProjectManagerImpl.initProject(path, this, true, null, null);
    Method method = ReflectionUtil
      .getDeclaredMethod(ProjectManagerImpl.class, "initProject", Path.class, ProjectImpl.class, boolean.class, Project.class,
                         ProgressIndicator.class);
    assert (method != null);
    try {
      method.invoke(null, path, this, true, null, null);
    }
    catch (IllegalAccessException | InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    finished = true;
  }
  finally {
    if (!finished) {
      TransactionGuard.submitTransaction(this, () -> WriteAction.run(() -> Disposer.dispose(this)));
    }
  }
}
 
Example #4
public void initPre41(@Nullable ProgressIndicator indicator) {
  boolean finished = false;
  try {
    //registerComponents();
    Method method = ReflectionUtil.getDeclaredMethod(ProjectImpl.class, "registerComponents");
    assert (method != null);
    try {
      method.invoke(this);
    }
    catch (IllegalAccessException | InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    getStateStore().setPath(path, true, null);
    super.init(indicator);
    finished = true;
  }
  finally {
    if (!finished) {
      TransactionGuard.submitTransaction(this, () -> WriteAction.run(() -> Disposer.dispose(this)));
    }
  }
}
 
Example #5
Source Project: consulo   Author: consulo   File: LightPlatformTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredWriteAction
public static synchronized void closeAndDeleteProject() {
  if (ourProject != null) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();
    for (Sdk registeredSdk : ourRegisteredSdks) {
      SdkTable.getInstance().removeSdk(registeredSdk);
    }
    ((ProjectImpl)ourProject).setTemporarilyDisposed(false);
    final VirtualFile projFile = ((ProjectEx)ourProject).getStateStore().getProjectFile();
    final File projectFile = projFile == null ? null : VfsUtilCore.virtualToIoFile(projFile);
    if (!ourProject.isDisposed()) Disposer.dispose(ourProject);

    if (projectFile != null) {
      FileUtil.delete(projectFile);
    }
    ourProject = null;
  }
}
 
Example #6
Source Project: intellij   Author: bazelbuild   File: ProjectViewUi.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * To support the custom language features, we need a ProjectImpl, and it's not desirable to
 * create one from scratch.<br>
 *
 * @return the current, non-default project, if one exists, else the default project.
 */
public static Project getProject() {
  Project project = (Project) DataManager.getInstance().getDataContext().getData("project");
  if (project != null && project instanceof ProjectImpl) {
    return project;
  }
  return ProjectManager.getInstance().getDefaultProject();
}
 
Example #7
Source Project: intellij   Author: bazelbuild   File: ServiceHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static <T> void registerProjectComponent(
    Project project, Class<T> key, T implementation, Disposable parentDisposable) {
  // #api193 (or #api201?): ComponentManagerImpl moved in 2020.1 dot releases. Check
  // ComponentManagerImpl directly when earlier releases are no longer supported
  boolean isComponentManagerImpl = project instanceof ProjectImpl;
  if (isComponentManagerImpl) {
    ServiceContainerUtil.registerComponentInstance(
        project, key, implementation, parentDisposable);
  } else {
    registerComponentInstance(
        (MutablePicoContainer) project.getPicoContainer(), key, implementation, parentDisposable);
  }
}
 
Example #8
Source Project: consulo   Author: consulo   File: ProjectStoreImpl.java    License: Apache License 2.0 5 votes vote down vote up
public static String readProjectName(@Nonnull File file) {
  if (file.isDirectory()) {
    final File nameFile = new File(new File(file, Project.DIRECTORY_STORE_FOLDER), ProjectImpl.NAME_FILE);
    if (nameFile.exists()) {
      try {
        return FileUtil.loadFile(nameFile, true);
      }
      catch (IOException ignored) {
      }
    }
  }
  return file.getName();
}
 
Example #9
Source Project: consulo   Author: consulo   File: ProjectStoreImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void loadProjectFromTemplate(@Nonnull ProjectImpl defaultProject) {
  defaultProject.save();

  Element element = ((DefaultProjectStoreImpl)defaultProject.getStateStore()).getStateCopy();
  if (element != null) {
    getDefaultFileStorage().setDefaultState(element);
  }
}
 
Example #10
Source Project: consulo   Author: consulo   File: PsiDocumentManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void documentChanged(@Nonnull DocumentEvent event) {
  super.documentChanged(event);
  // optimisation: avoid documents piling up during batch processing
  if (isUncommited(event.getDocument()) && FileDocumentManagerImpl.areTooManyDocumentsInTheQueue(myUncommittedDocuments)) {
    if (myUnitTestMode) {
      myStopTrackingDocuments = true;
      try {
        LOG.error("Too many uncommitted documents for " +
                  myProject +
                  "(" +
                  myUncommittedDocuments.size() +
                  ")" +
                  ":\n" +
                  StringUtil.join(myUncommittedDocuments, "\n") +
                  (myProject instanceof ProjectImpl ? "\n\n Project creation trace: " + ((ProjectImpl)myProject).getCreationTrace() : ""));
      }
      finally {
        //noinspection TestOnlyProblems
        clearUncommittedDocuments();
      }
    }
    // must not commit during document save
    if (PomModelImpl.isAllowPsiModification()
        // it can happen that document(forUseInNonAWTThread=true) outside write action caused this
        && ApplicationManager.getApplication().isWriteAccessAllowed()) {
      // commit one document to avoid OOME
      for (Document document : myUncommittedDocuments) {
        if (document != event.getDocument()) {
          doCommitWithoutReparse(document);
          break;
        }
      }
    }
  }
}
 
Example #11
Source Project: consulo   Author: consulo   File: MockProjectStore.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void loadProjectFromTemplate(@Nonnull ProjectImpl project) {
  throw new UnsupportedOperationException("Method loadProjectFromTemplate is not yet implemented in " + getClass().getName());
}
 
Example #12
Source Project: consulo   Author: consulo   File: LightPlatformTestCase.java    License: Apache License 2.0 4 votes vote down vote up
public static void doTearDown(@Nonnull final Project project, ApplicationStarter application, boolean checkForEditors) throws Exception {
  DocumentCommitThread.getInstance().clearQueue();
  CodeStyleSettingsManager.getInstance(project).dropTemporarySettings();
  checkAllTimersAreDisposed();
  UsefulTestCase.doPostponedFormatting(project);

  LookupManager lookupManager = LookupManager.getInstance(project);
  if (lookupManager != null) {
    lookupManager.hideActiveLookup();
  }
  ((StartupManagerImpl)StartupManager.getInstance(project)).prepareForNextTest();
  InspectionProfileManager.getInstance().deleteProfile(PROFILE);
  assertNotNull("Application components damaged", ProjectManager.getInstance());

  new WriteCommandAction.Simple(project) {
    @Override
    @RequiredWriteAction
    protected void run() throws Throwable {
      if (ourSourceRoot != null) {
        try {
          final VirtualFile[] children = ourSourceRoot.getChildren();
          for (VirtualFile child : children) {
            child.delete(this);
          }
        }
        catch (IOException e) {
          //noinspection CallToPrintStackTrace
          e.printStackTrace();
        }
      }
      EncodingManager encodingManager = EncodingManager.getInstance();
      if (encodingManager instanceof EncodingManagerImpl) ((EncodingManagerImpl)encodingManager).clearDocumentQueue();

      FileDocumentManager manager = FileDocumentManager.getInstance();

      ApplicationManager.getApplication().runWriteAction(EmptyRunnable.getInstance()); // Flush postponed formatting if any.
      manager.saveAllDocuments();
      if (manager instanceof FileDocumentManagerImpl) {
        ((FileDocumentManagerImpl)manager).dropAllUnsavedDocuments();
      }
    }
  }.execute().throwException();

  assertFalse(PsiManager.getInstance(project).isDisposed());

  PsiDocumentManagerImpl documentManager = clearUncommittedDocuments(project);
  ((HintManagerImpl)HintManager.getInstance()).cleanup();
  DocumentCommitThread.getInstance().clearQueue();

  UIUtil.invokeAndWaitIfNeeded(new Runnable() {
    @Override
    public void run() {
      ((UndoManagerImpl)UndoManager.getGlobalInstance()).dropHistoryInTests();
      ((UndoManagerImpl)UndoManager.getInstance(project)).dropHistoryInTests();

      UIUtil.dispatchAllInvocationEvents();
    }
  });

  TemplateDataLanguageMappings.getInstance(project).cleanupForNextTest();

  ProjectManagerEx.getInstanceEx().closeTestProject(project);
  //application.setDataProvider(null);
  ourTestCase = null;
  ((PsiManagerImpl)PsiManager.getInstance(project)).cleanupForNextTest();

  CompletionProgressIndicator.cleanupForNextTest();

  if (checkForEditors) {
    checkEditorsReleased();
  }
  if (isLight(project)) {
    // mark temporarily as disposed so that rogue component trying to access it will fail
    ((ProjectImpl)project).setTemporarilyDisposed(true);
    documentManager.clearUncommittedDocuments();
  }
}
 
Example #13
Source Project: consulo   Author: consulo   File: LeakHunter.java    License: Apache License 2.0 4 votes vote down vote up
@TestOnly
public static void checkProjectLeak(@Nonnull Object root) throws Exception {
  checkLeak(root, ProjectImpl.class);
}
 
Example #14
Source Project: consulo   Author: consulo   File: ProjectStoreImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Inject
ProjectStoreImpl(@Nonnull Project project, @Nonnull ProjectPathMacroManager pathMacroManager, @Nonnull Provider<ApplicationDefaultStoreCache> applicationDefaultStoreCache) {
  super(applicationDefaultStoreCache, pathMacroManager);
  myProject = (ProjectImpl)project;
}
 
Example #15
Source Project: consulo   Author: consulo   File: FileEditorManagerImpl.java    License: Apache License 2.0 4 votes vote down vote up
protected void projectOpened(@Nonnull MessageBusConnection connection) {
  //myFocusWatcher.install(myWindows.getComponent ());
  getMainSplitters().startListeningFocus();

  final FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject);
  if (fileStatusManager != null) {
    /*
      Updates tabs colors
     */
    final MyFileStatusListener myFileStatusListener = new MyFileStatusListener();
    fileStatusManager.addFileStatusListener(myFileStatusListener, myProject);
  }
  connection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener());
  connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyRootsListener());

  /*
    Updates tabs names
   */
  final MyVirtualFileListener myVirtualFileListener = new MyVirtualFileListener();
  VirtualFileManager.getInstance().addVirtualFileListener(myVirtualFileListener, myProject);
  /*
    Extends/cuts number of opened tabs. Also updates location of tabs.
   */
  connection.subscribe(UISettingsListener.TOPIC, new MyUISettingsListener());

  StartupManager.getInstance(myProject).registerPostStartupActivity((DumbAwareRunnable)() -> {
    if (myProject.isDisposed()) return;
    setTabsMode(UISettings.getInstance().getEditorTabPlacement() != UISettings.TABS_NONE);

    ToolWindowManager.getInstance(myProject).invokeLater(() -> {
      if (!myProject.isDisposed()) {
        CommandProcessor.getInstance().executeCommand(myProject, () -> {
          ApplicationManager.getApplication().invokeLater(() -> {
            long currentTime = System.nanoTime();
            Long startTime = myProject.getUserData(ProjectImpl.CREATION_TIME);
            if (startTime != null) {
              LOG.info("Project opening took " + (currentTime - startTime) / 1000000 + " ms");
              PluginManagerCore.dumpPluginClassStatistics(LOG);
            }
          }, myProject.getDisposed());
          // group 1
        }, "", null);
      }
    });
  });
}
 
Example #16
Source Project: consulo   Author: consulo   File: IProjectStore.java    License: Apache License 2.0 votes vote down vote up
void loadProjectFromTemplate(@Nonnull ProjectImpl project);