Skip to content

Commit 968ca24

Browse files
committed
[feature] Add a target to the simple build script to format the pom.xml files
1 parent afc5717 commit 968ca24

File tree

6 files changed

+340
-10
lines changed

6 files changed

+340
-10
lines changed

build.bat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ if /I "%~1"=="--debug" (
6868
set "TARGET=dependency-check"
6969
) else if /I "%~1"=="dependency-security-check" (
7070
set "TARGET=dependency-security-check"
71+
) else if /I "%~1"=="format-poms" (
72+
set "TARGET=format-poms"
7173
)
7274
shift
7375
goto parse_args
@@ -115,6 +117,18 @@ if "%TARGET%"=="clean" (
115117
set "CMD=%BASE_CMD% dependency:analyze"
116118
) else if "%TARGET%"=="dependency-security-check" (
117119
set "CMD=%BASE_CMD% dependency-check:check"
120+
) else if "%TARGET%"=="format-poms" (
121+
set "SAXON=%USERPROFILE%\.m2\repository\net\sf\saxon\Saxon-HE\9.9.1-8\Saxon-HE-9.9.1-8.jar"
122+
for /r %%POM in (pom.xml) do (
123+
echo | set /p dummyName="Formatting %%POM ..."
124+
java -jar "%SAXON%" -s:%%POM -xsl:format-pom.xslt -o:%%POM
125+
echo OK
126+
127+
echo | set /p dummyName="Checking for duplicate license entries in %%POM ... "
128+
java -cp "%SAXON%" net.sf.saxon.Query -q:check-pom-license-uniqueness.xq pom-file-uri=file:%%POM
129+
echo OK
130+
)
131+
goto end
118132
) else (
119133
echo Invalid target: %TARGET%
120134
goto show_useage

build.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ do
3838
key="$1"
3939

4040
case $key in
41-
clean|quick|quick-archives|quick-docker|quick-archives-docker|quick-install|test|site|license-check|license-format|dependency-check|dependency-security-check)
41+
clean|quick|quick-archives|quick-docker|quick-archives-docker|quick-install|test|site|license-check|license-format|dependency-check|dependency-security-check|format-poms)
4242
TARGET="$1"
4343
shift
4444
;;
@@ -75,6 +75,7 @@ function print-useage() {
7575
echo -e "\tlicence-format - Adds the correct license header to any source files that are missing it"
7676
echo -e "\tdependency-check - Checks that all modules have correctly declared their dependencies"
7777
echo -e "\tdependency-security-check - Checks that all dependencies have no unexpected CVE security issues"
78+
echo -e "\tformat-poms - Format the pom.xml files"
7879
echo -e "\tclean - Remove all built artifacts"
7980
echo -e "\n--offline - attempts to run the Maven build in offline mode"
8081
}
@@ -170,5 +171,24 @@ if [ "${TARGET}" == "dependency-security-check" ]; then
170171
exit 0;
171172
fi
172173

174+
if [ "${TARGET}" == "format-poms" ]; then
175+
SAXON="${HOME}/.m2/repository/net/sf/saxon/Saxon-HE/9.9.1-8/Saxon-HE-9.9.1-8.jar"
176+
POMS="$(find . -name pom.xml)"
177+
for pom in $POMS; do
178+
179+
echo -n "Formatting ${pom} ... "
180+
CMD="java -jar ${SAXON} -s:${pom} -xsl:format-pom.xslt -o:${pom}"
181+
$CMD
182+
echo "OK"
183+
184+
echo -n "Checking for duplicate license entries in ${pom} ... "
185+
CMD="java -cp ${SAXON} net.sf.saxon.Query -q:check-pom-license-uniqueness.xq pom-file-uri=file:${pom}"
186+
$CMD
187+
echo "OK"
188+
189+
done
190+
exit 0;
191+
fi
192+
173193
print-useage
174194
exit 0;

check-pom-license-uniqueness.xq

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
)

exist-core/pom.xml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,9 +1366,7 @@
13661366
<exclude>src/test/resources/org/exist/validation/entities/**</exclude>
13671367
<exclude>src/test/resources/org/exist/xmldb/allowAnyUri.xml</exclude>
13681368

1369-
<!--
1370-
Already under LGPL 2.1, but with a different Copyright
1371-
-->
1369+
<?license-section start description="Already under LGPL 2.1, but with a different Copyright"?>
13721370
<exclude>pom.xml</exclude>
13731371
<exclude>project-suppression.xml</exclude>
13741372
<exclude>src/test/resources/log4j2.xml</exclude>
@@ -2065,21 +2063,19 @@
20652063
<exclude>src/main/java/org/exist/xupdate/Update.java</exclude>
20662064
<exclude>src/main/java/org/exist/xupdate/XUpdateProcessor.java</exclude>
20672065
<exclude>src/test/java/org/exist/xupdate/XUpdateTest.java</exclude>
2066+
<?license-section end?>
20682067

2069-
<!--
2070-
Derivative work licensed under dbXML 1.0 and LGPL 2.1
2071-
-->
2068+
<?license-section start description="Derivative work licensed under dbXML 1.0 and LGPL 2.1"?>
20722069
<exclude>src/main/java/org/exist/storage/btree/BTree.java</exclude>
20732070
<exclude>src/main/java/org/exist/storage/btree/BTreeCallback.java</exclude>
20742071
<exclude>src/main/java/org/exist/storage/btree/BTreeException.java</exclude>
20752072
<exclude>src/main/java/org/exist/storage/btree/DBException.java</exclude>
20762073
<exclude>src/main/java/org/exist/storage/btree/IndexQuery.java</exclude>
20772074
<exclude>src/main/java/org/exist/storage/btree/Paged.java</exclude>
20782075
<exclude>src/main/java/org/exist/storage/btree/Value.java</exclude>
2076+
<?license-section end?>
20792077

2080-
<!--
2081-
Licensed under BSD 3
2082-
-->
2078+
<?license-section start description="Licensed under BSD 3"?>
20832079
<exclude>src/main/java/org/exist/util/CodePointString.java</exclude>
20842080
<exclude>src/test/java/org/exist/util/CodePointStringTest.java</exclude>
20852081
<exclude>src/main/java/org/exist/util/io/ByteBufferAccessor.java</exclude>
@@ -2093,6 +2089,7 @@
20932089
<exclude>src/main/java/org/exist/util/io/MemoryMappedFileFilterInputStreamCache.java</exclude>
20942090
<exclude>src/main/java/org/exist/util/io/TemporaryFileManager.java</exclude>
20952091
<exclude>src/main/java/org/exist/xquery/functions/fn/FnFormatNumbers.java</exclude>
2092+
<?license-section end?>
20962093
</excludes>
20972094
</licenseSet>
20982095

0 commit comments

Comments
 (0)