Search in sources :

Example 61 with ExecutionException

use of com.intellij.execution.ExecutionException in project android by JetBrains.

the class AndroidMavenExecutor method generateResources.

public static Map<CompilerMessageCategory, List<String>> generateResources(final Module module) {
    MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
    final MavenRunnerParameters parameters = new MavenRunnerParameters(true, projectsManager.findProject(module).getDirectory(), Collections.singletonList("process-resources"), projectsManager.getExplicitProfiles());
    final Map<CompilerMessageCategory, List<String>> result = new HashMap<CompilerMessageCategory, List<String>>();
    result.put(CompilerMessageCategory.ERROR, new ArrayList<String>());
    try {
        JavaParameters javaParams = ApplicationManager.getApplication().runReadAction(new Computable<JavaParameters>() {

            @Nullable
            @Override
            public JavaParameters compute() {
                try {
                    return MavenExternalParameters.createJavaParameters(module.getProject(), parameters);
                } catch (ExecutionException e) {
                    LOG.info(e);
                    result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
                    return null;
                }
            }
        });
        if (javaParams == null) {
            return result;
        }
        GeneralCommandLine commandLine = javaParams.toCommandLine();
        final StringBuildingOutputProcessor processor = new StringBuildingOutputProcessor();
        boolean success = AndroidUtils.executeCommand(commandLine, processor, WaitingStrategies.WaitForever.getInstance()) == ExecutionStatus.SUCCESS;
        String message = processor.getMessage();
        if (!success) {
            LOG.info(message);
            String lcmessage = message.toLowerCase();
            int buildErrorIndex = lcmessage.indexOf(BUILD_ERROR_INDICATOR);
            if (buildErrorIndex >= 0) {
                result.get(CompilerMessageCategory.ERROR).add(message.substring(buildErrorIndex));
            }
        }
    } catch (ExecutionException e) {
        LOG.info(e);
        result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
    }
    return result;
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) HashMap(com.intellij.util.containers.HashMap) StringBuildingOutputProcessor(org.jetbrains.android.util.StringBuildingOutputProcessor) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 62 with ExecutionException

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

the class GitExecutableDetector method runs.

/**
   * Checks if it is possible to run the specified program.
   * Made protected for tests not to start a process there.
   */
protected boolean runs(@NotNull String exec) {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(exec);
    commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset());
    try {
        CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
        ProcessOutput result = handler.runProcess((int) TimeUnit.SECONDS.toMillis(5));
        return !result.isTimeout();
    } catch (ExecutionException e) {
        return false;
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler)

Example 63 with ExecutionException

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

the class Tool method execute.

public void execute(AnActionEvent event, DataContext dataContext, long executionId, @Nullable final ProcessListener processListener) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return;
    }
    FileDocumentManager.getInstance().saveAllDocuments();
    try {
        if (isUseConsole()) {
            ExecutionEnvironment environment = ExecutionEnvironmentBuilder.create(project, DefaultRunExecutor.getRunExecutorInstance(), new ToolRunProfile(this, dataContext)).build();
            environment.setExecutionId(executionId);
            environment.getRunner().execute(environment, new ProgramRunner.Callback() {

                @Override
                public void processStarted(RunContentDescriptor descriptor) {
                    ProcessHandler processHandler = descriptor.getProcessHandler();
                    if (processHandler != null && processListener != null) {
                        LOG.assertTrue(!processHandler.isStartNotified(), "ProcessHandler is already startNotified, the listener won't be correctly notified");
                        processHandler.addProcessListener(processListener);
                    }
                }
            });
        } else {
            GeneralCommandLine commandLine = createCommandLine(dataContext);
            if (commandLine == null) {
                return;
            }
            OSProcessHandler handler = new OSProcessHandler(commandLine);
            handler.addProcessListener(new ToolProcessAdapter(project, synchronizeAfterExecution(), getName()));
            if (processListener != null) {
                handler.addProcessListener(processListener);
            }
            handler.startNotify();
        }
    } catch (ExecutionException ex) {
        ExecutionErrorDialog.show(ex, ToolsBundle.message("tools.process.start.error"), project);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException)

Example 64 with ExecutionException

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

the class BrowserLauncherAppless method doLaunch.

private boolean doLaunch(@Nullable String url, @NotNull List<String> command, @Nullable WebBrowser browser, @Nullable Project project, @NotNull String[] additionalParameters, @Nullable Runnable launchTask) {
    GeneralCommandLine commandLine = new GeneralCommandLine(command);
    if (url != null && url.startsWith("jar:")) {
        return false;
    }
    if (url != null) {
        commandLine.addParameter(url);
    }
    final BrowserSpecificSettings browserSpecificSettings = browser == null ? null : browser.getSpecificSettings();
    if (browserSpecificSettings != null) {
        commandLine.getEnvironment().putAll(browserSpecificSettings.getEnvironmentVariables());
    }
    addArgs(commandLine, browserSpecificSettings, additionalParameters);
    try {
        Process process = commandLine.createProcess();
        checkCreatedProcess(browser, project, commandLine, process, launchTask);
        return true;
    } catch (ExecutionException e) {
        showError(e.getMessage(), browser, project, null, null);
        return false;
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Example 65 with ExecutionException

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

the class GeneralCommandLine method createProcess.

@NotNull
public Process createProcess() throws ExecutionException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Executing [" + getCommandLineString() + "]");
        LOG.debug("  environment: " + myEnvParams + " (+" + myParentEnvironmentType + ")");
        LOG.debug("  charset: " + myCharset);
    }
    List<String> commands;
    try {
        checkWorkingDirectory();
        if (StringUtil.isEmptyOrSpaces(myExePath)) {
            throw new ExecutionException(IdeBundle.message("run.configuration.error.executable.not.specified"));
        }
        commands = CommandLineUtil.toCommandLine(myExePath, myProgramParams.getList());
    } catch (ExecutionException e) {
        LOG.info(e);
        throw e;
    }
    try {
        return startProcess(commands);
    } catch (IOException e) {
        LOG.info(e);
        throw new ProcessNotCreatedException(e.getMessage(), e, this);
    }
}
Also used : ProcessNotCreatedException(com.intellij.execution.process.ProcessNotCreatedException) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

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