Diff antlr-tool-3.5.3 with a antlr-tool-4.9.3

/usr/portage/dev-java/antlr-tool/antlr-tool-4.9.3.ebuild 2023-10-09 14:52:29.412368348 +0300
3 3

  
4 4
EAPI=8
5 5

  
6
# Artifact ID for antlr-tool is 'antlr'
7
# https://github.com/antlr/antlr3/blob/3.5.3/tool/pom.xml#L4
8
MAVEN_ID="org.antlr:antlr:3.5.3"
6
# Artifact ID for antlr-tool is 'antlr4'
7
# https://github.com/antlr/antlr4/blob/4.9.3/tool/pom.xml#L14
8
MAVEN_ID="org.antlr:antlr4:4.9.3"
9 9

  
10 10
JAVA_PKG_IUSE="doc source test"
11 11
JAVA_TESTING_FRAMEWORKS="junit-4"
......
15 15
MY_PN="${PN%-tool}"
16 16
MY_P="${MY_PN}-${PV}"
17 17

  
18
DESCRIPTION="The ANTLR 3 tool"
19
HOMEPAGE="https://www.antlr3.org/"
20
# Maven Central sources JAR for *.java sources pre-generated from *.g files;
21
# the source generation requires this package itself.
22
# Tarball for resources, the test suite, and DOCS files
18
DESCRIPTION="The ANTLR 4 grammar compiler"
19
HOMEPAGE="https://www.antlr.org/"
20
# Maven Central sources JAR for tool/src/org/antlr/v4/unicode/UnicodeData.java,
21
# which requires string-template-maven-plugin to generate; tarball for the rest
23 22
SRC_URI="
24
	https://repo1.maven.org/maven2/org/antlr/antlr/${PV}/${MY_P}-sources.jar -> ${P}-sources.jar
25
	https://github.com/antlr/antlr3/archive/${PV}.tar.gz -> ${MY_P}.tar.gz
23
	https://github.com/antlr/antlr4/archive/${PV}.tar.gz -> ${MY_P}.tar.gz
24
	https://repo1.maven.org/maven2/org/antlr/antlr4/${PV}/antlr4-${PV}-sources.jar -> ${P}-sources.jar
26 25
"
27 26

  
28 27
LICENSE="BSD"
29
SLOT="3.5"
28
SLOT="4"
30 29
KEYWORDS="amd64 ~arm arm64 ppc64 x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x64-solaris"
31 30

  
32 31
CP_DEPEND="
33 32
	~dev-java/antlr-runtime-${PV}:${SLOT}
33
	dev-java/antlr-runtime:3.5
34
	dev-java/jakarta-json-api:1
35
	dev-java/icu4j:70
34 36
	dev-java/stringtemplate:4
35
"
36

  
37
BDEPEND="
38
	app-arch/unzip
37
	dev-java/treelayout:0
39 38
"
40 39

  
41 40
DEPEND="
42 41
	>=virtual/jdk-1.8:*
43 42
	${CP_DEPEND}
43
	dev-java/antlr-tool:3.5
44
	test? (
45
		dev-java/jol-core:0
46
	)
44 47
"
45 48

  
46 49
RDEPEND="
......
48 51
	${CP_DEPEND}
49 52
"
50 53

  
51
S="${WORKDIR}"
52
TARBALL_S="${S}/${MY_PN}3-${PV}"
53

  
54
JAVA_SRC_DIR="org"
55
JAVA_RESOURCE_DIRS=( "${TARBALL_S}/tool/src/main/resources" )
56

  
57
JAVA_TEST_GENTOO_CLASSPATH="junit-4"
58
JAVA_TEST_SRC_DIR="${TARBALL_S}/tool/src/test/java"
54
S="${WORKDIR}/${MY_PN}4-${PV}"
59 55

  
60
DOCS=( "${TARBALL_S}/tool/CHANGES.txt" )
56
JAVA_SRC_DIR=(
57
	tool/src
58
	../src/org # For UnicodeData.java
59
)
60
JAVA_RESOURCE_DIRS=( tool/resources )
61

  
62
JAVA_TEST_GENTOO_CLASSPATH="junit-4,jol-core"
63
JAVA_TEST_SRC_DIR=(
64
	tool-testsuite/test
65
	# The runtime test suite is used as a library for tool test suite
66
	runtime-testsuite/{annotations,test}
67
)
68
JAVA_TEST_RESOURCE_DIRS=(
69
	# Some resources are mixed with test source files
70
	"${JAVA_TEST_SRC_DIR[0]}"
71
)
72

  
73
pkg_setup() {
74
	java-pkg-2_pkg_setup
75
	MY_JAVA="$(java-config -J)"
76
}
61 77

  
62 78
src_prepare() {
63 79
	java-pkg_clean
80
	eapply "${FILESDIR}/${PV}-test-fixes.patch"
64 81
	java-pkg-2_src_prepare
82
}
65 83

  
66
	# Some tests fail under Java 8 in ways that probably aren't limited
