summaryrefslogtreecommitdiff
blob: 012a2cdaba4c8880db89da697f89addfc64d79fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

EAPI=5

JAVA_PKG_IUSE="doc source"

inherit java-pkg-2 java-pkg-simple versionator

# Switch to ^^ when we switch to EAPI=6.
#MY_PN="${PN^^}"
MY_PN="GROOVY"
MY_PV="$(replace_all_version_separators _ ${PV})"
MY_P="${MY_PN}_${MY_PV}"

DESCRIPTION="A multi-faceted language for the Java platform"
HOMEPAGE="http://www.groovy-lang.org/"
SRC_URI="https://github.com/apache/incubator-${PN}/archive/${MY_P}.zip -> ${P}.zip"
LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="amd64 ppc64 x86"
IUSE=""

CDEPEND="
	dev-java/jansi:0
	dev-java/xstream:0
	dev-java/commons-cli:1
	>=dev-java/asm-5.0.3:4
	>=dev-java/antlr-2.7.7-r7:0"

RDEPEND="
	${CDEPEND}
	>=virtual/jre-1.6"

DEPEND="
	${CDEPEND}
	>=virtual/jdk-1.6
	source? ( app-arch/zip )"

JAVA_GENTOO_CLASSPATH="
	asm-4
	antlr
	jansi
	xstream
	commons-cli-1
"

S="${WORKDIR}/incubator-${PN}-${MY_P}"

# ExceptionUtil filename.
EU="ExceptionUtils.java"

# List of antlr grammar files.
ANTLR_GRAMMAR_FILES=(
	org/codehaus/groovy/antlr/groovy.g
	org/codehaus/groovy/antlr/java/java.g
)

# Patches utils.gradle. It basically rewrites ExceptionUtils.
PATCHES=(
	"${FILESDIR}"/"${P}-utils.gradle.patch"
)

# Add target/classes to the CP as we're generating an extra class there.
JAVA_GENTOO_CLASSPATH_EXTRA="target/classes"

# This function cleans up the source directory.
# We're ONLY interested in the "src/main" directory content and nothing else.
# (for the time being).
groovy_cleanup_source_files() {
	ebegin "Cleaning up useless files"
	mv src/main "${T}" || die
	mv gradle/utils.gradle "${T}" || die
	rm -rf * || die
	mv "${T}"/main/* . || die
	rm -rf "${T}"/main || die
	eend $?
}

java_prepare() {
	epatch "${PATCHES[@]}"
	groovy_cleanup_source_files
}

# This function generates the ANTLR grammar files.
generate_antlr_grammar() {
	for grammar_file in "${@}"; do
		local my_grammar_file=$(basename ${grammar_file})

		einfo "Generating \"${my_grammar_file}\" grammar file"
		local my_grammar_dir=$(dirname ${grammar_file})

		cd "${S}/${my_grammar_dir}" || die
		antlr ${my_grammar_file} || die

		cd "${S}" || die
	done
}

# This function generates ExceptionUtils.class.
# ExceptionUtils is a helper class needed when compiling Groovy 2.x.
# Normally, this class is generated via a Gradle task at compile time. Since we
# don't use Gradle here.. we've translated it into a plain Java file and have
# it generate the same data.
generate_exceptionutils() {
	ebegin "Copying ${EU}"
	mv "${T}/utils.gradle" "${EU}" || die
	eend $?

	ejavac -classpath "$(java-pkg_getjar --build-only asm-4 asm.jar)" ${EU}

	ebegin "Running ${EU%.java}"
	$(java-config -J) -classpath "$(java-pkg_getjar --build-only asm-4 asm.jar):." ${EU%.java} || die
	eend $?
}

src_compile() {
	generate_antlr_grammar "${ANTLR_GRAMMAR_FILES[@]}"
	generate_exceptionutils
	java-pkg-simple_src_compile
}

src_install() {
	java-pkg_dolauncher "groovyc" --main org.codehaus.groovy.tools.FileSystemCompiler
	java-pkg_dolauncher "groovy" --main groovy.ui.GroovyMain
	java-pkg-simple_src_install

	# TODO: groovy console and groovy shell are parts of the "subprojects"
	# directory. figure out a way to compile them. :\
	# java-pkg_dolauncher "groovysh" --main groovy.ui.InteractiveShell
	# java-pkg_dolauncher "groovyConsole" --main groovy.ui.Console

	# TODO: grape is written in groovy and to compile it, you need .. groovy.
	# java-pkg_dolauncher "grape" --main org.codehaus.groovy.tools.GrapeMain
}