# $Id: PKGBUILD 137694 2015-08-02 12:11:24Z arodseth $
# Maintainer: Alexander Rødseth <rodseth@gmail.com>
# Contributor: Musikolo <musikoloAThotmailDOTcom>
# Contributor: Ruben Fonseca <fonseka@gmail.com>
# Contributor: Andreas W. Hauser <andy-aur@splashground.de>

pkgname=groovy
pkgver=2.4.4
pkgrel=1
pkgdesc='Programming language based on Java, inspired by Python, Ruby and Smalltalk'
arch=('any')
url='http://groovy-lang.org/'
license=('APACHE')
depends=('bash' 'java-environment')
optdepends=('groovy-docs: html and pdf documentation for Groovy')
makedepends=('gendesk')
source=("http://dl.bintray.com/groovy/maven/apache-$pkgname-binary-$pkgver.zip"
        "$pkgname.png::https://raw.githubusercontent.com/apache/incubator-groovy/master/subprojects/groovy-console/src/main/resources/groovy/ui/ConsoleIcon.png")
sha256sums=('a7cc1e5315a14ea38db1b2b9ce0792e35174161141a6a3e2ef49b7b2788c258c'
            '24e539235b5762b1220f39d7953a52e9b4a458c2be4f66a60219755363ba6dba')

prepare() {
  # Generate desktop shortcut
  gendesk -f -n --pkgname "$pkgname" --pkgdesc 'Groovy programming language' \
    --exec 'groovyConsole' --name 'Groovy Console'

  # Set GROOVY_HOME correctly at the top of all the scripts.
  # There are probably better ways to do this, but this works.
  for f in "$pkgname-$pkgver/bin/"*; do
    sed 's:bin/sh:bin/sh\nGROOVY_HOME=/usr/share/groovy:' -i "$f"
  done

  cd "$pkgname-$pkgver/embeddable"
  ln -s "$pkgname-all-$pkgver.jar" "$pkgname-all.jar"
}

package() {
  cd "$pkgname-$pkgver"

  # Create the directories and package the files
  install -d "$pkgdir/usr/share/groovy" "$pkgdir/usr/bin"
  cp -r lib conf embeddable "$pkgdir/usr/share/groovy"
  cp bin/* "$pkgdir/usr/bin"

  # Remove all DOS/Windows batch files
  find $pkgdir -name '*.bat' -exec rm {} \;

  # Package the APACHE license
  install -Dm644 CLI-LICENSE.txt \
    "$pkgdir/usr/share/licenses/$pkgname/CLI-LICENSE"

  # Package the desktop shortcut for Groovy Console
  install -Dm644 "$srcdir/$pkgname.desktop" \
    "$pkgdir/usr/share/applications/$pkgname.desktop"
  install -Dm644 "$srcdir/$pkgname.png" \
    "$pkgdir/usr/share/pixmaps/$pkgname.png"
}

# getver: -u 2 groovy-lang.org/download.html
# vim:set ts=2 sw=2 et:
