Search in sources :

Example 1 with RuntimeConfigurationError

use of com.intellij.execution.configurations.RuntimeConfigurationError in project intellij-plugins by JetBrains.

the class DartCommandLineRunnerParameters method check.

public void check(@NotNull final Project project) throws RuntimeConfigurationError {
    // check sdk
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (sdk == null) {
        throw new RuntimeConfigurationError(DartBundle.message("dart.sdk.is.not.configured"), () -> DartConfigurable.openDartSettings(project));
    }
    // check main dart file
    getDartFileOrDirectory();
    // check working directory
    if (!StringUtil.isEmptyOrSpaces(myWorkingDirectory)) {
        final VirtualFile workDir = LocalFileSystem.getInstance().findFileByPath(myWorkingDirectory);
        if (workDir == null || !workDir.isDirectory()) {
            throw new RuntimeConfigurationError(DartBundle.message("work.dir.does.not.exist", FileUtil.toSystemDependentName(myWorkingDirectory)));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 2 with RuntimeConfigurationError

use of com.intellij.execution.configurations.RuntimeConfigurationError in project intellij-plugins by JetBrains.

the class DartCommandLineRunningState method doStartProcess.

protected ProcessHandler doStartProcess(@Nullable final String overriddenMainFilePath) throws ExecutionException {
    final GeneralCommandLine commandLine = createCommandLine(overriddenMainFilePath);
    // Workaround for "Observatory listening on ..." message that is concatenated (without line break) with the message following it
    final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine) {

        @Override
        public void coloredTextAvailable(@NotNull String text, @NotNull Key attributes) {
            if (text.startsWith(DartConsoleFilter.OBSERVATORY_LISTENING_ON)) {
                text += "\n";
            }
            super.coloredTextAvailable(text, attributes);
        }
    };
    processHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void onTextAvailable(final ProcessEvent event, final Key outputType) {
            final String prefix = DartConsoleFilter.OBSERVATORY_LISTENING_ON + "http://";
            final String text = event.getText().trim();
            if (text.startsWith(prefix)) {
                processHandler.removeProcessListener(this);
                final String url = "http://" + text.substring(prefix.length());
                for (Consumer<String> consumer : myObservatoryUrlConsumers) {
                    consumer.consume(url);
                }
            }
        }
    });
    // Check for and display any analysis errors when we launch a Dart app.
    final Project project = getEnvironment().getProject();
    try {
        final DartRunConfiguration dartRunConfiguration = (DartRunConfiguration) getEnvironment().getRunProfile();
        final VirtualFile launchFile = dartRunConfiguration.getRunnerParameters().getDartFileOrDirectory();
        String launchTitle = "Analysis issues with " + dartRunConfiguration.getName();
        DartExecutionHelper.displayIssues(project, launchFile, launchTitle, dartRunConfiguration.getIcon());
    } catch (RuntimeConfigurationError error) {
        DartExecutionHelper.clearIssueNotifications(project);
    }
    ProcessTerminatedListener.attach(processHandler, getEnvironment().getProject());
    return processHandler;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) DartRunConfiguration(com.jetbrains.lang.dart.ide.runner.base.DartRunConfiguration) Consumer(com.intellij.util.Consumer) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) Key(com.intellij.openapi.util.Key)

Example 3 with RuntimeConfigurationError

use of com.intellij.execution.configurations.RuntimeConfigurationError in project intellij-plugins by JetBrains.

the class DartRunner method doExecuteDartDebug.

private RunContentDescriptor doExecuteDartDebug(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env, @Nullable final String dasExecutionContextId) throws RuntimeConfigurationError, ExecutionException {
    final DartSdk sdk = DartSdk.getDartSdk(env.getProject());
    // already checked
    assert (sdk != null);
    final RunProfile runConfiguration = env.getRunProfile();
    final VirtualFile contextFileOrDir;
    VirtualFile currentWorkingDirectory;
    final ExecutionResult executionResult;
    final String debuggingHost;
    final int observatoryPort;
    if (runConfiguration instanceof DartRunConfigurationBase) {
        contextFileOrDir = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().getDartFileOrDirectory();
        final String cwd = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().computeProcessWorkingDirectory(env.getProject());
        currentWorkingDirectory = LocalFileSystem.getInstance().findFileByPath((cwd));
        executionResult = state.execute(env.getExecutor(), this);
        if (executionResult == null) {
            return null;
        }
        debuggingHost = null;
        observatoryPort = ((DartCommandLineRunningState) state).getObservatoryPort();
    } else if (runConfiguration instanceof DartRemoteDebugConfiguration) {
        final String path = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getDartProjectPath();
        contextFileOrDir = LocalFileSystem.getInstance().findFileByPath(path);
        if (contextFileOrDir == null) {
            throw new RuntimeConfigurationError("Folder not found: " + FileUtil.toSystemDependentName(path));
        }
        currentWorkingDirectory = contextFileOrDir;
        executionResult = null;
        debuggingHost = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getHost();
        observatoryPort = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getPort();
    } else {
        LOG.error("Unexpected run configuration: " + runConfiguration.getClass().getName());
        return null;
    }
    FileDocumentManager.getInstance().saveAllDocuments();
    final XDebuggerManager debuggerManager = XDebuggerManager.getInstance(env.getProject());
    final XDebugSession debugSession = debuggerManager.startSession(env, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            final DartUrlResolver dartUrlResolver = getDartUrlResolver(env.getProject(), contextFileOrDir);
            return new DartVmServiceDebugProcess(session, StringUtil.notNullize(debuggingHost, "localhost"), observatoryPort, executionResult, dartUrlResolver, dasExecutionContextId, runConfiguration instanceof DartRemoteDebugConfiguration, getTimeout(), currentWorkingDirectory);
        }
    });
    return debugSession.getRunContentDescriptor();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) DartRunConfigurationBase(com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile) NotNull(org.jetbrains.annotations.NotNull) DartVmServiceDebugProcess(com.jetbrains.lang.dart.ide.runner.server.vmService.DartVmServiceDebugProcess) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartRemoteDebugConfiguration(com.jetbrains.lang.dart.ide.runner.server.DartRemoteDebugConfiguration) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 4 with RuntimeConfigurationError

