Search in sources :

Example 21 with Application

use of com.intellij.openapi.application.Application in project ideavim by JetBrains.

the class VimPlugin method setupStatisticsReporter.

/**
   * Reports statistics about installed IdeaVim and enabled Vim emulation.
   *
   * See https://github.com/go-lang-plugin-org/go-lang-idea-plugin/commit/5182ab4a1d01ad37f6786268a2fe5e908575a217
   */
private void setupStatisticsReporter(@NotNull EventFacade eventFacade) {
    final Application application = ApplicationManager.getApplication();
    eventFacade.addEditorFactoryListener(new EditorFactoryAdapter() {

        @Override
        public void editorCreated(@NotNull EditorFactoryEvent event) {
            final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
            final long lastUpdate = propertiesComponent.getOrInitLong(IDEAVIM_STATISTICS_TIMESTAMP_KEY, 0);
            final boolean outOfDate = lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1);
            if (outOfDate && isEnabled()) {
                application.executeOnPooledThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            final String buildNumber = ApplicationInfo.getInstance().getBuild().asString();
                            final String pluginId = IDEAVIM_PLUGIN_ID;
                            final String version = URLEncoder.encode(getVersion(), CharsetToolkit.UTF8);
                            final String os = URLEncoder.encode(SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8);
                            final String uid = UpdateChecker.getInstallationUID(PropertiesComponent.getInstance());
                            final String url = "https://plugins.jetbrains.com/plugins/list" + "?pluginId=" + pluginId + "&build=" + buildNumber + "&pluginVersion=" + version + "&os=" + os + "&uuid=" + uid;
                            PropertiesComponent.getInstance().setValue(IDEAVIM_STATISTICS_TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
                            HttpRequests.request(url).connect(new HttpRequests.RequestProcessor<Object>() {

                                @Override
                                public Object process(@NotNull HttpRequests.Request request) throws IOException {
                                    LOG.info("Sending statistics: " + url);
                                    try {
                                        JDOMUtil.load(request.getInputStream());
                                    } catch (JDOMException e) {
                                        LOG.warn(e);
                                    }
                                    return null;
                                }
                            });
                        } catch (IOException e) {
                            LOG.warn(e);
                        }
                    }
                });
            }
        }
    }, application);
}
Also used : EditorFactoryAdapter(com.intellij.openapi.editor.event.EditorFactoryAdapter) EditorFactoryEvent(com.intellij.openapi.editor.event.EditorFactoryEvent) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) HttpRequests(com.intellij.util.io.HttpRequests) Application(com.intellij.openapi.application.Application) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 22 with Application

use of com.intellij.openapi.application.Application in project ideavim by JetBrains.

the class ActionHandler method execute.

public boolean execute(@NotNull Editor editor, @NotNull final DataContext context, @NotNull ExCommand cmd) throws ExException {
    final String actionName = cmd.getArgument().trim();
    final AnAction action = ActionManager.getInstance().getAction(actionName);
    if (action == null) {
        VimPlugin.showMessage("Action not found: " + actionName);
        return false;
    }
    final Application application = ApplicationManager.getApplication();
    if (application.isUnitTestMode()) {
        executeAction(action, context, actionName);
    } else {
        UiHelper.runAfterGotFocus(new Runnable() {

            @Override
            public void run() {
                executeAction(action, context, actionName);
            }
        });
    }
    return true;
}
Also used : AnAction(com.intellij.openapi.actionSystem.AnAction) Application(com.intellij.openapi.application.Application)

Example 23 with Application

use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.

the class CertificateManager method showAcceptDialog.

public static boolean showAcceptDialog(@NotNull final Callable<? extends DialogWrapper> dialogFactory) {
    Application app = ApplicationManager.getApplication();
    final CountDownLatch proceeded = new CountDownLatch(1);
    final AtomicBoolean accepted = new AtomicBoolean();
    final AtomicReference<DialogWrapper> dialogRef = new AtomicReference<>();
    Runnable showDialog = () -> {
        // skip if certificate was already rejected due to timeout or interrupt
        if (proceeded.getCount() == 0) {
            return;
        }
        try {
            DialogWrapper dialog = dialogFactory.call();
            dialogRef.set(dialog);
            accepted.set(dialog.showAndGet());
        } catch (Exception e) {
            LOG.error(e);
        } finally {
            proceeded.countDown();
        }
    };
    if (app.isDispatchThread()) {
        showDialog.run();
    } else {
        app.invokeLater(showDialog, ModalityState.any());
    }
    try {
        // IDEA-123467 and IDEA-123335 workaround
        boolean inTime = proceeded.await(DIALOG_VISIBILITY_TIMEOUT, TimeUnit.MILLISECONDS);
        if (!inTime) {
            DialogWrapper dialog = dialogRef.get();
            if (dialog == null || !dialog.isShowing()) {
                LOG.debug("After " + DIALOG_VISIBILITY_TIMEOUT + " ms dialog was not shown. " + "Rejecting certificate. Current thread: " + Thread.currentThread().getName());
                proceeded.countDown();
                return false;
            } else {
                // if dialog is already shown continue waiting
                proceeded.await();
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        proceeded.countDown();
    }
    return accepted.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Application(com.intellij.openapi.application.Application) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 24 with Application

use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.

the class ConfirmingTrustManager method confirmAndUpdate.

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;
    }
    if (app.isUnitTestMode() || app.isHeadlessEnvironment() || CertificateManager.getInstance().getState().ACCEPT_AUTOMATICALLY) {
        LOG.debug("Certificate will be accepted automatically");
        if (addToKeyStore) {
            myCustomManager.addCertificate(endPoint);
        }
        return true;
    }
    boolean accepted = askUser && CertificateManager.showAcceptDialog(() -> {
        // 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;
}
Also used : Application(com.intellij.openapi.application.Application) X509Certificate(java.security.cert.X509Certificate)

Example 25 with Application

use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.

the class WaitForProgressToShow method runOrInvokeAndWaitAboveProgress.

public static void runOrInvokeAndWaitAboveProgress(final Runnable command, @Nullable final ModalityState modalityState) {
    final Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        command.run();
    } else {
        final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
        if (pi != null) {
            execute(pi);
            application.invokeAndWait(command);
        } else {
            final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState;
            application.invokeAndWait(command, notNullModalityState);
        }
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModalityState(com.intellij.openapi.application.ModalityState) Application(com.intellij.openapi.application.Application)

Aggregations

Application (com.intellij.openapi.application.Application)188 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 IOException (java.io.IOException)14 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)9 ModalityState (com.intellij.openapi.application.ModalityState)8 Ref (com.intellij.openapi.util.Ref)7 ArrayList (java.util.ArrayList)7 List (java.util.List)6 ApplicationImpl (com.intellij.openapi.application.impl.ApplicationImpl)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)4 Document (com.intellij.openapi.editor.Document)4 Module (com.intellij.openapi.module.Module)4 Computable (com.intellij.openapi.util.Computable)4 PsiFile (com.intellij.psi.PsiFile)4 File (java.io.File)4 Editor (com.intellij.openapi.editor.Editor)3