# Contributor: Andres Almiray <aalmiray@yahoo.com>
# Maintainer: Andres Almiray <aalmiray@yahoo.com>
pkgname=jreleaser
pkgver=1.18.0
pkgrel=0
pkgdesc="Release projects quickly and easily with JReleaser"
url="https://jreleaser.org/"
# aarch64: openjdk currently segfaults
# ppc64le: openjdk hangs
# riscv64, loongarch64, 32-bit: no jdk11
arch="all !aarch64 !ppc64le !armv7 !armhf !x86 !riscv64 !loongarch64"
license="Apache-2.0"
depends="openjdk11-jdk"
makedepends="gradle"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/jreleaser/jreleaser/archive/refs/tags/v$pkgver.tar.gz"
options="!check" #Check occurs in build

prepare() {
	default_prepare

	# generate a copy of the wrapper with the chosen version
	mkdir "$srcdir"/temp
	cd "$srcdir"/temp
	echo "rootProject.name = 'wrapper-project'" > settings.gradle
	# this will fetch an older version of gradle
	gradle --no-daemon wrapper --gradle-version 8.14

	cd "$builddir"

	# copy wrapper files into source distribution
	cp -r "$srcdir"/temp/gradlew* "$builddir"
	cp -r "$srcdir"/temp/gradle/* "$builddir"/gradle/
}

build() {
	# build requires Java 11
	export JAVA_HOME="/usr/lib/jvm/java-11-openjdk"
	./gradlew --no-daemon -PreproducibleBuild=true -x :jreleaser:setupJdks :jreleaser:distZip
}

package() {
	unzip -qo plugins/jreleaser/build/distributions/jreleaser-$pkgver.zip

	local apphome="/usr/share/java/jreleaser"
	local destdir="$pkgdir/$apphome"

	rm "jreleaser-$pkgver"/bin/*.bat
	install -Dm755 "jreleaser-$pkgver"/bin/* -t "$destdir"/bin

	mkdir -p "$pkgdir"/usr/bin
	ln -sf ../share/java/jreleaser/bin/jreleaser "$pkgdir"/usr/bin/jreleaser

	install -Dm644 "jreleaser-$pkgver"/lib/*.jar -t "$destdir"/lib
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

sha512sums="
1ea3dbfbdd6bec92cd2364a1b15b501921f362ed8a23b9ba2ca9d91bf92ccfbcc338ce8060c0f3db13e54f6a73c31fff05534fcb359d79b7a5874091f8257faf  jreleaser-1.18.0.tar.gz
"
