[jOOQ/jOOQ#13399] jOOQ-checker should system property defaults that

apply to the entire checked code
This commit is contained in:
Lukas Eder 2022-06-02 21:16:56 +02:00
parent c98f4cf6f7
commit 1d943c9f58
3 changed files with 27 additions and 10 deletions

View File

@ -47,6 +47,7 @@ import java.io.PrintWriter;
import java.util.EnumSet;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
@ -92,6 +93,9 @@ final class Tools {
EnumSet<SQLDialect> allowed = EnumSet.noneOf(SQLDialect.class);
EnumSet<SQLDialect> required = EnumSet.noneOf(SQLDialect.class);
defaults("org.jooq.checker.dialects.allow", allowed);
defaults("org.jooq.checker.dialects.require", required);
boolean evaluateRequire = true;
while (enclosing != null) {
Allow allow = enclosing.getAnnotation(Allow.class);
@ -157,6 +161,14 @@ final class Tools {
return null;
}
private static void defaults(String property, EnumSet<SQLDialect> set) {
Stream.of(System.getProperty(property, "").split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(s -> SQLDialect.valueOf(s.toUpperCase()))
.forEach(set::add);
}
static final <T> T checkPlainSQL(
MethodInvocationTree node,
Supplier<Element> enclosingSupplier,

View File

@ -68,6 +68,9 @@
<annotationProcessor>org.jooq.checker.SQLDialectChecker</annotationProcessor>
<!-- <annotationProcessor>org.jooq.checker.PlainSQLChecker</annotationProcessor> -->
</annotationProcessors>
<compilerArgs>
<arg>-J-Dorg.jooq.checker.dialects.allow=HSQLDB</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
@ -99,6 +102,7 @@
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
<arg>-XDorg.jooq.checker.dialects.allow=HSQLDB</arg>
</compilerArgs>
</configuration>
<dependencies>

View File

@ -13,16 +13,17 @@ import org.jooq.impl.DSL;
// The class requires the H2, MYSQL, and POSTGRES_9_5 families
// The inherited @Allow annotation from the package allows only the MYSQL family, though.
// The system property also allows HSQLDB
@Require({ H2, MYSQL, POSTGRES_9_5 })
public class SQLDialectCheckerTests {
// @Allow = MYSQL (inherited from package)
// @Allow = { HSQLDB (inherited from the system property), MYSQL (inherited from package) }
// @Require = { H2, MYSQL, POSTGRES_9_5 }
public static void doesntCompileBecauseOnlyMySQLIsAllowed() {
public static void compilesBecauseOnlyHSQLDBIsAllowed() {
DSL.array(2);
}
// @Allow = { MYSQL (inherited from package), POSTGRES_9_4 }
// @Allow = { HSQLDB (inherited from the system property), MYSQL (inherited from package), POSTGRES_9_4 }
// @Require = { POSTGRES_9_4 }
@Allow(POSTGRES_9_4)
@Require(POSTGRES_9_4)
@ -30,7 +31,7 @@ public class SQLDialectCheckerTests {
DSL.cube(DSL.inline(1));
}
// @Allow = { MYSQL (inherited from package), POSTGRES_9_5 }
// @Allow = { HSQLDB (inherited from the system property), MYSQL (inherited from package), POSTGRES_9_5 }
// @Require = { POSTGRES_9_5 }
@Allow(POSTGRES_9_5)
@Require(POSTGRES_9_5)
@ -38,7 +39,7 @@ public class SQLDialectCheckerTests {
DSL.cube(DSL.inline(1));
}
// @Allow = { MYSQL (inherited from package), POSTGRES }
// @Allow = { HSQLDB (inherited from the system property), MYSQL (inherited from package), POSTGRES }
// @Require = { POSTGRES }
@Allow(POSTGRES)
@Require(POSTGRES)
@ -46,7 +47,7 @@ public class SQLDialectCheckerTests {
DSL.cube(DSL.inline(1));
}
// @Allow = { MYSQL (inherited from package), POSTGRES }
// @Allow = { HSQLDB (inherited from the system property), MYSQL (inherited from package), POSTGRES }
// @Require = { POSTGRES_9_4 }
@Allow(POSTGRES)
@Require(POSTGRES_9_4)
@ -54,7 +55,7 @@ public class SQLDialectCheckerTests {
DSL.cube(DSL.inline(1));
}
// @Allow = { MYSQL (inherited from package), POSTGRES_9_4 }
// @Allow = { HSQLDB (inherited from the system property), MYSQL (inherited from package), POSTGRES_9_4 }
// @Require = { POSTGRES }
@Allow(POSTGRES_9_4)
@Require(POSTGRES)
@ -62,14 +63,14 @@ public class SQLDialectCheckerTests {
DSL.lateral(DSL.dual());
}
// @Allow = { H2, MYSQL (inherited from package) }
// @Allow = { H2, HSQLDB (inherited from the system property), MYSQL (inherited from package) }
// @Require = { H2, MYSQL, POSTGRES_9_5 } (inherited from class)
@Allow(H2)
public static void doesntCompileBecauseMYSQLIsNotSupported() {
DSL.array(2);
}
// @Allow = { H2, MYSQL (inherited from package) }
// @Allow = { H2, HSQLDB (inherited from the system property), MYSQL (inherited from package) }
// @Require = { H2 }
@Allow(H2)
@Require(H2)
@ -77,7 +78,7 @@ public class SQLDialectCheckerTests {
DSL.array(2);
}
// @Allow = { H2, MYSQL (inherited from package) }
// @Allow = { H2, HSQLDB (inherited from the system property), MYSQL (inherited from package) }
// @Require = { H2 }
@Allow(H2)
@Require({ H2, ORACLE })