-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TRUNK-6252: Conditional resource path should be interpreted as a globs #4830
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ | |
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.net.URLStreamHandlerFactory; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.security.CodeSource; | ||
import java.security.ProtectionDomain; | ||
|
@@ -362,7 +365,7 @@ static boolean shouldResourceBeIncluded(Module module, URL fileUrl, String openm | |
boolean include = true; | ||
|
||
for (ModuleConditionalResource conditionalResource : module.getConditionalResources()) { | ||
if (fileUrl.getPath().matches(".*" + conditionalResource.getPath() + "$")) { | ||
if (isMatchingConditionalResource(module, fileUrl, conditionalResource)) { | ||
//if a resource matches a path of contidionalResource then it must meet all conditions | ||
include = false; | ||
|
||
|
@@ -405,6 +408,41 @@ static boolean shouldResourceBeIncluded(Module module, URL fileUrl, String openm | |
return include; | ||
} | ||
|
||
static boolean isMatchingConditionalResource(Module module, URL fileUrl, ModuleConditionalResource conditionalResource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you intentionally decide not to make this method private? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it was intentional, I think it was important to unit test this method separately from |
||
FileSystem fileSystem = FileSystems.getDefault(); | ||
if (ModuleUtil.matchRequiredVersions(module.getConfigVersion(), "2.0")) { | ||
return fileSystem.getPathMatcher(String.format("glob:**/%s", preprocessGlobPattern(conditionalResource.getPath()))) | ||
.matches(Paths.get(fileUrl.getPath())); | ||
} | ||
return fileUrl.getPath().matches(".*" + conditionalResource.getPath() + "$"); | ||
} | ||
|
||
private static String preprocessGlobPattern(String globPattern) { | ||
if (globPattern == null || globPattern.isEmpty()) { | ||
return ""; | ||
} | ||
|
||
globPattern = globPattern.replace("\\", "/"); | ||
globPattern = globPattern.replaceAll("//+", "/"); | ||
|
||
// Remove "file:" prefix if present | ||
if (globPattern.startsWith("file:/")) { | ||
globPattern = globPattern.substring(5); | ||
} | ||
|
||
// Remove drive letter if present (e.g., C:/) | ||
if (globPattern.matches("^[a-zA-Z]:/.*")) { | ||
globPattern = globPattern.substring(2); | ||
} | ||
|
||
if (globPattern.startsWith("/")) { | ||
globPattern = globPattern.substring(1); | ||
} | ||
|
||
return globPattern; | ||
} | ||
|
||
|
||
/** | ||
* Get the library cache folder for the given module. Each module has a different cache folder | ||
* to ease cleanup when unloading a module while openmrs is running | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Top level configuration element. | ||
--> | ||
<!ELEMENT module ( | ||
(id), | ||
(name), | ||
(version), | ||
(package), | ||
(author), | ||
(description), | ||
(activator), | ||
(updateURL?), | ||
(require_version?), | ||
(require_database_version?), | ||
(require_modules?), | ||
(aware_of_modules?), | ||
(start_before_modules?), | ||
(mandatory?), | ||
(library*), | ||
(extension*), | ||
(advice*), | ||
(privilege*), | ||
(globalProperty*), | ||
(dwr?), | ||
(servlet*), | ||
(filter*), | ||
(filter-mapping*), | ||
(messages*), | ||
(mappingFiles?), | ||
(packagesWithMappedClasses?), | ||
(conditionalResources?) | ||
)> | ||
<!ATTLIST module configVersion CDATA #FIXED "2.0"> | ||
|
||
<!ELEMENT id (#PCDATA)> | ||
<!ELEMENT name (#PCDATA)> | ||
<!ELEMENT version (#PCDATA)> | ||
<!ELEMENT package (#PCDATA)> | ||
<!ELEMENT author (#PCDATA)> | ||
<!ELEMENT description (#PCDATA)> | ||
<!ELEMENT activator (#PCDATA)> | ||
<!ELEMENT updateURL (#PCDATA)> | ||
<!ELEMENT require_version (#PCDATA)> | ||
<!ELEMENT require_database_version (#PCDATA)> | ||
|
||
<!ELEMENT require_modules (require_module+)> | ||
<!ELEMENT require_module (#PCDATA)> | ||
<!ATTLIST require_module version CDATA #IMPLIED> | ||
|
||
<!ELEMENT aware_of_modules (aware_of_module+)> | ||
<!ELEMENT aware_of_module (#PCDATA)> | ||
<!ATTLIST aware_of_module version CDATA #IMPLIED> | ||
|
||
<!ELEMENT start_before_modules (module+)> | ||
<!ELEMENT start_before_module (#PCDATA)> | ||
<!ATTLIST start_before_module version CDATA #IMPLIED> | ||
|
||
<!ELEMENT mandatory (#PCDATA)> | ||
|
||
<!ELEMENT library EMPTY> | ||
<!ATTLIST library | ||
id CDATA #REQUIRED | ||
path CDATA #REQUIRED | ||
type (resources|library) #REQUIRED | ||
> | ||
|
||
<!ELEMENT extension (point, class)> | ||
<!ELEMENT advice (point, class)> | ||
<!ELEMENT point (#PCDATA)> | ||
<!ELEMENT class (#PCDATA)> | ||
|
||
<!ELEMENT privilege (name, description)> | ||
|
||
<!ELEMENT globalProperty (property, defaultValue?, description)> | ||
<!ELEMENT property (#PCDATA)> | ||
<!ELEMENT defaultValue (#PCDATA)> | ||
|
||
<!ELEMENT dwr (allow, signatures?)> | ||
<!ELEMENT allow (create*, convert*)> | ||
|
||
<!ELEMENT create (param, include*)> | ||
<!ATTLIST create creator CDATA #REQUIRED javascript CDATA #REQUIRED> | ||
|
||
<!ELEMENT param EMPTY> | ||
<!ATTLIST param name CDATA #REQUIRED value CDATA #REQUIRED> | ||
|
||
<!ELEMENT include EMPTY> | ||
<!ATTLIST include method CDATA #REQUIRED> | ||
|
||
<!ELEMENT convert (param?)> | ||
<!ATTLIST convert converter CDATA #REQUIRED match CDATA #REQUIRED> | ||
|
||
<!ELEMENT signatures (#PCDATA)> | ||
|
||
<!ELEMENT servlet (servlet-name, servlet-class, init-param*)> | ||
<!ELEMENT servlet-name (#PCDATA)> | ||
<!ELEMENT servlet-class (#PCDATA)> | ||
|
||
<!ELEMENT filter (filter-name, filter-class, init-param*)> | ||
<!ELEMENT filter-name (#PCDATA)> | ||
<!ELEMENT filter-class (#PCDATA)> | ||
<!ELEMENT init-param (param-name, param-value)> | ||
<!ELEMENT param-name (#PCDATA)> | ||
<!ELEMENT param-value (#PCDATA)> | ||
|
||
<!ELEMENT filter-mapping (filter-name, (url-pattern | servlet-name))> | ||
<!ELEMENT url-pattern (#PCDATA)> | ||
|
||
<!ELEMENT messages (lang, file)> | ||
<!ELEMENT lang (#PCDATA)> | ||
<!ELEMENT file (#PCDATA)> | ||
|
||
<!ELEMENT mappingFiles (#PCDATA)> | ||
<!ELEMENT packagesWithMappedClasses (#PCDATA)> | ||
|
||
<!ELEMENT conditionalResources (conditionalResource+)> | ||
<!-- Beginning with configVersion="2.0", the "path" in <conditionalResource> uses glob syntax instead of regex. --> | ||
<!ELEMENT conditionalResource (path, (openmrsVersion | modules))> | ||
<!ELEMENT path (#PCDATA)> | ||
<!ELEMENT openmrsVersion (#PCDATA)> | ||
<!ELEMENT modules (module+)> | ||
<!ELEMENT module (moduleId, version)> | ||
<!ELEMENT moduleId (#PCDATA)> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put
@since
annotations on these? https://openmrs.atlassian.net/wiki/spaces/docs/pages/25477044/Java+Conventions#New-Public-Methods-and-ClassesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, added