summaryrefslogtreecommitdiff
blob: 3338b924006748ef2c03cdc6da232568cc952479 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/java-pkg.eclass,v 1.48 2006/12/03 15:27:48 betelgeuse Exp $

inherit multilib

EXPORT_FUNCTIONS pkg_setup

# We need to do a few things to add compatibility between
# generation-1 and generation-2.

# First we make sure java-config-1 will be used
export WANT_JAVA_CONFIG="1"

# We can't depend on java-config directly because some packages use this eclass
# only with the java use flag.
# http://bugs.gentoo.org/show_bug.cgi?id=137971
#DEPEND="
#	=dev-java/java-config-1.3*
#	=dev-java/java-config-2*"

# During pkg_setup, we need to do a few extra things to ensure things work in a
# mixed generation-1/generation-2 environment
# TODO need to make sure everything that inherits java-pkg and has a pkg_setup
# uses java-pkg_pkg_setup
java-pkg_pkg_setup() {
	java-pkg_announce-qa-violation "using deprecated eclass java-pkg"

	# We need to do a little magic if java-config-2 is around
	if has_version "=dev-java/java-config-2*"; then
		# we only want to enable the Java stuff if
		# there isn't a Java use flag (means its a pure Java pckage)
		# or if there is a Java use flag and it is enabled
		if ! hasq java ${IUSE} || use java; then
			initialize-java-environment
			if [[ -n ${GENTOO_VM} ]]; then
				einfo "Using Generation-1 System VM: ${GENTOO_VM}"
			else
				echo
				eerror "There was a problem determining which VM to use for generation-1"
				eerror "This is because the way Java is handled on Gentoo has drastically changed."
				if ! has_version "=virtual/jdk-1.4*" || ! has_version "=virtual/jdk-1.3*"; then
					ewarn "There does not seem to be a 1.4 or 1.3 JDK installed."
					ewarn "You should probably install =virtual/jdk-1.4* or =virtual/jdk-1.3*"
					ewarn "It is important to have either a 1.4 or 1.3 JDK installed"
					ewarn "in order for the old and new Java systems to coexist"
					ewarn "Details about this can be found at:"
					ewarn "\thttp://overlays.gentoo.org/proj/java/wiki/Why_We_Need_Java14"
					echo
				fi

				eerror "You should run, and follow the advice of:"
				eerror "\t/usr/bin/java-check-environment"

				eerror "You will also likely want to follow the Java Upgrade Guide:"
				eerror "\thttp://www.gentoo.org/proj/en/java/java-upgrade.xml"
				eerror "If you have problems with the guide, please see:"
				eerror "\thttp://overlays.gentoo.org/proj/java/wiki/Common_Problems"
				die "Expected VMHANDLE to be defined in the env"
			fi
		fi
	fi
}

initialize-java-environment() {
	if has_version "=dev-java/java-config-2*"; then
		# VMHANDLE is the variable in an env file that identifies how java-config-2
		# knows a VM. With each VM, we have a 'compatible' env file installed to
		# /etc/env.d/java, so java-config-1 can work.
		#
		# So, here we set GENTOO_VM to be VMHANDLE, and thus to the
		# generation-1 system VM.
		export GENTOO_VM=$(java-config-1 -g VMHANDLE)

		# use java-config-2, with GENTOO_VM set to generation-1 system vm, to
		# setup JAVA_HOME
		export JAVA_HOME=$(java-config-2 --jdk-home)
		export JDK_HOME=$(java-config-2 --jdk-home)
		# make sure JAVAC and JAVA are set correctly
		export JAVAC=$(java-config-2 --javac)
		export JAVA=$(java-config-2 --java)
	fi
	# Otherwise, JAVA_HOME should be defined already
}

# These are pre hooks to make sure JAVA_HOME is set properly.
# note: don't need pkg_setup, since we define it here
# FIXME remove these hooks after portage-2.1.1 is stable, as
# it has proper env saving
pre_src_unpack() {
	initialize-java-environment
}

pre_src_compile() {
	initialize-java-environment
}

pre_src_install() {
	initialize-java-environment
}

pre_src_test() {
	initialize-java-environment
}

pre_pkg_preinst() {
	initialize-java-environment
}

pre_pkg_postinst() {
	initialize-java-environment
}


pkglistpath="${T}/java-pkg-list"

java-pkg_doclass()
{
	debug-print-function ${FUNCNAME} $*
	java-pkg_dojar $*
}

java-pkg_do_init_()
{
	debug-print-function ${FUNCNAME} $*

	if [ -z "${JARDESTTREE}" ] ; then
		JARDESTTREE="lib"
		SODESTTREE=$(get_libdir)
	fi

	# Set install paths
	sharepath="${DESTTREE}/share"
	if [ "$SLOT" == "0" ] ; then
		pkg_name="${PN}"
	else
		pkg_name="${PN}-${SLOT}"
	fi

	shareroot="${sharepath}/${pkg_name}"

	if [ -z "${jardest}" ] ; then
		jardest="${shareroot}/${JARDESTTREE}"
	fi

	if [ -z "${sodest}" ] ; then
		sodest="/opt/${pkg_name}/${SODESTTREE}"
	fi

	package_env="${D}${shareroot}/package.env"

	debug-print "JARDESTTREE=${JARDESTTREE}"
	debug-print "SODESTTREE=${SODESTTREE}"
	debug-print "sharepath=${sharepath}"
	debug-print "shareroot=${shareroot}"
	debug-print "jardest=${jardest}"
	debug-print "sodest=${sodest}"
	debug-print "package_env=${package_env}"

}

