fixed finalguard when Gradle uses java compiler API directly without forking
All checks were successful
CI / build (push) Successful in 3m50s
All checks were successful
CI / build (push) Successful in 3m50s
This commit is contained in:
@@ -15,11 +15,13 @@ import org.gradle.api.tasks.compile.JavaCompile;
|
||||
|
||||
import javax.tools.Diagnostic;
|
||||
import java.net.URL;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
public class FinalGuardPlugin implements Plugin<Project> {
|
||||
private static final String FINALGUARD_PLUGIN_CONFIGURATION = "finalguard_plugin";
|
||||
private static final String PROPERTY_PREFIX = "net.woggioni.finalguard.diagnostic.";
|
||||
|
||||
@Override
|
||||
public void apply(final Project project) {
|
||||
@@ -52,54 +54,59 @@ public class FinalGuardPlugin implements Plugin<Project> {
|
||||
tasks.withType(JavaCompile.class, javaCompileTask -> {
|
||||
javaCompileTask.doFirst(t -> {
|
||||
final CompileOptions options = javaCompileTask.getOptions();
|
||||
final BiConsumer<String, Diagnostic.Kind> setProperty = (key, diagnosticKind) -> {
|
||||
final String propertyKey = PROPERTY_PREFIX + key;
|
||||
System.setProperty(propertyKey, diagnosticKind.toString());
|
||||
options.getForkOptions().getJvmArgs().add(String.format("-D%s=%s", propertyKey, diagnosticKind));
|
||||
};
|
||||
options.setAnnotationProcessorPath(options.getAnnotationProcessorPath().plus(javacPluginConfiguration));
|
||||
{
|
||||
final Property<Diagnostic.Kind> defaultLevel = finalGuardExtension.getDefaultLevel();
|
||||
if (defaultLevel.isPresent()) {
|
||||
final Diagnostic.Kind diagnosticKind = defaultLevel.get();
|
||||
options.getForkOptions().getJvmArgs().add("-Dnet.woggioni.finalguard.diagnostic.level=" + diagnosticKind);
|
||||
setProperty.accept("level", diagnosticKind);
|
||||
}
|
||||
}
|
||||
{
|
||||
final Property<Diagnostic.Kind> localVariableLevel = finalGuardExtension.getLocalVariableLevel();
|
||||
if (localVariableLevel.isPresent()) {
|
||||
final Diagnostic.Kind diagnosticKind = localVariableLevel.get();
|
||||
options.getForkOptions().getJvmArgs().add("-Dnet.woggioni.finalguard.diagnostic.local.variable.level=" + diagnosticKind);
|
||||
setProperty.accept("local.variable.level", diagnosticKind);
|
||||
}
|
||||
}
|
||||
{
|
||||
final Property<Diagnostic.Kind> methodParameterLevel = finalGuardExtension.getMethodParameterLevel();
|
||||
if (methodParameterLevel.isPresent()) {
|
||||
final Diagnostic.Kind diagnosticKind = methodParameterLevel.get();
|
||||
options.getForkOptions().getJvmArgs().add("-Dnet.woggioni.finalguard.diagnostic.method.param.level=" + diagnosticKind);
|
||||
setProperty.accept("method.param.level", diagnosticKind);
|
||||
}
|
||||
}
|
||||
{
|
||||
final Property<Diagnostic.Kind> forLoopParameterLevel = finalGuardExtension.getForLoopParameterLevel();
|
||||
if (forLoopParameterLevel.isPresent()) {
|
||||
final Diagnostic.Kind diagnosticKind = forLoopParameterLevel.get();
|
||||
options.getForkOptions().getJvmArgs().add("-Dnet.woggioni.finalguard.diagnostic.for.param.level=" + diagnosticKind);
|
||||
setProperty.accept("for.param.level", diagnosticKind);
|
||||
}
|
||||
}
|
||||
{
|
||||
final Property<Diagnostic.Kind> tryParameterLevel = finalGuardExtension.getTryWithResourceLevel();
|
||||
if (tryParameterLevel.isPresent()) {
|
||||
final Diagnostic.Kind diagnosticKind = tryParameterLevel.get();
|
||||
options.getForkOptions().getJvmArgs().add("-Dnet.woggioni.finalguard.diagnostic.try.param.level=" + diagnosticKind);
|
||||
setProperty.accept("try.param.level", diagnosticKind);
|
||||
}
|
||||
}
|
||||
{
|
||||
final Property<Diagnostic.Kind> catchParameterLevel = finalGuardExtension.getCatchParameterLevel();
|
||||
if (catchParameterLevel.isPresent()) {
|
||||
final Diagnostic.Kind diagnosticKind = catchParameterLevel.get();
|
||||
options.getForkOptions().getJvmArgs().add("-Dnet.woggioni.finalguard.diagnostic.catch.param.level=" + diagnosticKind);
|
||||
setProperty.accept("catch.param.level", diagnosticKind);
|
||||
}
|
||||
}
|
||||
{
|
||||
final Property<Diagnostic.Kind> lambdaParameterLevel = finalGuardExtension.getLambdaParameterLevel();
|
||||
if (lambdaParameterLevel.isPresent()) {
|
||||
final Diagnostic.Kind diagnosticKind = lambdaParameterLevel.get();
|
||||
options.getForkOptions().getJvmArgs().add("-Dnet.woggioni.finalguard.diagnostic.lambda.param.level=" + diagnosticKind);
|
||||
setProperty.accept("lambda.param.level", diagnosticKind);
|
||||
}
|
||||
}
|
||||
options.getCompilerArgs().add("-Xplugin:net.woggioni.finalguard.FinalGuardPlugin");
|
||||
|
||||
Reference in New Issue
Block a user