forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: KubernetesResource classes grabbed during build and recorde…
…d at static initialization Signed-off-by: Marc Nuri <marc@marcnuri.com>
- Loading branch information
Showing
3 changed files
with
51 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 3 additions & 20 deletions
23
...l/src/main/java/io/quarkus/kubernetes/client/runtime/KubernetesSerializationRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,14 @@ | ||
package io.quarkus.kubernetes.client.runtime; | ||
|
||
import java.util.HashSet; | ||
import java.util.ServiceLoader; | ||
import java.util.Set; | ||
|
||
import io.fabric8.kubernetes.api.model.KubernetesResource; | ||
import io.fabric8.kubernetes.internal.KubernetesDeserializer; | ||
import io.quarkus.runtime.RuntimeValue; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
|
||
@Recorder | ||
public class KubernetesSerializationRecorder { | ||
|
||
public RuntimeValue<Class<? extends KubernetesResource>[]> scanKubernetesResources() { | ||
final var classLoaders = new ClassLoader[] { | ||
Thread.currentThread().getContextClassLoader(), | ||
KubernetesDeserializer.class.getClassLoader() }; | ||
final Set<Class<? extends KubernetesResource>> resourceClasses = new HashSet<>(); | ||
for (var classLoader : classLoaders) { | ||
if (classLoader == null) { | ||
continue; | ||
} | ||
final var serviceLoader = ServiceLoader.load(KubernetesResource.class, classLoader); | ||
for (var kr : serviceLoader) { | ||
resourceClasses.add(kr.getClass()); | ||
} | ||
} | ||
return new RuntimeValue<>(resourceClasses.<Class<? extends KubernetesResource>> toArray(Class[]::new)); | ||
public RuntimeValue<Class<? extends KubernetesResource>[]> initKubernetesResources( | ||
Class<? extends KubernetesResource>[] resources) { | ||
return new RuntimeValue<>(resources); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ient/spi/src/main/java/io/quarkus/kubernetes/client/spi/KubernetesResourcesBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.kubernetes.client.spi; | ||
|
||
import io.fabric8.kubernetes.api.model.KubernetesResource; | ||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
public final class KubernetesResourcesBuildItem extends SimpleBuildItem { | ||
|
||
private final Class<? extends KubernetesResource>[] resourceClasses; | ||
|
||
public KubernetesResourcesBuildItem(Class<? extends KubernetesResource>[] resourceClasses) { | ||
this.resourceClasses = resourceClasses; | ||
} | ||
|
||
public Class<? extends KubernetesResource>[] getResourceClasses() { | ||
return resourceClasses; | ||
} | ||
} |