forked from gentoo/gentoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
java-utils-2.eclass
2917 lines (2542 loc) · 85.4 KB
/
java-utils-2.eclass
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2004-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
# @ECLASS: java-utils-2.eclass
# @MAINTAINER:
# @AUTHOR:
# Thomas Matthijs <[email protected]>, Karl Trygve Kalleberg <[email protected]>
# @BLURB: Base eclass for Java packages
# @DESCRIPTION:
# This eclass provides functionality which is used by java-pkg-2.eclass,
# java-pkg-opt-2.eclass and java-ant-2 eclass, as well as from ebuilds.
#
# This eclass should not be inherited this directly from an ebuild. Instead,
# you should inherit java-pkg-2 for Java packages or java-pkg-opt-2 for packages
# that have optional Java support. In addition you can inherit java-ant-2 for
# Ant-based packages.
inherit eutils versionator multilib
IUSE="elibc_FreeBSD"
# Make sure we use java-config-2
export WANT_JAVA_CONFIG="2"
# @VARIABLE: JAVA_PKG_PORTAGE_DEP
# @INTERNAL
# @DESCRIPTION:
# The version of portage we need to function properly. Previously it was
# portage with phase hooks support but now we use a version with proper env
# saving. For EAPI 2 we have new enough stuff so let's have cleaner deps.
has "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
# @VARIABLE: JAVA_PKG_E_DEPEND
# @INTERNAL
# @DESCRIPTION:
# This is a convience variable to be used from the other java eclasses. This is
# the version of java-config we want to use. Usually the latest stable version
# so that ebuilds can use new features without depending on specific versions.
JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.2.0-r3 ${JAVA_PKG_PORTAGE_DEP}"
has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
# @ECLASS-VARIABLE: JAVA_PKG_WANT_BOOTCLASSPATH
# @DEFAULT_UNSET
# @DESCRIPTION:
# The version of bootclasspath the package needs to work. Translates to a proper
# dependency. The bootclasspath can then be obtained by java-ant_rewrite-bootclasspath
if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then
if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then
JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98"
else
eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH"
# since die in global scope doesn't work, this will make repoman fail
JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH"
fi
fi
# @ECLASS-VARIABLE: JAVA_PKG_ALLOW_VM_CHANGE
# @DESCRIPTION:
# Allow this eclass to change the active VM?
# If your system VM isn't sufficient for the package, the build will fail
# instead of trying to switch to another VM.
#
# Overriding the default can be useful for testing specific VMs locally, but
# should not be used in the final ebuild.
JAVA_PKG_ALLOW_VM_CHANGE=${JAVA_PKG_ALLOW_VM_CHANGE:="yes"}
# @ECLASS-VARIABLE: JAVA_PKG_FORCE_VM
# @DEFAULT_UNSET
# @DESCRIPTION:
# Explicitly set a particular VM to use. If its not valid, it'll fall back to
# whatever /etc/java-config-2/build/jdk.conf would elect to use.
#
# Should only be used for testing and debugging.
#
# Example: use sun-jdk-1.5 to emerge foo:
# @CODE
# JAVA_PKG_FORCE_VM=sun-jdk-1.5 emerge foo
# @CODE
# @ECLASS-VARIABLE: JAVA_PKG_WANT_BUILD_VM
# @DEFAULT_UNSET
# @DESCRIPTION:
# A list of VM handles to choose a build VM from. If the list contains the
# currently active VM use that one, otherwise step through the list till a
# usable/installed VM is found.
#
# This allows to use an explicit list of JDKs in DEPEND instead of a virtual.
# Users of this variable must make sure at least one of the listed handles is
# covered by DEPEND.
# Requires JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET to be set as well.
# @ECLASS-VARIABLE: JAVA_PKG_WANT_SOURCE
# @DEFAULT_UNSET
# @DESCRIPTION:
# Specify a non-standard Java source version for compilation (via javac -source
# parameter or Ant equivalent via build.xml rewriting done by java-ant-2 eclass).
# Normally this is determined from the jdk version specified in DEPEND.
# See java-pkg_get-source function below.
#
# Should generally only be used for testing and debugging.
#
# Use 1.4 source to emerge baz
# @CODE
# JAVA_PKG_WANT_SOURCE=1.4 emerge baz
# @CODE
# @ECLASS-VARIABLE: JAVA_PKG_WANT_TARGET
# @DEFAULT_UNSET
# @DESCRIPTION:
# Same as JAVA_PKG_WANT_SOURCE (see above) but for javac -target parameter,
# which affects the version of generated bytecode.
# Normally this is determined from the jre/jdk version specified in RDEPEND.
# See java-pkg_get-target function below.
#
# Should generallyonly be used for testing and debugging.
#
# emerge bar to be compatible with 1.3
# @CODE
# JAVA_PKG_WANT_TARGET=1.3 emerge bar
# @CODE
# @ECLASS-VARIABLE: JAVA_PKG_DEBUG
# @DEFAULT_UNSET
# @DESCRIPTION:
# A variable to be set with "yes" or "y", or ANY string of length non equal to
# zero. When set, verbosity across java eclasses is increased and extra
# logging is displayed.
# @CODE
# JAVA_PKG_DEBUG="yes"
# @CODE
# @ECLASS-VARIABLE: JAVA_RM_FILES
# @DEFAULT_UNSET
# @DESCRIPTION:
# An array containing a list of files to remove. If defined, this array will be
# automatically handed over to java-pkg_rm_files for processing during the
# src_prepare phase.
#
# @CODE
# JAVA_RM_FILES=(
# path/to/File1.java
# DELETEME.txt
# )
# @CODE
# @VARIABLE: JAVA_PKG_COMPILER_DIR
# @INTERNAL
# @DESCRIPTION:
# Directory where compiler settings are saved, without trailing slash.
# You probably shouldn't touch this variable except local testing.
JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
# @VARIABLE: JAVA_PKG_COMPILERS_CONF
# @INTERNAL
# @DESCRIPTION:
# Path to file containing information about which compiler to use.
# Can be overloaded, but it should be overloaded only for local testing.
JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/compilers.conf"}
# @ECLASS-VARIABLE: JAVA_PKG_FORCE_COMPILER
# @INTERNAL
# @DEFAULT_UNSET
# @DESCRIPTION:
# Explicitly set a list of compilers to choose from. This is normally read from
# JAVA_PKG_COMPILERS_CONF.
#
# Useful for local testing.
#
# Use jikes and javac, in that order
# @CODE
# JAVA_PKG_FORCE_COMPILER="jikes javac"
# @CODE
# @ECLASS-VARIABLE: JAVA_PKG_FORCE_ANT_TASKS
# @DEFAULT_UNSET
# @DESCRIPTION:
# An $IFS separated list of ant tasks. Can be set in environment before calling
# emerge/ebuild to override variables set in ebuild, mainly for testing before
# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
# eant() call, not the dependencies specified in WANT_ANT_TASKS.
#
# @CODE
# JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
# ebuild foo.ebuild compile
# @CODE
# TODO document me
JAVA_PKG_QA_VIOLATIONS=0
# @FUNCTION: java-pkg_doexamples
# @USAGE: [--subdir <subdir>] <file1/dir1> [<file2> ...]
# @DESCRIPTION:
# Installs given arguments to /usr/share/doc/${PF}/examples
# If you give it only one parameter and it is a directory it will install
# everything in that directory to the examples directory.
#
# @CODE
# Parameters:
# --subdir - If the examples need a certain directory structure
# $* - list of files to install
#
# Examples:
# java-pkg_doexamples demo
# java-pkg_doexamples demo/* examples/*
# @CODE
java-pkg_doexamples() {
debug-print-function ${FUNCNAME} $*
[[ ${#} -lt 1 ]] && die "At least one argument needed"
java-pkg_check-phase install
java-pkg_init_paths_
local dest=/usr/share/doc/${PF}/examples
if [[ ${1} == --subdir ]]; then
local dest=${dest}/${2}
dodir ${dest}
shift 2
fi
if [[ ${#} = 1 && -d ${1} ]]; then
( # dont want to pollute calling env
insinto "${dest}"
doins -r ${1}/*
) || die "Installing examples failed"
else
( # dont want to pollute calling env
insinto "${dest}"
doins -r "$@"
) || die "Installing examples failed"
fi
# Let's make a symlink to the directory we have everything else under
dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die
}
# @FUNCTION: java-pkg_addres
# @USAGE: <jar> <dir> [<find arguments> ...]
# @DESCRIPTION:
# Adds resource files to an existing jar.
# It is important that the directory given is actually the root of the
# corresponding resource tree. The target directory as well as
# sources.lst, MANIFEST.MF, *.class, *.jar, and *.java files are
# automatically excluded. Symlinks are always followed. Additional
# arguments are passed through to find.
#
# @CODE
# java-pkg_addres ${PN}.jar resources ! -name "*.html"
# @CODE
#
# @param $1 - jar file
# @param $2 - resource tree directory
# @param $* - arguments to pass to find
java-pkg_addres() {
debug-print-function ${FUNCNAME} $*
[[ ${#} -lt 2 ]] && die "at least two arguments needed"
local jar=$(realpath "$1" || die "realpath $1 failed")
local dir="$2"
shift 2
pushd "${dir}" > /dev/null || die "pushd ${dir} failed"
find -L -type f ! -path "./target/*" ! -path "./sources.lst" ! -name "MANIFEST.MF" ! -regex ".*\.\(class\|jar\|java\)" "${@}" -print0 | xargs -r0 jar uf "${jar}" || die "jar failed"
popd > /dev/null || die "popd failed"
}
# @FUNCTION: java-pkg_rm_files
# @USAGE: java-pkg_rm_files File1.java File2.java ...
# @DESCRIPTION:
# Remove unneeded files in ${S}.
#
# Every now and then, you'll run into situations whereby a file needs removing,
# be it a unit test or a regular java class.
#
# You can use this function by either:
# - calling it yourself in src_prepare() and feeding java-pkg_rm_files with
# the list of files you wish to remove.
# - defining an array in the ebuild named JAVA_RM_FILES with the list of files
# you wish to remove.
#
# Both way work and it is left to the developer's preferences. If the
# JAVA_RM_FILES array is defined, it will be automatically handed over to
# java-pkg_rm_files during the src_prepare phase.
#
# See java-utils-2_src_prepare.
#
# @CODE
# java-pkg_rm_files File1.java File2.java
# @CODE
#
# @param $* - list of files to remove.
java-pkg_rm_files() {
debug-print-function ${FUNCNAME} $*
local IFS="\n"
for filename in "$@"; do
[[ ! -f "${filename}" ]] && die "${filename} is not a regular file. Aborting."
einfo "Removing unneeded file ${filename}"
rm -f "${S}/${filename}" || die "cannot remove ${filename}"
eend $?
done
}
# @FUNCTION: java-pkg_dojar
# @USAGE: <jar1> [<jar2> ...]
# @DESCRIPTION:
# Installs any number of jars.
# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
# You can use java-pkg_jarinto to change this path.
# You should never install a jar with a package version in the filename.
# Instead, use java-pkg_newjar defined below.
#
# @CODE
# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
# @CODE
#
# @param $* - list of jars to install
java-pkg_dojar() {
debug-print-function ${FUNCNAME} $*
[[ ${#} -lt 1 ]] && die "At least one argument needed"
java-pkg_check-phase install
java-pkg_init_paths_
# Create JARDEST if it doesn't exist
dodir ${JAVA_PKG_JARDEST}
local jar
# for each jar
for jar in "${@}"; do
local jar_basename=$(basename "${jar}")
java-pkg_check-versioned-jar ${jar_basename}
# check if it exists
if [[ -e "${jar}" ]] ; then
# Don't overwrite if jar has already been installed with the same
# name
local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
if [[ -e "${dest}" ]]; then
ewarn "Overwriting ${dest}"
fi
# install it into JARDEST if it's a non-symlink
if [[ ! -L "${jar}" ]] ; then
#but first check class version when in strict mode.
is-java-strict && java-pkg_verify-classes "${jar}"
(
insinto "${JAVA_PKG_JARDEST}"
doins "${jar}"
) || die "failed to install ${jar}"
java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
# make a symlink to the original jar if it's symlink
else
# TODO use dosym, once we find something that could use it
# -nichoj
ln -s "$(readlink "${jar}")" "${D}${JAVA_PKG_JARDEST}/${jar_basename}"
debug-print "${jar} is a symlink, linking accordingly"
fi
else
die "${jar} does not exist"
fi
done
# Extra logging if enabled.
if [[ -n ${JAVA_PKG_DEBUG} ]]; then
einfo "Verbose logging for \"${FUNCNAME}\" function"
einfo "Jar file(s) destination: ${JAVA_PKG_JARDEST}"
einfo "Jar file(s) created: ${@}"
einfo "Complete command:"
einfo "${FUNCNAME} ${@}"
fi
java-pkg_do_write_
}
# @FUNCTION: java-pkg_regjar
# @USAGE: </path/to/installed/jar>
# @DESCRIPTION:
# Records an already installed (in ${D}) jar in the package.env
# This would mostly be used if the package has make or a custom script to
# install things.
#
# WARNING:
# if you want to use shell expansion, you have to use ${D}/... as the for in
# this function will not be able to expand the path, here's an example:
#
# @CODE
# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
# @CODE
#
# TODO should we be making sure the jar is present on ${D} or wherever?
java-pkg_regjar() {
debug-print-function ${FUNCNAME} $*
java-pkg_check-phase install
[[ ${#} -lt 1 ]] && die "at least one argument needed"
java-pkg_init_paths_
local jar jar_dir jar_file
for jar in "${@}"; do
# TODO use java-pkg_check-versioned-jar
if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
[[ -d "${jar}" || -d "${D}${jar}" ]] \
&& die "Called ${FUNCNAME} on a directory $*"
#check that class version correct when in strict mode
is-java-strict && java-pkg_verify-classes "${jar}"
# nelchael: we should strip ${D} in this case too, here's why:
# imagine such call:
# java-pkg_regjar ${D}/opt/java/*.jar
# such call will fall into this case (-e ${jar}) and will
# record paths with ${D} in package.env
java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
else
if [[ ${jar} = *\** ]]; then
eerror "The argument ${jar} to ${FUNCNAME}"
eerror "has * in it. If you want it to glob in"
eerror '${D} add ${D} to the argument.'
fi
debug-print "${jar} or ${D}${jar} not found"
die "${jar} does not exist"
fi
done
java-pkg_do_write_
}
# @FUNCTION: java-pkg_newjar
# @USAGE: <path/to/oldname.jar> [<newname.jar>]
# @DESCRIPTION:
# Installs a jar with a new name (defaults to $PN.jar)
#
# For example, installs a versioned jar without the version
java-pkg_newjar() {
debug-print-function ${FUNCNAME} $*
local original_jar="${1}"
local new_jar="${2:-${PN}.jar}"
local new_jar_dest="${T}/${new_jar}"
[[ -z ${original_jar} ]] && die "Must specify a jar to install"
[[ ! -f ${original_jar} ]] \
&& die "${original_jar} does not exist or is not a file!"
rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
cp "${original_jar}" "${new_jar_dest}" \
|| die "Failed to copy ${original_jar} to ${new_jar_dest}"
java-pkg_dojar "${new_jar_dest}"
}
# @FUNCTION: java-pkg_addcp
# @USAGE: <classpath>
# @DESCRIPTION:
# Add something to the package's classpath. For jars, you should use dojar,
# newjar, or regjar. This is typically used to add directories to the classpath.
# The parameters of this function are appended to JAVA_PKG_CLASSPATH
java-pkg_addcp() {
java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
java-pkg_do_write_
}
# @FUNCTION: java-pkg_doso
# @USAGE: <path/to/file1.so> [...]
# @DESCRIPTION:
# Installs any number of JNI libraries
# They will be installed into /usr/lib by default, but java-pkg_sointo
# can be used change this path
#
# @CODE
# Example:
# java-pkg_doso *.so
# @CODE
java-pkg_doso() {
debug-print-function ${FUNCNAME} $*
java-pkg_check-phase install
[[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
java-pkg_init_paths_
local lib
# for each lib
for lib in "$@" ; do
# if the lib exists...
if [[ -e "${lib}" ]] ; then
# install if it isn't a symlink
if [[ ! -L "${lib}" ]] ; then
(
insinto "${JAVA_PKG_LIBDEST}"
insopts -m0755
doins "${lib}"
) || die "failed to install ${lib}"
java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
# otherwise make a symlink to the symlink's origin
else
dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
debug-print "${lib} is a symlink, linking accordantly"
fi
# otherwise die
else
die "${lib} does not exist"
fi
done
java-pkg_do_write_
}
# @FUNCTION: java-pkg_regso
# @USAGE: <file1.so> [...]
# @DESCRIPTION:
# Registers an already installed JNI library in package.env.
#
# @CODE
# Parameters:
# $@ - JNI libraries to register
#
# Example:
# java-pkg_regso *.so /path/*.so
# @CODE
java-pkg_regso() {
debug-print-function ${FUNCNAME} $*
java-pkg_check-phase install
[[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
java-pkg_init_paths_
local lib target_dir
for lib in "$@" ; do
# Check the absolute path of the lib
if [[ -e "${lib}" ]] ; then
target_dir="$(java-pkg_expand_dir_ ${lib})"
java-pkg_append_ JAVA_PKG_LIBRARY "/${target_dir#${D}}"
# Check the path of the lib relative to ${D}
elif [[ -e "${D}${lib}" ]]; then
target_dir="$(java-pkg_expand_dir_ ${D}${lib})"
java-pkg_append_ JAVA_PKG_LIBRARY "${target_dir}"
else
die "${lib} does not exist"
fi
done
java-pkg_do_write_
}
# @FUNCTION: java-pkg_jarinto
# @USAGE: </path/to/install/jars/into>
# @DESCRIPTION:
# Changes the path jars are installed into via subsequent java-pkg_dojar calls.
java-pkg_jarinto() {
debug-print-function ${FUNCNAME} $*
JAVA_PKG_JARDEST="${1}"
}
# @FUNCTION: java-pkg_sointo
# @USAGE: </path/to/install/sofiles/into>
# @DESCRIPTION:
# Changes the path that JNI libraries are installed into via subsequent
# java-pkg_doso calls.
java-pkg_sointo() {
debug-print-function ${FUNCNAME} $*
JAVA_PKG_LIBDEST="${1}"
}
# @FUNCTION: java-pkg_dohtml
# @USAGE: <path/to/javadoc/documentation> [...]
# @DESCRIPTION:
# Install Javadoc HTML documentation. Usage of java-pkg_dojavadoc is preferred.
#
# @CODE
# java-pkg_dohtml dist/docs/
# @CODE
java-pkg_dohtml() {
debug-print-function ${FUNCNAME} $*
[[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
# from /usr/lib/portage/bin/dohtml -h
# -f Set list of allowed extensionless file names.
dohtml -f package-list "$@"
# this probably shouldn't be here but it provides
# a reasonable way to catch # docs for all of the
# old ebuilds.
java-pkg_recordjavadoc
}
# @FUNCTION: java-pkg_dojavadoc
# @USAGE: [--symlink destination] <path/to/javadocs/root>
# @DESCRIPTION:
# Installs javadoc documentation. This should be controlled by the doc use flag.
#
# @CODE
# Parameters:
# $1: optional --symlink creates to symlink like this for html
# documentation bundles.
# $2: - The javadoc root directory.
#
# Examples:
# java-pkg_dojavadoc docs/api
# java-pkg_dojavadoc --symlink apidocs docs/api
# @CODE
java-pkg_dojavadoc() {
debug-print-function ${FUNCNAME} $*
# For html documentation bundles that link to Javadoc
local symlink
if [[ ${1} = --symlink ]]; then
symlink=${2}
shift 2
fi
local dir="$1"
local dest=/usr/share/doc/${PF}/html
# QA checks
java-pkg_check-phase install
java-pkg_init_paths_
[[ -z "${dir}" ]] && die "Must specify a directory!"
[[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
if [[ ! -e "${dir}/index.html" ]]; then
local msg="No index.html in javadoc directory"
ewarn "${msg}"
is-java-strict && die "${msg}"
fi
if [[ -e ${D}/${dest}/api ]]; then
eerror "${dest} already exists. Will not overwrite."
die "${dest}"
fi
# Renaming to match our directory layout
local dir_to_install="${dir}"
if [[ "$(basename "${dir}")" != "api" ]]; then
dir_to_install="${T}/api"
# TODO use doins
cp -r "${dir}" "${dir_to_install}" || die "cp failed"
fi
# Actual installation
java-pkg_dohtml -r "${dir_to_install}"
# Let's make a symlink to the directory we have everything else under
dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
if [[ ${symlink} ]]; then
debug-print "symlinking ${dest}/{api,${symlink}}"
dosym ${dest}/{api,${symlink}} || die
fi
# Extra logging if enabled.
if [[ -n ${JAVA_PKG_DEBUG} ]]; then
einfo "Verbose logging for \"${FUNCNAME}\" function"
einfo "Documentation destination: ${dest}"
einfo "Directory to install: ${dir_to_install}"
einfo "Complete command:"
einfo "${FUNCNAME} ${@}"
fi
}
# @FUNCTION: java-pkg_dosrc
# @USAGE: <path/to/sources> [...]
# @DESCRIPTION:
# Installs a zip containing the source for a package, so it can used in
# from IDEs like eclipse and netbeans.
# Ebuild needs to DEPEND on app-arch/zip to use this. It also should be controlled by USE=source.
#
# @CODE
# Example:
# java-pkg_dosrc src/*
# @CODE
# TODO change so it the arguments it takes are the base directories containing
# source -nichoj
#
# TODO should we be able to handle multiple calls to dosrc? -nichoj
#
# TODO maybe we can take an existing zip/jar? -nichoj
#
# FIXME apparently this fails if you give it an empty directories
java-pkg_dosrc() {
debug-print-function ${FUNCNAME} $*
[ ${#} -lt 1 ] && die "At least one argument needed"
java-pkg_check-phase install
[[ ${#} -lt 1 ]] && die "At least one argument needed"
if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
java-pkg_announce-qa-violation ${msg}
fi
java-pkg_init_paths_
local zip_name="${PN}-src.zip"
local zip_path="${T}/${zip_name}"
local dir
for dir in "${@}"; do
local dir_parent=$(dirname "${dir}")
local dir_name=$(basename "${dir}")
pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
zip -q -r ${zip_path} ${dir_name} -i '*.java'
local result=$?
# 12 means zip has nothing to do
if [[ ${result} != 12 && ${result} != 0 ]]; then
die "failed to zip ${dir_name}"
fi
popd >/dev/null || die
done
# Install the zip
(
insinto "${JAVA_PKG_SOURCESPATH}"
doins ${zip_path}
) || die "Failed to install source"
JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}"
# Extra logging if enabled.
if [[ -n ${JAVA_PKG_DEBUG} ]]; then
einfo "Verbose logging for \"${FUNCNAME}\" function"
einfo "Zip filename created: ${zip_name}"
einfo "Zip file destination: ${JAVA_PKG_SOURCESPATH}"
einfo "Directories zipped: ${@}"
einfo "Complete command:"
einfo "${FUNCNAME} ${@}"
fi
java-pkg_do_write_
}
# @FUNCTION: java-pkg_dolauncher
# @USAGE: <filename> [options]
# @DESCRIPTION:
# Make a wrapper script to lauch/start this package
# If necessary, the wrapper will switch to the appropriate VM.
#
# Can be called without parameters if the package installs only one jar
# that has the Main-class attribute set. The wrapper will be named ${PN}.
#
# @CODE
# Parameters:
# $1 - filename of launcher to create
# $2 - options, as follows:
# --main the.main.class.to.start
# --jar /the/jar/too/launch.jar or just <name>.jar
# --java_args 'Extra arguments to pass to java'
# --pkg_args 'Extra arguments to pass to the package'
# --pwd Directory the launcher changes to before executing java
# -into Directory to install the launcher to, instead of /usr/bin
# -pre Prepend contents of this file to the launcher
# @CODE
java-pkg_dolauncher() {
debug-print-function ${FUNCNAME} $*
java-pkg_check-phase install
java-pkg_init_paths_
if [[ ${#} = 0 ]]; then
local name="${PN}"
else
local name="${1}"
shift
fi
# TODO rename to launcher
local target="${T}/${name}"
local var_tmp="${T}/launcher_variables_tmp"
local target_dir pre
# Process the other the rest of the arguments
while [[ -n "${1}" && -n "${2}" ]]; do
local var="${1}" value="${2}"
if [[ "${var:0:2}" == "--" ]]; then
local var=${var:2}
echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
local gjl_${var}="${value}"
elif [[ "${var}" == "-into" ]]; then
target_dir="${value}"
elif [[ "${var}" == "-pre" ]]; then
pre="${value}"
fi
shift 2
done
# Test if no --jar and --main arguments were given and
# in that case check if the package only installs one jar
# and use that jar.
if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
local cp="${JAVA_PKG_CLASSPATH}"
if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
else
local msg="Not enough information to create a launcher given."
msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
die "${msg}"
fi
fi
# Write the actual script
echo "#!/bin/bash" > "${target}"
if [[ -n "${pre}" ]]; then
if [[ -f "${pre}" ]]; then
cat "${pre}" >> "${target}"
else
die "-pre specified file '${pre}' does not exist"
fi
fi
echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
cat "${var_tmp}" >> "${target}"
rm -f "${var_tmp}"
echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
if [[ -n "${target_dir}" ]]; then
(
into "${target_dir}"
dobin "${target}"
)
local ret=$?
return ${ret}
else
dobin "${target}"
fi
}
# @FUNCTION: java-pkg_dowar
# @DESCRIPTION:
# Install war files.
# TODO document
java-pkg_dowar() {
debug-print-function ${FUNCNAME} $*
# Check for arguments
[[ ${#} -lt 1 ]] && die "At least one argument needed"
java-pkg_check-phase install
java-pkg_init_paths_
local war
for war in $* ; do
local warpath
# TODO evaluate if we want to handle symlinks differently -nichoj
# Check for symlink
if [[ -L "${war}" ]] ; then
cp "${war}" "${T}"
warpath="${T}$(basename "${war}")"
# Check for directory
# TODO evaluate if we want to handle directories differently -nichoj
elif [[ -d "${war}" ]] ; then
echo "dowar: warning, skipping directory ${war}"
continue
else
warpath="${war}"
fi
# Install those files like you mean it
(
insopts -m0644
insinto "${JAVA_PKG_WARDEST}"
doins ${warpath}
)
done
}
# @FUNCTION: java-pkg_recordjavadoc
# @INTERNAL
# @DESCRIPTION:
# Scan for JavaDocs, and record their existence in the package.env file
# TODO make sure this in the proper section
java-pkg_recordjavadoc()
{
debug-print-function ${FUNCNAME} $*
# the find statement is important
# as some packages include multiple trees of javadoc
JAVADOC_PATH="$(find ${D}/usr/share/doc/ -name allclasses-frame.html -printf '%h:')"
# remove $D - TODO: check this is ok with all cases of the above
JAVADOC_PATH="${JAVADOC_PATH//${D}}"
if [[ -n "${JAVADOC_PATH}" ]] ; then
debug-print "javadocs found in ${JAVADOC_PATH%:}"
java-pkg_do_write_
else
debug-print "No javadocs found"
fi
}
# @FUNCTION: java-pkg_jar-from
# @USAGE: [--build-only] [--with-dependencies] [--virtual] [--into dir] <package> [<package.jar>] [<destination.jar>]
# @DESCRIPTION:
# Makes a symlink to a jar from a certain package
# A lot of java packages include dependencies in a lib/ directory
# You can use this function to replace these bundled dependencies.
# The dependency is recorded into package.env DEPEND line, unless "--build-only"
# is passed as the very first argument, for jars that have to be present only
# at build time and are not needed on runtime (junit testing etc).
#
# @CODE
# Example: get all jars from xerces slot 2
# java-pkg_jar-from xerces-2
#
# Example: get a specific jar from xerces slot 2
# java-pkg_jar-from xerces-2 xml-apis.jar
#
# Example: get a specific jar from xerces slot 2, and name it diffrently
# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
#
# Example: get junit.jar which is needed only for building
# java-pkg_jar-from --build-only junit junit.jar
# @CODE
#
# @CODE
# Parameters
# --build-only - makes the jar(s) not added into package.env DEPEND line.
# (assumed automatically when called inside src_test)
# --with-dependencies - get jars also from requested package's dependencies
# transitively.
# --virtual - Packages passed to this function are to be handled as virtuals
# and will not have individual jar dependencies recorded.
# --into $dir - symlink jar(s) into $dir (must exist) instead of .
# $1 - Package to get jars from, or comma-separated list of packages in
# case other parameters are not used.
# $2 - jar from package. If not specified, all jars will be used.
# $3 - When a single jar is specified, destination filename of the
# symlink. Defaults to the name of the jar.
# @CODE
# TODO could probably be cleaned up a little
java-pkg_jar-from() {
debug-print-function ${FUNCNAME} $*
local build_only=""
local destdir="."
local deep=""
local virtual=""
local record_jar=""
[[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
while [[ "${1}" == --* ]]; do
if [[ "${1}" = "--build-only" ]]; then
build_only="build"
elif [[ "${1}" = "--with-dependencies" ]]; then
deep="--with-dependencies"
elif [[ "${1}" = "--virtual" ]]; then
virtual="true"
elif [[ "${1}" = "--into" ]]; then
destdir="${2}"
shift
else
die "java-pkg_jar-from called with unknown parameter: ${1}"
fi
shift
done
local target_pkg="${1}" target_jar="${2}" destjar="${3}"
[[ -z ${target_pkg} ]] && die "Must specify a package"
if [[ "${EAPI}" == "1" ]]; then
target_pkg="${target_pkg//:/-}"
fi
# default destjar to the target jar
[[ -z "${destjar}" ]] && destjar="${target_jar}"
local error_msg="There was a problem getting the classpath for ${target_pkg}."
local classpath
classpath="$(java-config ${deep} --classpath=${target_pkg})"
[[ $? != 0 ]] && die ${error_msg}
# When we have commas this functions is called to bring jars from multiple
# packages. This affects recording of dependencencies performed later
# which expects one package only, so we do it here.
if [[ ${target_pkg} = *,* ]]; then
for pkg in ${target_pkg//,/ }; do
java-pkg_ensure-dep "${build_only}" "${pkg}"
[[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
done
# setting this disables further record-jar_ calls later
record_jar="true"