From c534dc9d55eebbdb1b7152c1f8415d7c7ea9677e Mon Sep 17 00:00:00 2001 From: sudhanshu_raj Date: Thu, 15 Oct 2026 00:46:56 +0530 Subject: [PATCH] Fixed getURI error on windows due to backslash path --- .../initializer/InitializerMessageSource.java | 10 ++++----- .../InitializerMessageSourceTest.java | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/initializer/InitializerMessageSource.java b/api/src/main/java/org/openmrs/module/initializer/InitializerMessageSource.java index a8b190c9c..349a012c8 100644 --- a/api/src/main/java/org/openmrs/module/initializer/InitializerMessageSource.java +++ b/api/src/main/java/org/openmrs/module/initializer/InitializerMessageSource.java @@ -231,8 +231,8 @@ protected Map getMessagePropertyResourcesFromClasspath() { for (Resource resource : coreResources) { Properties properties = new Properties(); OpenmrsUtil.loadProperties(properties, resource.getInputStream()); - ret.put(resource.getURI().toString(), properties); - log.trace("Added " + properties.size() + " from " + resource.getURI().toString()); + ret.put(resource.getURL().toString(), properties); + log.trace("Added " + properties.size() + " from " + resource.getURL().toString()); } // Load modules in their startup order, so these can overwrite each other where appropriate @@ -244,11 +244,11 @@ protected Map getMessagePropertyResourcesFromClasspath() { for (Resource resource : moduleResources) { // Module classpath entries contain other modules and core version libraries. // We need to limit the resources processed to just those defined by this specific module - if (resource.getURI().toString().contains("/" + module.getModuleId() + "/")) { + if (resource.getURL().toString().replace('\\', '/').contains("/" + module.getModuleId() + "/")) { Properties properties = new Properties(); OpenmrsUtil.loadProperties(properties, resource.getInputStream()); - ret.put("classpath:" + resource.getURI().toString(), properties); - log.trace("Added " + properties.size() + " from " + resource.getURI().toString()); + ret.put("classpath:" + resource.getURL().toString(), properties); + log.trace("Added " + properties.size() + " from " + resource.getURL().toString()); } } } diff --git a/api/src/test/java/org/openmrs/module/initializer/InitializerMessageSourceTest.java b/api/src/test/java/org/openmrs/module/initializer/InitializerMessageSourceTest.java index 2c46cfcfd..e6a4c23bb 100644 --- a/api/src/test/java/org/openmrs/module/initializer/InitializerMessageSourceTest.java +++ b/api/src/test/java/org/openmrs/module/initializer/InitializerMessageSourceTest.java @@ -12,11 +12,17 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import java.io.IOException; +import java.net.URISyntaxException; import java.util.Locale; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; public class InitializerMessageSourceTest { @@ -51,4 +57,19 @@ public void getLocaleFromFileBaseName_shouldAllowUnderscoresInDirectory() { Locale.setDefault(Locale.US); assertEquals(Locale.ENGLISH, src.getLocaleFromFileBaseName("/tmp/test_dir/basename")); } + + @Test + public void getURI_shouldFailOnWindowsJarUrlResource() throws IOException { + Resource jarResource = new UrlResource("jar:file:C:\\Users\\test\\.m2\\repository\\module.jar!/messages.properties"); + IOException ex = assertThrows(IOException.class, jarResource::getURI); + assertTrue(ex.getCause() instanceof URISyntaxException); + } + + @Test + public void getURL_shouldSucceedOnWindowsJarUrlResource() throws IOException { + Resource jarResource = new UrlResource( + "jar:file:C:\\Users\\test\\.m2\\repository\\module.jar!/messages_fr.properties"); + String urlString = jarResource.getURL().toString(); + assertEquals("jar:file:C:\\Users\\test\\.m2\\repository\\module.jar!/messages_fr.properties", urlString); + } }