From 23f43c3d3be6f479f86f697888856a8c65d8136d Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 24 Jun 2022 20:44:24 +0100 Subject: [PATCH] Allow to override the Oracle JDBC metadata for native images also on Windows --- .../deployment/OracleMetadataOverrides.java | 13 ++++++--- .../oracle/deployment/RegexMatchTest.java | 29 ++++++++++++++----- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/extensions/jdbc/jdbc-oracle/deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/OracleMetadataOverrides.java b/extensions/jdbc/jdbc-oracle/deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/OracleMetadataOverrides.java index 632df697aec2c..494d9ed1fec0f 100644 --- a/extensions/jdbc/jdbc-oracle/deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/OracleMetadataOverrides.java +++ b/extensions/jdbc/jdbc-oracle/deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/OracleMetadataOverrides.java @@ -35,7 +35,8 @@ public final class OracleMetadataOverrides { static final String DRIVER_JAR_MATCH_REGEX = ".*com\\.oracle\\.database\\.jdbc.*"; - static final String NATIVE_IMAGE_RESOURCE_MATCH_REGEX = "/META-INF/native-image/(?:native-image\\.properties|reflect-config\\.json)"; + static final String NATIVE_IMAGE_RESOURCE_MATCH_REGEX = "/META-INF/native-image/native-image\\.properties"; + static final String NATIVE_IMAGE_REFLECT_CONFIG_MATCH_REGEX = "/META-INF/native-image/reflect-config\\.json"; /** * Should match the contents of {@literal reflect-config.json} @@ -106,9 +107,13 @@ void runtimeInitializeDriver(BuildProducer run } @BuildStep - ExcludeConfigBuildItem excludeOracleDirectives() { - // Excludes both native-image.properties and reflect-config.json, which are reimplemented above - return new ExcludeConfigBuildItem(DRIVER_JAR_MATCH_REGEX, NATIVE_IMAGE_RESOURCE_MATCH_REGEX); + void excludeOracleDirectives(BuildProducer nativeImageExclusions) { + // Excludes both native-image.properties and reflect-config.json, which are reimplemented above. + // N.B. this could be expressed by using a single regex to match both resources, + // but such a regex would include a ? char, which breaks arguments parsing on Windows. + nativeImageExclusions.produce(new ExcludeConfigBuildItem(DRIVER_JAR_MATCH_REGEX, NATIVE_IMAGE_RESOURCE_MATCH_REGEX)); + nativeImageExclusions + .produce(new ExcludeConfigBuildItem(DRIVER_JAR_MATCH_REGEX, NATIVE_IMAGE_REFLECT_CONFIG_MATCH_REGEX)); } @BuildStep diff --git a/extensions/jdbc/jdbc-oracle/deployment/src/test/java/io/quarkus/jdbc/oracle/deployment/RegexMatchTest.java b/extensions/jdbc/jdbc-oracle/deployment/src/test/java/io/quarkus/jdbc/oracle/deployment/RegexMatchTest.java index 5a66b4d51b26a..8bef768890a50 100644 --- a/extensions/jdbc/jdbc-oracle/deployment/src/test/java/io/quarkus/jdbc/oracle/deployment/RegexMatchTest.java +++ b/extensions/jdbc/jdbc-oracle/deployment/src/test/java/io/quarkus/jdbc/oracle/deployment/RegexMatchTest.java @@ -26,20 +26,33 @@ public void jarRegexIsMatching() { } @Test - public void resourceRegexIsMatching() { - //We need to exclude both of these: + public void nativeImageResourceRegexIsMatching() { + //We need to exclude this one: final String RES1 = "/META-INF/native-image/native-image.properties"; - final String RES2 = "/META-INF/native-image/reflect-config.json"; final Pattern pattern = Pattern.compile(OracleMetadataOverrides.NATIVE_IMAGE_RESOURCE_MATCH_REGEX); Assert.assertTrue(pattern.matcher(RES1).find()); - Assert.assertTrue(pattern.matcher(RES2).find()); - //While this one should NOT be ignored: - final String RES3 = "/META-INF/native-image/resource-config.json"; - final String RES4 = "/META-INF/native-image/jni-config.json"; + //While these should NOT be ignored: + final String RES2 = "/META-INF/native-image/resource-config.json"; + final String RES3 = "/META-INF/native-image/jni-config.json"; + Assert.assertFalse(pattern.matcher(RES2).find()); + Assert.assertFalse(pattern.matcher(RES3).find()); + } + + @Test + public void nativeImageReflectConfigRegexIsMatching() { + //We need to exclude this one: + final String RES1 = "/META-INF/native-image/reflect-config.json"; + final Pattern pattern = Pattern.compile(OracleMetadataOverrides.NATIVE_IMAGE_REFLECT_CONFIG_MATCH_REGEX); + + Assert.assertTrue(pattern.matcher(RES1).find()); + + //While these should NOT be ignored: + final String RES2 = "/META-INF/native-image/resource-config.json"; + final String RES3 = "/META-INF/native-image/jni-config.json"; + Assert.assertFalse(pattern.matcher(RES2).find()); Assert.assertFalse(pattern.matcher(RES3).find()); - Assert.assertFalse(pattern.matcher(RES4).find()); } }