Revert "Ignore JDBC Drivers artifacts (#22443)" (#24938)

This reverts commit d0bfbde7ad.

Signed-off-by: Václav Muzikář <vmuzikar@redhat.com>
This commit is contained in:
Václav Muzikář 2023-11-22 20:11:06 +01:00 committed by GitHub
parent e13d3264a2
commit 33dd830914
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 140 deletions

View file

@ -18,7 +18,6 @@
package org.keycloak.config.database; package org.keycloak.config.database;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -52,12 +51,6 @@ public final class Database {
return false; return false;
} }
public static Optional<Vendor> getVendorByDbKind(String dbKind) {
return Arrays.stream(Vendor.values())
.filter(v -> v.isOfKind(dbKind))
.findAny();
}
public static Optional<String> getDatabaseKind(String alias) { public static Optional<String> getDatabaseKind(String alias) {
Vendor vendor = DATABASES.get(alias); Vendor vendor = DATABASES.get(alias);

View file

@ -17,13 +17,9 @@
package org.keycloak.quarkus.runtime.configuration; package org.keycloak.quarkus.runtime.configuration;
import org.keycloak.common.Profile; import org.keycloak.common.Profile;
import org.keycloak.config.database.Database;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.keycloak.quarkus.runtime.Environment.getCurrentOrCreateFeatureProfile; import static org.keycloak.quarkus.runtime.Environment.getCurrentOrCreateFeatureProfile;
@ -33,12 +29,9 @@ import static org.keycloak.quarkus.runtime.Environment.getCurrentOrCreateFeature
public class IgnoredArtifacts { public class IgnoredArtifacts {
public static Set<String> getDefaultIgnoredArtifacts() { public static Set<String> getDefaultIgnoredArtifacts() {
return Stream.of( return new Builder()
fips(), .append(fips())
jdbcDrivers() .build();
)
.flatMap(Collection::stream)
.collect(Collectors.toUnmodifiableSet());
} }
// FIPS // FIPS
@ -63,71 +56,23 @@ public class IgnoredArtifacts {
return isFipsEnabled ? FIPS_ENABLED : FIPS_DISABLED; return isFipsEnabled ? FIPS_ENABLED : FIPS_DISABLED;
} }
// JDBC Drivers /**
public static final Set<String> JDBC_H2 = Set.of( * Builder for artifacts aggregation
"io.quarkus:quarkus-jdbc-h2", */
"io.quarkus:quarkus-jdbc-h2-deployment", private static final class Builder {
"com.h2database:h2" private final Set<String> finalIgnoredArtifacts;
);
public static final Set<String> JDBC_POSTGRES = Set.of( public Builder() {
"io.quarkus:quarkus-jdbc-postgresql", this.finalIgnoredArtifacts = new HashSet<>();
"io.quarkus:quarkus-jdbc-postgresql-deployment", }
"org.postgresql:postgresql"
);
public static final Set<String> JDBC_MARIADB = Set.of( public Builder append(Set<String> ignoredArtifacts) {
"io.quarkus:quarkus-jdbc-mariadb", finalIgnoredArtifacts.addAll(ignoredArtifacts);
"io.quarkus:quarkus-jdbc-mariadb-deployment", return this;
"org.mariadb.jdbc:mariadb-java-client" }
);
public static final Set<String> JDBC_MYSQL = Set.of( public Set<String> build() {
"io.quarkus:quarkus-jdbc-mysql", return finalIgnoredArtifacts;
"io.quarkus:quarkus-jdbc-mysql-deployment", }
"mysql:mysql-connector-java"
);
public static final Set<String> JDBC_MSSQL = Set.of(
"io.quarkus:quarkus-jdbc-mssql",
"io.quarkus:quarkus-jdbc-mssql-deployment",
"com.microsoft.sqlserver:mssql-jdbc"
);
public static final Set<String> JDBC_ORACLE = Set.of(
"io.quarkus:quarkus-jdbc-oracle",
"io.quarkus:quarkus-jdbc-oracle-deployment",
"com.oracle.database.jdbc:ojdbc11",
"com.oracle.database.nls:orai18n"
);
public static final Set<String> JDBC_DRIVERS = Stream.of(
JDBC_H2,
JDBC_POSTGRES,
JDBC_MARIADB,
JDBC_MYSQL,
JDBC_MSSQL,
JDBC_ORACLE
)
.flatMap(Collection::stream)
.collect(Collectors.toUnmodifiableSet());
private static Set<String> jdbcDrivers() {
final Database.Vendor vendor = Configuration.getOptionalValue("quarkus.datasource.db-kind")
.flatMap(Database::getVendorByDbKind)
.orElse(Database.Vendor.H2);
final Set<String> jdbcArtifacts = switch (vendor) {
case H2 -> JDBC_H2;
case MYSQL -> JDBC_MYSQL;
case MARIADB -> JDBC_MARIADB;
case POSTGRES -> JDBC_POSTGRES;
case MSSQL -> JDBC_MSSQL;
case ORACLE -> JDBC_ORACLE;
};
final Set<String> allJdbcDrivers = new HashSet<>(JDBC_DRIVERS);
allJdbcDrivers.removeAll(jdbcArtifacts);
return allJdbcDrivers;
} }
} }

View file

@ -17,27 +17,15 @@
package org.keycloak.quarkus.runtime.configuration.test; package org.keycloak.quarkus.runtime.configuration.test;
import org.hamcrest.CoreMatchers;
import org.junit.Test; import org.junit.Test;
import org.keycloak.common.Profile; import org.keycloak.common.Profile;
import org.keycloak.common.profile.PropertiesProfileConfigResolver; import org.keycloak.common.profile.PropertiesProfileConfigResolver;
import org.keycloak.config.DatabaseOptions;
import org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts; import org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts;
import org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider;
import java.util.HashSet;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts.JDBC_H2;
import static org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts.JDBC_MARIADB;
import static org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts.JDBC_MSSQL;
import static org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts.JDBC_MYSQL;
import static org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts.JDBC_ORACLE;
import static org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts.JDBC_POSTGRES;
public class IgnoredArtifactsTest { public class IgnoredArtifactsTest {
@ -61,52 +49,4 @@ public class IgnoredArtifactsTest {
var ignoredArtifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts(); var ignoredArtifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts();
assertThat(ignoredArtifacts.containsAll(IgnoredArtifacts.FIPS_ENABLED), is(true)); assertThat(ignoredArtifacts.containsAll(IgnoredArtifacts.FIPS_ENABLED), is(true));
} }
@Test
public void jdbcH2() {
assertJdbc("h2", JDBC_H2);
}
@Test
public void jdbcMssql() {
assertJdbc("mssql", JDBC_MSSQL);
}
@Test
public void jdbcMariadb() {
assertJdbc("mariadb", JDBC_MARIADB);
}
@Test
public void jdbcMysql() {
assertJdbc("mysql", JDBC_MYSQL);
}
@Test
public void jdbcOracle() {
assertJdbc("oracle", JDBC_ORACLE);
}
@Test
public void jdbcPostgres() {
assertJdbc("postgres", JDBC_POSTGRES);
}
private void assertJdbc(String vendor, Set<String> notIgnored) {
System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + DatabaseOptions.DB.getKey(), vendor);
try {
final var resultArtifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts();
assertThat(String.format("Ignored artifacts does not comply with the specified artifacts for '%s' JDBC driver", vendor),
resultArtifacts,
not(CoreMatchers.hasItems(notIgnored.toArray(new String[0]))));
final var includedArtifacts = new HashSet<>(IgnoredArtifacts.JDBC_DRIVERS);
includedArtifacts.removeAll(notIgnored);
assertThat("Ignored artifacts does not contain items for the other JDBC drivers",
resultArtifacts,
CoreMatchers.hasItems(includedArtifacts.toArray(new String[0])));
} finally {
System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + DatabaseOptions.DB.getKey(), "");
}
}
} }