Skip to content

Commit f3da643

Browse files
committed
Initial implementation of %jp_binding macro
Add new experimental %jp_binding macro for generating binding packages, which are typically used to configure Java applications such as Maven to run with particular JVM implementation, but the mechanism is generic and can be used for other things as well. Unlike earlier implementations of binding packages, the new approach does not lead to creating conflicting packages. Instead a hierarchy of symlinks is maintained, similarly to the alternatives system. Currently there is no way to specify which binding will be selected in case when there is more than one installed (there is nothing like priorities yet), but this subject to change in the future. The implementation of %jp_binding relies on "dynamic spec generation" (aka "specparts") feature of RPM 4.19, but later it could be updated to work with older RPM versions too. More info in RPM docs: https://rpm-software-management.github.io/rpm/manual/dynamic_specs.html
1 parent 1da6867 commit f3da643

8 files changed

Lines changed: 276 additions & 0 deletions

File tree

build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ expand macros.d/macros.jpackage
6767
expand macros.d/macros.fjava
6868
expand macros.d/macros.javapackages-compat
6969
expand java-utils/java-functions
70+
expand java-utils/jp_binding.sh
7071
expand depgenerators/maven.req
7172
expand depgenerators/maven.prov
7273
expand depgenerators/osgi.req

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jvmprivdir
6060
jvmsysconfdir
6161
mavenpomdir
6262
ivyxmldir
63+
jpbindingdir
6364
pyinterpreter
6465
abrtlibdir
6566
"

expand.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ expand()
4545
-e "s|@{javadir}|${javadir}|g" \
4646
-e "s|@{jnidir}|${jnidir}|g" \
4747
-e "s|@{jvmdir}|${jvmdir}|g" \
48+
-e "s|@{jpbindingdir}|${jpbindingdir}|g" \
4849
-e "s|@{m2home}|${m2home}|g" \
4950
-e "s|@{prefix}|${prefix}|g" \
5051
-e "s|@{rundir}|${rundir}|g" \

install

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ dir "${jnidir}"
8989
dir "${javadocdir}"
9090
dir "${mavenpomdir}"
9191
dir "${ivyxmldir}"
92+
dir "${jpbindingdir}"
9293
dir "${datadir}/maven-metadata"
9394
dir "${prefix}/lib/eclipse"
9495
dir "${prefix}/lib/eclipse/features"
@@ -125,6 +126,7 @@ inst_config target/eclipse.conf "${javaconfdir}"
125126

126127
inst_data target/java-functions "${javadir}-utils"
127128
inst_exec java-utils/java-wrapper "${javadir}-utils"
129+
inst_exec target/jp_binding.sh "${javadir}-utils"
128130

129131
inst_data target/macros.jpackage "${rpmmacrodir}"
130132

