# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=5

inherit java-pkg-2 xdg-utils

DESCRIPTION="Digital is an easy-to-use digital logic designer and circuit simulator designed for educational purposes."
HOMEPAGE="https://github.com/hneemann/Digital"

SRC_URI="https://github.com/hneemann/Digital/releases/download/v${PV}/Digital.zip -> ${P}.zip"
LICENSE="GPL-3"
RESTRICT=""
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""

RDEPEND=">=virtual/jre-1.6
	dev-util/desktop-file-utils
"

S="${WORKDIR}/Digital"

pkg_setup() { :; }

src_compile() { :; }

src_install() {
	local dir="/opt/${PN}"

	# buggy binary crap also requires the demo dir ??
	insinto "${dir}"
	doins -r examples lib

	# Xerces has been patched hope this gets upstream was version 2.9.1
	# relaxng is a heavely modified version of jing 20030619
	java-pkg_jarinto "${dir}"
	java-pkg_dojar Digital.jar
	#local dep="javahelp,saxon-6.5,saxon-9,xml-commons-resolver"
	#java-pkg_register-dependency ${dep}

	# put launchers into the xxe/bin dir as expected by the xxe.jar
	into "${dir}"
        java-pkg_dolauncher ${PN} \
		--main "de.neemann.digital.gui.Main" \
		--java_args "-Xss4m -Xmx512m"

	# for direct run without creating an env.d file link them
	dodir /opt/bin
	dosym ${dir}/bin/${PN} /opt/bin/${PN}

	dodoc docu/* *.txt *.me

	newicon icon.svg ${PN}.svg
	
	sed -e "s,<EXEC_LOCATION>,${dir}/bin/${PN},g" \
	-e "s,<ICON_LOCATION>,${PN},g" "${S}/linux/desktop.template" > "${S}/${PN}.desktop"
	domenu ${PN}.desktop

	# Install mime info (from Ubuntu)
	insinto /usr/share/mime/packages/
	doins "linux/digital-simulator.xml"

}

pkg_postinst() {
    xdg_desktop_database_update
    xdg_mimeinfo_database_update
}

pkg_postrm() {
    xdg_desktop_database_update
    xdg_mimeinfo_database_update
}