Search in sources :

Example 1 with Key

use of com.intellij.openapi.util.Key in project intellij-community by JetBrains.

the class PydevConsoleRunnerImpl method connect.

private void connect(final String[] statements2execute) {
    if (handshake()) {
        ApplicationManager.getApplication().invokeLater(() -> {
            // Propagate console communication to language console
            final PythonConsoleView consoleView = myConsoleView;
            consoleView.setConsoleCommunication(myPydevConsoleCommunication);
            consoleView.setSdk(mySdk);
            consoleView.setExecutionHandler(myConsoleExecuteActionHandler);
            myProcessHandler.addProcessListener(new ProcessAdapter() {

                @Override
                public void onTextAvailable(ProcessEvent event, Key outputType) {
                    consoleView.print(event.getText(), outputType);
                }
            });
            if (myEnableAfterConnection) {
                enableConsoleExecuteAction();
            }
            for (String statement : statements2execute) {
                consoleView.executeStatement(statement + "\n", ProcessOutputTypes.SYSTEM);
            }
            fireConsoleInitializedEvent(consoleView);
            consoleView.initialized();
        });
    } else {
        myConsoleView.print("Couldn't connect to console process.", ProcessOutputTypes.STDERR);
        myProcessHandler.destroyProcess();
        myConsoleView.setEditable(false);
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Key(com.intellij.openapi.util.Key)

Example 2 with Key

use of com.intellij.openapi.util.Key in project intellij-community by JetBrains.

the class StaticImportInsertHandler method importAlreadyExists.

private static boolean importAlreadyExists(final PsiMember member, final GroovyFile file, final PsiElement place) {
    final PsiManager manager = file.getManager();
    PsiScopeProcessor processor = new PsiScopeProcessor() {

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            return !manager.areElementsEquivalent(element, member);
        }

        @Override
        public <T> T getHint(@NotNull Key<T> hintKey) {
            return null;
        }

        @Override
        public void handleEvent(@NotNull Event event, Object associated) {
        }
    };
    boolean skipStaticImports = member instanceof PsiClass;
    final GrImportStatement[] imports = file.getImportStatements();
    final ResolveState initial = ResolveState.initial();
    for (GrImportStatement anImport : imports) {
        if (skipStaticImports == anImport.isStatic())
            continue;
        if (!anImport.processDeclarations(processor, initial, null, place))
            return true;
    }
    return false;
}
Also used : PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) NotNull(org.jetbrains.annotations.NotNull) Key(com.intellij.openapi.util.Key)

Example 3 with Key

use of com.intellij.openapi.util.Key in project intellij-community by JetBrains.

the class CmdInfoClient method execute.

private String execute(@NotNull List<String> parameters, @NotNull File path) throws SvnBindException {
    // workaround: separately capture command output - used in exception handling logic to overcome svn 1.8 issue (see below)
    final ProcessOutput output = new ProcessOutput();
    LineCommandListener listener = new LineCommandAdapter() {

        @Override
        public void onLineAvailable(String line, Key outputType) {
            if (outputType == ProcessOutputTypes.STDOUT) {
                output.appendStdout(line);
            }
        }
    };
    try {
        CommandExecutor command = execute(myVcs, SvnTarget.fromFile(path), SvnCommandName.info, parameters, listener);
        return command.getOutput();
    } catch (SvnBindException e) {
        final String text = StringUtil.notNullize(e.getMessage());
        if (text.contains("W155010")) {
            // files should be parsed from output
            return output.getStdout();
        }
        // "E155007: '' is not a working copy"
        if (text.contains("is not a working copy") && StringUtil.isNotEmpty(output.getStdout())) {
            // but the requested info is still in the output except root closing tag
            return output.getStdout() + "</info>";
        }
        throw e;
    }
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) Key(com.intellij.openapi.util.Key)

Example 4 with Key

use of com.intellij.openapi.util.Key in project intellij-community by JetBrains.

the class IpnbConnectionManager method startIpythonServer.

