Search in sources :

Example 16 with ExecutionException

use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.

the class CreateSnapShotAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    if (project == null || view == null) {
        return;
    }
    final PsiDirectory dir = view.getOrChooseDirectory();
    if (dir == null)
        return;
    final SnapShotClient client = new SnapShotClient();
    List<RunnerAndConfigurationSettings> appConfigurations = new ArrayList<>();
    RunnerAndConfigurationSettings snapshotConfiguration = null;
    boolean connected = false;
    ApplicationConfigurationType cfgType = ApplicationConfigurationType.getInstance();
    List<RunnerAndConfigurationSettings> racsi = RunManager.getInstance(project).getConfigurationSettingsList(cfgType);
    for (RunnerAndConfigurationSettings config : racsi) {
        if (config.getConfiguration() instanceof ApplicationConfiguration) {
            ApplicationConfiguration appConfig = (ApplicationConfiguration) config.getConfiguration();
            appConfigurations.add(config);
            if (appConfig.ENABLE_SWING_INSPECTOR) {
                SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
                snapshotConfiguration = config;
                if (settings.getLastPort() > 0) {
                    try {
                        client.connect(settings.getLastPort());
                        connected = true;
                    } catch (IOException ex) {
                        connected = false;
                    }
                }
            }
            if (connected)
                break;
        }
    }
    if (snapshotConfiguration == null) {
        snapshotConfiguration = promptForSnapshotConfiguration(project, appConfigurations);
        if (snapshotConfiguration == null)
            return;
    }
    if (!connected) {
        int rc = Messages.showYesNoDialog(project, UIDesignerBundle.message("snapshot.run.prompt"), UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon());
        if (rc == Messages.NO)
            return;
        final ApplicationConfiguration appConfig = (ApplicationConfiguration) snapshotConfiguration.getConfiguration();
        final SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
        settings.setNotifyRunnable(() -> SwingUtilities.invokeLater(() -> {
            Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.prepare.notice"), UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
            try {
                client.connect(settings.getLastPort());
            } catch (IOException ex) {
                Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.connection.error"), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
                return;
            }
            runSnapShooterSession(client, project, dir, view);
        }));
        try {
            ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), snapshotConfiguration).buildAndExecute();
        } catch (ExecutionException ex) {
            Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.run.error", ex.getMessage()), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
        }
    } else {
        runSnapShooterSession(client, project, dir, view);
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) IdeView(com.intellij.ide.IdeView) ApplicationConfigurationType(com.intellij.execution.application.ApplicationConfigurationType) Project(com.intellij.openapi.project.Project) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExecutionException(com.intellij.execution.ExecutionException) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

Example 17 with ExecutionException

use of com.intellij.execution.ExecutionException 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 18 with ExecutionException

use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.

the class GriffonFramework method createJavaParameters.

@Override
public JavaParameters createJavaParameters(@NotNull Module module, boolean forCreation, boolean forTests, boolean classpathFromDependencies, @NotNull MvcCommand command) throws ExecutionException {
    JavaParameters params = new JavaParameters();
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    params.setJdk(sdk);
    final VirtualFile sdkRoot = getSdkRoot(module);
    if (sdkRoot == null) {
        return params;
    }
    params.addEnv(getSdkHomePropertyName(), FileUtil.toSystemDependentName(sdkRoot.getPath()));
    final VirtualFile lib = sdkRoot.findChild("lib");
    if (lib != null) {
        for (final VirtualFile child : lib.getChildren()) {
            final String name = child.getName();
            if (name.startsWith("groovy-all-") && name.endsWith(".jar")) {
                params.getClassPath().add(child);
            }
        }
    }
    final VirtualFile dist = sdkRoot.findChild("dist");
    if (dist != null) {
        for (final VirtualFile child : dist.getChildren()) {
            final String name = child.getName();
            if (name.endsWith(".jar")) {
                if (name.startsWith("griffon-cli-") || name.startsWith("griffon-rt-") || name.startsWith("griffon-resources-")) {
                    params.getClassPath().add(child);
                }
            }
        }
    }
    /////////////////////////////////////////////////////////////
    params.setMainClass("org.codehaus.griffon.cli.support.GriffonStarter");
    final VirtualFile rootFile;
    if (forCreation) {
        VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
        if (roots.length != 1) {
            throw new ExecutionException("Failed to initialize griffon module: module " + module.getName() + " contains more than one root");
        }
        command.getArgs().add(0, roots[0].getName());
        rootFile = roots[0].getParent();
    } else {
        rootFile = findAppRoot(module);
        if (rootFile == null) {
            throw new ExecutionException("Failed to run griffon command: module " + module.getName() + " is not a Griffon module");
        }
    }
    String workDir = VfsUtilCore.virtualToIoFile(rootFile).getAbsolutePath();
    params.getVMParametersList().addParametersString(command.getVmOptions());
    if (!params.getVMParametersList().getParametersString().contains(XMX_JVM_PARAMETER)) {
        params.getVMParametersList().add("-Xmx256M");
    }
    final String griffonHomePath = FileUtil.toSystemDependentName(sdkRoot.getPath());
    params.getVMParametersList().add("-Dgriffon.home=" + griffonHomePath);
    params.getVMParametersList().add("-Dbase.dir=" + workDir);
    assert sdk != null;
    params.getVMParametersList().add("-Dtools.jar=" + ((JavaSdkType) sdk.getSdkType()).getToolsPath(sdk));
    final String confpath = griffonHomePath + GROOVY_STARTER_CONF;
    params.getVMParametersList().add("-Dgroovy.starter.conf=" + confpath);
    params.getVMParametersList().add("-Dgroovy.sanitized.stacktraces=\"groovy., org.codehaus.groovy., java., javax., sun., gjdk.groovy., gant., org.codehaus.gant.\"");
    params.getProgramParametersList().add("--main");
    params.getProgramParametersList().add("org.codehaus.griffon.cli.GriffonScriptRunner");
    params.getProgramParametersList().add("--conf");
    params.getProgramParametersList().add(confpath);
    if (!forCreation && classpathFromDependencies) {
        final String path = getApplicationClassPath(module).getPathsString();
        if (StringUtil.isNotEmpty(path)) {
            params.getProgramParametersList().add("--classpath");
            params.getProgramParametersList().add(path);
        }
    }
    params.setWorkingDirectory(workDir);
    ParametersList paramList = new ParametersList();
    command.addToParametersList(paramList);
    params.getProgramParametersList().add(paramList.getParametersString());
    params.setDefaultCharset(module.getProject());
    return params;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) ParametersList(com.intellij.execution.configurations.ParametersList) JavaParameters(com.intellij.execution.configurations.JavaParameters) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Example 19 with ExecutionException

