From 4123b7a91ea86dc922eea457cbd7f15e263f6806 Mon Sep 17 00:00:00 2001 From: mposolda Date: Thu, 10 Sep 2020 17:54:35 +0200 Subject: [PATCH] KEYCLOAK-11678 Remove dummy resource. Adding keycloak-services and liquibase to jandex indexing --- quarkus/deployment/pom.xml | 63 ---------------- .../deployment/LiquibaseProcessor.java | 74 +++++++++---------- .../keycloak/services/resources/Dummy.java | 23 ------ .../src/main/resources/application.properties | 7 +- .../services/error/KeycloakErrorHandler.java | 1 - .../services/util/ObjectMapperResolver.java | 1 - 6 files changed, 40 insertions(+), 129 deletions(-) delete mode 100644 quarkus/runtime/src/main/java/org/keycloak/services/resources/Dummy.java diff --git a/quarkus/deployment/pom.xml b/quarkus/deployment/pom.xml index 4578bcb648..74d1d58de7 100644 --- a/quarkus/deployment/pom.xml +++ b/quarkus/deployment/pom.xml @@ -95,69 +95,6 @@ - - org.apache.maven.plugins - maven-dependency-plugin - - - extract-liquibase-for-indexing - generate-sources - - unpack-dependencies - - - org.liquibase - ${project.build.directory}/liquibase-extracted - - - - - - org.jboss.jandex - jandex-maven-plugin - - - make-index - - jandex - - process-sources - - liquibase.idx - false - - - ${project.build.directory}/liquibase-extracted - - - - - - - - maven-resources-plugin - - - copy-liquibase-index - process-resources - - copy-resources - - - ${project.build.directory}/classes/ - - - ${project.build.directory}/liquibase-extracted - - META-INF/liquibase.idx - - false - - - - - - maven-surefire-plugin diff --git a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/LiquibaseProcessor.java b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/LiquibaseProcessor.java index 239874f27d..796c104b4f 100644 --- a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/LiquibaseProcessor.java +++ b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/LiquibaseProcessor.java @@ -1,7 +1,5 @@ package org.keycloak.quarkus.deployment; -import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; @@ -11,11 +9,11 @@ import java.util.List; import java.util.Map; import java.util.Set; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; -import org.jboss.jandex.Index; -import org.jboss.jandex.IndexReader; +import org.jboss.jandex.IndexView; import org.keycloak.connections.jpa.updater.liquibase.lock.CustomInsertLockRecordGenerator; import org.keycloak.connections.jpa.updater.liquibase.lock.CustomLockDatabaseChangeLogGenerator; import org.keycloak.connections.jpa.updater.liquibase.lock.DummyLockService; @@ -37,48 +35,44 @@ class LiquibaseProcessor { @Record(ExecutionTime.STATIC_INIT) @BuildStep - void configure(KeycloakRecorder recorder) { + void configure(KeycloakRecorder recorder, CombinedIndexBuildItem indexBuildItem) { DotName liquibaseServiceName = DotName.createSimple(LiquibaseService.class.getName()); Map> services = new HashMap<>(); - try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/liquibase.idx")) { - IndexReader reader = new IndexReader(in); - Index index = reader.read(); - for (Class c : Arrays.asList(liquibase.diff.compare.DatabaseObjectComparator.class, - liquibase.parser.NamespaceDetails.class, - liquibase.precondition.Precondition.class, - Database.class, - ChangeLogParser.class, - liquibase.change.Change.class, - liquibase.snapshot.SnapshotGenerator.class, - liquibase.changelog.ChangeLogHistoryService.class, - liquibase.datatype.LiquibaseDataType.class, - liquibase.executor.Executor.class, - LockService.class, - SqlGenerator.class)) { - List impls = new ArrayList<>(); - services.put(c.getName(), impls); - Set classes = new HashSet<>(); - if (c.isInterface()) { - classes.addAll(index.getAllKnownImplementors(DotName.createSimple(c.getName()))); - } else { - classes.addAll(index.getAllKnownSubclasses(DotName.createSimple(c.getName()))); + IndexView index = indexBuildItem.getIndex(); + + for (Class c : Arrays.asList(liquibase.diff.compare.DatabaseObjectComparator.class, + liquibase.parser.NamespaceDetails.class, + liquibase.precondition.Precondition.class, + Database.class, + ChangeLogParser.class, + liquibase.change.Change.class, + liquibase.snapshot.SnapshotGenerator.class, + liquibase.changelog.ChangeLogHistoryService.class, + liquibase.datatype.LiquibaseDataType.class, + liquibase.executor.Executor.class, + LockService.class, + SqlGenerator.class)) { + List impls = new ArrayList<>(); + services.put(c.getName(), impls); + Set classes = new HashSet<>(); + if (c.isInterface()) { + classes.addAll(index.getAllKnownImplementors(DotName.createSimple(c.getName()))); + } else { + classes.addAll(index.getAllKnownSubclasses(DotName.createSimple(c.getName()))); + } + for (ClassInfo found : classes) { + if (Modifier.isAbstract(found.flags()) || + Modifier.isInterface(found.flags()) || + !found.hasNoArgsConstructor() || + !Modifier.isPublic(found.flags())) { + continue; } - for (ClassInfo found : classes) { - if (Modifier.isAbstract(found.flags()) || - Modifier.isInterface(found.flags()) || - !found.hasNoArgsConstructor() || - !Modifier.isPublic(found.flags())) { - continue; - } - AnnotationInstance annotationInstance = found.classAnnotation(liquibaseServiceName); - if (annotationInstance == null || !annotationInstance.value("skip").asBoolean()) { - impls.add(found.name().toString()); - } + AnnotationInstance annotationInstance = found.classAnnotation(liquibaseServiceName); + if (annotationInstance == null || !annotationInstance.value("skip").asBoolean()) { + impls.add(found.name().toString()); } } - } catch (IOException cause) { - throw new RuntimeException("Failed to get liquibase jandex index", cause); } services.put(Logger.class.getName(), Arrays.asList(KeycloakLogger.class.getName())); diff --git a/quarkus/runtime/src/main/java/org/keycloak/services/resources/Dummy.java b/quarkus/runtime/src/main/java/org/keycloak/services/resources/Dummy.java deleted file mode 100644 index d68eb4c2f5..0000000000 --- a/quarkus/runtime/src/main/java/org/keycloak/services/resources/Dummy.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.keycloak.services.resources; - -import javax.inject.Inject; -import javax.persistence.EntityManagerFactory; -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -/** - * Quarkus doesn't pick up the Application if there's no JAX-RS endpoints - */ -@Path("/dummy") -public class Dummy { - - @Inject - EntityManagerFactory entityManagerFactory; - - // ...and doesn't load Resteasy providers unless there is at least one resource method - @GET - public String hello() { - return "Hello World!"; - } - -} diff --git a/quarkus/server/src/main/resources/application.properties b/quarkus/server/src/main/resources/application.properties index 090ff45bbd..d7b3f36262 100644 --- a/quarkus/server/src/main/resources/application.properties +++ b/quarkus/server/src/main/resources/application.properties @@ -6,4 +6,9 @@ quarkus.package.user-providers-directory=../providers quarkus.http.root-path=/auth quarkus.application.name=Keycloak -quarkus.banner.enabled=false \ No newline at end of file +quarkus.banner.enabled=false + +quarkus.index-dependency.kc-services-idx.group-id=org.keycloak +quarkus.index-dependency.kc-services-idx.artifact-id=keycloak-services +quarkus.index-dependency.liquibase-idx.group-id=org.liquibase +quarkus.index-dependency.liquibase-idx.artifact-id=liquibase-core diff --git a/services/src/main/java/org/keycloak/services/error/KeycloakErrorHandler.java b/services/src/main/java/org/keycloak/services/error/KeycloakErrorHandler.java index a2b23091f3..b38c5a1347 100644 --- a/services/src/main/java/org/keycloak/services/error/KeycloakErrorHandler.java +++ b/services/src/main/java/org/keycloak/services/error/KeycloakErrorHandler.java @@ -37,7 +37,6 @@ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -@Provider public class KeycloakErrorHandler implements ExceptionMapper { private static final Logger logger = Logger.getLogger(KeycloakErrorHandler.class); diff --git a/services/src/main/java/org/keycloak/services/util/ObjectMapperResolver.java b/services/src/main/java/org/keycloak/services/util/ObjectMapperResolver.java index 6aa1169ba0..ebeee69045 100755 --- a/services/src/main/java/org/keycloak/services/util/ObjectMapperResolver.java +++ b/services/src/main/java/org/keycloak/services/util/ObjectMapperResolver.java @@ -35,7 +35,6 @@ import java.util.stream.Stream; * @author Bill Burke * @version $Revision: 1 $ */ -@Provider public class ObjectMapperResolver implements ContextResolver { protected ObjectMapper mapper = new ObjectMapper();