Java Code Examples for com.intellij.openapi.application.Application#isHeadlessEnvironment()

The following examples show how to use com.intellij.openapi.application.Application#isHeadlessEnvironment() . 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
Source File: PantsOpenProjectProvider.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private AddModuleWizard openNewProjectWizard(VirtualFile projectFile) {
  PantsProjectImportProvider provider = new PantsProjectImportProvider();
  AddModuleWizard dialog = new AddModuleWizard(null, projectFile.getPath(), provider);

  ProjectImportBuilder builder = provider.getBuilder();
  builder.setUpdate(false);
  dialog.getWizardContext().setProjectBuilder(builder);

  // dialog can only be shown in a non-headless environment
  Application application = ApplicationManager.getApplication();
  if (application.isHeadlessEnvironment() || dialog.showAndGet()) {
    return dialog;
  }
  else {
    return null;
  }
}
 
Example 2
Source File: ShowAutoImportPass.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showImports() {
  Application application = ApplicationManager.getApplication();
  application.assertIsDispatchThread();
  if (!application.isHeadlessEnvironment() && !myEditor.getContentComponent().hasFocus()) return;
  if (DumbService.isDumb(myProject) || !myFile.isValid()) return;
  if (myEditor.isDisposed() || myEditor instanceof EditorWindow && !((EditorWindow)myEditor).isValid()) return;

  int caretOffset = myEditor.getCaretModel().getOffset();
  importUnambiguousImports(caretOffset);
  List<HighlightInfo> visibleHighlights = getVisibleHighlights(myStartOffset, myEndOffset, myProject, myEditor, hasDirtyTextRange);

  for (int i = visibleHighlights.size() - 1; i >= 0; i--) {
    HighlightInfo info = visibleHighlights.get(i);
    if (info.startOffset <= caretOffset && showAddImportHint(info)) return;
  }

  for (HighlightInfo visibleHighlight : visibleHighlights) {
    if (visibleHighlight.startOffset > caretOffset && showAddImportHint(visibleHighlight)) return;
  }
}
 
Example 3
Source File: InspectionManagerEx.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void buildInspectionSearchIndexIfNecessary() {
  if (!myToolsAreInitialized.getAndSet(true)) {
    final SearchableOptionsRegistrar myOptionsRegistrar = SearchableOptionsRegistrar.getInstance();
    final InspectionToolRegistrar toolRegistrar = InspectionToolRegistrar.getInstance();
    final Application app = ApplicationManager.getApplication();
    if (app.isUnitTestMode() || app.isHeadlessEnvironment()) return;

    app.executeOnPooledThread(new Runnable(){
      @Override
      public void run() {
        List<InspectionToolWrapper> tools = toolRegistrar.createTools();
        for (InspectionToolWrapper toolWrapper : tools) {
          processText(toolWrapper.getDisplayName().toLowerCase(), toolWrapper, myOptionsRegistrar);

          final String description = toolWrapper.loadDescription();
          if (description != null) {
            @NonNls String descriptionText = HTML_PATTERN.matcher(description).replaceAll(" ");
            processText(descriptionText, toolWrapper, myOptionsRegistrar);
          }
        }
      }
    });
  }
}
 
Example 4
Source File: VcsBalloonProblemNotifier.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void show(final Project project, final String message, final MessageType type, final boolean showOverChangesView,
                         @Nullable final NamedRunnable[] notificationListener) {
  final Application application = ApplicationManager.getApplication();
  if (application.isHeadlessEnvironment()) return;
  final Runnable showErrorAction = new Runnable() {
    public void run() {
      new VcsBalloonProblemNotifier(project, message, type, showOverChangesView, notificationListener).run();
    }
  };
  if (application.isDispatchThread()) {
    showErrorAction.run();
  }
  else {
    application.invokeLater(showErrorAction);
  }
}
 
Example 5
Source File: ClipboardSynchronizer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
public ClipboardSynchronizer(Application application) {
  if (application.isHeadlessEnvironment() && application.isUnitTestMode()) {
    myClipboardHandler = new HeadlessClipboardHandler();
  }
  else if (Patches.SLOW_GETTING_CLIPBOARD_CONTENTS && SystemInfo.isMac) {
    myClipboardHandler = new MacClipboardHandler();
  }
  else if (Patches.SLOW_GETTING_CLIPBOARD_CONTENTS && SystemInfo.isXWindow) {
    myClipboardHandler = new XWinClipboardHandler();
  }
  else {
    myClipboardHandler = new ClipboardHandler();
  }
  myClipboardHandler.init();
}
 