67
	# to the tests. This is bad but upstream is never going to update
68
	# 3.5. At the time of writing, we only use it to build 4 anyway.
69
	rm -v "${JAVA_TEST_SRC_DIR}/org/antlr/test/"Test{DFAConversion,SemanticPredicates,TopologicalSort}.java || die
84
src_compile() {
85
	einfo "Generating ANTLR 3 parsers"
86
	"${MY_JAVA}" -cp "$(java-pkg_getjars \
87
		--build-only --with-dependencies antlr-tool-3.5)" \
88
		org.antlr.Tool $(find "${JAVA_SRC_DIR[@]}" -name "*.g") ||
89
		die "Failed to generate ANTLR 3 parsers"
90
	java-pkg-simple_src_compile
70 91
}
71 92

  
72
src_install() {
73
	java-pkg-simple_src_install
74
	einstalldocs # https://bugs.gentoo.org/789582
93
src_test() {
94
	# Build classpath for tests
95
	local test_deps=(
96
		"${JAVA_TEST_GENTOO_CLASSPATH}"
97
		antlr-runtime-${SLOT}
98
		antlr-runtime-3.5
99
		jakarta-json-api-1
100
		icu4j-70
101
		stringtemplate-4
102
		treelayout
103
	)
104
	local CP="${S}/${JAVA_JAR_FILENAME}"
105
	for test_dep in "${test_deps[@]}"; do
106
		CP+=":$(java-pkg_getjars --with-dependencies "${test_dep}")"
107
	done
108
	for res_dir in "${JAVA_TEST_RESOURCE_DIRS[@]}"; do
109
		CP+=":${res_dir}"
110
	done
111

  
112
	einfo "Generating ANTLR 4 parsers for tests"
113
	pushd runtime-testsuite/test > /dev/null ||
114
		die "Failed to enter runtime test source directory"
115
	g4_files=( $(find * -name "*.g4") )
116
	for file in "${g4_files[@]}"; do
117
		java_pkg="${file%/*.g4}"
118
		java_pkg="${java_pkg//\//.}"
119
		"${MY_JAVA}" -cp "${CP}" org.antlr.v4.Tool \
120
			-visitor -package "${java_pkg}" "${file}" ||
121
			die "Failed to generate ANTLR 4 parser from ${file}"
122
	done
123
	popd > /dev/null || die "Failed to leave runtime test source directory"
124

  
125
	# Compile Java test sources
126
	local classes="target/classes"
127
	ejavac -d "${classes}" -cp "${CP}" \
128
		$(find "${JAVA_TEST_SRC_DIR[@]}" -name "*.java")
129

  
130
	# Create a list of tests to run
131
	pushd "${JAVA_TEST_SRC_DIR[0]}" > /dev/null ||
132
		die "Failed to enter test source directory for ${PN}"
133
	local TESTS=$(find * -type f \
134
		\( -name "Test*.java" -o -name "*Test.java" \) \
135
		-not -name "BaseJavaToolTest.java" # No runnable methods
136
	)
137
	TESTS="${TESTS//.java}"
138
	TESTS="${TESTS//\//.}"
139
	popd > /dev/null || die "Failed to leave test source directory for ${PN}"
140

  
141
	ejunit4 -classpath "${classes}:${CP}" ${TESTS}
75 142
}
Thank you!