Add MessageCollector#hasErrors, get rid of MessageSeverityCollector
Also fix duplicated wrapping of a message collector into a message severity collector (in CLICompiler and in the beginning of doExecute in K2JVMCompiler/K2JSCompiler)
This commit is contained in:
+4
@@ -28,4 +28,8 @@ public enum CompilerMessageSeverity {
|
||||
|
||||
public static final EnumSet<CompilerMessageSeverity> ERRORS = EnumSet.of(ERROR, EXCEPTION);
|
||||
public static final EnumSet<CompilerMessageSeverity> VERBOSE = EnumSet.of(OUTPUT, LOGGING);
|
||||
|
||||
public boolean isError() {
|
||||
return ERRORS.contains(this);
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -36,4 +36,9 @@ public class FilteringMessageCollector implements MessageCollector {
|
||||
messageCollector.report(severity, message, location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasErrors() {
|
||||
return messageCollector.hasErrors();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-9
@@ -47,19 +47,23 @@ public class GroupingMessageCollector implements MessageCollector {
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
boolean hasError = false;
|
||||
|
||||
Collection<String> keys = sortedKeys();
|
||||
for (String path : keys) {
|
||||
for (Message message : groupedMessages.get(path)) {
|
||||
hasError |= CompilerMessageSeverity.ERRORS.contains(message.severity);
|
||||
@Override
|
||||
public boolean hasErrors() {
|
||||
for (Map.Entry<String, Message> entry : groupedMessages.entries()) {
|
||||
if (entry.getValue().severity.isError()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String path : keys) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
boolean hasErrors = hasErrors();
|
||||
|
||||
for (String path : sortedKeys()) {
|
||||
for (Message message : groupedMessages.get(path)) {
|
||||
if (!hasError || CompilerMessageSeverity.ERRORS.contains(message.severity)) {
|
||||
if (!hasErrors || message.severity.isError()) {
|
||||
delegate.report(message.severity, message.message, message.location);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -19,17 +19,19 @@ package org.jetbrains.kotlin.cli.common.messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface MessageCollector {
|
||||
|
||||
MessageCollector NONE = new MessageCollector() {
|
||||
@Override
|
||||
public void report(
|
||||
@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location
|
||||
) {
|
||||
public void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasErrors() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
|
||||
|
||||
boolean hasErrors();
|
||||
}
|
||||
|
||||
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.messages;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
public class MessageSeverityCollector implements MessageCollector {
|
||||
|
||||
private final MessageCollector delegate;
|
||||
|
||||
private final Set<CompilerMessageSeverity> reportedSeverities = Sets.newHashSet();
|
||||
|
||||
public MessageSeverityCollector(@NotNull MessageCollector delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(
|
||||
@NotNull CompilerMessageSeverity severity,
|
||||
@NotNull String message,
|
||||
@NotNull CompilerMessageLocation location
|
||||
) {
|
||||
delegate.report(severity, message, location);
|
||||
|
||||
reportedSeverities.add(severity);
|
||||
}
|
||||
|
||||
public boolean anyReported(@NotNull CompilerMessageSeverity... severities) {
|
||||
return reportedSeverities.containsAll(Arrays.asList(severities));
|
||||
}
|
||||
}
|
||||
@@ -187,9 +187,8 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
}
|
||||
Disposable rootDisposable = Disposer.newDisposable();
|
||||
try {
|
||||
MessageSeverityCollector severityCollector = new MessageSeverityCollector(groupingCollector);
|
||||
ExitCode code = doExecute(arguments, services, severityCollector, rootDisposable);
|
||||
exitCode = severityCollector.anyReported(CompilerMessageSeverity.ERROR) ? COMPILATION_ERROR : code;
|
||||
ExitCode code = doExecute(arguments, services, groupingCollector, rootDisposable);
|
||||
exitCode = groupingCollector.hasErrors() ? COMPILATION_ERROR : code;
|
||||
}
|
||||
catch (CompilationCanceledException e) {
|
||||
messageCollector.report(CompilerMessageSeverity.INFO, "Compilation was canceled", CompilerMessageLocation.NO_LOCATION);
|
||||
|
||||
+2
-5
@@ -42,10 +42,7 @@ import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
||||
import java.util.*
|
||||
|
||||
|
||||
class AnalyzerWithCompilerReport(collector: MessageCollector) {
|
||||
private val messageCollector: MessageSeverityCollector = MessageSeverityCollector(collector)
|
||||
|
||||
class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector) {
|
||||
lateinit var analysisResult: AnalysisResult
|
||||
|
||||
private fun reportIncompleteHierarchies() {
|
||||
@@ -115,7 +112,7 @@ class AnalyzerWithCompilerReport(collector: MessageCollector) {
|
||||
class SyntaxErrorReport(val isHasErrors: Boolean, val isAllErrorsAtEof: Boolean)
|
||||
|
||||
fun hasErrors(): Boolean {
|
||||
return messageCollector.anyReported(CompilerMessageSeverity.ERROR)
|
||||
return messageCollector.hasErrors()
|
||||
}
|
||||
|
||||
interface Analyzer {
|
||||
|
||||
+9
@@ -21,12 +21,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class PrintingMessageCollector implements MessageCollector {
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public static final MessageCollector PLAIN_TEXT_TO_SYSTEM_ERR =
|
||||
new PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false);
|
||||
|
||||
private final boolean verbose;
|
||||
private final PrintStream errStream;
|
||||
private final MessageRenderer messageRenderer;
|
||||
private boolean hasErrors = false;
|
||||
|
||||
public PrintingMessageCollector(@NotNull PrintStream errStream, @NotNull MessageRenderer messageRenderer, boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
@@ -42,6 +44,13 @@ public class PrintingMessageCollector implements MessageCollector {
|
||||
) {
|
||||
if (!verbose && CompilerMessageSeverity.VERBOSE.contains(severity)) return;
|
||||
|
||||
hasErrors |= severity.isError();
|
||||
|
||||
errStream.println(messageRenderer.render(severity, message, location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasErrors() {
|
||||
return hasErrors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,10 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants;
|
||||
import org.jetbrains.kotlin.cli.common.messages.*;
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CompilerJarLocator;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
@@ -74,27 +77,24 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
return new K2JSCompilerArguments();
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected ExitCode doExecute(
|
||||
@NotNull K2JSCompilerArguments arguments,
|
||||
@NotNull Services services,
|
||||
@NotNull MessageCollector messageCollector,
|
||||
@NotNull final MessageCollector messageCollector,
|
||||
@NotNull Disposable rootDisposable
|
||||
) {
|
||||
final MessageSeverityCollector messageSeverityCollector = new MessageSeverityCollector(messageCollector);
|
||||
|
||||
if (arguments.freeArgs.isEmpty()) {
|
||||
if (arguments.version) {
|
||||
return OK;
|
||||
}
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "Specify at least one source file or directory", NO_LOCATION);
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify at least one source file or directory", NO_LOCATION);
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageSeverityCollector);
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
||||
|
||||
CompilerJarLocator locator = services.get(CompilerJarLocator.class);
|
||||
if (locator != null) {
|
||||
@@ -109,21 +109,21 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
List<KtFile> sourcesFiles = environmentForJS.getSourceFiles();
|
||||
|
||||
if (arguments.outputFile == null) {
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "Specify output file via -output", CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify output file via -output", CompilerMessageLocation.NO_LOCATION);
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) {
|
||||
if (messageCollector.hasErrors()) {
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
if (sourcesFiles.isEmpty()) {
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION);
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
if (arguments.verbose) {
|
||||
reportCompiledSourcesList(messageSeverityCollector, sourcesFiles);
|
||||
reportCompiledSourcesList(messageCollector, sourcesFiles);
|
||||
}
|
||||
|
||||
File outputFile = new File(arguments.outputFile);
|
||||
@@ -132,14 +132,14 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
if (config.checkLibFilesAndReportErrors(new Function1<String, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(String message) {
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
})) {
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
AnalyzerWithCompilerReport analyzerWithCompilerReport = analyzeAndReportErrors(messageSeverityCollector, sourcesFiles, config);
|
||||
AnalyzerWithCompilerReport analyzerWithCompilerReport = analyzeAndReportErrors(messageCollector, sourcesFiles, config);
|
||||
if (analyzerWithCompilerReport.hasErrors()) {
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
if (arguments.outputPrefix != null) {
|
||||
outputPrefixFile = new File(arguments.outputPrefix);
|
||||
if (!outputPrefixFile.exists()) {
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR,
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"Output prefix file '" + arguments.outputPrefix + "' not found",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
@@ -165,7 +165,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
if (arguments.outputPostfix != null) {
|
||||
outputPostfixFile = new File(arguments.outputPostfix);
|
||||
if (!outputPostfixFile.exists()) {
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR,
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"Output postfix file '" + arguments.outputPostfix + "' not found",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
@@ -185,7 +185,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
|
||||
|
||||
AnalyzerWithCompilerReport.Companion.reportDiagnostics(translationResult.getDiagnostics(), messageSeverityCollector);
|
||||
AnalyzerWithCompilerReport.Companion.reportDiagnostics(translationResult.getDiagnostics(), messageCollector);
|
||||
|
||||
if (!(translationResult instanceof TranslationResult.Success)) return ExitCode.COMPILATION_ERROR;
|
||||
|
||||
@@ -193,7 +193,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
OutputFileCollection outputFiles = successResult.getOutputFiles(outputFile, outputPrefixFile, outputPostfixFile);
|
||||
|
||||
if (outputFile.isDirectory()) {
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR,
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"Cannot open output file '" + outputFile.getPath() + "': is a directory",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
@@ -206,7 +206,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
|
||||
|
||||
OutputUtilsKt.writeAll(outputFiles, outputDir, messageSeverityCollector);
|
||||
OutputUtilsKt.writeAll(outputFiles, outputDir, messageCollector);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -47,17 +47,16 @@ import java.util.concurrent.TimeUnit
|
||||
|
||||
class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
override fun doExecute(arguments: K2JVMCompilerArguments, services: Services, messageCollector: MessageCollector, rootDisposable: Disposable): ExitCode {
|
||||
val messageSeverityCollector = MessageSeverityCollector(messageCollector)
|
||||
val paths = if (arguments.kotlinHome != null)
|
||||
KotlinPathsFromHomeDir(File(arguments.kotlinHome))
|
||||
else
|
||||
PathUtil.getKotlinPathsForCompiler()
|
||||
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.LOGGING, "Using Kotlin home directory " + paths.homePath, CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Using Kotlin home directory " + paths.homePath, CompilerMessageLocation.NO_LOCATION)
|
||||
PerformanceCounter.setTimeCounterEnabled(arguments.reportPerf)
|
||||
|
||||
val configuration = CompilerConfiguration()
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageSeverityCollector)
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
|
||||
|
||||
if (IncrementalCompilation.isEnabled()) {
|
||||
val incrementalCompilationComponents = services.get(IncrementalCompilationComponents::class.java)
|
||||
@@ -73,32 +72,32 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
MessageCollectorUtil.reportException(messageSeverityCollector, t)
|
||||
MessageCollectorUtil.reportException(messageCollector, t)
|
||||
return INTERNAL_ERROR
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
PluginCliParser.loadPlugins(arguments, configuration)
|
||||
}
|
||||
catch (e: PluginCliOptionProcessingException) {
|
||||
val message = e.message + "\n\n" + cliPluginUsageString(e.pluginId, e.options)
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION)
|
||||
return INTERNAL_ERROR
|
||||
}
|
||||
catch (e: CliOptionProcessingException) {
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, e.message!!, CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, e.message!!, CompilerMessageLocation.NO_LOCATION)
|
||||
return INTERNAL_ERROR
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
MessageCollectorUtil.reportException(messageSeverityCollector, t)
|
||||
MessageCollectorUtil.reportException(messageCollector, t)
|
||||
return INTERNAL_ERROR
|
||||
}
|
||||
|
||||
|
||||
if (arguments.script) {
|
||||
if (arguments.freeArgs.isEmpty()) {
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "Specify script source path to evaluate", CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR, "Specify script source path to evaluate", CompilerMessageLocation.NO_LOCATION
|
||||
)
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
configuration.addKotlinSourceRoot(arguments.freeArgs.get(0))
|
||||
@@ -138,16 +137,16 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
|
||||
putAdvancedOptions(configuration, arguments)
|
||||
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment", CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment", CompilerMessageLocation.NO_LOCATION)
|
||||
try {
|
||||
val destination = arguments.destination
|
||||
|
||||
if (arguments.module != null) {
|
||||
val sanitizedCollector = FilteringMessageCollector(messageSeverityCollector, `in`(CompilerMessageSeverity.VERBOSE))
|
||||
val sanitizedCollector = FilteringMessageCollector(messageCollector, `in`(CompilerMessageSeverity.VERBOSE))
|
||||
val moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.module, sanitizedCollector)
|
||||
|
||||
if (destination != null) {
|
||||
messageSeverityCollector.report(
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.WARNING,
|
||||
"The '-d' option with a directory destination is ignored because '-module' is specified",
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
@@ -161,14 +160,14 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
configuration.put(JVMConfigurationKeys.MODULE_XML_FILE, moduleFile)
|
||||
|
||||
val environment = createCoreEnvironment(rootDisposable, configuration)
|
||||
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR
|
||||
if (messageCollector.hasErrors()) return COMPILATION_ERROR
|
||||
|
||||
KotlinToJVMBytecodeCompiler.compileModules(environment, directory)
|
||||
}
|
||||
else if (arguments.script) {
|
||||
val scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size)
|
||||
val environment = createCoreEnvironment(rootDisposable, configuration)
|
||||
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR
|
||||
if (messageCollector.hasErrors()) return COMPILATION_ERROR
|
||||
|
||||
return KotlinToJVMBytecodeCompiler.compileAndExecuteScript(environment, paths, scriptArgs)
|
||||
}
|
||||
@@ -183,13 +182,13 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
|
||||
val environment = createCoreEnvironment(rootDisposable, configuration)
|
||||
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR
|
||||
if (messageCollector.hasErrors()) return COMPILATION_ERROR
|
||||
|
||||
if (environment.getSourceFiles().isEmpty()) {
|
||||
if (arguments.version) {
|
||||
return OK
|
||||
}
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION)
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
|
||||
@@ -204,7 +203,11 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
return OK
|
||||
}
|
||||
catch (e: CompilationException) {
|
||||
messageSeverityCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e), MessageUtil.psiElementToMessageLocation(e.element))
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.EXCEPTION,
|
||||
OutputMessageUtil.renderException(e),
|
||||
MessageUtil.psiElementToMessageLocation(e.element)
|
||||
)
|
||||
return INTERNAL_ERROR
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.io.IOException;
|
||||
|
||||
public abstract class AbstractModuleXmlParserTest extends TestCase {
|
||||
|
||||
protected void doTest(String xmlPath) throws IOException {
|
||||
protected static void doTest(String xmlPath) throws IOException {
|
||||
File txtFile = new File(FileUtil.getNameWithoutExtension(xmlPath) + ".txt");
|
||||
|
||||
ModuleScriptData result = ModuleXmlParser.parseModuleScript(xmlPath, new MessageCollector() {
|
||||
@@ -43,6 +43,11 @@ public abstract class AbstractModuleXmlParserTest extends TestCase {
|
||||
) {
|
||||
throw new AssertionError(MessageRenderer.PLAIN_FULL_PATHS.render(severity, message, location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasErrors() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
});
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -689,8 +689,10 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
||||
}
|
||||
|
||||
class MessageCollectorAdapter(private val context: CompileContext) : MessageCollector {
|
||||
private var hasErrors = false
|
||||
|
||||
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
|
||||
hasErrors = hasErrors or severity.isError
|
||||
var prefix = ""
|
||||
if (severity == EXCEPTION) {
|
||||
prefix = INTERNAL_ERROR_PREFIX
|
||||
@@ -705,6 +707,8 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
||||
))
|
||||
}
|
||||
|
||||
override fun hasErrors(): Boolean = hasErrors
|
||||
|
||||
private fun renderLocationIfNeeded(location: CompilerMessageLocation): String {
|
||||
if (location == CompilerMessageLocation.NO_LOCATION) return ""
|
||||
|
||||
|
||||
+8
-1
@@ -687,11 +687,18 @@ private fun <T: Any> ExtraPropertiesExtension.getOrNull(id: String): T? {
|
||||
}
|
||||
|
||||
class GradleMessageCollector(val logger: Logger, val outputCollector: OutputItemsCollector? = null) : MessageCollector {
|
||||
private var hasErrors = false
|
||||
|
||||
override fun hasErrors() = hasErrors
|
||||
|
||||
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
|
||||
val text = with(StringBuilder()) {
|
||||
append(when (severity) {
|
||||
in CompilerMessageSeverity.VERBOSE -> "v"
|
||||
in CompilerMessageSeverity.ERRORS -> "e"
|
||||
in CompilerMessageSeverity.ERRORS -> {
|
||||
hasErrors = true
|
||||
"e"
|
||||
}
|
||||
CompilerMessageSeverity.INFO -> "i"
|
||||
CompilerMessageSeverity.WARNING -> "w"
|
||||
else -> throw IllegalArgumentException("Unknown CompilerMessageSeverity: $severity")
|
||||
|
||||
+1
-2
@@ -35,7 +35,6 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.component.repository.ComponentDependency;
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageSeverityCollector;
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
@@ -158,7 +157,7 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo {
|
||||
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, new MessageSeverityCollector(messageCollector));
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
||||
|
||||
List<File> deps = new ArrayList<File>();
|
||||
|
||||
|
||||
+7
@@ -24,11 +24,17 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
|
||||
public class MavenPluginLogMessageCollector implements MessageCollector {
|
||||
private final Log log;
|
||||
private boolean hasErrors = false;
|
||||
|
||||
public MavenPluginLogMessageCollector(Log log) {
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasErrors() {
|
||||
return hasErrors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
|
||||
String path = location.getPath();
|
||||
@@ -39,6 +45,7 @@ public class MavenPluginLogMessageCollector implements MessageCollector {
|
||||
if (CompilerMessageSeverity.VERBOSE.contains(severity)) {
|
||||
log.debug(text);
|
||||
} else if (CompilerMessageSeverity.ERRORS.contains(severity)) {
|
||||
hasErrors = true;
|
||||
log.error(text);
|
||||
} else if (severity == CompilerMessageSeverity.INFO) {
|
||||
log.info(text);
|
||||
|
||||
Reference in New Issue
Block a user