Example 6
Source File: ModuleManagerComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void fireModulesAdded() {
  Runnable runnableWithProgress = () -> {
    for (final Module module : myModuleModel.getModules()) {
      final Application app = ApplicationManager.getApplication();
      final Runnable swingRunnable = () -> fireModuleAddedInWriteAction(module);
      if (app.isDispatchThread() || app.isHeadlessEnvironment()) {
        swingRunnable.run();
      }
      else {
        ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
        app.invokeAndWait(swingRunnable, pi.getModalityState());
      }
    }
  };

  ProgressIndicator progressIndicator = myProgressManager.getProgressIndicator();
  if (progressIndicator == null) {
    myProgressManager.runProcessWithProgressSynchronously(runnableWithProgress, "Loading modules", false, myProject);
  }
  else {
    runnableWithProgress.run();
  }
}
 
Example 7
Source File: InspectionProjectProfileManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void projectClosed() {
  final Application app = ApplicationManager.getApplication();
  Runnable cleanupInspectionProfilesRunnable = new Runnable() {
    @Override
    public void run() {
      for (InspectionProfileWrapper wrapper : myName2Profile.values()) {
        wrapper.cleanup(myProject);
      }
      fireProfilesShutdown();
    }
  };
  if (app.isUnitTestMode() || app.isHeadlessEnvironment()) {
    cleanupInspectionProfilesRunnable.run();
  }
  else {
    app.executeOnPooledThread(cleanupInspectionProfilesRunnable);
  }
}
 
Example 8
Source File: GeneralTestEventsProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void addToInvokeLater(final Runnable runnable) {
  final Application application = ApplicationManager.getApplication();
  if (application.isUnitTestMode()) {
    UIUtil.invokeLaterIfNeeded(() -> {
      if (!myProject.isDisposed()) {
        runnable.run();
      }
    });
  }
  else if (application.isHeadlessEnvironment() || SwingUtilities.isEventDispatchThread()) {
    runnable.run();
  }
  else {
    myTransferToEDTQueue.offer(runnable);
  }
}
 
Example 9
Source File: ConfirmingTrustManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean confirmAndUpdate(final X509Certificate[] chain, boolean addToKeyStore, boolean askUser) {
  Application app = ApplicationManager.getApplication();
  final X509Certificate endPoint = chain[0];
  // IDEA-123467 and IDEA-123335 workaround
  String threadClassName = StringUtil.notNullize(Thread.currentThread().getClass().getCanonicalName());
  if (threadClassName.equals("sun.awt.image.ImageFetcher")) {
    LOG.debug("Image Fetcher thread is detected. Certificate check will be skipped.");
    return true;
  }
  CertificateManager.Config config = CertificateManager.getInstance().getState();
  if (app.isUnitTestMode() || app.isHeadlessEnvironment() || config.ACCEPT_AUTOMATICALLY) {
    LOG.debug("Certificate will be accepted automatically");
    if (addToKeyStore) {
      myCustomManager.addCertificate(endPoint);
    }
    return true;
  }
  boolean accepted = askUser && CertificateManager.showAcceptDialog(new Callable<DialogWrapper>() {
    @Override
    public DialogWrapper call() throws Exception {
      // TODO may be another kind of warning, if default trust store is missing
      return CertificateWarningDialog.createUntrustedCertificateWarning(endPoint);
    }
  });
  if (accepted) {
    LOG.info("Certificate was accepted by user");
    if (addToKeyStore) {
      myCustomManager.addCertificate(endPoint);
    }
  }
  return accepted;
}
 
Example 10
Source File: ProjectMacrosUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean showMacrosConfigurationDialog(Project project, final Collection<String> undefinedMacros) {
  final String text = ProjectBundle.message("project.load.undefined.path.variables.message");
  final Application application = ApplicationManager.getApplication();
  if (application.isHeadlessEnvironment() || application.isUnitTestMode()) {
    throw new RuntimeException(text + ": " + StringUtil.join(undefinedMacros, ", "));
  }
  final UndefinedMacrosConfigurable configurable =
    new UndefinedMacrosConfigurable(text, undefinedMacros);
  final SingleConfigurableEditor editor = new SingleConfigurableEditor(project, configurable);
  editor.show();
  return editor.isOK();
}
 
Example 11
Source File: FileInEditorProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean shouldNotify() {
  Application application = ApplicationManager.getApplication();
  if (application.isUnitTestMode() || application.isHeadlessEnvironment()) {
    return false;
  }
  EditorSettingsExternalizable.OptionSet editorOptions = EditorSettingsExternalizable.getInstance().getOptions();
  return editorOptions.SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION && myEditor != null && !myProcessSelectedText;
}
 
