public class ModuleUtil extends Object
Modifier and Type | Method and Description |
---|---|
static Boolean |
allowAdmin() |
static Boolean |
checkForModuleUpdates()
Iterates over the modules and checks each update.rdf file for an update
|
protected static void |
checkMandatoryModulesStarted()
Looks at the <moduleid>.mandatory properties and at the currently started modules to make
sure that all mandatory modules have been started successfully.
|
protected static void |
checkOpenmrsCoreModulesStarted()
Looks at the list of modules in
ModuleConstants.CORE_MODULES to make sure that all
modules that are core to OpenMRS are started and have at least a minimum version that OpenMRS
needs. |
static void |
checkRequiredVersion(String version,
String versionRange)
This method is an enhancement of
compareVersion(String, String) and adds support for
wildcard characters and upperbounds. |
static int |
compareVersion(String version,
String value)
Compares
version to value version and value are strings like
1.9.2.0 Returns 0 if either version or value is null. |
static void |
expandJar(File fileToExpand,
File tmpModuleDir,
String name,
boolean keepFullPath)
Expand the given
fileToExpand jar to the tmpModuleFile directory
If name is null, the entire jar is expanded. |
static URL |
file2url(File file)
Utility method to convert a
File object to a local URL. |
static File |
getDevelopmentDirectory(String moduleId)
Gets the root folder of a module's sources during development
|
static List<String> |
getMandatoryModules()
Returns all modules that are marked as mandatory.
|
static Module |
getModuleForPath(String path)
Gets the module that should handle a path.
|
static File |
getModuleRepository()
Gets the folder where modules are stored.
|
static Collection<String> |
getPackagesFromFile(File file)
This loops over all FILES in this jar to get the package names.
|
static String |
getPathForResource(Module module,
String path)
Takes a global path and returns the local path within the specified module.
|
static InputStream |
getResourceFromApi(JarFile jarFile,
String moduleId,
String version,
String resource)
Get a resource as from the module's api jar.
|
static String |
getURL(URL url)
Downloads the contents of a URL and copies them to a string (Borrowed from oreilly)
|
static InputStream |
getURLStream(URL url)
Downloads the contents of a URL and copies them to a string (Borrowed from oreilly)
|
static boolean |
ignoreCoreModules()
Uses the runtime properties to determine if the core modules should be enforced or not.
|
static File |
insertModuleFile(InputStream inputStream,
String filename)
Add the
inputStream as a file in the modules repository |
static boolean |
isOpenmrsVersionInVersions(String... versions)
Checks if the current OpenMRS version is in an array of versions.
|
static boolean |
isVersionWithQualifier(String version)
Checks for qualifier version (i.e "-SNAPSHOT", "-ALPHA" etc. after maven version conventions)
|
static boolean |
matchRequiredVersions(String version,
String versionRange)
This method is an enhancement of
compareVersion(String, String) and adds support for
wildcard characters and upperbounds. |
protected static InputStream |
openConnectionCheckRedirects(URLConnection c)
Convenience method to follow http to https redirects.
|
static org.springframework.context.support.AbstractRefreshableApplicationContext |
refreshApplicationContext(org.springframework.context.support.AbstractRefreshableApplicationContext ctx) |
static org.springframework.context.support.AbstractRefreshableApplicationContext |
refreshApplicationContext(org.springframework.context.support.AbstractRefreshableApplicationContext ctx,
boolean isOpenmrsStartup,
Module startedModule)
Refreshes the given application context "properly" in OpenMRS.
|
static void |
shutdown()
Stops the module system by calling stopModule for all modules that are currently started
|
static void |
startup(Properties props)
Start up the module system with the given properties.
|
public static void startup(Properties props) throws ModuleMustStartException
props
- Properties (OpenMRS runtime properties)ModuleMustStartException
public static void shutdown()
public static File insertModuleFile(InputStream inputStream, String filename)
inputStream
as a file in the modules repositoryinputStream
- InputStream
to loadpublic static boolean isOpenmrsVersionInVersions(String... versions)
This method calls matchRequiredVersions(String, String)
internally.
versions
- the openmrs versions to be checked against the current openmrs versionpublic static boolean matchRequiredVersions(String version, String versionRange)
compareVersion(String, String)
and adds support for
wildcard characters and upperbounds. checkRequiredVersion(String, String)
internally. Again the possible require version number formats with their interpretation:
version
- openmrs version number to be comparedversionRange
- value in the config file for required openmrs versionversion
is within the value
Should allow ranged required version
Should allow ranged required version with wild card
Should allow ranged required version with wild card on one end
Should allow single entry for required version
Should allow required version with wild card
Should allow non numeric character required version
Should allow ranged non numeric character required version
Should allow ranged non numeric character with wild card
Should allow ranged non numeric character with wild card on one end
Should return false when openmrs version beyond wild card range
Should return false when required version beyond openmrs version
Should return false when required version with wild card beyond openmrs version
Should return false when required version with wild card on one end beyond openmrs version
Should return false when single entry required version beyond openmrs version
Should allow release type in the version
Should match when revision number is below maximum revision number
Should not match when revision number is above maximum revision number
Should correctly set upper and lower limit for versionRange with qualifiers and wild card
Should match when version has wild card plus qualifier and is within boundary
Should not match when version has wild card plus qualifier and is outside boundary
Should match when version has wild card and is within boundary
Should not match when version has wild card and is outside boundary
Should return true when required version is emptypublic static void checkRequiredVersion(String version, String versionRange) throws ModuleException
compareVersion(String, String)
and adds support for
wildcard characters and upperbounds. Again the possible require version number formats with their interpretation:
version
- openmrs version number to be comparedversionRange
- value in the config file for required openmrs versionModuleException
- if the version
is not within the value
Should throw ModuleException if openmrs version beyond wild card range
Should throw ModuleException if required version beyond openmrs version
Should throw ModuleException if required version with wild card beyond openmrs version
Should throw ModuleException if required version with wild card on one end beyond openmrs
version
Should throw ModuleException if single entry required version beyond openmrs version
Should throw ModuleException if SNAPSHOT not handled correctly
Should handle SNAPSHOT versions
Should handle ALPHA versionspublic static int compareVersion(String version, String value)
version
to value
version and value are strings like
1.9.2.0 Returns 0
if either version
or value
is null.version
- String like 1.9.2.0value
- String like 1.9.2.00
if version
is equal to the argument
value
; a value less than 0
if version
is
numerically less than the argument value
; and a value greater than
0
if version
is numerically greater than the argument
value
Should correctly comparing two version numbers
Should treat SNAPSHOT as earliest versionpublic static boolean isVersionWithQualifier(String version)
version
- String like 1.9.2-SNAPSHOTpublic static File getModuleRepository()
public static URL file2url(File file) throws MalformedURLException
File
object to a local URL.file
- a file objectMalformedURLException
- if file can't be represented as URL for some reasonpublic static void expandJar(File fileToExpand, File tmpModuleDir, String name, boolean keepFullPath) throws IOException
fileToExpand
jar to the tmpModuleFile
directory
If name
is null, the entire jar is expanded. Ifname
is not null,
then only that path/file is expanded.fileToExpand
- file pointing at a .jartmpModuleDir
- directory in which to place the filesname
- filename inside of the jar to look for and expandkeepFullPath
- if true, will recreate entire directory structure in tmpModuleDir
relating to name
. if false will start directory structure at
name
Should expand entire jar if name is null
Should expand entire jar if name is empty string
Should expand directory with parent tree if name is directory and keepFullPath is true
Should expand directory without parent tree if name is directory and keepFullPath is false
Should expand file with parent tree if name is file and keepFullPath is trueIOException
public static InputStream getURLStream(URL url)
url
- protected static InputStream openConnectionCheckRedirects(URLConnection c) throws IOException
c
- the URLConnection
to openInputStream
that is not necessarily at the same url, possibly at a 403
redirect.IOException
getURLStream(URL)
public static String getURL(URL url)
url
- public static Boolean checkForModuleUpdates() throws ModuleException
ModuleException
public static Boolean allowAdmin()
public static org.springframework.context.support.AbstractRefreshableApplicationContext refreshApplicationContext(org.springframework.context.support.AbstractRefreshableApplicationContext ctx)
public static org.springframework.context.support.AbstractRefreshableApplicationContext refreshApplicationContext(org.springframework.context.support.AbstractRefreshableApplicationContext ctx, boolean isOpenmrsStartup, Module startedModule)
ctx
- Spring application context that needs refreshing.isOpenmrsStartup
- if this refresh is being done at application startup.startedModule
- the module that was just started and waiting on the context refresh.protected static void checkMandatoryModulesStarted() throws ModuleException
ModuleException
- if a mandatory module isn't started
Should throw ModuleException if a mandatory module is not startedprotected static void checkOpenmrsCoreModulesStarted() throws OpenmrsCoreModuleException
ModuleConstants.CORE_MODULES
to make sure that all
modules that are core to OpenMRS are started and have at least a minimum version that OpenMRS
needs.ModuleException
- if a module that is core to OpenMRS is not started
Should throw ModuleException if a core module is not startedOpenmrsCoreModuleException
public static boolean ignoreCoreModules()
public static List<String> getMandatoryModules()
public static Module getModuleForPath(String path)
Gets the module that should handle a path. The path you pass in should be a module id (in path format, i.e. /ui/springmvc, not ui.springmvc) followed by a resource. Something like the following: /ui/springmvc/css/ui.css The first running module out of the following would be returned: ui.springmvc.css ui.springmvc ui
path
- public static String getPathForResource(Module module, String path)
module
- path
- public static Collection<String> getPackagesFromFile(File file)
file
- jar file to look intopublic static InputStream getResourceFromApi(JarFile jarFile, String moduleId, String version, String resource)
jarFile
- omod file loaded as jarmoduleId
- id of the moduleversion
- version of the moduleresource
- name of a resource from the api jarnull
if resource cannot be loaded
Should load file from api as input stream
Should return null if api is not found
Should return null if file is not found in apiCopyright © 2024 OpenMRS Inc.. All rights reserved.