~zorba-coders/zorba/feature-cloudant

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
(:
 : Copyright 2006-2011 The FLWOR Foundation.
 :
 : Licensed under the Apache License, Version 2.0 (the "License");
 : you may not use this file except in compliance with the License.
 : You may obtain a copy of the License at
 :
 : http://www.apache.org/licenses/LICENSE-2.0
 :
 : Unless required by applicable law or agreed to in writing, software
 : distributed under the License is distributed on an "AS IS" BASIS,
 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 : See the License for the specific language governing permissions and
 : limitations under the License.
:)

import module namespace file = "http://expath.org/ns/file";
declare namespace ann = "http://www.zorba-xquery.com/annotations";
declare namespace notice = "http://www.zorba-xquery.com/notice";

declare variable $local:path-to-zorba := "${PROJECT_SOURCE_DIR}"; 
declare variable $local:zorba-version := "${ZORBA_MAJOR_NUMBER}.${ZORBA_MINOR_NUMBER}.${ZORBA_PATCH_NUMBER}";

declare %ann:nondeterministic function local:read-notice-file($dirname as xs:string) as node()?
{
  let $ftxt := fn:concat($dirname, "/NOTICE.xml")
  return
    if(file:is-file($ftxt)) then
      fn:parse-xml(file:read-text($ftxt))
    else
      ()
};

declare function local:header() as xs:string
{
  concat(
    "-----------", "
",
    "Zorba ", $local:zorba-version, "
",
    "-----------", "

",
    "(Note: This file is generated automatically from NOTICE.xml.
",
    "Please do not modify this file directly.)

"
  )
};

declare function local:contents($notice as node()?)
{
  string-join(
    (
      local:header(), "
",
      local:native-license($notice),
      local:other-files($notice),
      local:external-libs($notice),
      local:external-apps($notice)
    ),
    "
"
  )
};

declare function local:native-license($notice as node()?) as xs:string
{
  concat(
    string($notice/notice:notice/notice:master-license/notice:license),
    "
",
    string($notice/notice:notice/notice:master-license/notice:text)
  )
};

declare function local:external-apps($notice as node()?) as xs:string
{
  concat(
    "
",
    "External applications used by this project:",
    "
----------------------------------------------------

",
    string-join(
      for $el in $notice/notice:notice/notice:external-app
      return
        concat (
          "Name: ", string($el/notice:name), "
",
          "Preferred version: ", string($el/notice:version),"
",
          "Is mandatory: ",
          let $m := string($el/@mandatory)
          return if($m = "") then "true" else $m,
          "
",
          "Website: ", string($el/notice:website), "
",
          if ($el/notice:license)
          then
            concat("License: ", string($el/notice:license),"
")
          else
            "",
          "Copyright: ", string($el/notice:copyright),"
",
          "External notice: 
", string($el/notice:foreign-notice)
       ),
     "
----------------------------------------------------

"
   )
  )
};

declare function local:external-libs($notice as node()?) as xs:string
{
  concat(
    "
",
    "External libraries used by this project:",
    "
----------------------------------------------------

",
    string-join(
      for $el in $notice/notice:notice/notice:external-lib
      return
        concat (
          "Name: ", string($el/notice:name), "
",
          "Preferred version: ", string($el/notice:version),"
",
          "Is mandatory: ",
          let $m := string($el/@mandatory)
          return if($m = "") then "true" else $m,
          "
",
          "Website: ", string($el/notice:website), "
",
          if ($el/notice:license)
          then
            concat("License: ", string($el/notice:license),"
")
          else
            "",
          "Copyright: ", string($el/notice:copyright),"
",
          "External notice: 
", string($el/notice:foreign-notice)
       ),
     "
----------------------------------------------------

"
   )
  )
};

declare function local:other-files($notice as node()?) as xs:string
{
  concat(
    "
",
    "Other files used by this project:",
    "
----------------------------------------------------

",
    string-join(
      for $ff in  $notice/notice:notice/notice:foreign-files
      return
        concat (
          string-join(
            for $f in $ff/notice:file
            return
              concat(
                fn:string($f),
                let $m := string($f/@is-modified)
                return if($m = "true") then " (has been modified)" else ""
              ),
            "
"
          ),
          "
",
          "
",
          concat("Copyright: ", string($ff/notice:copyright)),
          "
",
          if ($ff/notice:website)
          then
           concat("Website: ", $ff/notice:website)
          else
           "",
          "
",
          string($ff/notice:foreign-notice)
       ),
       "
----------------------------------------------------

"
     )
  )
};

declare %ann:sequential function local:generate-notice (
  $relpath-from-this as xs:string, 
  $notice as node()?
)
{
  if(fn:empty($notice)) then
    ()
  else
    let $contents := local:contents($notice)
    return file:write (
      fn:concat($relpath-from-this, "/NOTICE.txt"), $contents,
      <output:serialization-parameters
             xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization">
        <output:method value="text"/>
      </output:serialization-parameters>
    )
};


(" generate NOTICE.txt for Zorba in ", $local:path-to-zorba, "
",
local:generate-notice($local:path-to-zorba, local:read-notice-file($local:path-to-zorba))
)