diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java index 680449827e0e4..e13ac3ef3d543 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java @@ -104,6 +104,7 @@ import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem; import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.index.IndexingUtil; import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild; @@ -311,6 +312,7 @@ public void configurationDescriptorBuilding( BuildProducer nativeImageResources, BuildProducer hotDeploymentWatchedFiles, BuildProducer persistenceUnitDescriptors, + BuildProducer reflectiveMethods, List dbKindMetadataBuildItems) { if (!hasEntities(jpaModel)) { @@ -348,7 +350,7 @@ public void configurationDescriptorBuilding( handleHibernateORMWithNoPersistenceXml(hibernateOrmConfig, index, persistenceXmlDescriptors, jdbcDataSources, applicationArchivesBuildItem, launchMode.getLaunchMode(), jpaModel, capabilities, systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors, - dbKindMetadataBuildItems); + reflectiveMethods, dbKindMetadataBuildItems); } } @@ -824,6 +826,7 @@ private void handleHibernateORMWithNoPersistenceXml( BuildProducer nativeImageResources, BuildProducer hotDeploymentWatchedFiles, BuildProducer persistenceUnitDescriptors, + BuildProducer reflectiveMethods, List dbKindMetadataBuildItems) { if (!descriptors.isEmpty()) { if (hibernateOrmConfig.isAnyNonPersistenceXmlPropertySet()) { @@ -872,7 +875,7 @@ private void handleHibernateORMWithNoPersistenceXml( jpaModel.getXmlMappings(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME), jdbcDataSources, applicationArchivesBuildItem, launchMode, capabilities, systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors, - storageEngineCollector, dbKindMetadataBuildItems); + reflectiveMethods, storageEngineCollector, dbKindMetadataBuildItems); } else if (!modelClassesAndPackagesForDefaultPersistenceUnit.isEmpty() && (!hibernateOrmConfig.defaultPersistenceUnit().datasource().isPresent() || DataSourceUtil.isDefault(hibernateOrmConfig.defaultPersistenceUnit().datasource().get())) @@ -892,7 +895,7 @@ private void handleHibernateORMWithNoPersistenceXml( jpaModel.getXmlMappings(persistenceUnitEntry.getKey()), jdbcDataSources, applicationArchivesBuildItem, launchMode, capabilities, systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors, - storageEngineCollector, dbKindMetadataBuildItems); + reflectiveMethods, storageEngineCollector, dbKindMetadataBuildItems); } if (storageEngineCollector.size() > 1) { @@ -915,6 +918,7 @@ private static void producePersistenceUnitDescriptorFromConfig( BuildProducer nativeImageResources, BuildProducer hotDeploymentWatchedFiles, BuildProducer persistenceUnitDescriptors, + BuildProducer reflectiveMethods, Set storageEngineCollector, List dbKindMetadataBuildItems) { Optional jdbcDataSource = findJdbcDataSource(persistenceUnitName, persistenceUnitConfig, @@ -943,7 +947,7 @@ private static void producePersistenceUnitDescriptorFromConfig( MultiTenancyStrategy multiTenancyStrategy = getMultiTenancyStrategy(persistenceUnitConfig.multitenant()); collectDialectConfig(persistenceUnitName, persistenceUnitConfig, dbKindMetadataBuildItems, jdbcDataSource, multiTenancyStrategy, - systemProperties, descriptor.getProperties()::setProperty, storageEngineCollector); + systemProperties, reflectiveMethods, descriptor.getProperties()::setProperty, storageEngineCollector); // Physical Naming Strategy persistenceUnitConfig.physicalNamingStrategy().ifPresent( @@ -1134,6 +1138,7 @@ private static void collectDialectConfig(String persistenceUnitName, List dbKindMetadataBuildItems, Optional jdbcDataSource, MultiTenancyStrategy multiTenancyStrategy, BuildProducer systemProperties, + BuildProducer reflectiveMethods, BiConsumer puPropertiesCollector, Set storageEngineCollector) { Optional explicitDialect = persistenceUnitConfig.dialect().dialect(); Optional dbKind = jdbcDataSource.map(JdbcDataSourceBuildItem::getDbKind); @@ -1210,6 +1215,14 @@ private static void collectDialectConfig(String persistenceUnitName, if (dbProductVersion.isPresent()) { puPropertiesCollector.accept(AvailableSettings.JAKARTA_HBM2DDL_DB_VERSION, dbProductVersion.get()); } + + if ((dbKind.isPresent() && DatabaseKind.isPostgreSQL(dbKind.get()) + || (dialect.isPresent() && dialect.get().toLowerCase(Locale.ROOT).contains("postgres")))) { + // Workaround for https://hibernate.atlassian.net/browse/HHH-19063 + reflectiveMethods.produce(new ReflectiveMethodBuildItem( + "Accessed in org.hibernate.engine.jdbc.env.internal.DefaultSchemaNameResolver.determineAppropriateResolverDelegate", + true, "org.postgresql.jdbc.PgConnection", "getSchema")); + } } private static void collectDialectConfigForPersistenceXml(String persistenceUnitName, diff --git a/extensions/jdbc/jdbc-postgresql/deployment/src/main/java/io/quarkus/jdbc/postgresql/deployment/JDBCPostgreSQLProcessor.java b/extensions/jdbc/jdbc-postgresql/deployment/src/main/java/io/quarkus/jdbc/postgresql/deployment/JDBCPostgreSQLProcessor.java index abc4f56e90893..b88ce76447f7e 100644 --- a/extensions/jdbc/jdbc-postgresql/deployment/src/main/java/io/quarkus/jdbc/postgresql/deployment/JDBCPostgreSQLProcessor.java +++ b/extensions/jdbc/jdbc-postgresql/deployment/src/main/java/io/quarkus/jdbc/postgresql/deployment/JDBCPostgreSQLProcessor.java @@ -14,6 +14,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.NativeImageFeatureBuildItem; import io.quarkus.deployment.builditem.SslNativeConfigBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild; @@ -40,9 +41,12 @@ RuntimeReinitializedClassBuildItem runtimeReinitialize() { @BuildStep void registerDriver(BuildProducer jdbcDriver, + BuildProducer resources, SslNativeConfigBuildItem sslNativeConfigBuildItem) { jdbcDriver.produce(new JdbcDriverBuildItem(DatabaseKind.POSTGRESQL, "org.postgresql.Driver", "org.postgresql.xa.PGXADataSource")); + // Accessed in org.postgresql.Driver.loadDefaultProperties + resources.produce(new NativeImageResourceBuildItem("org/postgresql/driverconfig.properties")); } @BuildStep diff --git a/extensions/micrometer/deployment/src/main/java/io/quarkus/micrometer/deployment/MicrometerProcessor.java b/extensions/micrometer/deployment/src/main/java/io/quarkus/micrometer/deployment/MicrometerProcessor.java index 0d9e7d21a6861..aa462457c0bc3 100644 --- a/extensions/micrometer/deployment/src/main/java/io/quarkus/micrometer/deployment/MicrometerProcessor.java +++ b/extensions/micrometer/deployment/src/main/java/io/quarkus/micrometer/deployment/MicrometerProcessor.java @@ -39,6 +39,7 @@ import io.quarkus.deployment.builditem.ShutdownContextBuildItem; import io.quarkus.deployment.builditem.SystemPropertyBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem; import io.quarkus.deployment.logging.LoggingSetupBuildItem; import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem; import io.quarkus.deployment.metrics.MetricsFactoryConsumerBuildItem; @@ -79,6 +80,11 @@ public class MicrometerProcessor { private static final DotName TIMED_INTERCEPTOR = DotName.createSimple(MicrometerTimedInterceptor.class.getName()); private static final DotName METER_TAG_SUPPORT = DotName.createSimple(MeterTagsSupport.class.getName()); + private static final List OPERATING_SYSTEM_BEAN_CLASS_NAMES = List.of( + "com.ibm.lang.management.OperatingSystemMXBean", // J9 + "com.sun.management.OperatingSystemMXBean" // HotSpot + ); + public static class MicrometerEnabled implements BooleanSupplier { MicrometerConfig mConfig; @@ -116,7 +122,8 @@ UnremovableBeanBuildItem registerAdditionalBeans(CombinedIndexBuildItem indexBui BuildProducer providerClasses, BuildProducer reflectiveClasses, BuildProducer additionalBeans, - BuildProducer interceptorBindings) { + BuildProducer interceptorBindings, + BuildProducer reflectiveMethods) { // Create and keep some basic Providers additionalBeans.produce(AdditionalBeanBuildItem.builder() @@ -158,6 +165,14 @@ public List getAdditionalBindings() { "org.HdrHistogram.ConcurrentHistogram") .build()); + for (String beanClassName : OPERATING_SYSTEM_BEAN_CLASS_NAMES) { + String reason = "Accessed by io.micrometer.core.instrument.binder.system.ProcessorMetrics.ProcessorMetrics(java.lang.Iterable)"; + reflectiveMethods.produce(new ReflectiveMethodBuildItem(reason, false, beanClassName, "getCpuLoad")); + reflectiveMethods.produce(new ReflectiveMethodBuildItem(reason, false, beanClassName, "getSystemCpuLoad")); + reflectiveMethods.produce(new ReflectiveMethodBuildItem(reason, false, beanClassName, "getProcessCpuLoad")); + reflectiveMethods.produce(new ReflectiveMethodBuildItem(reason, false, beanClassName, "getProcessCpuTime")); + } + return UnremovableBeanBuildItem.beanTypes(METER_REGISTRY, METER_BINDER, METER_FILTER, METER_REGISTRY_CUSTOMIZER, NAMING_CONVENTION); }