~zorba-coders/zorba/bugs-912586-912593-912722

« back to all changes in this revision

Viewing changes to test/rbkt/Queries/zorba/xqdoc/moduleDocumentation.xq

  • Committer: Cezar Andrei
  • Date: 2012-03-28 15:42:12 UTC
  • mfrom: (10606.1.129 zorba)
  • Revision ID: cezar.lp@cezarandrei.com-20120328154212-jh2heq49xcqjppce
Merge from trunck and resolve ChangeLog conflict.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
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";
5
6
 
6
7
import schema namespace xqdoc = "http://www.xqdoc.org/1.0";
7
8
 
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";
10
12
 
11
13
declare copy-namespaces preserve, inherit;
12
14
 
13
15
 
14
16
(:~
15
 
 : This variable contains the path to Zorba directory
16
 
 :)
17
 
declare variable $ZorbaPath as xs:string external;
18
 
 
19
 
(:~
20
 
 : This variable contains the path to Zorba directory
21
 
 :)
22
 
declare variable $ZorbaBuildPath as xs:string external;
23
 
 
24
 
(: 
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
27
 
 :)
28
 
declare %ann:nondeterministic function local:get-src-dirs() as xs:string*
 
17
 : This variable contains the path to ZorbaManifestPath.xml
 
18
 :)
 
19
declare variable $ZorbaManifestPath as xs:string external;
 
20
 
 
21
declare %private %ann:nondeterministic function local:load-manifest()
29
22
{
30
 
  (: set the path to the Zorba core modules :)
31
 
  let $ZorbaCoreModules := fn:resolve-uri(concat($ZorbaPath,"modules"))
32
 
  
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],"
36
 
")
37
 
  let $resolved := fn:resolve-uri($ZorbaModulesDir)
38
 
  return
39
 
    if (file:exists($resolved))
40
 
    then
41
 
      let $dirs := file:list(fn:resolve-uri($ZorbaModulesDir))
42
 
      return( $ZorbaCoreModules,
43
 
              for $dir in $dirs
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)))
49
 
    else ()
 
23
  try 
 
24
  {
 
25
    fn:parse-xml(file:read-text($ZorbaManifestPath)) 
 
26
  }
 
27
  catch *
 
28
  {
 
29
    fn:error(fn:concat("The file <",$ZorbaManifestPath,"> does not have the correct structure."))
 
30
  }
50
31
};
51
32
 
52
33
(:~
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.
55
36
 :
56
 
 : @param $modulePath where to search for modules recursively.
57
37
 :)
58
 
declare %ann:nondeterministic function local:testXQDoc($modulesPath as xs:string) as xs:string?
 
38
declare %ann:sequential function local:testXQDoc() as xs:string?
59
39
{
60
 
  variable $res := 
61
 
  for $file in file:list(fn:resolve-uri($modulesPath), fn:true(), "*.xq")
62
 
  let $filePath := fn:concat($modulesPath, file:directory-separator(), $file)
63
 
  return
64
 
    try {
65
 
      let $xqdoc := xqd:xqdoc(file:path-to-uri($filePath))/self::xqdoc:xqdoc
66
 
      let $moduleUri := data($xqdoc/xqdoc:module/xqdoc:uri)
67
 
      return string-join(
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 ()
74
 
        else(
75
 
        local:test-module($xqdoc),
76
 
        local:test-functions($xqdoc),
77
 
        local:test-variables($xqdoc)
78
 
      ),"")
79
 
    } catch * {
 
40
  if(not(file:is-file($ZorbaManifestPath))) then
 
41
  {
 
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.");
 
43
    fn:error($message)
 
44
  }
 
45
  else
 
46
  {
 
47
    variable $manifestXML := local:load-manifest();
 
48
    variable $moduleManifests := $manifestXML/zm:manifest/zm:module;
 
49
    variable $res :=
 
50
    if(count($moduleManifests) eq xs:integer(0)) then ()
 
51
    else
 
52
    {
 
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")
 
56
      return
 
57
      try {
 
58
          let $xqdoc := xqd:xqdoc-content($moduleFetched)/self::xqdoc:xqdoc
 
59
          let $moduleUri := data($xqdoc/xqdoc:module/xqdoc:uri)
 
60
          return string-join(
 
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 ()
 
67
            else(
 
68
            local:test-module($xqdoc),
 
69
            local:test-functions($xqdoc),
 
70
            local:test-variables($xqdoc)
 
71
          ),"")
 
72
      } catch * {
80
73
    fn:concat("ERROR: ", $err:code, " Message: ", $err:description, "
81
 
processing file: ", $filePath)
82
 
    };
83
 
    string-join($res,"")
 
74
processing module: ", $moduleURI)
 
75
      }
 
76
     };
 
77
     
 
78
   fn:string-join($res,"")
 
79
   }
84
80
};
85
81
 
86
82
declare function local:test-module($xqdoc as element(xqdoc:xqdoc)) as xs:string?
201
197
};
202
198
 
203
199
 
204
 
variable $errors as xs:string :=  string-join(for $complete-dir in local:get-src-dirs()
205
 
                                              return local:testXQDoc($complete-dir),"");
 
200
variable $errors as xs:string := local:testXQDoc();
206
201
 
207
202
variable $errorsCount := count(fn:analyze-string($errors,"ERROR:")//fn:match);
208
203