Fix maven plugin after IC build reports were introduced to Gradle
This commit is contained in:
committed by
Zalim Bashorov
parent
b8d9b563a9
commit
d5507734e8
+1
-1
@@ -253,7 +253,7 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
||||
File kotlinClassesDir = new File(cachesDir, "classes");
|
||||
File snapshotsFile = new File(cachesDir, "snapshots.bin");
|
||||
String classpath = arguments.getClasspath();
|
||||
MavenICReporter icReporter = MavenICReporter.get(getLog());
|
||||
MavenICReporter icReporter = new MavenICReporter(getLog());
|
||||
|
||||
try {
|
||||
arguments.setDestination(kotlinClassesDir.getAbsolutePath());
|
||||
|
||||
+51
-88
@@ -20,121 +20,84 @@ 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.incremental.ICReporter;
|
||||
import org.jetbrains.kotlin.incremental.ICReporterBase;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class MavenICReporter implements ICReporter {
|
||||
public class MavenICReporter extends ICReporterBase {
|
||||
private static final String IC_LOG_LEVEL_PROPERTY_NAME = "kotlin.compiler.incremental.log.level";
|
||||
private static final String IC_LOG_LEVEL_NONE = "none";
|
||||
private static final String IC_LOG_LEVEL_INFO = "info";
|
||||
private static final String IC_LOG_LEVEL_DEBUG = "debug";
|
||||
private final Log log;
|
||||
private final LogLevel logLevel;
|
||||
|
||||
public static MavenICReporter get(@NotNull final Log log) {
|
||||
String logLevel = System.getProperty(IC_LOG_LEVEL_PROPERTY_NAME);
|
||||
if (logLevel == null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
logLevel = IC_LOG_LEVEL_DEBUG;
|
||||
}
|
||||
else {
|
||||
logLevel = IC_LOG_LEVEL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if (logLevel.equalsIgnoreCase(IC_LOG_LEVEL_INFO)) {
|
||||
return MavenICReporter.info(log);
|
||||
}
|
||||
else if (logLevel.equalsIgnoreCase(IC_LOG_LEVEL_DEBUG)) {
|
||||
return MavenICReporter.debug(log);
|
||||
}
|
||||
else {
|
||||
if (!logLevel.equalsIgnoreCase(IC_LOG_LEVEL_NONE)) {
|
||||
log.warn("Unknown incremental compilation log level '" + logLevel + "'," +
|
||||
"possible values: " + IC_LOG_LEVEL_NONE + ", " + IC_LOG_LEVEL_INFO + ", " + IC_LOG_LEVEL_DEBUG);
|
||||
}
|
||||
|
||||
return MavenICReporter.noLog();
|
||||
}
|
||||
}
|
||||
|
||||
private static MavenICReporter info(@NotNull final Log log) {
|
||||
return new MavenICReporter() {
|
||||
@Override
|
||||
protected boolean isLogEnabled() {
|
||||
return log.isInfoEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void log(String str) {
|
||||
log.info(str);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static MavenICReporter debug(@NotNull final Log log) {
|
||||
return new MavenICReporter() {
|
||||
@Override
|
||||
protected boolean isLogEnabled() {
|
||||
return log.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void log(String str) {
|
||||
log.debug(str);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static MavenICReporter noLog() {
|
||||
return new MavenICReporter();
|
||||
private enum LogLevel {
|
||||
NONE, INFO, DEBUG
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final Set<File> compiledKotlinFiles = new HashSet<>();
|
||||
|
||||
protected boolean isLogEnabled() {
|
||||
return false;
|
||||
}
|
||||
public MavenICReporter(@NotNull final Log log) {
|
||||
super(null);
|
||||
|
||||
protected void log(String str) {
|
||||
}
|
||||
LogLevel logLevel;
|
||||
if (log.isDebugEnabled()) {
|
||||
logLevel = LogLevel.DEBUG;
|
||||
} else if (log.isInfoEnabled()) {
|
||||
logLevel = LogLevel.INFO;
|
||||
} else {
|
||||
logLevel = LogLevel.NONE;
|
||||
}
|
||||
|
||||
private MavenICReporter() {
|
||||
String userLogLevel = System.getProperty(IC_LOG_LEVEL_PROPERTY_NAME);
|
||||
if (userLogLevel != null) {
|
||||
for (LogLevel enumEntry : LogLevel.values()) {
|
||||
if (enumEntry.name().equalsIgnoreCase(userLogLevel)) {
|
||||
logLevel = enumEntry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
log.warn("Unknown incremental compilation log level '" + logLevel + "'," +
|
||||
"possible values: " + "'none', 'info', 'debug'");
|
||||
}
|
||||
|
||||
this.logLevel = logLevel;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(Function0<String> getMessage) {
|
||||
if (isLogEnabled()) {
|
||||
log(getMessage.invoke());
|
||||
public void report(@NotNull Function0<String> getMessage) {
|
||||
switch (logLevel) {
|
||||
case NONE:
|
||||
break;
|
||||
case INFO:
|
||||
log.info(getMessage.invoke());
|
||||
break;
|
||||
case DEBUG:
|
||||
log.debug(getMessage.invoke());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportCompileIteration(Collection<? extends File> sourceFiles, ExitCode exitCode) {
|
||||
compiledKotlinFiles.addAll(sourceFiles);
|
||||
if (isLogEnabled()) {
|
||||
log("Kotlin compile iteration: " + pathsAsString(sourceFiles));
|
||||
log("Exit code: " + exitCode.toString());
|
||||
public void reportVerbose(@NotNull Function0<String> getMessage) {
|
||||
if (logLevel == LogLevel.DEBUG) {
|
||||
log.debug(getMessage.invoke());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String pathsAsString(Iterable<? extends File> files) {
|
||||
return ICReporter.DefaultImpls.pathsAsString(this, files);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String pathsAsString(File... files) {
|
||||
return ICReporter.DefaultImpls.pathsAsString(this, files);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<File> getCompiledKotlinFiles() {
|
||||
return compiledKotlinFiles;
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user