# Maintainer: Thomas Dziedzic < gostrc at gmail >
# Contributor: Geoffroy Carrier <geoffroy.carrier@aur.archlinux.org>
# Contributor: Jason Chu <jason@archlinux.org>
# Contributor: Daniel J Griffiths <ghost1227@archlinux.us>
# Contributor: Guillaume ALAUX <Guillaume at alaux dot net>

pkgname=('jre' 'jdk')
pkgbase=java-sun
pkgver=6u23
pkgrel=4
pkgdesc="Sun/Oracle's implementation of tha Java 6 specification"
arch=('i686' 'x86_64')
  [ "${CARCH}" = 'i686' ]   && _arch=i586
  [ "${CARCH}" = 'x86_64' ] && _arch=amd64
url='http://java.sun.com'
license=('custom')
makedepends=('java-runtime')
source=("http://download.java.net/dlj/binaries/jdk-${pkgver}-dlj-linux-${_arch}.bin"
        'https://jdk-distros.dev.java.net/source/browse/*checkout*/jdk-distros/trunk/utils/construct.sh'
        'jdk.profile'
        'java-control-panel.desktop'
        'java-monitoring-and-management-console.desktop'
        'java-policy-settings.desktop'
        'java-visualvm.desktop'
        'java-web-start.desktop'
        'jre.profile'
        'jre.profile.csh'
        'jdk.profile.csh'
        'derby-network-server'
        'derby-network-server.conf')

build() {
  mkdir unbundle-jdk
  cd unbundle-jdk
  sh ../jdk-${pkgver}-dlj-linux-$_arch.bin --accept-license
  cd ..
  sh construct.sh unbundle-jdk linux-jdk linux-jre
}

package_jre() {
  pkgdesc="Sun/Oracle's Java Runtime Environment"
  depends=('glibc' 'libxtst')
  provides=('j2re' 'java-runtime=6')
  conflicts=('j2re' 'java-runtime')
  replaces=('j2re')
  install='jre.install'

  # main files
  mkdir -p ${pkgdir}/opt/java
  cp -R linux-jdk/jre ${pkgdir}/opt/java

  # profiles
  install -D ${srcdir}/jre.profile \
    ${pkgdir}/etc/profile.d/jre.sh
  install -D ${srcdir}/jre.profile.csh \
    ${pkgdir}/etc/profile.d/jre.csh

  mkdir -p ${pkgdir}/usr/lib/mozilla/plugins

  if [ "$CARCH" = "i686" ]; then
    ln -s /opt/java/jre/lib/i386/libnpjp2.so ${pkgdir}/usr/lib/mozilla/plugins
  else ln -s /opt/java/jre/lib/amd64/libnpjp2.so ${pkgdir}/usr/lib/mozilla/plugins
  fi

  # licenses
  install -d ${pkgdir}/usr/share/licenses/jre
  install -m644 ${pkgdir}/opt/java/jre/COPYRIGHT \
    ${pkgdir}/usr/share/licenses/jre
  install -m644 ${pkgdir}/opt/java/jre/LICENSE \
    ${pkgdir}/usr/share/licenses/jre
  install -m644 ${pkgdir}/opt/java/jre/THIRDPARTYLICENSEREADME.txt \
    ${pkgdir}/usr/share/licenses/jre

  # Fix system prefs folder (FS#18872)
  install -d ${pkgdir}/etc/.java/.systemPrefs
}

package_jdk() {
  pkgdesc="Sun/Oracle's Java Development Kit"
  depends=('glibc' 'jre')
  provides=('java-environment=6' 'j2sdk')
  conflicts=('java-environment' 'j2sdk')
  replaces=('j2sdk')
  install='jdk.install'

  #copy icon
  install -D -m644 ${srcdir}/linux-jdk/jre/lib/desktop/icons/hicolor/48x48/apps/sun-java.png \
    ${pkgdir}/usr/share/pixmaps/java.png

  # main files
  rm -rf linux-jdk/jre
  install -d ${pkgdir}/opt
  mv linux-jdk ${pkgdir}/opt/java

  # profiles
  install -D ${srcdir}/jdk.profile \
    ${pkgdir}/etc/profile.d/jdk.sh
  install -D ${srcdir}/jdk.profile.csh \
    ${pkgdir}/etc/profile.d/jdk.csh

  # licenses
  install -d ${pkgdir}/usr/share/licenses/jdk
  install -m644 ${pkgdir}/opt/java/COPYRIGHT \
    ${pkgdir}/usr/share/licenses/jdk
  install -m644 ${pkgdir}/opt/java/LICENSE \
    ${pkgdir}/usr/share/licenses/jdk
  install -m644 ${pkgdir}/opt/java/THIRDPARTYLICENSEREADME.txt \
    ${pkgdir}/usr/share/licenses/jdk

  # desktop entries
  install -Dm644 ${srcdir}/java-control-panel.desktop \
    ${pkgdir}/usr/share/applications/java-control-panel.desktop
  install -Dm644 ${srcdir}/java-monitoring-and-management-console.desktop \
    ${pkgdir}/usr/share/applications/java-monitoring-and-management-console.desktop
  install -Dm644 ${srcdir}/java-policy-settings.desktop \
    ${pkgdir}/usr/share/applications/java-policy-settings.desktop
  install -Dm644 ${srcdir}/java-visualvm.desktop \
    ${pkgdir}/usr/share/applications/java-visualvm.desktop
  install -Dm644 ${srcdir}/java-web-start.desktop \
    ${pkgdir}/usr/share/applications/java-web-start.desktop

  # javadb (apache derby) daemon files
  install -D ${srcdir}/derby-network-server \
    ${pkgdir}/etc/rc.d/derby-network-server
  install -D -m644 ${srcdir}/derby-network-server.conf \
    ${pkgdir}/etc/conf.d/derby-network-server
}
md5sums=('cd02f6e8f46fb4171811150cb820c6ed'
         '94065b612df0046d9ae758943f9f6a75'
         'b83ab5742651b4234b7d2e20785c6693'
         'e4d814c0f310d77ed6990c731bccd0fb'
         '4bc2b0be93f76ed07b471e3c89eb5a8a'
         '8e3cec7ab641ec449cabd068be583f5c'
         '9ba148ebabce8ed3351b813a9a66b6e5'
         '568451cf45fc8c7adb83a222a61ca2c6'
         '50b4f5ac4129097461d246645d73a622'
         '3d3fe0a598a53df1d6bec6b416e3b9d0'
         '6f4cbf332816d2c4e9578ecd1d0dce7f'
         'a279e195e249000646895d93e199860d'
         '4bdff6982c66d24a879c424aaac3d04d')