3
3
import module namespace file = "http://expath.org/ns/file";
4
4
import module namespace xqd = "http://www.zorba-xquery.com/modules/xqdoc";
5
import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
6
7
import schema namespace xqdoc = "http://www.xqdoc.org/1.0";
8
9
declare namespace ann = "http://www.zorba-xquery.com/annotations";
9
10
declare namespace err = "http://www.w3.org/2005/xqt-errors";
11
declare namespace zm = "http://www.zorba-xquery.com/manifest";
11
13
declare copy-namespaces preserve, inherit;
15
: This variable contains the path to Zorba directory
17
declare variable $ZorbaPath as xs:string external;
20
: This variable contains the path to Zorba directory
22
declare variable $ZorbaBuildPath as xs:string external;
25
: This function returns a sequence of valid PATHS where modules can be found:
26
: this includes the Zorba core modules path and also all the paths to the external modules that are checked out
28
declare %ann:nondeterministic function local:get-src-dirs() as xs:string*
17
: This variable contains the path to ZorbaManifestPath.xml
19
declare variable $ZorbaManifestPath as xs:string external;
21
declare %private %ann:nondeterministic function local:load-manifest()
30
(: set the path to the Zorba core modules :)
31
let $ZorbaCoreModules := fn:resolve-uri(concat($ZorbaPath,"modules"))
33
(: read from CMakeCache.txt the path where the external modules are checked out (if any) :)
34
let $ZorbaCMakeCache := fn:resolve-uri(concat($ZorbaBuildPath, file:directory-separator(), "CMakeCache.txt"))
35
let $ZorbaModulesDir := substring-before(tokenize(file:read-text($ZorbaCMakeCache),"ZORBA_MODULES_DIR:PATH=")[2],"
37
let $resolved := fn:resolve-uri($ZorbaModulesDir)
39
if (file:exists($resolved))
41
let $dirs := file:list(fn:resolve-uri($ZorbaModulesDir))
42
return( $ZorbaCoreModules,
44
let $file := fn:resolve-uri(concat($ZorbaModulesDir,file:directory-separator(),$dir,file:directory-separator(),"CMakeLists.txt"))
45
let $text := file:read-text($file)
46
let $as := fn:analyze-string($text, "ADD_SUBDIRECTORY\((.*?)\)")
47
let $match := replace($as/fn:match/fn:group[@nr eq 1],'"',"")
48
return fn:resolve-uri(concat($ZorbaModulesDir,file:directory-separator(),$dir,file:directory-separator(),$match)))
25
fn:parse-xml(file:read-text($ZorbaManifestPath))
29
fn:error(fn:concat("The file <",$ZorbaManifestPath,"> does not have the correct structure."))
53
: This function generates the XQDoc XML for all the modules found in
54
: <pre>$modulesPath</pre> and tests it for validity.
34
: This function generates the XQDoc XML for all correctly configured in Zorba
35
: (in other words all modules present in ZorbaManifest.xml) and checks if the modules are correctly documented.
56
: @param $modulePath where to search for modules recursively.
58
declare %ann:nondeterministic function local:testXQDoc($modulesPath as xs:string) as xs:string?
38
declare %ann:sequential function local:testXQDoc() as xs:string?
61
for $file in file:list(fn:resolve-uri($modulesPath), fn:true(), "*.xq")
62
let $filePath := fn:concat($modulesPath, file:directory-separator(), $file)
65
let $xqdoc := xqd:xqdoc(file:path-to-uri($filePath))/self::xqdoc:xqdoc
66
let $moduleUri := data($xqdoc/xqdoc:module/xqdoc:uri)
68
if(($moduleUri = "http://www.w3.org/2005/xpath-functions") or
69
($moduleUri = "http://www.w3.org/2005/xpath-functions/math") or
70
($moduleUri = "http://www.functx.com/") or
71
($moduleUri = "http://www.w3.org/2005/xqt-errors") or
72
($moduleUri = "http://www.zorba-xquery.com/errors") or
73
($moduleUri = "http://www.zorba-xquery.com/warnings")) then ()
75
local:test-module($xqdoc),
76
local:test-functions($xqdoc),
77
local:test-variables($xqdoc)
40
if(not(file:is-file($ZorbaManifestPath))) then
42
variable $message := fn:concat("The file <ZorbaManifest.xml> was not found: <", $ZorbaManifestPath, ">. Suggestion: run 'cmake' in your build folder such that ZorbaManifest.xml is regenerated.");
47
variable $manifestXML := local:load-manifest();
48
variable $moduleManifests := $manifestXML/zm:manifest/zm:module;
50
if(count($moduleManifests) eq xs:integer(0)) then ()
53
for $module in $moduleManifests
54
let $moduleURI := if(ends-with(data($module/zm:uri),".xq")) then substring-before(data($module/zm:uri),".xq") else data($module/zm:uri)
55
let $moduleFetched := fetch:content($moduleURI, "MODULE")
58
let $xqdoc := xqd:xqdoc-content($moduleFetched)/self::xqdoc:xqdoc
59
let $moduleUri := data($xqdoc/xqdoc:module/xqdoc:uri)
61
if(($moduleUri = "http://www.w3.org/2005/xpath-functions") or
62
($moduleUri = "http://www.w3.org/2005/xpath-functions/math") or
63
($moduleUri = "http://www.functx.com/") or
64
($moduleUri = "http://www.w3.org/2005/xqt-errors") or
65
($moduleUri = "http://www.zorba-xquery.com/errors") or
66
($moduleUri = "http://www.zorba-xquery.com/warnings")) then ()
68
local:test-module($xqdoc),
69
local:test-functions($xqdoc),
70
local:test-variables($xqdoc)
80
73
fn:concat("ERROR: ", $err:code, " Message: ", $err:description, "
81
processing file: ", $filePath)
74
processing module: ", $moduleURI)
78
fn:string-join($res,"")
86
82
declare function local:test-module($xqdoc as element(xqdoc:xqdoc)) as xs:string?