Search in sources :

Example 96 with ExecutionException

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

the class DebugProcessImpl method attachVirtualMachine.

@Nullable
public ExecutionResult attachVirtualMachine(final DebugEnvironment environment, final DebuggerSession session) throws ExecutionException {
    mySession = session;
    myWaitFor.down();
    ApplicationManager.getApplication().assertIsDispatchThread();
    LOG.assertTrue(isInInitialState());
    myConnection = environment.getRemoteConnection();
    createVirtualMachine(environment);
    ExecutionResult executionResult;
    try {
        synchronized (myProcessListeners) {
            executionResult = environment.createExecutionResult();
            myExecutionResult = executionResult;
            if (executionResult == null) {
                fail();
                return null;
            }
            for (ProcessListener processListener : myProcessListeners) {
                executionResult.getProcessHandler().addProcessListener(processListener);
            }
            myProcessListeners.clear();
        }
    } catch (ExecutionException e) {
        fail();
        throw e;
    }
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return executionResult;
    }
    return executionResult;
}
Also used : ExecutionResult(com.intellij.execution.ExecutionResult) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 97 with ExecutionException

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

the class RemoteProcessSupport method startProcess.

private void startProcess(Target target, Parameters configuration, @NotNull Pair<Target, Parameters> key) {
    ProgramRunner runner = new DefaultProgramRunner() {

        @Override
        @NotNull
        public String getRunnerId() {
            return "MyRunner";
        }

        @Override
        public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
            return true;
        }
    };
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    ProcessHandler processHandler;
    try {
        RunProfileState state = getRunProfileState(target, configuration, executor);
        ExecutionResult result = state.execute(executor, runner);
        //noinspection ConstantConditions
        processHandler = result.getProcessHandler();
    } catch (Exception e) {
        dropProcessInfo(key, e instanceof ExecutionException ? e.getMessage() : ExceptionUtil.getUserStackTrace(e, LOG), null);
        return;
    }
    processHandler.addProcessListener(getProcessListener(key));
    processHandler.startNotify();
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) RunProfileState(com.intellij.execution.configurations.RunProfileState) DefaultProgramRunner(com.intellij.execution.runners.DefaultProgramRunner) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile) DefaultProgramRunner(com.intellij.execution.runners.DefaultProgramRunner) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull) ExecutionException(com.intellij.execution.ExecutionException)

Example 98 with ExecutionException

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

the class DebuggerManagerImpl method checkTargetJPDAInstalled.