java-pkg_do_write_()
{
	debug-print-function ${FUNCNAME} $*
	# Create directory for package.env
	dodir "${shareroot}"

	# Create package.env
	echo "DESCRIPTION=${DESCRIPTION}" > "${package_env}"
	echo "GENERATION=1" >> "${package_env}"
	if [ -n "${cp_pkg}" ]; then
		debug-print "cp_prepend: ${cp_prepend}"
		debug-print "cp_pkg: ${cp_pkg}"
		debug-print "cp_append: ${cp_append}"
		echo "CLASSPATH=${cp_prepend}:${cp_pkg}:${cp_append}" >> "${package_env}"
	fi
	if [ -n "${lp_pkg}" ]; then
		echo "LIBRARY_PATH=${lp_prepend}:${lp_pkg}:${lp_append}" >> "${package_env}"
	fi
	if [ -f ${pkglistpath} ] ; then
		pkgs=$(cat ${pkglistpath} | tr '\n' ':')
		echo "DEPEND=${pkgs}" >> "${package_env}"
	fi

	# Strip unnecessary leading and trailing colons
	sed -e "s/=:/=/" -e "s/:$//" -i "${package_env}"
}

java-pkg_do_getsrc_()
{
	# Check for symlink
	if [ -L "${i}" ] ; then
		cp "${i}" "${T}"
		echo "${T}"/`/usr/bin/basename "${i}"`

	# Check for directory
	elif [ -d "${i}" ] ; then
		echo "java-pkg: warning, skipping directory ${i}"
		continue
	else
		echo "${i}"
	fi
}


java-pkg_doso()
{
	debug-print-function ${FUNCNAME} $*
	[ -z "$1" ]

	java-pkg_do_init_

	# Check for arguments
	if [ -z "$*" ] ; then
		die "at least one argument needed"
	fi

	# Make sure directory is created
	if [ ! -d "${D}${sodest}" ] ; then
		install -d "${D}${sodest}"
	fi

	for i in $* ; do
		mysrc=$(java-pkg_do_getsrc_)

		# Install files
		install -m 0755 "${mysrc}" "${D}${sodest}" || die "${mysrc} not found"
	done
	lp_pkg="${sodest}"

	java-pkg_do_write_
}

java-pkg_dojar()
{
	debug-print-function ${FUNCNAME} $*
	[ -z "$1" ]

	java-pkg_do_init_

	if [ -n "${DEP_PREPEND}" ] ; then
		for i in ${DEP_PREPEND}
		do
			if [ -f "${sharepath}/${i}/package.env" ] ; then
				debug-print "${i} path: ${sharepath}/${i}"
				if [ -z "${cp_prepend}" ] ; then
					cp_prepend=`grep "CLASSPATH=" "${sharepath}/${i}/package.env" | sed "s/CLASSPATH=//"`
				else
					cp_prepend="${cp_prepend}:"`grep "CLASSPATH=" "${sharepath}/${i}/package.env" | sed "s/CLASSPATH=//"`
				fi
			else
				debug-print "Error:  Package ${i} not found."
				debug-print "${i} path: ${sharepath}/${i}"
				die "Error in DEP_PREPEND."
			fi
			debug-print "cp_prepend=${cp_prepend}"

		done
	fi

	if [ -n "${DEP_APPEND}" ] ; then
		for i in ${DEP_APPEND}
		do
			if [ -f "${sharepath}/${i}/package.env" ] ; then
				debug-print "${i} path: ${sharepath}/${i}"
				# Before removing the quotes this caused
				# https://bugs.gentoo.org/show_bug.cgi?id=155590
				# There was also an extra quote in the else that could also be
				# the cause.
				if [ -z "${cp_append}" ] ; then
					cp_append=$(grep "CLASSPATH=" "${sharepath}/${i}/package.env" \
						| sed -e "s/CLASSPATH=//" -e 's/"//g')
				else
					cp_append="${cp_append}:$(grep "CLASSPATH=" \
					"${sharepath}/${i}/package.env" \
						| sed -e "s/CLASSPATH=//" -e 's/"//g')"
				fi
			else
				debug-print "Error:  Package ${i} not found."
				debug-print "${i} path: ${sharepath}/${i}"
				die "Error in DEP_APPEND."
			fi
			debug-print "cp_append=${cp_append}"
		done
	fi

	# Check for arguments
	if [ -z "$*" ] ; then
		die "at least one argument needed"
	fi

	# Make sure directory is created
	dodir ${jardest}

	for i in $* ; do
		mysrc=$(java-pkg_do_getsrc_)

		# Install files
		install -m 0644 "${mysrc}" "${D}${jardest}" || die "${mysrc} not found"

		# Build CLASSPATH
		if [ -z "${cp_pkg}" ] ; then
			cp_pkg="${jardest}"/`/usr/bin/basename "${i}"`
		else
			cp_pkg="${cp_pkg}:${jardest}/"`/usr/bin/basename "${i}"`
		fi
	done

	java-pkg_do_write_
}

