# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Robin Candau <antiz@archlinux.org>
# Contributor: Alexander Rødseth <rodseth@gmail.com>
# Contributor: Marcel Huber <marcelhuberfoo at gmail dott com>
# Contributor: Illarion Kovalchuk <illarion.kovalchuk at gmail dot com>

pkgname=jenkins
pkgver=2.467
pkgrel=1
_java=17
pkgdesc='Extendable continuous integration server (latest)'
arch=(any)
url='https://jenkins.io'
license=('MIT')
depends=("java-runtime=${_java}" 'ttf-dejavu' 'fontconfig')
makedepends=("java-environment=${_java}" 'git' 'maven')
provides=('jenkins-ci')
conflicts=('jenkins-ci')
replaces=('jenkins-ci')
backup=('etc/conf.d/jenkins')
install='jenkins.install'
source=("https://github.com/jenkinsci/jenkins/archive/refs/tags/jenkins-${pkgver}.tar.gz"
        'jenkins.conf'
        'jenkins.service'
        'jenkins.tmpfiles'
        'jenkins.sysusers'
        'skip-failing-test.patch')
sha512sums=('9359213ad3f752c6028c9be97aac744d8114713dec56c3702bcef227c5af28bdcb3ebb6eb2608dd479904cb0bf17b4f1f9442eb5feaa9e0d7189a21fb99fae37'
            '482b642988027b623995e0488cc00011be5bbe9890a6d40dd6979197fa50794889ff731f798891106b367962cf60cb59b0260caadfcee9685b358a966f759553'
            'c1e9a542bfd3db54ea0ef57acdac47ad5180330f9ffab44296762b0e69e75ce595d85a77d46025586fb507aedce4f1a032379dcd16b7b886fe475a99849fa4b2'
            'a845a7147be54affc586dfce9a188ec24c92e673e88dec0b62da386d2e597de6ecda103429008562abd897f179a52c37cf2188ebc65b8c636efd07d707e18f90'
            '896cbc64eadb2f3bb9fa7fc26dbfc527b1823d8bff3158be7f1936cc250f55eeafe89079e1ceb8f3d269041662573ccbbb36248140b4ba24144a564366f8847a'
            '876180dc1674ec56c32a4fceac7d9608f450520ace7d3ecb68cbe7ba8f1bcba31f2c063f52a9076c432b78fd31157da3febc65e98e7d9050a4134d4e0304e8bd')

prepare() {
  cd "${pkgname}-${pkgname}-${pkgver}"
  patch -Np1 <"${srcdir}"/skip-failing-test.patch
}

build() {
  cd "${pkgname}-${pkgname}-${pkgver}"
  export PATH="/usr/lib/jvm/java-${_java}-openjdk/bin:${PATH}"
  mvn -am -pl war,bom -Pquick-build -Dproject.build.outputTimestamp="${SOURCE_DATE_EPOCH}" package
}

check() {
  cd "${pkgname}-${pkgname}-${pkgver}"
  export PATH="/usr/lib/jvm/java-${_java}-openjdk/bin:${PATH}"
  mvn -am -Plight-test -Dproject.build.outputTimestamp="${SOURCE_DATE_EPOCH}" test
}

package() {
  cd "${pkgname}-${pkgname}-${pkgver}"
  install -Dm 644 war/target/jenkins.war "${pkgdir}/usr/share/java/jenkins/jenkins.war"
  install -Dm 644 LICENSE.txt "${pkgdir}/usr/share/licenses/jenkins/LICENSE"
  install -Dm 644 ../jenkins.service "${pkgdir}/usr/lib/systemd/system/jenkins.service"
  install -Dm 644 ../jenkins.tmpfiles "${pkgdir}/usr/lib/tmpfiles.d/jenkins.conf"
  install -Dm 644 ../jenkins.sysusers "${pkgdir}/usr/lib/sysusers.d/jenkins.conf"
  install -Dm 644 ../jenkins.conf "${pkgdir}/etc/conf.d/jenkins"
}
