Skip to content

Commit e8c00e9

Browse files
authored
Merge pull request #142 from evolvedbinary/7.x.x/refactor/pom-licensing-order
[7.x.x] Utilities to format and order license declarations in pom.xml files
2 parents afc5717 + d46d235 commit e8c00e9

File tree

63 files changed

+583
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+583
-231
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+
)

elemental-parent/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@
409409
</dependency>
410410
</dependencies>
411411
<configuration>
412-
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory" />
412+
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
413413
<forkCount>${surefire.forkCount}</forkCount>
414414
<reuseForks>${surefire.reuseForks}</reuseForks>
415415
<argLine>@{jacocoArgLine} --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.ref=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED -Dfile.encoding=${project.build.sourceEncoding}</argLine>
@@ -705,4 +705,4 @@
705705
</repository>
706706
</distributionManagement>
707707

708-
</project>
708+
</project>

exist-ant/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@
172172
</multi>
173173
<includes>
174174
<include>pom.xml</include>
175-
<include>src/test/resources/log4j2.xml</include>
176175
<include>src/test/resources-filtered/conf.xml</include>
176+
<include>src/test/resources/log4j2.xml</include>
177177
</includes>
178178
</licenseSet>
179179

@@ -183,14 +183,14 @@
183183
-->
184184
<header>${project.parent.relativePath}/../exist-parent/existdb-LGPL-21-license.template.txt</header>
185185
<excludes>
186-
<exclude>**.txt</exclude>
187186
<exclude>**.md</exclude>
188-
<exclude>**LICENSE</exclude>
187+
<exclude>**.txt</exclude>
189188
<exclude>**.xar</exclude>
190-
<exclude>xquery-license-style.xml</exclude>
189+
<exclude>**LICENSE</exclude>
191190
<exclude>pom.xml</exclude>
192-
<exclude>src/test/resources/log4j2.xml</exclude>
191+
<exclude>xquery-license-style.xml</exclude>
193192
<exclude>src/test/resources-filtered/conf.xml</exclude>
193+
<exclude>src/test/resources/log4j2.xml</exclude>
194194
</excludes>
195195
</licenseSet>
196196
</licenseSets>
@@ -200,4 +200,4 @@
200200

201201
</build>
202202

203-
</project>
203+
</project>

exist-core-jcstress/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@
167167
</plugins>
168168
</build>
169169

170-
</project>
170+
</project>

exist-core-jmh/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,4 @@
218218
</plugins>
219219
</build>
220220

221-
</project>
221+
</project>

0 commit comments

Comments
 (0)