# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>

pkgname=jedit
pkgver=5.4.0
pkgrel=5.parabola1
pkgdesc='Editor for programmers'
arch=('any')
url='http://jedit.org/'
license=('GPL')
depends=('java-runtime>=8')
makedepends=('java-environment=8' 'apache-ant' 'apache-ant-contrib' 'apache-ivy' 'beanshell' 'docbook-xsl-saxon'
             'gendesk' 'java-hamcrest' 'jsr305' 'junit' 'xerces2-java')
optdepends=('noto-fonts: usable font')
options=('!emptydirs')
source=("http://sourceforge.net/projects/$pkgname/files/$pkgname/$pkgver/jedit${pkgver}source.tar.bz2"
        'jedit.sh' 'jeditbg.sh' 'jedit.props' 'jedit-fix_build.patch')
sha256sums=('b42dec6c81936b8974308f03c8f356487586cec782d79659b8ae67953c8edf71'
            '91d9b4b0c4855c9624ceea8c6b40c90b53fb15a020b6d954f4bb6b4b934e0348'
            '5cf267b6ee1f908ee7e9a830dc98f03a3a4a53db2822fce6a2cb5ed02d444c69'
            'dc5fe0050321d4f34bce556895fbc39cc6f7df194e14eb4f6ea53166a4d82347'
            '1d747fb3d4b0d4af3d3e752d92858067e02e8160d4d22cf820bd9f45c0fff90b')

prepare() {
  gendesk -f -n \
    --pkgname "$pkgname" \
    --pkgdesc "$pkgdesc" \
    --exec 'jeditbg %U' \
    --name jEdit \
    --genericname Editor

  cd jEdit
  mkdir -p lib/{ant-contrib,compile,docbook,ivy,default-plugins,scripting,test}
  ln -sf /usr/share/java/ant-contrib.jar lib/ant-contrib/ant-contrib.jar
  ln -sf /usr/share/java/apache-ivy/ivy.jar lib/ivy/ivy.jar
  ln -sf /usr/share/java/bsh.jar lib/ant-contrib/bsh.jar
  ln -sf /usr/share/java/docbook-xsl-saxon.jar lib/docbook/docbook-xsl-saxon.jar
  ln -sf /usr/share/java/saxon.jar lib/docbook/saxon.jar
  ln -sf /usr/share/java/xercesImpl.jar lib/docbook/xercesImpl.jar
  ln -sf /usr/share/java/hamcrest-core.jar lib/test/hamcrest-core.jar
  ln -sf /usr/share/java/hamcrest-library.jar lib/test/hamcrest-library.jar
  ln -sf /usr/share/java/jsr305.jar lib/compile/jsr305.jar
  ln -sf /usr/share/java/junit.jar lib/test/junit.jar
  patch -Np1 -i "${srcdir}/jedit-fix_build.patch"
}

build() {
  cd jEdit
  export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
  ant build docs-html \
    -Divy.done=true
}

package() {
  cd jEdit

  # Install documentation
  install -d "$pkgdir/usr/share/java/$pkgname"
  cp -r build/doc "$pkgdir/usr/share/java/$pkgname"

  # Install jars
  install -D -m644 build/$pkgname.jar "$pkgdir/usr/share/java/$pkgname/$pkgname.jar"

  # Install keymaps
  cp -r build/keymaps "${pkgdir}/usr/share/java/${pkgname}"

  # Install macros
  cp -r build/macros "${pkgdir}/usr/share/java/${pkgname}"

  # Install modes
  cp -r build/modes "${pkgdir}/usr/share/java/${pkgname}"

  # Install properties
  cp -r build/properties "${pkgdir}/usr/share/java/${pkgname}"

  # Install startup
  cp -r build/startup "${pkgdir}/usr/share/java/${pkgname}"

  # Man pages
  install -Dm644 package-files/linux/$pkgname.1 "$pkgdir/usr/share/man/man1/$pkgname.1"

  install -d "$pkgdir/usr/bin"
  install -Dm755 "$srcdir/$pkgname.sh" "$pkgdir/usr/bin/$pkgname"
  install -Dm755 "$srcdir/${pkgname}bg.sh" "$pkgdir/usr/bin/${pkgname}bg"
  install -Dm644 "$srcdir/$pkgname.props" "$pkgdir/usr/share/$pkgname/default.props"
  install -Dm644 doc/$pkgname.png "$pkgdir/usr/share/pixmaps/$pkgname.png"
  install -Dm644 "$srcdir/$pkgname.desktop" "$pkgdir/usr/share/applications/$pkgname.desktop"
}
