Drop $Id$ per council decision in bug #611234.
[gentoo.git] / dev-java / jflex / jflex-1.6.1.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="5"
5
6 JAVA_PKG_IUSE="doc source"
7
8 inherit eutils java-pkg-2 java-pkg-simple
9
10 DESCRIPTION="JFlex is a lexical analyzer generator for Java"
11 HOMEPAGE="http://www.jflex.de/"
12 SRC_URI="http://${PN}.de/${P}.tar.gz"
13 LICENSE="BSD"
14 SLOT="0"
15 KEYWORDS="amd64 ~arm ppc64 x86 ~amd64-fbsd ~ppc-macos ~x64-macos ~x86-macos"
16 IUSE="examples test vim-syntax"
17
18 CDEPEND="dev-java/ant-core:0"
19
20 RDEPEND=">=virtual/jre-1.6
21         vim-syntax? ( || ( app-editors/vim app-editors/gvim ) )
22         ${CDEPEND}"
23
24 DEPEND=">=virtual/jdk-1.6
25         test? ( dev-java/junit:4 )
26         ${CDEPEND}"
27
28 PDEPEND=">=dev-java/javacup-0.11b_p20151001:0"
29
30 S="${WORKDIR}/${P}"
31 JAVA_SRC_DIR="src/main/java"
32
33 java_prepare() {
34         # See below for details.
35         epatch "${FILESDIR}/icedtea-arm.patch"
36
37         # We need the bundled jflex.jar.
38         rm -rv ${JAVA_SRC_DIR}/java_cup examples/pom.xml || die
39
40         # Remove the bundled java-cup.jar if unneeded.
41         if has_version ${PDEPEND}; then
42                 rm -v lib/java-cup-*.jar || die
43         fi
44 }
45
46 src_configure() {
47         # javacup is a cyclic dependency. Use the package if we have it,
48         # otherwise use the bundled version and install the package later.
49         if has_version ${PDEPEND}; then
50                 # Use PORTAGE_QUIET to suppress a QA warning that is spurious
51                 # thanks to has_version above. This is Portage-specific but
52                 # showing the warning elsewhere isn't the end of the world.
53                 JAVACUP=$(PORTAGE_QUIET=1 java-pkg_getjar --build-only javacup javacup.jar)
54         else
55                 JAVACUP=$(echo lib/java-cup-*.jar)
56         fi
57
58         JAVA_GENTOO_CLASSPATH_EXTRA="$(java-pkg_getjars --build-only ant-core):${JAVACUP}"
59 }
60
61 jflex_compile() {
62         java "${@}" jflex.Main -d ${JAVA_SRC_DIR}/${PN} --skel src/main/${PN}/skeleton.nested src/main/${PN}/LexScan.flex || die
63         java-pkg-simple_src_compile
64         java-pkg_addres ${PN}.jar src/main/resources
65 }
66
67 src_compile() {
68         java -jar "${JAVACUP}" -destdir ${JAVA_SRC_DIR}/${PN} -package ${PN} -parser LexParse -interface src/main/cup/LexParse.cup || die
69
70         # The IcedTea ARM HotSpot port (as of 2.6.1) hangs when running
71         # jflex. We have patched jflex to fix it but we have to run the
72         # bundled version first. -Xint works around the problem. See
73         # http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=2678.
74         use arm && local JFLEX_ARGS="-Xint"
75
76         # First compile (without doc/source) using the bundled jflex.
77         JAVA_PKG_IUSE= jflex_compile -cp "lib/${P}.jar:${JAVACUP}" ${JFLEX_ARGS}
78
79         # Then recompile using the fresh jflex.
80         jflex_compile -cp "${PN}.jar:${JAVACUP}"
81 }
82
83 src_install() {
84         java-pkg-simple_src_install
85         java-pkg_dolauncher ${PN} --main ${PN}.Main
86
87         java-pkg_register-dependency javacup javacup-runtime.jar
88         java-pkg_register-ant-task
89
90         use examples && java-pkg_doexamples examples
91         dodoc {changelog,README}.md
92
93         if use doc; then
94                 dodoc doc/*.pdf
95                 docinto html
96                 dodoc doc/*.{css,html,png} doc/COPYRIGHT
97         fi
98
99         if use vim-syntax; then
100                 insinto /usr/share/vim/vimfiles/syntax
101                 doins lib/${PN}.vim
102         fi
103 }
104
105 src_test() {
106         if use arm && java-pkg_current-vm-matches oracle-jdk-bin-1.8; then
107                 # This results in a StackOverflowError as of 1.8.0.65 but works
108                 # fine on icedtea:7. Don't know about icedtea:8 yet.
109                 rm -v src/test/java/jflex/EmitterTest.java || die
110         fi
111
112         local CP="src/test/java:${PN}.jar:${JAVA_GENTOO_CLASSPATH_EXTRA}:$(java-pkg_getjars junit-4)"
113
114         local TESTS=$(find src/test/java -name "*Test*.java" -printf "%P\n")
115         TESTS="${TESTS//.java}"
116         TESTS="${TESTS//\//.}"
117
118         ejavac -classpath "${CP}" $(find src/test/java -name "*.java")
119         ejunit4 -classpath "${CP}" ${TESTS}
120 }