# Template file for 'dbeaver'
pkgname=dbeaver
version=24.3.2
revision=1
_dbeaver_common_commit=bc3c2e688a2578156efc42550ff750254dea0378
_dbeaver_jdbc_libsql_commit=dc67e1440c64dd2da15707e14680087103e0a19f
# the build downloads binaries linked to glibc
archs="x86_64 aarch64"
build_wrksrc="dbeaver"
hostmakedepends="apache-maven openjdk17"
depends="openjdk17"
short_desc="Free Universal Database Tool"
maintainer="Kyle Nusbaum <knusbaum+void@sdf.org>"
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/${_dbeaver_common_commit}.tar.gz
 https://github.com/dbeaver/dbeaver-jdbc-libsql/archive/${_dbeaver_jdbc_libsql_commit}.tar.gz"
checksum="7f2f16566396f800a9345218eb4aecd5cf9e6611480454fc2372948c54c878aa
 8ed55dffcea0c266e466559bba608086b16c3060d57d62b57e43c992db6983c2
 a84bd6e105a0fe8ccafd506710c08cacd038f97ff1b5b83431287564efce2271"
nopie=true

post_extract() {
	mv ${wrksrc}/dbeaver-${version} ${wrksrc}/dbeaver
	mv ${wrksrc}/dbeaver-common-${_dbeaver_common_commit} ${wrksrc}/dbeaver-common
	mv ${wrksrc}/dbeaver-jdbc-libsql-${_dbeaver_jdbc_libsql_commit} ${wrksrc}/dbeaver-jdbc-libsql
}

do_build() {
	. /etc/profile.d/jdk.sh
	cd "product/aggregate"
	mvn package -P all-platforms
}

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.15.0.v20240915-2000/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
}
