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 kotlinClassesDir = new File(cachesDir, "classes");
|
||||||
File snapshotsFile = new File(cachesDir, "snapshots.bin");
|
File snapshotsFile = new File(cachesDir, "snapshots.bin");
|
||||||
String classpath = arguments.getClasspath();
|
String classpath = arguments.getClasspath();
|
||||||
MavenICReporter icReporter = MavenICReporter.get(getLog());
|
MavenICReporter icReporter = new MavenICReporter(getLog());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
arguments.setDestination(kotlinClassesDir.getAbsolutePath());
|
arguments.setDestination(kotlinClassesDir.getAbsolutePath());
|
||||||
|
|||||||
+51
-88
@@ -20,121 +20,84 @@ import kotlin.jvm.functions.Function0;
|
|||||||
import org.apache.maven.plugin.logging.Log;
|
import org.apache.maven.plugin.logging.Log;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode;
|
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.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
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_PROPERTY_NAME = "kotlin.compiler.incremental.log.level";
|
||||||
private static final String IC_LOG_LEVEL_NONE = "none";
|
private final Log log;
|
||||||
private static final String IC_LOG_LEVEL_INFO = "info";
|
private final LogLevel logLevel;
|
||||||
private static final String IC_LOG_LEVEL_DEBUG = "debug";
|
|
||||||
|
|
||||||
public static MavenICReporter get(@NotNull final Log log) {
|
private enum LogLevel {
|
||||||
String logLevel = System.getProperty(IC_LOG_LEVEL_PROPERTY_NAME);
|
NONE, INFO, DEBUG
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Set<File> compiledKotlinFiles = new HashSet<>();
|
private final Set<File> compiledKotlinFiles = new HashSet<>();
|
||||||
|
|
||||||
protected boolean isLogEnabled() {
|
public MavenICReporter(@NotNull final Log log) {
|
||||||
return false;
|
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
|
@Override
|
||||||
public void report(Function0<String> getMessage) {
|
public void report(@NotNull Function0<String> getMessage) {
|
||||||
if (isLogEnabled()) {
|
switch (logLevel) {
|
||||||
log(getMessage.invoke());
|
case NONE:
|
||||||
|
break;
|
||||||
|
case INFO:
|
||||||
|
log.info(getMessage.invoke());
|
||||||
|
break;
|
||||||
|
case DEBUG:
|
||||||
|
log.debug(getMessage.invoke());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reportCompileIteration(Collection<? extends File> sourceFiles, ExitCode exitCode) {
|
public void reportVerbose(@NotNull Function0<String> getMessage) {
|
||||||
compiledKotlinFiles.addAll(sourceFiles);
|
if (logLevel == LogLevel.DEBUG) {
|
||||||
if (isLogEnabled()) {
|
log.debug(getMessage.invoke());
|
||||||
log("Kotlin compile iteration: " + pathsAsString(sourceFiles));
|
|
||||||
log("Exit code: " + exitCode.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@NotNull
|
||||||
public Set<File> getCompiledKotlinFiles() {
|
public Set<File> getCompiledKotlinFiles() {
|
||||||
return compiledKotlinFiles;
|
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