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

# TODO Look to actually splitting this into 2 packages.
# Maybe not.  j3d-core-utils requires j3d-core's build.xml files to build.
# they are more or less the same package.  Maybe just add a use flag to install
# utils jar/javadoc

EAPI=5

WANT_ANT_TASKS="ant-nodeps"
JAVA_PKG_IUSE="doc source"
inherit eutils subversion java-pkg-2 java-ant-2

DESCRIPTION="Java3D Core API and Utils package"
HOMEPAGE="https://java3d.java.net/"

LICENSE="GPL-2-with-exceptions BSD"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""

COMMON_DEP="~dev-java/vecmath-${PV}"

RDEPEND=">=virtual/jre-1.5
		${COMMON_DEP}"
DEPEND=">=virtual/jdk-1.5
		app-arch/unzip
		dev-java/eclipse-ecj:4.2[ant]
		${COMMON_DEP}"

ESVN_PROJECTS=(
	"${P}"
	"${PN}-utils-${PV}"
)
ESVN_REPOS=(
	"https://svn.java.net/svn/${PN}~svn/tags/rel-${PV//./_}-fcs"
	"https://svn.java.net/svn/${PN}-utils~svn/tags/rel-${PV//./_}-fcs"
)
EANT_BUILD_TARGET="jar-opt"
EANT_DOC_TARGET="docs"
ANT_OPTS="-Xmx1g"
JAVA_PKG_FORCE_COMPILER="ecj-4.2"

S="${WORKDIR}"/${PN}

src_unpack() {
	# we have to fetch sources from two repositories
	for k in 0 1
	do
		# remove version from dirs for the patches and for the reference in build.xml
		outd=${ESVN_PROJECTS[$k]}
		outd=${outd%-*}

		ESVN_PROJECT=${ESVN_PROJECTS[$k]}
		subversion_fetch ${ESVN_REPOS[$k]} ../${outd}
	done
}

src_prepare() {
	# prepare references to external libs
	for d in "${WORKDIR}"/vecmath/build/opt/lib/ext "${WORKDIR}"/vecmath/build/debug/lib/ext
	do
		mkdir -p "${d}"

	    cd "${d}"
		java-pkg_jarfrom vecmath
	done

	# not using subversion.eclass patch facility because it changes dir to ${S}
	cd "${WORKDIR}"
	epatch "${FILESDIR}"/${P}-build.patch
	epatch "${FILESDIR}"/${P}-java1_7-codec-jpeg.patch
}

src_install() {
	local arch=""
	use x86 && arch="linux-i586"
	use amd64 && arch="linux-amd64"
	java-pkg_dojar build/default/opt/lib/ext/*.jar
	java-pkg_doso build/default/opt/native/*.so
	use doc && \
		mv build/${arch}/javadocs/{docs-public,api} && \
		dohtml -r build/${arch}/javadocs/api
	use source && java-pkg_dosrc src/classes/jogl/javax src/classes/share/javax \
		src/classes/x11/javax src/classes/win32/javax
}