java-pkg_newjar()
{
	if [ -z "${T}" ] || [ -z "${2}" ] ; then
		die "java-pkg_newjar: Nothing defined to do"
	fi

	rm -rf "${T}/${2}"
	cp "${1}" "${T}/${2}"
	java-pkg_dojar "${T}/${2}"
}

java-pkg_dowar()
{
	debug-print-function ${FUNCNAME} $*
	[ -z "$1" ]

	# Check for arguments
	if [ -z "$*" ] ; then
		die "at least one argument needed"
	fi

	if [ -z "${WARDESTTREE}" ] ; then
		WARDESTTREE="webapps"
	fi

	sharepath="${DESTTREE}/share"
	shareroot="${sharepath}/${PN}"
	wardest="${shareroot}/${WARDESTTREE}"

	debug-print "WARDESTTREE=${WARDESTTREE}"
	debug-print "sharepath=${sharepath}"
	debug-print "shareroot=${shareroot}"
	debug-print "wardest=${wardest}"

	# Patch from Joerg Schaible <joerg.schaible@gmx.de>
	# Make sure directory is created
	if [ ! -d "${D}${wardest}" ] ; then
		install -d "${D}${wardest}"
	fi

	for i in $* ; do
		# Check for symlink
		if [ -L "${i}" ] ; then
			cp "${i}" "${T}"
			mysrc="${T}"/`/usr/bin/basename "${i}"`

		# Check for directory
		elif [ -d "${i}" ] ; then
			echo "dowar: warning, skipping directory ${i}"
			continue
		else
			mysrc="${i}"
		fi

		# Install files
		install -m 0644 "${mysrc}" "${D}${wardest}"
	done
}

java-pkg_dozip()
{
	debug-print-function ${FUNCNAME} $*
	java-pkg_dojar $*
}

_record-jar()
{
	echo "$(basename $2)@$1" >> ${pkglistpath}
}

java-pkg_jarfrom() {
	java-pkg_jar-from "$@"
}

java-pkg_jar-from()
{
	debug-print-function ${FUNCNAME} $*

	local pkg=$1
	local jar=$2
	local destjar=$3

	if [ -z "${destjar}" ] ; then
		destjar=${jar}
	fi

	for x in $(java-config --classpath=${pkg} | tr ':' ' '); do
		if [ ! -f ${x} ] ; then
			die "Installation problems with jars in ${pkg} - is it installed?"
			return 1
		fi
		_record-jar ${pkg} ${x}
		if [ -z "${jar}" ] ; then
			[[ -f $(basename ${x}) ]]  && rm $(basename ${x})
			ln -snf ${x} $(basename ${x})
		elif [ "$(basename ${x})" == "${jar}" ] ; then
			[[ -f ${destjar} ]]  && rm ${destjar}
			ln -snf ${x} ${destjar}
			return 0
		fi
	done
	if [ -z "${jar}" ] ; then
		return 0
	else
		die "failed to find ${jar}"
	fi
}

java-pkg_getjar()
{

	debug-print-function ${FUNCNAME} $*

	local pkg=$1
	local jar=$2

	for x in $(java-config --classpath=${pkg} | tr ':' ' '); do

		if [ ! -f ${x} ] ; then
			die "Installation problems with jars in ${pkg} - is it installed?"
		fi

		_record-jar ${pkg} ${x}

		if [ "$(basename ${x})" == "${jar}" ] ; then
			echo ${x}
			return 0
		fi
	done
	die "Could not find $2 in $1"
}

java-pkg_getjars()
{
	java-config --classpath=$1
}


java-pkg_dohtml()
{
	dohtml -f package-list $@
}

java-pkg_jarinto()
{
	jardest=$1
}

java-pkg_sointo()
{
	sodest=$1
}

java-pkg_dosrc() {
	java-pkg_do_init_

	[ $# -lt 1 ] && die "${FUNCNAME[0]}: at least one argument needed"

	local target="${shareroot}/source/"

	local files
	local startdir=$(pwd)
	for x in ${@}; do
		cd $(dirname ${x})
		zip -q -r ${T}/${PN}-src.zip $(basename ${x}) -i '*.java'
		local res=$?
		if [[ ${res} != 12 && ${res} != 0 ]]; then
			die "zip failed"
		fi

		cd ${startdir}
	done

	dodir ${target}
	install ${INSOPTIONS} "${T}/${PN}-src.zip" "${D}${target}" \
		|| die "failed to install sources"
}


java-pkg_announce-qa-violation() {
	if hasq java-strict ${FEATURES}; then
		echo "Java QA Notice: $@" >&2
	fi
}