Exit code is COMPILATION_ERROR whenever an error was reported through a message collector
This commit is contained in:
+11
@@ -18,10 +18,13 @@ package org.jetbrains.jet.cli.common.messages;
|
||||
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public class PrintingMessageCollector implements MessageCollector {
|
||||
|
||||
@@ -32,6 +35,8 @@ public class PrintingMessageCollector implements MessageCollector {
|
||||
// File path (nullable) -> error message
|
||||
private final Multimap<String, String> groupedMessages = LinkedHashMultimap.create();
|
||||
|
||||
private final Set<CompilerMessageSeverity> reportedSeverities = Sets.newHashSet();
|
||||
|
||||
public PrintingMessageCollector(PrintStream errStream,
|
||||
MessageRenderer messageRenderer,
|
||||
boolean verbose) {
|
||||
@@ -44,6 +49,8 @@ public class PrintingMessageCollector implements MessageCollector {
|
||||
public void report(@NotNull CompilerMessageSeverity severity,
|
||||
@NotNull String message,
|
||||
@NotNull CompilerMessageLocation location) {
|
||||
reportedSeverities.add(severity);
|
||||
|
||||
String text = messageRenderer.render(severity, message, location);
|
||||
if (severity == CompilerMessageSeverity.LOGGING || severity == CompilerMessageSeverity.OUTPUT) {
|
||||
if (!verbose) {
|
||||
@@ -74,4 +81,8 @@ public class PrintingMessageCollector implements MessageCollector {
|
||||
public void setVerbose(boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
public boolean anyReported(@NotNull CompilerMessageSeverity... severities) {
|
||||
return reportedSeverities.containsAll(Arrays.asList(severities));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.COMPILATION_ERROR;
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.OK;
|
||||
import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
|
||||
|
||||
public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
@@ -87,7 +89,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
|
||||
Config config = getConfig(arguments, project);
|
||||
if (analyzeAndReportErrors(messageCollector, environmentForJS.getSourceFiles(), config)) {
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
String outputFile = arguments.outputFile;
|
||||
@@ -132,7 +134,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
// for example inside a mvn plugin we need to see the stack trace
|
||||
return ExitCode.INTERNAL_ERROR;
|
||||
}
|
||||
return ExitCode.OK;
|
||||
return messageCollector.anyReported(CompilerMessageSeverity.ERROR) ? COMPILATION_ERROR : OK;
|
||||
}
|
||||
|
||||
private static boolean analyzeAndReportErrors(@NotNull PrintingMessageCollector messageCollector,
|
||||
|
||||
@@ -118,27 +118,26 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
File jar = arguments.jar != null ? new File(arguments.jar) : null;
|
||||
File outputDir = arguments.outputDir != null ? new File(arguments.outputDir) : null;
|
||||
|
||||
boolean noErrors;
|
||||
if (arguments.module != null) {
|
||||
boolean oldVerbose = messageCollector.isVerbose();
|
||||
messageCollector.setVerbose(false);
|
||||
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(paths, arguments.module, messageCollector);
|
||||
messageCollector.setVerbose(oldVerbose);
|
||||
File directory = new File(arguments.module).getParentFile();
|
||||
noErrors = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules,
|
||||
KotlinToJVMBytecodeCompiler.compileModules(configuration, modules,
|
||||
directory, jar, outputDir,
|
||||
arguments.includeRuntime);
|
||||
}
|
||||
else if (arguments.script) {
|
||||
List<String> scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size());
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, configuration);
|
||||
noErrors = KotlinToJVMBytecodeCompiler.compileAndExecuteScript(paths, environment, scriptArgs);
|
||||
KotlinToJVMBytecodeCompiler.compileAndExecuteScript(paths, environment, scriptArgs);
|
||||
}
|
||||
else {
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, configuration);
|
||||
noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, jar, outputDir, arguments.includeRuntime);
|
||||
KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, jar, outputDir, arguments.includeRuntime);
|
||||
}
|
||||
return noErrors ? OK : COMPILATION_ERROR;
|
||||
return messageCollector.anyReported(CompilerMessageSeverity.ERROR) ? COMPILATION_ERROR : OK;
|
||||
}
|
||||
catch (CompilationException e) {
|
||||
messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(e),
|
||||
|
||||
Reference in New Issue
Block a user