# Template file for 'dbeaver'
pkgname=dbeaver
version=26.1.5
revision=1
_version=${version//./_}
# the build downloads binaries linked to glibc
archs="x86_64 aarch64"
build_wrksrc="dbeaver"
hostmakedepends="apache-maven openjdk25"
depends="openjdk25"
short_desc="Free Universal Database Tool"
maintainer="Arjan Mossel <arjanmossel@gmail.com>"
license="Apache-2.0"
homepage="https://dbeaver.io"
changelog="https://dbeaver.io/news/"
distfiles="https://github.com/dbeaver/dbeaver/archive/${version}.tar.gz
 https://github.com/dbeaver/dbeaver-common/archive/refs/heads/release_${_version}.tar.gz>dbeaver-common-${version}.tar.gz
 https://github.com/dbeaver/dbeaver-jdbc-libsql/archive/refs/heads/release_${_version}.tar.gz>dbeaver-jdbc-libsql-${version}.tar.gz"
checksum="ed5f852893ed9e4821bf7837a641e7f66a9fd77215fb9e957480a4630beff6e1
 f93e443d1668298d921a9b7babaa574e2c03bb95708671f844cb3fbd37d65812
 18dfe8cf99020939e3b252e9650e80e1a6d242fa1092e5a7afab2e1dbc4b3590"
nopie=true

post_extract() {
	mv ${wrksrc}/dbeaver-${version} ${wrksrc}/dbeaver
	mv ${wrksrc}/dbeaver-common-release_${_version} ${wrksrc}/dbeaver-common
	mv ${wrksrc}/dbeaver-jdbc-libsql-release_${_version} ${wrksrc}/dbeaver-jdbc-libsql
}

do_build() {
	. /etc/profile.d/jdk.sh
	mvn package -Pproduct-dbeaver-ce,product-dbeaver-eclipse-ce,appstore -T 1C -f "product/aggregate"
}

do_install() {
	vmkdir /usr/lib
	vcopy "product/community/target/products/org.jkiss.dbeaver.core.product/linux/gtk/${XBPS_TARGET_MACHINE}/dbeaver" /usr/lib/

	# Delete folders with Java Native Access .so's for different architectures
	jna_dir="${DESTDIR}/usr/lib/dbeaver/plugins/com.sun.jna_5.18.1.v20251001-0800/com/sun/jna"
	jna_arch="linux-${XBPS_TARGET_MACHINE//_/-}"
	find "$jna_dir" -depth -mindepth 1 -type d -not -name $jna_arch -exec rm -rf {} \;

	vmkdir /usr/bin
	ln -s /usr/lib/dbeaver/dbeaver ${DESTDIR}/usr/bin/dbeaver

	vinstall product/community/icons/dbeaver.png 644 usr/share/pixmaps
	vinstall product/community/icons/dbeaver.xpm 644 usr/share/pixmaps
	vinstall ${FILESDIR}/dbeaver.desktop 0644 usr/share/applications
}
