# Maintainer (Arch): Guillaume ALAUX <guillaume@archlinux.org>
# Maintainer (Hyperbola): André Silva <emulatorman@hyperbola.info>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>
pkgname=java-runtime-common
pkgbase=java-common
pkgver=3
pkgrel=1.parabola1
pkgdesc='Common files for Java Runtime Environments (Parabola rebranded)'
arch=('any')
url='https://www.parabola.nu/packages/libre/any/java-runtime-common/'
license=('GPL')
checkdepends=('wget')
_shunitver=2.1.6
conflicts=('java-common')
replaces=('java-common')
backup=(etc/profile.d/jre.sh
        etc/profile.d/jre.csh)
install=install_java-runtime-common.sh
source=(profile_jre.csh
        profile_jre.sh
        bin_parabola-java
        test_parabola-java
        shunit2-${_shunitver}.tar.gz::https://github.com/kward/shunit2/archive/source.tar.gz)

sha256sums=('fb981764fbdcb33976085405d002a1427b5401da5f13f1dd00008dbe8306583a'
            '36e07f9387f24ff0c6dff1b4c6d9011eedef4bd22634e0c5a6335817991dc151'
            'b5d2bbbad708a84d4f2674dcba9053d777c735130843f6f924f063f456f2601d'
            'aab03dee5a3567c12d1af30374486aeaa6e317404ecf018dcb675124225f5853'
            '6beca93d20b72b46083c8271c4cf1da21b45f250a92b401c2565c65e1d75138f')

check() {
  cd "${srcdir}"
  ln -s shunit2-source/${_shunitver} shunit2
  ./test_parabola-java
}

package() {
  cd "${srcdir}"

  install -d -m 755 "${pkgdir}/usr/lib/jvm/"
  ln -s /dev/null "${pkgdir}/usr/lib/jvm/default"
  ln -s /dev/null "${pkgdir}/usr/lib/jvm/default-runtime"

  install -D -m 644 profile_jre.sh  "${pkgdir}/etc/profile.d/jre.sh"
  install -D -m 644 profile_jre.csh "${pkgdir}/etc/profile.d/jre.csh"
  install -D -m 755 bin_parabola-java "${pkgdir}/usr/bin/parabola-java"
  ln -s parabola-java "${pkgdir}/usr/bin/archlinux-java"

  install -d -m 755 "${pkgdir}/usr/bin/"
  # Official list of binaries that Java headless runtime packages MUST provide
  # This list is based on Parabola' default Java implementation: "OpenJDK 7 Icedtea"
  for b in \
    java keytool orbd pack200 rmid rmiregistry servertool tnameserv unpack200;
  do
    ln -s /usr/lib/jvm/default-runtime/bin/${b} "${pkgdir}/usr/bin/${b}"
  done
}
