Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c298bb7cf6
Fetching contributors…

Cannot retrieve contributors at this time

58 lines (48 sloc) 1.405 kb
xquery version "1.0-ml";
module namespace modules-fs = "http://github.com/robwhitby/xray/modules-fs";
declare function get-modules(
$test-dir as xs:string,
$pattern as xs:string?
) as xs:string*
{
let $test-dir :=
if (xdmp:platform() eq "winnt")
then fn:replace($test-dir, "/", "\\")
else fn:replace($test-dir, "\\", "/")
let $fs-dir := fn:concat(xdmp:modules-root(), fn:replace($test-dir, "^[/\\]+", ""))
where filesystem-directory-exists($fs-dir)
return
module-filenames($fs-dir)[fn:matches(fn:substring-after(., $fs-dir), fn:string($pattern))]
};
declare function get-module(
$module-path as xs:string
) as xs:string
{
fn:string(xdmp:filesystem-file($module-path))
};
declare private function module-filenames(
$dir as xs:string
) as xs:string*
{
for $entry in xdmp:filesystem-directory($dir)/dir:entry
order by $entry/dir:type descending, $entry/dir:filename ascending
return
if ($entry/dir:type = "file")
then
if (fn:matches($entry/dir:pathname, "\.xqy?$"))
then $entry/dir:pathname/fn:string()
else ()
else module-filenames($entry/dir:pathname/fn:string())
};
declare private function filesystem-directory-exists(
$dir as xs:string
) as xs:boolean
{
try { fn:exists(xdmp:filesystem-directory($dir)) }
catch($e)
{
if ($e/error:code = "SVC-DIROPEN")
then fn:false()
else xdmp:rethrow()
}
};
Jump to Line
Something went wrong with that request. Please try again.