public boolean startIpythonServer(@NotNull final String initUrl, @NotNull final IpnbFileEditor fileEditor) {
    final Module module = ProjectFileIndex.SERVICE.getInstance(myProject).getModuleForFile(fileEditor.getVirtualFile());
    if (module == null)
        return false;
    final Sdk sdk = PythonSdkType.findPythonSdk(module);
    if (sdk == null) {
        showWarning(fileEditor, "Please check Python Interpreter in Settings->Python Interpreter", null);
        return false;
    }
    final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
    final PyPackage ipythonPackage = packages != null ? PyPackageUtil.findPackage(packages, "ipython") : null;
    final PyPackage jupyterPackage = packages != null ? PyPackageUtil.findPackage(packages, "jupyter") : null;
    if (ipythonPackage == null && jupyterPackage == null) {
        showWarning(fileEditor, "Add Jupyter to the interpreter of the current project.", null);
        return false;
    }
    String url = showDialogUrl(initUrl);
    if (url == null)
        return false;
    final IpnbSettings ipnbSettings = IpnbSettings.getInstance(myProject);
    ipnbSettings.setURL(url);
    final Pair<String, String> hostPort = getHostPortFromUrl(url);
    if (hostPort == null) {
        showWarning(fileEditor, "Please, check Jupyter Notebook URL in <a href=\"\">Settings->Tools->Jupyter Notebook</a>", new IpnbSettingsAdapter());
        return false;
    }
    final String homePath = sdk.getHomePath();
    if (homePath == null) {
        showWarning(fileEditor, "Python Sdk is invalid, please check Python Interpreter in Settings->Python Interpreter", null);
        return false;
    }
    Map<String, String> env = null;
    final ArrayList<String> parameters = Lists.newArrayList(homePath);
    String ipython = findJupyterRunner(homePath);
    if (ipython == null) {
        ipython = findIPythonRunner(homePath);
        if (ipython == null) {
            ipython = PythonHelper.LOAD_ENTRY_POINT.asParamString();
            env = ImmutableMap.of("PYCHARM_EP_DIST", "ipython", "PYCHARM_EP_NAME", "ipython");
        }
        parameters.add(ipython);
        parameters.add("notebook");
    } else {
        parameters.add(ipython);
    }
    parameters.add("--no-browser");
    if (hostPort.getFirst() != null) {
        parameters.add("--ip");
        parameters.add(hostPort.getFirst());
    }
    if (hostPort.getSecond() != null) {
        parameters.add("--port");
        parameters.add(hostPort.getSecond());
    }
    final String arguments = ipnbSettings.getArguments();
    if (!StringUtil.isEmptyOrSpaces(arguments)) {
        parameters.addAll(StringUtil.split(arguments, " "));
    }
    final String directory = ipnbSettings.getWorkingDirectory();
    final String baseDir = !StringUtil.isEmptyOrSpaces(directory) ? directory : ModuleRootManager.getInstance(module).getContentRoots()[0].getCanonicalPath();
    final GeneralCommandLine commandLine = new GeneralCommandLine(parameters).withWorkDirectory(baseDir);
    if (env != null) {
        commandLine.withEnvironment(env);
    }
    try {
        final boolean[] serverStarted = { false };
        final KillableColoredProcessHandler processHandler = new KillableColoredProcessHandler(commandLine) {

            @Override
            protected void doDestroyProcess() {
                super.doDestroyProcess();
                myKernels.clear();
                myToken = null;
                UnixProcessManager.sendSigIntToProcessTree(getProcess());
            }

            @Override
            public void coloredTextAvailable(@NotNull @NonNls String text, @NotNull Key attributes) {
                super.coloredTextAvailable(text, attributes);
                if (text.toLowerCase().contains("active kernels")) {
                    serverStarted[0] = true;
                }
                final String token = "?token=";
                if (text.toLowerCase().contains(token)) {
                    myToken = text.substring(text.indexOf(token) + token.length()).trim();
                }
            }

            @Override
            public boolean isSilentlyDestroyOnClose() {
                return true;
            }
        };
        processHandler.setShouldDestroyProcessRecursively(true);
        GuiUtils.invokeLaterIfNeeded(() -> new RunContentExecutor(myProject, processHandler).withTitle("Jupyter Notebook").withStop(() -> {
            myKernels.clear();
            processHandler.destroyProcess();
            UnixProcessManager.sendSigIntToProcessTree(processHandler.getProcess());
        }, () -> !processHandler.isProcessTerminated()).withRerun(() -> startIpythonServer(url, fileEditor)).withHelpId("reference.manage.py").withFilter(new UrlFilter()).run(), ModalityState.defaultModalityState());
        int countAttempt = 0;
        while (!serverStarted[0] && countAttempt < MAX_ATTEMPTS) {
            countAttempt += 1;
            TimeoutUtil.sleep(1000);
        }
        return true;
    } catch (ExecutionException e) {
        return false;
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) UrlFilter(com.intellij.execution.filters.UrlFilter) NotNull(org.jetbrains.annotations.NotNull) PyPackage(com.jetbrains.python.packaging.PyPackage) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunContentExecutor(com.intellij.execution.RunContentExecutor) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler)

Example 5 with Key

use of com.intellij.openapi.util.Key in project intellij-community by JetBrains.

the class MavenEmbeddersManager method forEachPooled.

private void forEachPooled(boolean includeInUse, Function<MavenEmbedderWrapper, ?> func) {
    for (Trinity<Key, String, String> each : myPool.keySet()) {
        MavenEmbedderWrapper embedder = myPool.get(each);
        // collected
        if (embedder == null)
            continue;
        if (!includeInUse && myEmbeddersInUse.contains(embedder))
            continue;
        func.fun(embedder);
    }
}
Also used : MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) Key(com.intellij.openapi.util.Key)

Aggregations

Key (com.intellij.openapi.util.Key)88 ProcessEvent (com.intellij.execution.process.ProcessEvent)30 NotNull (org.jetbrains.annotations.NotNull)29 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)25 ExecutionException (com.intellij.execution.ExecutionException)19 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)17 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)13 Project (com.intellij.openapi.project.Project)9 IOException (java.io.IOException)9 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)8 Nullable (org.jetbrains.annotations.Nullable)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)6 ConsoleViewContentType (com.intellij.execution.ui.ConsoleViewContentType)6 ProcessListener (com.intellij.execution.process.ProcessListener)5 BaseOSProcessHandler (com.intellij.execution.process.BaseOSProcessHandler)4 Module (com.intellij.openapi.module.Module)4 File (java.io.File)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4