/* Remoting */
private static void checkTargetJPDAInstalled(JavaParameters parameters) throws ExecutionException {
    final Sdk jdk = parameters.getJdk();
    if (jdk == null) {
        throw new ExecutionException(DebuggerBundle.message("error.jdk.not.specified"));
    }
    final JavaSdkVersion version = JavaSdk.getInstance().getVersion(jdk);
    String versionString = jdk.getVersionString();
    if (version == JavaSdkVersion.JDK_1_0 || version == JavaSdkVersion.JDK_1_1) {
        throw new ExecutionException(DebuggerBundle.message("error.unsupported.jdk.version", versionString));
    }
    if (SystemInfo.isWindows && version == JavaSdkVersion.JDK_1_2) {
        final VirtualFile homeDirectory = jdk.getHomeDirectory();
        if (homeDirectory == null || !homeDirectory.isValid()) {
            throw new ExecutionException(DebuggerBundle.message("error.invalid.jdk.home", versionString));
        }
        //noinspection HardCodedStringLiteral
        File dllFile = new File(homeDirectory.getPath().replace('/', File.separatorChar) + File.separator + "bin" + File.separator + "jdwp.dll");
        if (!dllFile.exists()) {
            GetJPDADialog dialog = new GetJPDADialog();
            dialog.show();
            throw new ExecutionException(DebuggerBundle.message("error.debug.libraries.missing"));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) GetJPDADialog(com.intellij.debugger.ui.GetJPDADialog)

Example 99 with ExecutionException

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

the class DebuggerManagerImpl method createDebugParameters.

@SuppressWarnings({ "HardCodedStringLiteral" })
public static RemoteConnection createDebugParameters(final JavaParameters parameters, final boolean debuggerInServerMode, int transport, final String debugPort, boolean checkValidity) throws ExecutionException {
    if (checkValidity) {
        checkTargetJPDAInstalled(parameters);
    }
    final boolean useSockets = transport == DebuggerSettings.SOCKET_TRANSPORT;
    String address = "";
    if (StringUtil.isEmptyOrSpaces(debugPort)) {
        try {
            address = DebuggerUtils.getInstance().findAvailableDebugAddress(useSockets);
        } catch (ExecutionException e) {
            if (checkValidity) {
                throw e;
            }
        }
    } else {
        address = debugPort;
    }
    final TransportServiceWrapper transportService = TransportServiceWrapper.getTransportService(useSockets);
    final String debugAddress = debuggerInServerMode && useSockets ? "127.0.0.1:" + address : address;
    String debuggeeRunProperties = "transport=" + transportService.transportId() + ",address=" + debugAddress;
    if (debuggerInServerMode) {
        debuggeeRunProperties += ",suspend=y,server=n";
    } else {
        debuggeeRunProperties += ",suspend=n,server=y";
    }
    if (StringUtil.containsWhitespaces(debuggeeRunProperties)) {
        debuggeeRunProperties = "\"" + debuggeeRunProperties + "\"";
    }
    final String _debuggeeRunProperties = debuggeeRunProperties;
    ApplicationManager.getApplication().runReadAction(() -> {
        JavaSdkUtil.addRtJar(parameters.getClassPath());
        final Sdk jdk = parameters.getJdk();
        final boolean forceClassicVM = shouldForceClassicVM(jdk);
        final boolean forceNoJIT = shouldForceNoJIT(jdk);
        final String debugKey = System.getProperty(DEBUG_KEY_NAME, "-Xdebug");
        final boolean needDebugKey = shouldAddXdebugKey(jdk) || !"-Xdebug".equals(debugKey);
        if (forceClassicVM || forceNoJIT || needDebugKey || !isJVMTIAvailable(jdk)) {
            parameters.getVMParametersList().replaceOrPrepend("-Xrunjdwp:", "-Xrunjdwp:" + _debuggeeRunProperties);
        } else {
            // use newer JVMTI if available
            parameters.getVMParametersList().replaceOrPrepend("-Xrunjdwp:", "");
            parameters.getVMParametersList().replaceOrPrepend("-agentlib:jdwp=", "-agentlib:jdwp=" + _debuggeeRunProperties);
        }
        if (forceNoJIT) {
            parameters.getVMParametersList().replaceOrPrepend("-Djava.compiler=", "-Djava.compiler=NONE");
            parameters.getVMParametersList().replaceOrPrepend("-Xnoagent", "-Xnoagent");
        }
        if (needDebugKey) {
            parameters.getVMParametersList().replaceOrPrepend(debugKey, debugKey);
        } else {
            // deliberately skip outdated parameter because it can disable full-speed debugging for some jdk builds
            // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6272174
            parameters.getVMParametersList().replaceOrPrepend("-Xdebug", "");
        }
        parameters.getVMParametersList().replaceOrPrepend("-classic", forceClassicVM ? "-classic" : "");
    });
    return new RemoteConnection(useSockets, "127.0.0.1", address, debuggerInServerMode);
}
Also used : TransportServiceWrapper(com.intellij.debugger.apiAdapters.TransportServiceWrapper) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) RemoteConnection(com.intellij.execution.configurations.RemoteConnection)

Example 100 with ExecutionException

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

the class JavaTestFrameworkDebuggerRunner method createContentDescriptor.

@Nullable
@Override
protected RunContentDescriptor createContentDescriptor(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    final RunContentDescriptor res = super.createContentDescriptor(state, environment);
    final ServerSocket socket = ((JavaTestFrameworkRunnableState) state).getForkSocket();
    if (socket != null) {
        Thread thread = new Thread(getThreadName() + " debugger runner") {

            @Override
            public void run() {
                try {
                    final Socket accept = socket.accept();
                    try {
                        DataInputStream stream = new DataInputStream(accept.getInputStream());
                        try {
                            int read = stream.readInt();
                            while (read != -1) {
                                final DebugProcess process = DebuggerManager.getInstance(environment.getProject()).getDebugProcess(res.getProcessHandler());
                                if (process == null)
                                    break;
                                final RemoteConnection connection = new RemoteConnection(true, "127.0.0.1", String.valueOf(read), true);
                                final DebugEnvironment env = new DefaultDebugEnvironment(environment, state, connection, true);
                                SwingUtilities.invokeLater(() -> {
                                    try {
                                        ((DebugProcessImpl) process).reattach(env);
                                        accept.getOutputStream().write(0);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                });
                                read = stream.readInt();
                            }
                        } finally {
                            stream.close();
                        }
                    } finally {
                        accept.close();
                    }
                } catch (EOFException ignored) {
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.setDaemon(true);
        thread.start();
    }
    return res;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JavaTestFrameworkRunnableState(com.intellij.execution.JavaTestFrameworkRunnableState) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ExecutionException(com.intellij.execution.ExecutionException) IOException(java.io.IOException) EOFException(java.io.EOFException) DebugProcess(com.intellij.debugger.engine.DebugProcess) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) EOFException(java.io.EOFException) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugEnvironment(com.intellij.debugger.DebugEnvironment) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Nullable(org.jetbrains.annotations.Nullable)

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