# Maintainer:  Marty Plummer (The_NetZ) <ntzrmtthihu777 (at) gmail (dot) com>
# Maintainer:  Simon Legner <Simon.Legner@gmail.com>
# Maintainer:  Chris Molozian (novabyte) <chris DOT molozian AT gmail DOT com>
# Maintainer:  Maximilian Salomon <msal.coding@gmail.com>
# Maintainer:  Piotr Fusik <piotr AT fusion-lang DOT org>
# Contributor: Sanjuro Makabe (itti) <vuck AT gmx DOT de>
# Contributor: Simón Oroño <simonorono AT protonmail DOT com>
# Contributor: Eon Jeong <administrator@korea.ac.kr>

pkgname=('gradle' 'gradle-doc')
pkgver=9.1.0
pkgrel=1
arch=('any')
url='https://www.gradle.org/'
msys2_references=(
  'cpe: cpe:/a:gradle:gradle'
)
license=('APACHE')
source=("https://services.gradle.org/distributions/gradle-${pkgver}-all.zip"
        "gradle.sh")
sha256sums=('b84e04fa845fecba48551f425957641074fcc00a88a84d2aae5808743b35fc85'
            '0d6699a246bc86c40fb2da3fe73f8e3b228201a8781194d8b303e239d2fa758e')

package_gradle(){
  pkgdesc="A powerful build system for the JVM"
  # install profile.d script
  install -dm755 "${pkgdir}"/etc/profile.d
  install -m755 "${srcdir}/${pkgname}.sh" "${pkgdir}/etc/profile.d/"
  cd "${srcdir}/${pkgname}-${pkgver}"

  # create the necessary directory structure
  mkdir -p "${pkgdir}/usr/share/java/${pkgname}/bin"
  mkdir -p "${pkgdir}/usr/share/java/${pkgname}/lib/agents"
  mkdir -p "${pkgdir}/usr/share/java/${pkgname}/lib/plugins"
  mkdir -p "${pkgdir}/usr/bin"

  # copy across jar files
  install -Dm644 lib/*.jar "${pkgdir}/usr/share/java/${pkgname}/lib" || return 1
  install -Dm644 lib/agents/*.jar "${pkgdir}/usr/share/java/${pkgname}/lib/agents" || return 1
  install -Dm644 lib/plugins/*.jar "${pkgdir}/usr/share/java/${pkgname}/lib/plugins" || return 1

  # copy across supporting text documentation and scripts
  install -m644 LICENSE "${pkgdir}/usr/share/java/${pkgname}" || return 1            # license
  install -m644 NOTICE "${pkgdir}/usr/share/java/${pkgname}" || return 1             # license notes
  install -m755 bin/gradle "${pkgdir}/usr/share/java/${pkgname}/bin" || return 1     # UNIX script
  install -m755 bin/gradle.bat "${pkgdir}/usr/share/java/${pkgname}/bin" || return 1 # Windows script
}

package_gradle-doc() {
  pkgdesc="A powerful build system for the JVM (documentation)"
  options=('!strip')
  optdepends=("gradle")
  cd "${srcdir}/gradle-${pkgver}"

  # create the necessary directory structure
  mkdir -p "${pkgdir}/usr/share/java/gradle/docs/"

  # copy across documentation
  cp --recursive docs/* "${pkgdir}/usr/share/java/gradle/docs/"
}
