|
1 | 1 | package io.quarkus.restclient.deployment; |
2 | 2 |
|
| 3 | +import static org.jboss.jandex.gizmo2.Jandex2Gizmo.classDescOf; |
| 4 | + |
3 | 5 | import java.io.Closeable; |
| 6 | +import java.lang.constant.ClassDesc; |
4 | 7 | import java.lang.reflect.Modifier; |
5 | 8 | import java.util.ArrayList; |
6 | 9 | import java.util.Arrays; |
|
79 | 82 | import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; |
80 | 83 | import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem; |
81 | 84 | import io.quarkus.deployment.pkg.NativeConfig; |
82 | | -import io.quarkus.gizmo.MethodDescriptor; |
83 | | -import io.quarkus.gizmo.ResultHandle; |
| 85 | +import io.quarkus.gizmo2.Const; |
| 86 | +import io.quarkus.gizmo2.Expr; |
| 87 | +import io.quarkus.gizmo2.creator.BlockCreator; |
| 88 | +import io.quarkus.gizmo2.desc.ConstructorDesc; |
| 89 | +import io.quarkus.gizmo2.desc.MethodDesc; |
84 | 90 | import io.quarkus.restclient.NoopHostnameVerifier; |
85 | 91 | import io.quarkus.restclient.config.RegisteredRestClient; |
86 | 92 | import io.quarkus.restclient.config.RestClientsConfig; |
@@ -276,34 +282,30 @@ void createBeans( |
276 | 282 | // The spec is not clear whether we should add superinterfaces too - let's keep aligned with SmallRye for now |
277 | 283 | configurator.addType(restClient.getClassInfo().name()); |
278 | 284 | configurator.addQualifier(REST_CLIENT); |
279 | | - List<String> clientProviders = checkRestClientProviders(restClient.getClassInfo(), restClientProviders); |
| 285 | + List<ClassDesc> clientProviders = checkRestClientProviders(restClient.getClassInfo(), restClientProviders); |
280 | 286 | configurator.scope(restClientBuildTimeConfig.getScope(capabilities, restClient.getClassInfo()) |
281 | 287 | .orElse(BuiltinScope.DEPENDENT).getInfo()); |
282 | | - configurator.creator(m -> { |
| 288 | + configurator.creator(cg -> { |
| 289 | + BlockCreator bc = cg.createMethod(); |
| 290 | + |
283 | 291 | // return new RestClientBase(proxyType, baseUri).create(); |
284 | | - ResultHandle interfaceHandle = m.loadClassFromTCCL(restClient.getClassInfo().name().toString()); |
285 | | - ResultHandle baseUriHandle = restClient.getDefaultBaseUri().isPresent() |
286 | | - ? m.load(restClient.getDefaultBaseUri().get()) |
287 | | - : m.loadNull(); |
288 | | - ResultHandle configKeyHandle = restClient.getConfigKey().isPresent() ? m.load(restClient.getConfigKey().get()) |
289 | | - : m.loadNull(); |
290 | | - ResultHandle restClientProvidersHandle; |
| 292 | + Const rtInterface = Const.of(classDescOf(restClient.getClassInfo())); // TODO load from TCCL |
| 293 | + Const rtBaseUri = restClient.getDefaultBaseUri().isPresent() |
| 294 | + ? Const.of(restClient.getDefaultBaseUri().get()) |
| 295 | + : Const.ofNull(String.class); |
| 296 | + Const rtConfigKey = restClient.getConfigKey().isPresent() |
| 297 | + ? Const.of(restClient.getConfigKey().get()) |
| 298 | + : Const.ofNull(String.class); |
| 299 | + Expr rtRestClientProviders; |
291 | 300 | if (!clientProviders.isEmpty()) { |
292 | | - restClientProvidersHandle = m.newArray(Class.class, clientProviders.size()); |
293 | | - for (int i = 0; i < clientProviders.size(); i++) { |
294 | | - m.writeArrayValue(restClientProvidersHandle, i, m.loadClassFromTCCL(clientProviders.get(i))); |
295 | | - } |
| 301 | + rtRestClientProviders = bc.newArray(Class.class, clientProviders, Const::of); // TODO load from TCCL |
296 | 302 | } else { |
297 | | - restClientProvidersHandle = m.loadNull(); |
| 303 | + rtRestClientProviders = Const.ofNull(Class[].class); |
298 | 304 | } |
299 | | - ResultHandle baseHandle = m.newInstance( |
300 | | - MethodDescriptor.ofConstructor(RestClientBase.class, Class.class, String.class, |
301 | | - String.class, |
302 | | - Class[].class), |
303 | | - interfaceHandle, baseUriHandle, configKeyHandle, restClientProvidersHandle); |
304 | | - ResultHandle ret = m.invokeVirtualMethod( |
305 | | - MethodDescriptor.ofMethod(RestClientBase.class, "create", Object.class), baseHandle); |
306 | | - m.returnValue(ret); |
| 305 | + Expr base = bc.new_( |
| 306 | + ConstructorDesc.of(RestClientBase.class, Class.class, String.class, String.class, Class[].class), |
| 307 | + rtInterface, rtBaseUri, rtConfigKey, rtRestClientProviders); |
| 308 | + bc.return_(bc.invokeVirtual(MethodDesc.of(RestClientBase.class, "create", Object.class), base)); |
307 | 309 | }); |
308 | 310 | configurator.destroyer(BeanDestroyer.CloseableDestroyer.class); |
309 | 311 | syntheticBeans.produce(configurator.done()); |
@@ -338,10 +340,12 @@ private boolean isRequired(Capabilities capabilities, |
338 | 340 | && metricsCapability.get().metricsSupported(MetricsFactory.MICROMETER))); |
339 | 341 | } |
340 | 342 |
|
341 | | - private static List<String> checkRestClientProviders(ClassInfo classInfo, |
| 343 | + private static List<ClassDesc> checkRestClientProviders(ClassInfo classInfo, |
342 | 344 | List<RestClientPredicateProviderBuildItem> restClientProviders) { |
343 | | - return restClientProviders.stream().filter(p -> p.appliesTo(classInfo)) |
344 | | - .map(p -> p.getProviderClass()).collect(Collectors.toList()); |
| 345 | + return restClientProviders.stream() |
| 346 | + .filter(p -> p.appliesTo(classInfo)) |
| 347 | + .map(p -> ClassDesc.of(p.getProviderClass())) |
| 348 | + .toList(); |
345 | 349 | } |
346 | 350 |
|
347 | 351 | @BuildStep |
|
0 commit comments