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();
}
}
Aggregations