use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.

the class PyRemoteProcessStarter method startRemoteProcess.

public ProcessHandler startRemoteProcess(@NotNull Sdk sdk, @NotNull GeneralCommandLine commandLine, @Nullable Project project, @Nullable PyRemotePathMapper pathMapper) throws ExecutionException {
    PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
    if (manager != null) {
        PyRemoteProcessHandlerBase processHandler;
        try {
            processHandler = doStartRemoteProcess(sdk, commandLine, manager, project, pathMapper);
        } catch (ExecutionException e) {
            final Application application = ApplicationManager.getApplication();
            if (application != null && (application.isUnitTestMode() || application.isHeadlessEnvironment())) {
                throw new RuntimeException(e);
            }
            throw new ExecutionException("Can't run remote python interpreter: " + e.getMessage(), e);
        }
        ProcessTerminatedListener.attach(processHandler);
        return processHandler;
    } else {
        throw new PythonRemoteInterpreterManager.PyRemoteInterpreterExecutionException();
    }
}
Also used : PyRemoteProcessHandlerBase(com.jetbrains.python.remote.PyRemoteProcessHandlerBase) ExecutionException(com.intellij.execution.ExecutionException) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) Application(com.intellij.openapi.application.Application)

Example 20 with ExecutionException

use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.

the class StudyRunAction method executeFile.

private void executeFile(@NotNull final Project project, @NotNull final VirtualFile openedFile, @NotNull final String filePath) {
    GeneralCommandLine cmd = new GeneralCommandLine();
    cmd.withWorkDirectory(openedFile.getParent().getCanonicalPath());
    TaskFile selectedTaskFile = StudyUtils.getTaskFile(project, openedFile);
    assert selectedTaskFile != null;
    final Task currentTask = selectedTaskFile.getTask();
    final Sdk sdk = StudyUtils.findSdk(currentTask, project);
    if (sdk == null) {
        StudyUtils.showNoSdkNotification(currentTask, project);
        return;
    }
    String sdkHomePath = sdk.getHomePath();
    if (sdkHomePath != null) {
        cmd.setExePath(sdkHomePath);
        StudyUtils.setCommandLineParameters(cmd, project, filePath, sdkHomePath, currentTask);
        try {
            myHandler = new OSProcessHandler(cmd);
        } catch (ExecutionException e) {
            LOG.error(e);
            return;
        }
        for (ProcessListener processListener : myProcessListeners) {
            myHandler.addProcessListener(processListener);
        }
        final RunContentExecutor executor = StudyUtils.getExecutor(project, currentTask, myHandler);
        if (executor != null) {
            Disposer.register(project, executor);
            executor.run();
        }
        EduUtils.synchronize();
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessListener(com.intellij.execution.process.ProcessListener) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunContentExecutor(com.intellij.execution.RunContentExecutor) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)154 NotNull (org.jetbrains.annotations.NotNull)42 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)39 IOException (java.io.IOException)35 File (java.io.File)34 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 Sdk (com.intellij.openapi.projectRoots.Sdk)20 Nullable (org.jetbrains.annotations.Nullable)20 Project (com.intellij.openapi.project.Project)19 ProcessHandler (com.intellij.execution.process.ProcessHandler)17 ProcessOutput (com.intellij.execution.process.ProcessOutput)17 Module (com.intellij.openapi.module.Module)13 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)12 Key (com.intellij.openapi.util.Key)12 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)10 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)9 ProcessEvent (com.intellij.execution.process.ProcessEvent)8 JavaParameters (com.intellij.execution.configurations.JavaParameters)7 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)7 ArrayList (java.util.ArrayList)7