Skip to content

Commit

Permalink
Merge pull request #26357 from Sanne/oracleMetaWindows
Browse files Browse the repository at this point in the history
Allow to override the Oracle JDBC metadata for native images also on Windows
  • Loading branch information
Sanne committed Jun 27, 2022
2 parents f94a8d0 + 23f43c3 commit 5f27683
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -106,9 +107,13 @@ void runtimeInitializeDriver(BuildProducer<RuntimeInitializedClassBuildItem> 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<ExcludeConfigBuildItem> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

0 comments on commit 5f27683

Please sign in to comment.