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