Warn in Gradle log when incremental compilation fails

When incremental compilation fails, we currently log it at the `debug`
level (and fall back to non-incremental compilation). This commit will
change it to `warning` so that we can get more user reports, which will
allow us to fix the root cause.

Also make sure the warning includes a stack trace.

Additionally, let ReportSeverity.fromCode() return a non-null value
or throw an exception otherwise as that case is not expected.

^KT-52839 In Progress
This commit is contained in:
Hung Nguyen
2022-06-16 15:56:41 +01:00
committed by teamcity
parent 623f832bfd
commit e01c2bc651
23 changed files with 358 additions and 118 deletions
@@ -20,6 +20,8 @@ import kotlin.jvm.functions.Function0;
import org.apache.maven.plugin.logging.Log;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.ExitCode;
import org.jetbrains.kotlin.build.report.ICReporter;
import org.jetbrains.kotlin.build.report.ICReporterKt;
import org.jetbrains.kotlin.build.report.ICReporterBase;
import java.io.File;
@@ -69,26 +71,31 @@ public class MavenICReporter extends ICReporterBase {
}
@Override
public void report(@NotNull Function0<String> getMessage) {
public void report(@NotNull Function0<String> getMessage, @NotNull ICReporter.ReportSeverity severity) {
switch (logLevel) {
case NONE:
break;
case INFO:
log.info(getMessage.invoke());
if (severity == ICReporter.ReportSeverity.WARNING) {
log.warn(getMessage.invoke());
} else if (severity == ICReporter.ReportSeverity.INFO) {
log.info(getMessage.invoke());
} else if (severity == ICReporter.ReportSeverity.DEBUG) {
// Don't log
} else throw new IllegalArgumentException(severity.toString() + " is not yet handled");
break;
case DEBUG:
log.debug(getMessage.invoke());
if (severity == ICReporter.ReportSeverity.WARNING) {
log.warn(getMessage.invoke());
} else if (severity == ICReporter.ReportSeverity.INFO) {
log.info(getMessage.invoke());
} else if (severity == ICReporter.ReportSeverity.DEBUG) {
log.debug(getMessage.invoke());
} else throw new IllegalArgumentException(severity.toString() + " is not yet handled");
break;
}
}
@Override
public void reportVerbose(@NotNull Function0<String> getMessage) {
if (logLevel == LogLevel.DEBUG) {
log.debug(getMessage.invoke());
}
}
@NotNull
public Set<File> getCompiledKotlinFiles() {
return compiledKotlinFiles;
@@ -97,7 +104,7 @@ public class MavenICReporter extends ICReporterBase {
@Override
public void reportCompileIteration(boolean b, @NotNull Collection<? extends File> sourceFiles, @NotNull ExitCode exitCode) {
compiledKotlinFiles.addAll(sourceFiles);
report(() -> "Kotlin compile iteration: " + pathsAsString(sourceFiles));
report(() -> "Exit code: " + exitCode.toString());
ICReporterKt.info(this, () -> "Kotlin compile iteration: " + pathsAsString(sourceFiles));
ICReporterKt.info(this, () -> "Exit code: " + exitCode.toString());
}
}