java-utils/jp_binding.sh

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
#!/bin/sh
2+
# Copyright (c) 2024, Red Hat, Inc.
3+
#
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions
8+
# are met:
9+
#
10+
# 1. Redistributions of source code must retain the above copyright
11+
# notice, this list of conditions and the following disclaimer.
12+
# 2. Redistributions in binary form must reproduce the above copyright
13+
# notice, this list of conditions and the following disclaimer in the
14+
# documentation and/or other materials provided with the
15+
# distribution.
16+
# 3. Neither the name of the Red Hat nor the names of its
17+
# contributors may be used to endorse or promote products derived
18+
# from this software without specific prior written permission.
19+
#
20+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
#
32+
# Authors: Mikolaj Izdebski <mizdebsk@redhat.com>
33+
34+
set -eu
35+
jpbindingdir="@{jpbindingdir}"
36+
37+
if [ -z "${RPM_BUILD_ROOT:-}" ]; then
38+
echo RPM_BUILD_ROOT env variable has not been set >&2
39+
exit 1
40+
fi
41+
if [ -z "${RPM_SPECPARTS_DIR:-}" ]; then
42+
echo RPM_BUILD_ROOT env variable has not been set >&2
43+
exit 1
44+
fi
45+
46+
rpmname=""
47+
basepkg=""
48+
pkg=""
49+
ghost=""
50+
target=""
51+
variant=""
52+
provides=""
53+
requires=""
54+
recommends=""
55+
with_meta_requires=true
56+
description=""
57+
with_description=true
58+
summary=""
59+
with_summary=true
60+
with_files=true
61+
with_package=true
62+
with_install=true
63+
verbose=false
64+
65+
while [ $# -gt 0 ]; do
66+
case "$1" in
67+
--rpm-name)
68+
rpmname="$2"
69+
shift
70+
;;
71+
--base-pkg)
72+
basepkg="$2"
73+
shift
74+
;;
75+
--binding-pkg)
76+
pkg="$2"
77+
shift
78+
;;
79+
--ghost)
80+
ghost="$2"
81+
shift
82+
;;
83+
--target)
84+
target="$2"
85+
shift
86+
;;
87+
--variant)
88+
variant="$2"
89+
shift
90+
;;
91+
--provides)
92+
provides="${provides}
93+
Provides: $2"
94+
shift
95+
;;
96+
--requires)
97+
requires="${requires}
98+
Requires: $2"
99+
shift
100+
;;
101+
--recommends)
102+
recommends="${recommends}
103+
Recommends: $2"
104+
shift
105+
;;
106+
--no-meta-requires)
107+
with_meta_requires=false
108+
;;
109+
--description)
110+
description="$2"
111+
shift
112+
;;
113+
--no-description)
114+
with_description=false
115+
;;
116+
--summary)
117+
summary="$2"
118+
shift
119+
;;
120+
--no-summary)
121+
with_summary=false
122+
;;
123+
--no-files)
124+
with_files=false
125+
;;
126+
--no-package)
127+
with_package=false
128+
;;
129+
--no-install)
130+
with_install=false
131+
;;
132+
--verbose)
133+
verbose=true
134+
;;
135+
*)
136+
echo "Unknown option $1" >&2
137+
exit 1
138+
esac
139+
shift
140+
done
141+
142+
debug()
143+
{
144+
if ${verbose}; then
145+
echo "$@" >&2
146+
fi
147+
}
148+
149+
if [ -z "${basepkg}" ]; then
150+
if [ -n "${rpmname}" ]; then
151+
basepkg="${rpmname}"
152+
debug "Assuming default --base-pkg ${basepkg}"
153+
else
154+
echo "Missing required option --base-pkg" >&2
155+
exit 1
156+
fi
157+
fi
158+
159+
if [ -z "${ghost}" ]; then
160+
echo "Missing required option --ghost" >&2
161+
exit 1
162+
fi
163+
164+
if [ -z "${target}" ]; then
165+
echo "Missing required option --target" >&2
166+
exit 1
167+
fi
168+
169+
if [ -z "${variant}" ]; then
170+
echo "Missing required option --variant" >&2
171+
exit 1
172+
fi
173+
174+
if [ -z "${pkg}" ]; then
175+
pkg="${basepkg}-${variant}"
176+
debug "Assuming default --binding-pkg ${pkg}"
177+
fi
178+
179+
if [ -z "${summary}" ]; then
180+
summary="${basepkg} binding for ${variant}"
181+
fi
182+
183+
if [ -z "${description}" ]; then
184+
description="Configures ${basepkg} to work with ${variant}."
185+
fi
186+
187+
sp=${RPM_SPECPARTS_DIR}/${pkg}.specpart
188+
: >${sp}
189+
190+
if ${with_package}; then
191+
echo "%package -n ${pkg}" >>${sp}
192+
if ${with_summary}; then
193+
echo "Summary: ${summary}" >>${sp}
194+
fi
195+
echo "${provides}" >>${sp}
196+
echo "${requires}" >>${sp}
197+
echo "${recommends}" >>${sp}
198+
echo "Requires: javapackages-tools" >>${sp}
199+
if ${with_meta_requires}; then
200+
echo "Requires(meta): ${basepkg}" >>${sp}
201+
fi
202+
echo "" >>${sp}
203+
fi
204+
205+
if ${with_description}; then
206+
echo "%description -n ${pkg}" >>${sp}
207+
echo "${description}" | fold >>${sp}
208+
echo "" >>${sp}
209+
fi
210+
211+
if ${with_files}; then
212+
echo "%files -n ${pkg}" >>${sp}
213+
echo "%ghost ${jpbindingdir}/${ghost}" >>${sp}
214+
echo "%dir ${jpbindingdir}/${ghost}.d" >>${sp}
215+
echo "${jpbindingdir}/${ghost}.d/${variant}" >>${sp}
216+
fi
217+
218+
if ${verbose}; then
219+
debug "Added the following package:"
220+
sed 's/./ :: &/' ${sp} >&2
221+
fi
222+
223+
if ${with_install}; then
224+
install -d -m 755 ${RPM_BUILD_ROOT}${jpbindingdir}/${ghost}.d/
225+
ln -sf ${target} ${RPM_BUILD_ROOT}${jpbindingdir}/${ghost}.d/${variant}
226+
fi

