public class ModuleUtil extends Object
Constructor and Description |
---|
ModuleUtil() |
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
|
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
w.x.y.z 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 |
static URL |
file2url(File file)
Utility method to convert a
File object to a local URL. |
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 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 |
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, OpenmrsCoreModuleException
props
- Properties (OpenMRS runtime properties)ModuleMustStartException
OpenmrsCoreModuleException
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 matchRequiredVersions(String version, String versionRange)
compareVersion(String, String)
and adds support for
wildcard characters and upperbounds. checkRequiredVersion(String, String)
internally. version
- openmrs version number to be comparedversionRange
- value in the config file for required openmrs versionversion
is within the value
public static void checkRequiredVersion(String version, String versionRange) throws ModuleException
compareVersion(String, String)
and adds support for
wildcard characters and upperbounds. version
- openmrs version number to be comparedversionRange
- value in the config file for required openmrs versionModuleException
- if the version
is not within the value
public static int compareVersion(String version, String value)
version
to value
version and value are strings like
w.x.y.z Returns 0
if either version
or value
is null.version
- String like w.x.y.zvalue
- String like w.x.y.z0
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
public 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
IOException
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)
ModuleUtil#refreshApplicationContext(AbstractRefreshableApplicationContext, Module)
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 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 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 intoCopyright © 2018 OpenMRS LLC.. All Rights Reserved.