Example 12
Source File: UndoManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void commandStarted(UndoConfirmationPolicy undoConfirmationPolicy, boolean recordOriginalReference) {
  if (myCommandLevel == 0) {
    myCurrentMerger = new CommandMerger(this, CommandProcessor.getInstance().isUndoTransparentActionInProgress());

    if (recordOriginalReference && myProject != null) {
      Editor editor = null;
      final Application application = ApplicationManager.getApplication();
      if (application.isUnitTestMode() || application.isHeadlessEnvironment()) {
        editor = DataManager.getInstance().getDataContext().getData(CommonDataKeys.EDITOR);
      }
      else {
        Component component = WindowManagerEx.getInstanceEx().getFocusedComponent(myProject);
        if (component != null) {
          editor = DataManager.getInstance().getDataContext(component).getData(CommonDataKeys.EDITOR);
        }
      }

      if (editor != null) {
        Document document = editor.getDocument();
        VirtualFile file = FileDocumentManager.getInstance().getFile(document);
        if (file != null && file.isValid()) {
          myOriginatorReference = DocumentReferenceManager.getInstance().create(file);
        }
      }
    }
  }
  LOG.assertTrue(myCurrentMerger != null, String.valueOf(myCommandLevel));
  myCurrentMerger.setBeforeState(getCurrentState());
  myCurrentMerger.mergeUndoConfirmationPolicy(undoConfirmationPolicy);

  myCommandLevel++;

}
 
Example 13
Source File: RecentProjectsManagerBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected RecentProjectsManagerBase(@Nonnull Application application) {
  MessageBusConnection connection = application.getMessageBus().connect();
  connection.subscribe(AppLifecycleListener.TOPIC, new MyAppLifecycleListener());
  if (!application.isHeadlessEnvironment()) {
    connection.subscribe(ProjectManager.TOPIC, new MyProjectListener());
  }
}
 
Example 14
Source File: InspectionToolWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected URL getDescriptionUrl() {
  Application app = ApplicationManager.getApplication();
  if (myEP == null || app.isUnitTestMode() || app.isHeadlessEnvironment()) {
    return superGetDescriptionUrl();
  }
  String fileName = getDescriptionFileName();
  return myEP.getLoaderForClass().getResource("/inspectionDescriptions/" + fileName);
}
 
Example 15
Source File: SMRunnerUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Adds runnable to Event Dispatch Queue
 * if we aren't in UnitTest of Headless environment mode
 * @param runnable Runnable
 */
public static void addToInvokeLater(final Runnable runnable) {
  final Application application = ApplicationManager.getApplication();
  if (application.isHeadlessEnvironment() && !application.isUnitTestMode()) {
    runnable.run();
  } else {
    UIUtil.invokeLaterIfNeeded(runnable);
  }
}
 
Example 16
Source File: VfsAwareMapReduceIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void requestRebuild(@Nonnull Throwable ex) {
  Runnable action = () -> FileBasedIndex.getInstance().requestRebuild((ID<?, ?>)myIndexId, ex);
  Application application = ApplicationManager.getApplication();
  if (application.isUnitTestMode() || application.isHeadlessEnvironment()) {
    // avoid deadlock due to synchronous update in DumbServiceImpl#queueTask
    TransactionGuard.getInstance().submitTransactionLater(application, action);
  }
  else {
    action.run();
  }
}
 
Example 17
Source File: TextFieldWithBrowseButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void installPathCompletion(final FileChooserDescriptor fileChooserDescriptor,
                                     @Nullable Disposable parent) {
  final Application application = ApplicationManager.getApplication();
  if (application == null || application.isUnitTestMode() || application.isHeadlessEnvironment()) return;
  FileChooserFactory.getInstance().installFileCompletion(getChildComponent(), fileChooserDescriptor, true, parent);
}
 
Example 18
Source File: Messages.java    From consulo with Apache License 2.0 4 votes vote down vote up
static boolean isApplicationInUnitTestOrHeadless() {
  final Application application = ApplicationManager.getApplication();
  return application != null && (application.isUnitTestMode() || application.isHeadlessEnvironment());
}
 
Example 19
Source File: DialogWrapperPeer.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isHeadlessEnv() {
  Application app = ApplicationManager.getApplication();
  if (app == null) return GraphicsEnvironment.isHeadless();

  return app.isUnitTestMode() || app.isHeadlessEnvironment();
}
 
Example 20
Source File: SystemNotifications.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static SystemNotifications getInstance() {
  Application app = ApplicationManager.getApplication();
  return app.isHeadlessEnvironment() || app.isUnitTestMode() ? NULL : ServiceManager.getService(SystemNotifications.class);
}