1+ (:
2+ : Elemental
3+ : Copyright (C) 2024, Evolved Binary Ltd
4+ :
5+ 6+ : https://www.evolvedbinary.com | https://www.elemental.xyz
7+ :
8+ : This library is free software; you can redistribute it and/or
9+ : modify it under the terms of the GNU Lesser General Public
10+ : License as published by the Free Software Foundation; version 2.1.
11+ :
12+ : This library is distributed in the hope that it will be useful,
13+ : but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+ : Lesser General Public License for more details.
16+ :
17+ : You should have received a copy of the GNU Lesser General Public
18+ : License along with this library; if not, write to the Free Software
19+ : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+ :)
21+ xquery version "3.1" ;
22+
23+ (:~
24+ : Checks within the <excludes> and <includes> of each <licenseSet> with a pom.xml
25+ : file to make sure there are no duplicate entries.
26+ :)
27+
28+ declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization" ;
29+ declare namespace pom = "http://maven.apache.org/POM/4.0.0" ;
30+
31+ declare option output:omit-xml-declaration "yes" ;
32+
33+
34+ (: Must be set externally with the URI to the pom.xml file :)
35+ declare variable $pom-file-uri as xs:string external ;
36+
37+ let $pom := doc ($pom-file-uri)
38+ return
39+ (
40+
41+ let $includes-elements := $pom//pom:includes
42+ for $includes-element in $includes-elements
43+ let $total-includes := count ($includes-element/pom:include/string (.))
44+ let $distinct-includes := count (distinct-values ($includes-element/pom:include/string (.)))
45+ return
46+ if ($total-includes ne $distinct-includes)
47+ then
48+ let $duplicates :=
49+ distinct-values (
50+ for $include in $includes-element/pom:include/string (.)
51+ where count ($includes-element/pom:include[. eq $include]) gt 1
52+ return $include
53+ )
54+ return
55+ error (xs:QName ("duplicate-include" ), "There are duplicate 'include' license entries within a 'licenseSet' in: " || $pom-file-uri || " at: " || path ($includes-element) || " duplicates: " || string-join ($duplicates, ", " ))
56+ else
57+ ()
58+
59+ ,
60+
61+ let $excludes-elements := $pom//pom:excludes[parent::pom:licenseSet]
62+ for $excludes-element in $excludes-elements
63+ let $total-excludes := count ($excludes-element/pom:exclude/string (.))
64+ let $distinct-excludes := count (distinct-values ($excludes-element/pom:exclude/string (.)))
65+ return
66+ if ($total-excludes ne $distinct-excludes)
67+ then
68+ let $duplicates :=
69+ distinct-values (
70+ for $exclude in $excludes-element/pom:exclude/string (.)
71+ where count ($excludes-element/pom:exclude[. eq $exclude]) gt 1
72+ return $exclude
73+ )
74+ return
75+ error (xs:QName ("duplicate-exclude" ), "There are duplicate 'exclude' license entries within a 'licenseSet' in: " || $pom-file-uri || " at: " || path ($excludes-element) || " duplicates: " || string-join ($duplicates, ", " ))
76+ else
77+ ()
78+
79+ )
0 commit comments