use of com.intellij.execution.configurations.RuntimeConfigurationError in project intellij-plugins by JetBrains.

the class DartRunner method doExecute.

@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
    final String executorId = env.getExecutor().getId();
    if (!DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)) {
        LOG.error("Unexpected executor id: " + executorId);
        return null;
    }
    try {
        final String dasExecutionContextId;
        final RunProfile runConfig = env.getRunProfile();
        if (runConfig instanceof DartRunConfigurationBase && DartAnalysisServerService.getInstance(env.getProject()).serverReadyForRequest(env.getProject())) {
            final String path = ((DartRunConfigurationBase) runConfig).getRunnerParameters().getFilePath();
            // already checked
            assert path != null;
            dasExecutionContextId = DartAnalysisServerService.getInstance(env.getProject()).execution_createContext(path);
        } else {
            // remote debug or can't start DAS
            dasExecutionContextId = null;
        }
        return doExecuteDartDebug(state, env, dasExecutionContextId);
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
}
Also used : DartRunConfigurationBase(com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase) RunProfile(com.intellij.execution.configurations.RunProfile) ExecutionException(com.intellij.execution.ExecutionException) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 5 with RuntimeConfigurationError

use of com.intellij.execution.configurations.RuntimeConfigurationError in project intellij-plugins by JetBrains.

the class DartCommandLineRunningState method setupParameters.

private void setupParameters(@NotNull final GeneralCommandLine commandLine, @Nullable final String overriddenMainFilePath) throws ExecutionException {
    int customObservatoryPort = -1;
    final String vmOptions = myRunnerParameters.getVMOptions();
    if (vmOptions != null) {
        final StringTokenizer vmOptionsTokenizer = new CommandLineTokenizer(vmOptions);
        while (vmOptionsTokenizer.hasMoreTokens()) {
            final String vmOption = vmOptionsTokenizer.nextToken();
            commandLine.addParameter(vmOption);
            try {
                if (vmOption.equals("--enable-vm-service") || vmOption.equals("--observe")) {
                    // default port, see https://www.dartlang.org/tools/dart-vm/
                    customObservatoryPort = 8181;
                } else if (vmOption.startsWith("--enable-vm-service:")) {
                    customObservatoryPort = parseIntBeforeSlash(vmOption.substring("--enable-vm-service:".length()));
                } else if (vmOption.startsWith("--observe:")) {
                    customObservatoryPort = parseIntBeforeSlash(vmOption.substring("--observe:".length()));
                }
            } catch (NumberFormatException ignore) {
            /**/
            }
        }
    }
    if (myRunnerParameters.isCheckedMode()) {
        commandLine.addParameter(DartiumUtil.CHECKED_MODE_OPTION);
    }
    final VirtualFile dartFile;
    try {
        dartFile = myRunnerParameters.getDartFileOrDirectory();
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
    if (DefaultDebugExecutor.EXECUTOR_ID.equals(getEnvironment().getExecutor().getId())) {
        commandLine.addParameter("--pause_isolates_on_start");
    }
    if (customObservatoryPort > 0) {
        myObservatoryPort = customObservatoryPort;
    } else {
        try {
            myObservatoryPort = NetUtils.findAvailableSocketPort();
        } catch (IOException e) {
            throw new ExecutionException(e);
        }
        commandLine.addParameter("--enable-vm-service:" + myObservatoryPort);
        if (getEnvironment().getRunner() instanceof DartCoverageProgramRunner) {
            commandLine.addParameter("--pause-isolates-on-exit");
        }
    }
    commandLine.addParameter(FileUtil.toSystemDependentName(overriddenMainFilePath == null ? dartFile.getPath() : overriddenMainFilePath));
    final String arguments = myRunnerParameters.getArguments();
    if (arguments != null) {
        StringTokenizer argumentsTokenizer = new CommandLineTokenizer(arguments);
        while (argumentsTokenizer.hasMoreTokens()) {
            commandLine.addParameter(argumentsTokenizer.nextToken());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) DartCoverageProgramRunner(com.jetbrains.lang.dart.coverage.DartCoverageProgramRunner) CommandLineTokenizer(com.intellij.execution.configurations.CommandLineTokenizer)

Aggregations

RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)53 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 Test (org.junit.Test)16 Module (com.intellij.openapi.module.Module)9 File (java.io.File)7 ExecutionException (com.intellij.execution.ExecutionException)6 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)5 PsiFile (com.intellij.psi.PsiFile)5 RuntimeConfigurationWarning (com.intellij.execution.configurations.RuntimeConfigurationWarning)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)4 Sdk (com.intellij.openapi.projectRoots.Sdk)4 NotNull (org.jetbrains.annotations.NotNull)4 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 JSFile (com.intellij.lang.javascript.psi.JSFile)3 Project (com.intellij.openapi.project.Project)3 PsiElement (com.intellij.psi.PsiElement)3 DartSdk (com.jetbrains.lang.dart.sdk.DartSdk)3 UserSpecifiedPathDeploymentSource (com.google.cloud.tools.intellij.appengine.cloud.flexible.UserSpecifiedPathDeploymentSource)2 MalformedYamlFileException (com.google.cloud.tools.intellij.appengine.project.MalformedYamlFileException)2