javapackages-tools.spec

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
%global maven_home %{_usr}/share/xmvn
1111

12+
%global _jpbindingdir %{_datadir}/jpbinding
13+
1214
Name: javapackages-tools
1315
Version: [...]
1416
Release: %autorelease
@@ -165,6 +167,36 @@ ln -s %{_datadir}/java-utils %{buildroot}%{_usr}/share/java-utils
165167
%check
166168
./check
167169

170+
%transfiletriggerin -- %{_jpbindingdir}
171+
shopt -s nullglob
172+
grep -E '^%{_jpbindingdir}/.*\.d/' | sed 's|%{_jpbindingdir}/\(.*\)/\(.*\)|\1 \2|' | while read dir tgt; do
173+
lnk=${dir/%.d}
174+
ln -sf "$dir/$tgt" %{_jpbindingdir}/"$lnk"
175+
done
176+
177+
%transfiletriggerun -- %{_jpbindingdir}
178+
shopt -s nullglob
179+
grep -E '^%{_jpbindingdir}/.*\.d/' | sed 's|%{_jpbindingdir}/\(.*\)/\(.*\)|\1 \2|' | while read dir tgt; do
180+
lnk=${dir/%.d}
181+
was=$(readlink %{_jpbindingdir}/"$lnk" || :)
182+
if [[ "$was" = "$dir/$tgt" ]]; then
183+
unlink %{_jpbindingdir}/"$lnk"
184+
fi
185+
done
186+
187+
%transfiletriggerpostun -- %{_jpbindingdir}
188+
shopt -s nullglob
189+
for bindd in %{_jpbindingdir}/*.d/; do
190+
lnk=${bindd/%.d\/}
191+
if ! [[ -e "$lnk" ]]; then
192+
for ftgt in "$bindd"*; do
193+
tgt=$(realpath -m -s --relative-to=%{_jpbindingdir} "$ftgt")
194+
ln -sf "$tgt" "$lnk"
195+
break
196+
done
197+
fi
198+
done
199+
168200
%files -f files-tools
169201
%if 0%{?flatpak}
170202
%{_usr}/bin/build-classpath

macros.d/macros.javapackages-filesystem

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,9 @@
8080
# Directory for Ivy XML files
8181
#
8282
%_ivyxmldir %{_datadir}/ivy-xmls
83+
84+
#
85+
# Directory containing binding symlinks
86+
# EXPERIMENTAL, subject to change or removal
87+
#
88+
%_jpbindingdir %{_datadir}/jpbinding

macros.d/macros.jpackage

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,10 @@ run "\\$@"\
6868
EOF\
6969
chmod 755 %{buildroot}%{_bindir}/%5\
7070
%{nil}
71+
72+
73+
#
74+
# Creates binding subpackages
75+
# EXPERIMENTAL, subject to change or removal
76+
#
77+
%jp_binding @{javadir}-utils/jp_binding.sh --rpm-name %{name}

0 commit comments

Comments
 (0)