Search in sources :

Example 31 with ExecutionException

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

the class RerunFailedActionsTestTools method findRestartActionState.

/**
   * Searches for "rerun failed tests" action and fetches state from it
   *
   * @param descriptor previous run descriptor
   * @return state (if found)
   */
@Nullable
public static RunProfileState findRestartActionState(@NotNull final RunContentDescriptor descriptor) {
    final ExecutionEnvironment action = findRestartAction(descriptor);
    if (action == null) {
        return null;
    }
    final Ref<RunProfileState> stateRef = new Ref<>();
    ApplicationManager.getApplication().invokeAndWait(() -> {
        try {
            stateRef.set(action.getState());
        } catch (final ExecutionException e) {
            throw new IllegalStateException("Error obtaining execution state", e);
        }
    }, ModalityState.NON_MODAL);
    return stateRef.get();
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Ref(com.intellij.openapi.util.Ref) RunProfileState(com.intellij.execution.configurations.RunProfileState) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 32 with ExecutionException

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

the class EditExternallyAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    Options options = OptionsManager.getInstance().getOptions();
    String executablePath = options.getExternalEditorOptions().getExecutablePath();
    if (StringUtil.isEmpty(executablePath)) {
        Messages.showErrorDialog(project, ImagesBundle.message("error.empty.external.editor.path"), ImagesBundle.message("error.title.empty.external.editor.path"));
        ImagesConfigurable.show(project);
    } else {
        if (files != null) {
            Map<String, String> env = EnvironmentUtil.getEnvironmentMap();
            for (String varName : env.keySet()) {
                if (SystemInfo.isWindows) {
                    executablePath = StringUtil.replace(executablePath, "%" + varName + "%", env.get(varName), true);
                } else {
                    executablePath = StringUtil.replace(executablePath, "${" + varName + "}", env.get(varName), false);
                }
            }
            executablePath = FileUtil.toSystemDependentName(executablePath);
            File executable = new File(executablePath);
            GeneralCommandLine commandLine = new GeneralCommandLine();
            final String path = executable.exists() ? executable.getAbsolutePath() : executablePath;
            if (SystemInfo.isMac) {
                commandLine.setExePath(ExecUtil.getOpenCommandPath());
                commandLine.addParameter("-a");
                commandLine.addParameter(path);
            } else {
                commandLine.setExePath(path);
            }
            ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
            for (VirtualFile file : files) {
                if (file.isInLocalFileSystem() && typeManager.isImage(file)) {
                    commandLine.addParameter(VfsUtilCore.virtualToIoFile(file).getAbsolutePath());
                }
            }
            commandLine.setWorkDirectory(new File(executablePath).getParentFile());
            try {
                commandLine.createProcess();
            } catch (ExecutionException ex) {
                Messages.showErrorDialog(project, ex.getLocalizedMessage(), ImagesBundle.message("error.title.launching.external.editor"));
                ImagesConfigurable.show(project);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Options(org.intellij.images.options.Options) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ImageFileTypeManager(org.intellij.images.fileTypes.ImageFileTypeManager) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 33 with ExecutionException

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

the class DebugProcessImpl method createVirtualMachineInt.

private VirtualMachine createVirtualMachineInt() throws ExecutionException {
    try {
        if (myArguments != null) {
            throw new IOException(DebuggerBundle.message("error.debugger.already.listening"));
        }
        final String address = myConnection.getAddress();
        if (myConnection.isServerMode()) {
            ListeningConnector connector = (ListeningConnector) findConnector(myConnection.isUseSockets() ? SOCKET_LISTENING_CONNECTOR_NAME : SHMEM_LISTENING_CONNECTOR_NAME);
            if (connector == null) {
                throw new CantRunException(DebuggerBundle.message("error.debug.connector.not.found", DebuggerBundle.getTransportName(myConnection)));
            }
            myArguments = connector.defaultArguments();
            if (myArguments == null) {
                throw new CantRunException(DebuggerBundle.message("error.no.debug.listen.port"));
            }
            if (address == null) {
                throw new CantRunException(DebuggerBundle.message("error.no.debug.listen.port"));
            }
            // zero port number means the caller leaves to debugger to decide at which port to listen
            //noinspection HardCodedStringLiteral
            final Connector.Argument portArg = myConnection.isUseSockets() ? myArguments.get("port") : myArguments.get("name");
            if (portArg != null) {
                portArg.setValue(address);
            }
            //noinspection HardCodedStringLiteral
            final Connector.Argument timeoutArg = myArguments.get("timeout");
            if (timeoutArg != null) {
                // wait forever
                timeoutArg.setValue("0");
            }
            String listeningAddress = connector.startListening(myArguments);
            String port = StringUtil.substringAfter(listeningAddress, ":");
            if (port != null) {
                listeningAddress = port;
            }
            myConnection.setAddress(listeningAddress);
            myDebugProcessDispatcher.getMulticaster().connectorIsReady();
            try {
                return connector.accept(myArguments);
            } finally {
                if (myArguments != null) {
                    try {
                        connector.stopListening(myArguments);
                    } catch (IllegalArgumentException | IllegalConnectorArgumentsException ignored) {
                    // ignored
                    }
                }
            }
        } else {
            // is client mode, should attach to already running process
            AttachingConnector connector = (AttachingConnector) findConnector(myConnection.isUseSockets() ? SOCKET_ATTACHING_CONNECTOR_NAME : SHMEM_ATTACHING_CONNECTOR_NAME);
            if (connector == null) {
                throw new CantRunException(DebuggerBundle.message("error.debug.connector.not.found", DebuggerBundle.getTransportName(myConnection)));
            }
            myArguments = connector.defaultArguments();
            if (myConnection.isUseSockets()) {
                //noinspection HardCodedStringLiteral
                final Connector.Argument hostnameArg = myArguments.get("hostname");
                if (hostnameArg != null && myConnection.getHostName() != null) {
                    hostnameArg.setValue(myConnection.getHostName());
                }
                if (address == null) {
                    throw new CantRunException(DebuggerBundle.message("error.no.debug.attach.port"));
                }
                //noinspection HardCodedStringLiteral
                final Connector.Argument portArg = myArguments.get("port");
                if (portArg != null) {
                    portArg.setValue(address);
                }
            } else {
                if (address == null) {
                    throw new CantRunException(DebuggerBundle.message("error.no.shmem.address"));
                }
                //noinspection HardCodedStringLiteral
                final Connector.Argument nameArg = myArguments.get("name");
                if (nameArg != null) {
                    nameArg.setValue(address);
                }
            }
            //noinspection HardCodedStringLiteral
            final Connector.Argument timeoutArg = myArguments.get("timeout");
            if (timeoutArg != null) {
                // wait forever
                timeoutArg.setValue("0");
            }
            myDebugProcessDispatcher.getMulticaster().connectorIsReady();
            try {
                return connector.attach(myArguments);
            } catch (IllegalArgumentException e) {
                throw new CantRunException(e.getLocalizedMessage());
            }
        }
    } catch (IOException e) {
        throw new ExecutionException(processIOException(e, DebuggerBundle.getAddressDisplayName(myConnection)), e);
    } catch (IllegalConnectorArgumentsException e) {
        throw new ExecutionException(processError(e), e);
    } finally {
        myArguments = null;
    }
}
Also used : CantRunException(com.intellij.execution.CantRunException) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException)

Example 34 with ExecutionException

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

the class DebugProcessImpl method createVirtualMachine.

private void createVirtualMachine(final DebugEnvironment environment) {
    final String sessionName = environment.getSessionName();
    final long pollTimeout = environment.getPollTimeout();
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    final AtomicBoolean connectorIsReady = new AtomicBoolean(false);
    myDebugProcessDispatcher.addListener(new DebugProcessListener() {

        @Override
        public void connectorIsReady() {
            connectorIsReady.set(true);
            semaphore.up();
            myDebugProcessDispatcher.removeListener(this);
        }
    });
    // reload to make sure that source positions are initialized
    DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().reloadBreakpoints();
    getManagerThread().schedule(new DebuggerCommandImpl() {

        @Override
        protected void action() {
            VirtualMachine vm = null;
            try {
                final long time = System.currentTimeMillis();
                do {
                    try {
                        vm = createVirtualMachineInt();
                        break;
                    } catch (final ExecutionException e) {
                        if (pollTimeout > 0 && !myConnection.isServerMode() && e.getCause() instanceof IOException) {
                            synchronized (this) {
                                try {
                                    wait(500);
                                } catch (InterruptedException ignored) {
                                    break;
                                }
                            }
                        } else {
                            ProcessHandler processHandler = getProcessHandler();
                            boolean terminated = processHandler != null && (processHandler.isProcessTerminating() || processHandler.isProcessTerminated());
                            fail();
                            DebuggerInvocationUtil.swingInvokeLater(myProject, () -> {
                                // this problem to the user
                                if ((myExecutionResult != null && !terminated) || !connectorIsReady.get()) {
                                    ExecutionUtil.handleExecutionError(myProject, ToolWindowId.DEBUG, sessionName, e);
                                }
                            });
                            break;
                        }
                    }
                } while (System.currentTimeMillis() - time < pollTimeout);
            } finally {
                semaphore.up();
            }
            if (vm != null) {
                final VirtualMachine vm1 = vm;
                afterProcessStarted(() -> getManagerThread().schedule(new DebuggerCommandImpl() {

                    @Override
                    protected void action() throws Exception {
                        commitVM(vm1);
                    }
                }));
            }
        }

        @Override
        protected void commandCancelled() {
            try {
                super.commandCancelled();
            } finally {
                semaphore.up();
            }
        }
    });
    semaphore.waitFor();
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CantRunException(com.intellij.execution.CantRunException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) ExecutionException(com.intellij.execution.ExecutionException)

Example 35 with ExecutionException

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

the class DebugProcessImpl method findConnector.

static Connector findConnector(String connectorName) throws ExecutionException {
    VirtualMachineManager virtualMachineManager;
    try {
        virtualMachineManager = Bootstrap.virtualMachineManager();
    } catch (Error e) {
        final String error = e.getClass().getName() + " : " + e.getLocalizedMessage();
        throw new ExecutionException(DebuggerBundle.message("debugger.jdi.bootstrap.error", error));
    }
    List connectors;
    if (SOCKET_ATTACHING_CONNECTOR_NAME.equals(connectorName) || SHMEM_ATTACHING_CONNECTOR_NAME.equals(connectorName)) {
        connectors = virtualMachineManager.attachingConnectors();
    } else if (SOCKET_LISTENING_CONNECTOR_NAME.equals(connectorName) || SHMEM_LISTENING_CONNECTOR_NAME.equals(connectorName)) {
        connectors = virtualMachineManager.listeningConnectors();
    } else {
        return null;
    }
    for (Object connector1 : connectors) {
        Connector connector = (Connector) connector1;
        if (connectorName.equals(connector.name())) {
            return connector;
        }
    }
    return null;
}
Also used : 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