Search in sources :

Example 1 with CompilationCanceledException

use of org.jetbrains.kotlin.progress.CompilationCanceledException in project kotlin by JetBrains.

the class CLICompiler method exec.

// Used in maven (see KotlinCompileMojoBase.java)
@SuppressWarnings("WeakerAccess")
@NotNull
public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) {
    printVersionIfNeeded(messageCollector, arguments);
    if (arguments.suppressWarnings) {
        messageCollector = new FilteringMessageCollector(messageCollector, Predicates.equalTo(CompilerMessageSeverity.WARNING));
    }
    reportUnknownExtraFlags(messageCollector, arguments);
    reportUnsupportedJavaVersion(messageCollector, arguments);
    GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector);
    CompilerConfiguration configuration = new CompilerConfiguration();
    configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, groupingCollector);
    setupCommonArgumentsAndServices(configuration, arguments, services);
    setupPlatformSpecificArgumentsAndServices(configuration, arguments, services);
    try {
        ExitCode exitCode = OK;
        int repeatCount = 1;
        if (arguments.repeat != null) {
            try {
                repeatCount = Integer.parseInt(arguments.repeat);
            } catch (NumberFormatException ignored) {
            }
        }
        CompilationCanceledStatus canceledStatus = services.get(CompilationCanceledStatus.class);
        ProgressIndicatorAndCompilationCanceledStatus.setCompilationCanceledStatus(canceledStatus);
        for (int i = 0; i < repeatCount; i++) {
            if (i > 0) {
                K2JVMCompiler.Companion.resetInitStartTime();
            }
            Disposable rootDisposable = Disposer.newDisposable();
            try {
                setIdeaIoUseFallback();
                ExitCode code = doExecute(arguments, configuration, rootDisposable);
                exitCode = groupingCollector.hasErrors() ? COMPILATION_ERROR : code;
            } catch (CompilationCanceledException e) {
                messageCollector.report(CompilerMessageSeverity.INFO, "Compilation was canceled", CompilerMessageLocation.NO_LOCATION);
                return ExitCode.OK;
            } catch (RuntimeException e) {
                Throwable cause = e.getCause();
                if (cause instanceof CompilationCanceledException) {
                    messageCollector.report(CompilerMessageSeverity.INFO, "Compilation was canceled", CompilerMessageLocation.NO_LOCATION);
                    return ExitCode.OK;
                } else {
                    throw e;
                }
            } finally {
                Disposer.dispose(rootDisposable);
            }
        }
        return exitCode;
    } catch (Throwable t) {
        groupingCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(t), CompilerMessageLocation.NO_LOCATION);
        return INTERNAL_ERROR;
    } finally {
        groupingCollector.flush();
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) CompilationCanceledException(org.jetbrains.kotlin.progress.CompilationCanceledException) ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) ProgressIndicatorAndCompilationCanceledStatus(org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus) CompilationCanceledStatus(org.jetbrains.kotlin.progress.CompilationCanceledStatus) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Disposable (com.intellij.openapi.Disposable)1 NotNull (org.jetbrains.annotations.NotNull)1 ExitCode (org.jetbrains.kotlin.cli.common.ExitCode)1 CompilationCanceledException (org.jetbrains.kotlin.progress.CompilationCanceledException)1 CompilationCanceledStatus (org.jetbrains.kotlin.progress.CompilationCanceledStatus)1 ProgressIndicatorAndCompilationCanceledStatus (org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus)1