java-utils-2.eclass 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920
  1. # Copyright 2004-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: java-utils-2.eclass
  4. # @MAINTAINER:
  5. # java@gentoo.org
  6. # @AUTHOR:
  7. # Thomas Matthijs <axxo@gentoo.org>, Karl Trygve Kalleberg <karltk@gentoo.org>
  8. # @BLURB: Base eclass for Java packages
  9. # @DESCRIPTION:
  10. # This eclass provides functionality which is used by java-pkg-2.eclass,
  11. # java-pkg-opt-2.eclass and java-ant-2 eclass, as well as from ebuilds.
  12. #
  13. # This eclass should not be inherited this directly from an ebuild. Instead,
  14. # you should inherit java-pkg-2 for Java packages or java-pkg-opt-2 for packages
  15. # that have optional Java support. In addition you can inherit java-ant-2 for
  16. # Ant-based packages.
  17. inherit eutils versionator multilib
  18. IUSE="elibc_FreeBSD"
  19. # Make sure we use java-config-2
  20. export WANT_JAVA_CONFIG="2"
  21. # Prefix variables are only available for EAPI>=3
  22. has "${EAPI:-0}" 0 1 2 && ED="${D}" EPREFIX= EROOT="${ROOT}"
  23. # @VARIABLE: JAVA_PKG_PORTAGE_DEP
  24. # @INTERNAL
  25. # @DESCRIPTION:
  26. # The version of portage we need to function properly. Previously it was
  27. # portage with phase hooks support but now we use a version with proper env
  28. # saving. For EAPI 2 we have new enough stuff so let's have cleaner deps.
  29. has "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
  30. # @VARIABLE: JAVA_PKG_E_DEPEND
  31. # @INTERNAL
  32. # @DESCRIPTION:
  33. # This is a convience variable to be used from the other java eclasses. This is
  34. # the version of java-config we want to use. Usually the latest stable version
  35. # so that ebuilds can use new features without depending on specific versions.
  36. JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.2.0-r3 ${JAVA_PKG_PORTAGE_DEP}"
  37. has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
  38. # @ECLASS-VARIABLE: JAVA_PKG_WANT_BOOTCLASSPATH
  39. # @DEFAULT_UNSET
  40. # @DESCRIPTION:
  41. # The version of bootclasspath the package needs to work. Translates to a proper
  42. # dependency. The bootclasspath can then be obtained by java-ant_rewrite-bootclasspath
  43. if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then
  44. if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then
  45. JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98"
  46. else
  47. eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH"
  48. # since die in global scope doesn't work, this will make repoman fail
  49. JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH"
  50. fi
  51. fi
  52. # @ECLASS-VARIABLE: JAVA_PKG_ALLOW_VM_CHANGE
  53. # @DESCRIPTION:
  54. # Allow this eclass to change the active VM?
  55. # If your system VM isn't sufficient for the package, the build will fail
  56. # instead of trying to switch to another VM.
  57. #
  58. # Overriding the default can be useful for testing specific VMs locally, but
  59. # should not be used in the final ebuild.
  60. JAVA_PKG_ALLOW_VM_CHANGE=${JAVA_PKG_ALLOW_VM_CHANGE:="yes"}
  61. # @ECLASS-VARIABLE: JAVA_PKG_FORCE_VM
  62. # @DEFAULT_UNSET
  63. # @DESCRIPTION:
  64. # Explicitly set a particular VM to use. If its not valid, it'll fall back to
  65. # whatever /etc/java-config-2/build/jdk.conf would elect to use.
  66. #
  67. # Should only be used for testing and debugging.
  68. #
  69. # Example: use sun-jdk-1.5 to emerge foo:
  70. # @CODE
  71. # JAVA_PKG_FORCE_VM=sun-jdk-1.5 emerge foo
  72. # @CODE
  73. # @ECLASS-VARIABLE: JAVA_PKG_WANT_BUILD_VM
  74. # @DEFAULT_UNSET
  75. # @DESCRIPTION:
  76. # A list of VM handles to choose a build VM from. If the list contains the
  77. # currently active VM use that one, otherwise step through the list till a
  78. # usable/installed VM is found.
  79. #
  80. # This allows to use an explicit list of JDKs in DEPEND instead of a virtual.
  81. # Users of this variable must make sure at least one of the listed handles is
  82. # covered by DEPEND.
  83. # Requires JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET to be set as well.
  84. # @ECLASS-VARIABLE: JAVA_PKG_WANT_SOURCE
  85. # @DEFAULT_UNSET
  86. # @DESCRIPTION:
  87. # Specify a non-standard Java source version for compilation (via javac -source
  88. # parameter or Ant equivalent via build.xml rewriting done by java-ant-2 eclass).
  89. # Normally this is determined from the jdk version specified in DEPEND.
  90. # See java-pkg_get-source function below.
  91. #
  92. # Should generally only be used for testing and debugging.
  93. #
  94. # Use 1.4 source to emerge baz
  95. # @CODE
  96. # JAVA_PKG_WANT_SOURCE=1.4 emerge baz
  97. # @CODE
  98. # @ECLASS-VARIABLE: JAVA_PKG_WANT_TARGET
  99. # @DEFAULT_UNSET
  100. # @DESCRIPTION:
  101. # Same as JAVA_PKG_WANT_SOURCE (see above) but for javac -target parameter,
  102. # which affects the version of generated bytecode.
  103. # Normally this is determined from the jre/jdk version specified in RDEPEND.
  104. # See java-pkg_get-target function below.
  105. #
  106. # Should generallyonly be used for testing and debugging.
  107. #
  108. # emerge bar to be compatible with 1.3
  109. # @CODE
  110. # JAVA_PKG_WANT_TARGET=1.3 emerge bar
  111. # @CODE
  112. # @ECLASS-VARIABLE: JAVA_PKG_DEBUG
  113. # @DEFAULT_UNSET
  114. # @DESCRIPTION:
  115. # A variable to be set with "yes" or "y", or ANY string of length non equal to
  116. # zero. When set, verbosity across java eclasses is increased and extra
  117. # logging is displayed.
  118. # @CODE
  119. # JAVA_PKG_DEBUG="yes"
  120. # @CODE
  121. # @ECLASS-VARIABLE: JAVA_RM_FILES
  122. # @DEFAULT_UNSET
  123. # @DESCRIPTION:
  124. # An array containing a list of files to remove. If defined, this array will be
  125. # automatically handed over to java-pkg_rm_files for processing during the
  126. # src_prepare phase.
  127. #
  128. # @CODE
  129. # JAVA_RM_FILES=(
  130. # path/to/File1.java
  131. # DELETEME.txt
  132. # )
  133. # @CODE
  134. # @VARIABLE: JAVA_PKG_COMPILER_DIR
  135. # @INTERNAL
  136. # @DESCRIPTION:
  137. # Directory where compiler settings are saved, without trailing slash.
  138. # You probably shouldn't touch this variable except local testing.
  139. JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
  140. # @VARIABLE: JAVA_PKG_COMPILERS_CONF
  141. # @INTERNAL
  142. # @DESCRIPTION:
  143. # Path to file containing information about which compiler to use.
  144. # Can be overloaded, but it should be overloaded only for local testing.
  145. JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/compilers.conf"}
  146. # @ECLASS-VARIABLE: JAVA_PKG_FORCE_COMPILER
  147. # @INTERNAL
  148. # @DEFAULT_UNSET
  149. # @DESCRIPTION:
  150. # Explicitly set a list of compilers to choose from. This is normally read from
  151. # JAVA_PKG_COMPILERS_CONF.
  152. #
  153. # Useful for local testing.
  154. #
  155. # Use jikes and javac, in that order
  156. # @CODE
  157. # JAVA_PKG_FORCE_COMPILER="jikes javac"
  158. # @CODE
  159. # @ECLASS-VARIABLE: JAVA_PKG_FORCE_ANT_TASKS
  160. # @DEFAULT_UNSET
  161. # @DESCRIPTION:
  162. # An $IFS separated list of ant tasks. Can be set in environment before calling
  163. # emerge/ebuild to override variables set in ebuild, mainly for testing before
  164. # putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
  165. # eant() call, not the dependencies specified in WANT_ANT_TASKS.
  166. #
  167. # @CODE
  168. # JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
  169. # ebuild foo.ebuild compile
  170. # @CODE
  171. # TODO document me
  172. JAVA_PKG_QA_VIOLATIONS=0
  173. # @FUNCTION: java-pkg_doexamples
  174. # @USAGE: [--subdir <subdir>] <file1/dir1> [<file2> ...]
  175. # @DESCRIPTION:
  176. # Installs given arguments to /usr/share/doc/${PF}/examples
  177. # If you give it only one parameter and it is a directory it will install
  178. # everything in that directory to the examples directory.
  179. #
  180. # @CODE
  181. # Parameters:
  182. # --subdir - If the examples need a certain directory structure
  183. # $* - list of files to install
  184. #
  185. # Examples:
  186. # java-pkg_doexamples demo
  187. # java-pkg_doexamples demo/* examples/*
  188. # @CODE
  189. java-pkg_doexamples() {
  190. debug-print-function ${FUNCNAME} $*
  191. [[ ${#} -lt 1 ]] && die "At least one argument needed"
  192. java-pkg_check-phase install
  193. java-pkg_init_paths_
  194. local dest=/usr/share/doc/${PF}/examples
  195. if [[ ${1} == --subdir ]]; then
  196. local dest=${dest}/${2}
  197. dodir ${dest}
  198. shift 2
  199. fi
  200. if [[ ${#} = 1 && -d ${1} ]]; then
  201. ( # dont want to pollute calling env
  202. insinto "${dest}"
  203. doins -r ${1}/*
  204. ) || die "Installing examples failed"
  205. else
  206. ( # dont want to pollute calling env
  207. insinto "${dest}"
  208. doins -r "$@"
  209. ) || die "Installing examples failed"
  210. fi
  211. # Let's make a symlink to the directory we have everything else under
  212. dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die
  213. }
  214. # @FUNCTION: java-pkg_addres
  215. # @USAGE: <jar> <dir> [<find arguments> ...]
  216. # @DESCRIPTION:
  217. # Adds resource files to an existing jar.
  218. # It is important that the directory given is actually the root of the
  219. # corresponding resource tree. The target directory as well as
  220. # sources.lst, MANIFEST.MF, *.class, *.jar, and *.java files are
  221. # automatically excluded. Symlinks are always followed. Additional
  222. # arguments are passed through to find.
  223. #
  224. # @CODE
  225. # java-pkg_addres ${PN}.jar resources ! -name "*.html"
  226. # @CODE
  227. #
  228. # @param $1 - jar file
  229. # @param $2 - resource tree directory
  230. # @param $* - arguments to pass to find
  231. java-pkg_addres() {
  232. debug-print-function ${FUNCNAME} $*
  233. [[ ${#} -lt 2 ]] && die "at least two arguments needed"
  234. local jar=$(realpath "$1" || die "realpath $1 failed")
  235. local dir="$2"
  236. shift 2
  237. pushd "${dir}" > /dev/null || die "pushd ${dir} failed"
  238. 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"
  239. popd > /dev/null || die "popd failed"
  240. }
  241. # @FUNCTION: java-pkg_rm_files
  242. # @USAGE: java-pkg_rm_files File1.java File2.java ...
  243. # @DESCRIPTION:
  244. # Remove unneeded files in ${S}.
  245. #
  246. # Every now and then, you'll run into situations whereby a file needs removing,
  247. # be it a unit test or a regular java class.
  248. #
  249. # You can use this function by either:
  250. # - calling it yourself in src_prepare() and feeding java-pkg_rm_files with
  251. # the list of files you wish to remove.
  252. # - defining an array in the ebuild named JAVA_RM_FILES with the list of files
  253. # you wish to remove.
  254. #
  255. # Both way work and it is left to the developer's preferences. If the
  256. # JAVA_RM_FILES array is defined, it will be automatically handed over to
  257. # java-pkg_rm_files during the src_prepare phase.
  258. #
  259. # See java-utils-2_src_prepare.
  260. #
  261. # @CODE
  262. # java-pkg_rm_files File1.java File2.java
  263. # @CODE
  264. #
  265. # @param $* - list of files to remove.
  266. java-pkg_rm_files() {
  267. debug-print-function ${FUNCNAME} $*
  268. local IFS="\n"
  269. for filename in "$@"; do
  270. [[ ! -f "${filename}" ]] && die "${filename} is not a regular file. Aborting."
  271. einfo "Removing unneeded file ${filename}"
  272. rm -f "${S}/${filename}" || die "cannot remove ${filename}"
  273. eend $?
  274. done
  275. }
  276. # @FUNCTION: java-pkg_dojar
  277. # @USAGE: <jar1> [<jar2> ...]
  278. # @DESCRIPTION:
  279. # Installs any number of jars.
  280. # Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
  281. # You can use java-pkg_jarinto to change this path.
  282. # You should never install a jar with a package version in the filename.
  283. # Instead, use java-pkg_newjar defined below.
  284. #
  285. # @CODE
  286. # java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
  287. # @CODE
  288. #
  289. # @param $* - list of jars to install
  290. java-pkg_dojar() {
  291. debug-print-function ${FUNCNAME} $*
  292. [[ ${#} -lt 1 ]] && die "At least one argument needed"
  293. java-pkg_check-phase install
  294. java-pkg_init_paths_
  295. # Create JARDEST if it doesn't exist
  296. dodir ${JAVA_PKG_JARDEST}
  297. local jar
  298. # for each jar
  299. for jar in "${@}"; do
  300. local jar_basename=$(basename "${jar}")
  301. java-pkg_check-versioned-jar ${jar_basename}
  302. # check if it exists
  303. if [[ -e "${jar}" ]] ; then
  304. # Don't overwrite if jar has already been installed with the same
  305. # name
  306. local dest="${ED}${JAVA_PKG_JARDEST}/${jar_basename}"
  307. if [[ -e "${dest}" ]]; then
  308. ewarn "Overwriting ${dest}"
  309. fi
  310. # install it into JARDEST if it's a non-symlink
  311. if [[ ! -L "${jar}" ]] ; then
  312. #but first check class version when in strict mode.
  313. is-java-strict && java-pkg_verify-classes "${jar}"
  314. (
  315. insinto "${JAVA_PKG_JARDEST}"
  316. doins "${jar}"
  317. ) || die "failed to install ${jar}"
  318. java-pkg_append_ JAVA_PKG_CLASSPATH "${EPREFIX}/${JAVA_PKG_JARDEST}/${jar_basename}"
  319. debug-print "installed ${jar} to ${ED}${JAVA_PKG_JARDEST}"
  320. # make a symlink to the original jar if it's symlink
  321. else
  322. # TODO use dosym, once we find something that could use it
  323. # -nichoj
  324. ln -s "$(readlink "${jar}")" "${ED}${JAVA_PKG_JARDEST}/${jar_basename}"
  325. debug-print "${jar} is a symlink, linking accordingly"
  326. fi
  327. else
  328. die "${jar} does not exist"
  329. fi
  330. done
  331. # Extra logging if enabled.
  332. if [[ -n ${JAVA_PKG_DEBUG} ]]; then
  333. einfo "Verbose logging for \"${FUNCNAME}\" function"
  334. einfo "Jar file(s) destination: ${JAVA_PKG_JARDEST}"
  335. einfo "Jar file(s) created: ${@}"
  336. einfo "Complete command:"
  337. einfo "${FUNCNAME} ${@}"
  338. fi
  339. java-pkg_do_write_
  340. }
  341. # @FUNCTION: java-pkg_regjar
  342. # @USAGE: </path/to/installed/jar>
  343. # @DESCRIPTION:
  344. # Records an already installed (in ${D}) jar in the package.env
  345. # This would mostly be used if the package has make or a custom script to
  346. # install things.
  347. #
  348. # WARNING:
  349. # if you want to use shell expansion, you have to use ${D}/... as the for in
  350. # this function will not be able to expand the path, here's an example:
  351. #
  352. # @CODE
  353. # java-pkg_regjar ${D}/opt/my-java/lib/*.jar
  354. # @CODE
  355. #
  356. # TODO should we be making sure the jar is present on ${D} or wherever?
  357. java-pkg_regjar() {
  358. debug-print-function ${FUNCNAME} $*
  359. java-pkg_check-phase install
  360. [[ ${#} -lt 1 ]] && die "at least one argument needed"
  361. java-pkg_init_paths_
  362. local jar jar_dir jar_file
  363. for jar in "${@}"; do
  364. # TODO use java-pkg_check-versioned-jar
  365. if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
  366. [[ -d "${jar}" || -d "${D}${jar}" ]] \
  367. && die "Called ${FUNCNAME} on a directory $*"
  368. #check that class version correct when in strict mode
  369. is-java-strict && java-pkg_verify-classes "${jar}"
  370. # nelchael: we should strip ${D} in this case too, here's why:
  371. # imagine such call:
  372. # java-pkg_regjar ${D}/opt/java/*.jar
  373. # such call will fall into this case (-e ${jar}) and will
  374. # record paths with ${D} in package.env
  375. java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
  376. else
  377. if [[ ${jar} = *\** ]]; then
  378. eerror "The argument ${jar} to ${FUNCNAME}"
  379. eerror "has * in it. If you want it to glob in"
  380. eerror '${D} add ${D} to the argument.'
  381. fi
  382. debug-print "${jar} or ${D}${jar} not found"
  383. die "${jar} does not exist"
  384. fi
  385. done
  386. java-pkg_do_write_
  387. }
  388. # @FUNCTION: java-pkg_newjar
  389. # @USAGE: <path/to/oldname.jar> [<newname.jar>]
  390. # @DESCRIPTION:
  391. # Installs a jar with a new name (defaults to $PN.jar)
  392. #
  393. # For example, installs a versioned jar without the version
  394. java-pkg_newjar() {
  395. debug-print-function ${FUNCNAME} $*
  396. local original_jar="${1}"
  397. local new_jar="${2:-${PN}.jar}"
  398. local new_jar_dest="${T}/${new_jar}"
  399. [[ -z ${original_jar} ]] && die "Must specify a jar to install"
  400. [[ ! -f ${original_jar} ]] \
  401. && die "${original_jar} does not exist or is not a file!"
  402. rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
  403. cp "${original_jar}" "${new_jar_dest}" \
  404. || die "Failed to copy ${original_jar} to ${new_jar_dest}"
  405. java-pkg_dojar "${new_jar_dest}"
  406. }
  407. # @FUNCTION: java-pkg_addcp
  408. # @USAGE: <classpath>
  409. # @DESCRIPTION:
  410. # Add something to the package's classpath. For jars, you should use dojar,
  411. # newjar, or regjar. This is typically used to add directories to the classpath.
  412. # The parameters of this function are appended to JAVA_PKG_CLASSPATH
  413. java-pkg_addcp() {
  414. java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
  415. java-pkg_do_write_
  416. }
  417. # @FUNCTION: java-pkg_doso
  418. # @USAGE: <path/to/file1.so> [...]
  419. # @DESCRIPTION:
  420. # Installs any number of JNI libraries
  421. # They will be installed into /usr/lib by default, but java-pkg_sointo
  422. # can be used change this path
  423. #
  424. # @CODE
  425. # Example:
  426. # java-pkg_doso *.so
  427. # @CODE
  428. java-pkg_doso() {
  429. debug-print-function ${FUNCNAME} $*
  430. java-pkg_check-phase install
  431. [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
  432. java-pkg_init_paths_
  433. local lib
  434. # for each lib
  435. for lib in "$@" ; do
  436. # if the lib exists...
  437. if [[ -e "${lib}" ]] ; then
  438. # install if it isn't a symlink
  439. if [[ ! -L "${lib}" ]] ; then
  440. (
  441. insinto "${JAVA_PKG_LIBDEST}"
  442. insopts -m0755
  443. doins "${lib}"
  444. ) || die "failed to install ${lib}"
  445. java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
  446. debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
  447. # otherwise make a symlink to the symlink's origin
  448. else
  449. dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
  450. debug-print "${lib} is a symlink, linking accordantly"
  451. fi
  452. # otherwise die
  453. else
  454. die "${lib} does not exist"
  455. fi
  456. done
  457. java-pkg_do_write_
  458. }
  459. # @FUNCTION: java-pkg_regso
  460. # @USAGE: <file1.so> [...]
  461. # @DESCRIPTION:
  462. # Registers an already installed JNI library in package.env.
  463. #
  464. # @CODE
  465. # Parameters:
  466. # $@ - JNI libraries to register
  467. #
  468. # Example:
  469. # java-pkg_regso *.so /path/*.so
  470. # @CODE
  471. java-pkg_regso() {
  472. debug-print-function ${FUNCNAME} $*
  473. java-pkg_check-phase install
  474. [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
  475. java-pkg_init_paths_
  476. local lib target_dir
  477. for lib in "$@" ; do
  478. # Check the absolute path of the lib
  479. if [[ -e "${lib}" ]] ; then
  480. target_dir="$(java-pkg_expand_dir_ ${lib})"
  481. java-pkg_append_ JAVA_PKG_LIBRARY "/${target_dir#${D}}"
  482. # Check the path of the lib relative to ${D}
  483. elif [[ -e "${D}${lib}" ]]; then
  484. target_dir="$(java-pkg_expand_dir_ ${D}${lib})"
  485. java-pkg_append_ JAVA_PKG_LIBRARY "${target_dir}"
  486. else
  487. die "${lib} does not exist"
  488. fi
  489. done
  490. java-pkg_do_write_
  491. }
  492. # @FUNCTION: java-pkg_jarinto
  493. # @USAGE: </path/to/install/jars/into>
  494. # @DESCRIPTION:
  495. # Changes the path jars are installed into via subsequent java-pkg_dojar calls.
  496. java-pkg_jarinto() {
  497. debug-print-function ${FUNCNAME} $*
  498. JAVA_PKG_JARDEST="${1}"
  499. }
  500. # @FUNCTION: java-pkg_sointo
  501. # @USAGE: </path/to/install/sofiles/into>
  502. # @DESCRIPTION:
  503. # Changes the path that JNI libraries are installed into via subsequent
  504. # java-pkg_doso calls.
  505. java-pkg_sointo() {
  506. debug-print-function ${FUNCNAME} $*
  507. JAVA_PKG_LIBDEST="${1}"
  508. }
  509. # @FUNCTION: java-pkg_dohtml
  510. # @USAGE: <path/to/javadoc/documentation> [...]
  511. # @DESCRIPTION:
  512. # Install Javadoc HTML documentation. Usage of java-pkg_dojavadoc is preferred.
  513. #
  514. # @CODE
  515. # java-pkg_dohtml dist/docs/
  516. # @CODE
  517. java-pkg_dohtml() {
  518. debug-print-function ${FUNCNAME} $*
  519. [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
  520. # Do away with dohtml and rely on dodoc instead to do the deed.
  521. docinto html
  522. dodoc "$@"
  523. # This probably shouldn't be here but it provides
  524. # a reasonable way to catch # docs for all of the
  525. # old ebuilds.
  526. java-pkg_recordjavadoc
  527. }
  528. # @FUNCTION: java-pkg_dojavadoc
  529. # @USAGE: [--symlink destination] <path/to/javadocs/root>
  530. # @DESCRIPTION:
  531. # Installs javadoc documentation. This should be controlled by the doc use flag.
  532. #
  533. # @CODE
  534. # Parameters:
  535. # $1: optional --symlink creates to symlink like this for html
  536. # documentation bundles.
  537. # $2: - The javadoc root directory.
  538. #
  539. # Examples:
  540. # java-pkg_dojavadoc docs/api
  541. # java-pkg_dojavadoc --symlink apidocs docs/api
  542. # @CODE
  543. java-pkg_dojavadoc() {
  544. debug-print-function ${FUNCNAME} $*
  545. # For html documentation bundles that link to Javadoc
  546. local symlink
  547. if [[ ${1} = --symlink ]]; then
  548. symlink=${2}
  549. shift 2
  550. fi
  551. local dir="$1"
  552. local dest=/usr/share/doc/${PF}/html
  553. # QA checks
  554. java-pkg_check-phase install
  555. java-pkg_init_paths_
  556. [[ -z "${dir}" ]] && die "Must specify a directory!"
  557. [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
  558. if [[ ! -e "${dir}/index.html" ]]; then
  559. local msg="No index.html in javadoc directory"
  560. ewarn "${msg}"
  561. is-java-strict && die "${msg}"
  562. fi
  563. if [[ -e ${D}/${dest}/api ]]; then
  564. eerror "${dest} already exists. Will not overwrite."
  565. die "${dest}"
  566. fi
  567. # Renaming to match our directory layout
  568. local dir_to_install="${dir}"
  569. if [[ "$(basename "${dir}")" != "api" ]]; then
  570. dir_to_install="${T}/api"
  571. # TODO use doins
  572. cp -r "${dir}" "${dir_to_install}" || die "cp failed"
  573. fi
  574. # Actual installation
  575. java-pkg_dohtml -r "${dir_to_install}"
  576. # Let's make a symlink to the directory we have everything else under
  577. dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
  578. if [[ ${symlink} ]]; then
  579. debug-print "symlinking ${dest}/{api,${symlink}}"
  580. dosym ${dest}/{api,${symlink}} || die
  581. fi
  582. # Extra logging if enabled.
  583. if [[ -n ${JAVA_PKG_DEBUG} ]]; then
  584. einfo "Verbose logging for \"${FUNCNAME}\" function"
  585. einfo "Documentation destination: ${dest}"
  586. einfo "Directory to install: ${dir_to_install}"
  587. einfo "Complete command:"
  588. einfo "${FUNCNAME} ${@}"
  589. fi
  590. }
  591. # @FUNCTION: java-pkg_dosrc
  592. # @USAGE: <path/to/sources> [...]
  593. # @DESCRIPTION:
  594. # Installs a zip containing the source for a package, so it can used in
  595. # from IDEs like eclipse and netbeans.
  596. # Ebuild needs to DEPEND on app-arch/zip to use this. It also should be controlled by USE=source.
  597. #
  598. # @CODE
  599. # Example:
  600. # java-pkg_dosrc src/*
  601. # @CODE
  602. # TODO change so it the arguments it takes are the base directories containing
  603. # source -nichoj
  604. #
  605. # TODO should we be able to handle multiple calls to dosrc? -nichoj
  606. #
  607. # TODO maybe we can take an existing zip/jar? -nichoj
  608. #
  609. # FIXME apparently this fails if you give it an empty directories
  610. java-pkg_dosrc() {
  611. debug-print-function ${FUNCNAME} $*
  612. [ ${#} -lt 1 ] && die "At least one argument needed"
  613. java-pkg_check-phase install
  614. [[ ${#} -lt 1 ]] && die "At least one argument needed"
  615. if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
  616. local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
  617. java-pkg_announce-qa-violation ${msg}
  618. fi
  619. java-pkg_init_paths_
  620. local zip_name="${PN}-src.zip"
  621. local zip_path="${T}/${zip_name}"
  622. local dir
  623. for dir in "${@}"; do
  624. local dir_parent=$(dirname "${dir}")
  625. local dir_name=$(basename "${dir}")
  626. pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
  627. zip -q -r ${zip_path} ${dir_name} -i '*.java'
  628. local result=$?
  629. # 12 means zip has nothing to do
  630. if [[ ${result} != 12 && ${result} != 0 ]]; then
  631. die "failed to zip ${dir_name}"
  632. fi
  633. popd >/dev/null || die
  634. done
  635. # Install the zip
  636. (
  637. insinto "${JAVA_PKG_SOURCESPATH}"
  638. doins ${zip_path}
  639. ) || die "Failed to install source"
  640. JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}"
  641. # Extra logging if enabled.
  642. if [[ -n ${JAVA_PKG_DEBUG} ]]; then
  643. einfo "Verbose logging for \"${FUNCNAME}\" function"
  644. einfo "Zip filename created: ${zip_name}"
  645. einfo "Zip file destination: ${JAVA_PKG_SOURCESPATH}"
  646. einfo "Directories zipped: ${@}"
  647. einfo "Complete command:"
  648. einfo "${FUNCNAME} ${@}"
  649. fi
  650. java-pkg_do_write_
  651. }
  652. # @FUNCTION: java-pkg_dolauncher
  653. # @USAGE: <filename> [options]
  654. # @DESCRIPTION:
  655. # Make a wrapper script to lauch/start this package
  656. # If necessary, the wrapper will switch to the appropriate VM.
  657. #
  658. # Can be called without parameters if the package installs only one jar
  659. # that has the Main-class attribute set. The wrapper will be named ${PN}.
  660. #
  661. # @CODE
  662. # Parameters:
  663. # $1 - filename of launcher to create
  664. # $2 - options, as follows:
  665. # --main the.main.class.to.start
  666. # --jar /the/jar/too/launch.jar or just <name>.jar
  667. # --java_args 'Extra arguments to pass to java'
  668. # --pkg_args 'Extra arguments to pass to the package'
  669. # --pwd Directory the launcher changes to before executing java
  670. # -into Directory to install the launcher to, instead of /usr/bin
  671. # -pre Prepend contents of this file to the launcher
  672. # @CODE
  673. java-pkg_dolauncher() {
  674. debug-print-function ${FUNCNAME} $*
  675. java-pkg_check-phase install
  676. java-pkg_init_paths_
  677. if [[ ${#} = 0 ]]; then
  678. local name="${PN}"
  679. else
  680. local name="${1}"
  681. shift
  682. fi
  683. # TODO rename to launcher
  684. local target="${T}/${name}"
  685. local var_tmp="${T}/launcher_variables_tmp"
  686. local target_dir pre
  687. # Process the other the rest of the arguments
  688. while [[ -n "${1}" && -n "${2}" ]]; do
  689. local var="${1}" value="${2}"
  690. if [[ "${var:0:2}" == "--" ]]; then
  691. local var=${var:2}
  692. echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
  693. local gjl_${var}="${value}"
  694. elif [[ "${var}" == "-into" ]]; then
  695. target_dir="${value}"
  696. elif [[ "${var}" == "-pre" ]]; then
  697. pre="${value}"
  698. fi
  699. shift 2
  700. done
  701. # Test if no --jar and --main arguments were given and
  702. # in that case check if the package only installs one jar
  703. # and use that jar.
  704. if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
  705. local cp="${JAVA_PKG_CLASSPATH}"
  706. if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
  707. echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
  708. else
  709. local msg="Not enough information to create a launcher given."
  710. msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
  711. die "${msg}"
  712. fi
  713. fi
  714. # Write the actual script
  715. echo "#!/bin/bash" > "${target}"
  716. if [[ -n "${pre}" ]]; then
  717. if [[ -f "${pre}" ]]; then
  718. cat "${pre}" >> "${target}"
  719. else
  720. die "-pre specified file '${pre}' does not exist"
  721. fi
  722. fi
  723. echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
  724. cat "${var_tmp}" >> "${target}"
  725. rm -f "${var_tmp}"
  726. echo "source ${EPREFIX}/usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
  727. if [[ -n "${target_dir}" ]]; then
  728. (
  729. into "${target_dir}"
  730. dobin "${target}"
  731. )
  732. local ret=$?
  733. return ${ret}
  734. else
  735. dobin "${target}"
  736. fi
  737. }
  738. # @FUNCTION: java-pkg_dowar
  739. # @DESCRIPTION:
  740. # Install war files.
  741. # TODO document
  742. java-pkg_dowar() {
  743. debug-print-function ${FUNCNAME} $*
  744. # Check for arguments
  745. [[ ${#} -lt 1 ]] && die "At least one argument needed"
  746. java-pkg_check-phase install
  747. java-pkg_init_paths_
  748. local war
  749. for war in $* ; do
  750. local warpath
  751. # TODO evaluate if we want to handle symlinks differently -nichoj
  752. # Check for symlink
  753. if [[ -L "${war}" ]] ; then
  754. cp "${war}" "${T}"
  755. warpath="${T}$(basename "${war}")"
  756. # Check for directory
  757. # TODO evaluate if we want to handle directories differently -nichoj
  758. elif [[ -d "${war}" ]] ; then
  759. echo "dowar: warning, skipping directory ${war}"
  760. continue
  761. else
  762. warpath="${war}"
  763. fi
  764. # Install those files like you mean it
  765. (
  766. insopts -m0644
  767. insinto "${JAVA_PKG_WARDEST}"
  768. doins ${warpath}
  769. )
  770. done
  771. }
  772. # @FUNCTION: java-pkg_recordjavadoc
  773. # @INTERNAL
  774. # @DESCRIPTION:
  775. # Scan for JavaDocs, and record their existence in the package.env file
  776. # TODO make sure this in the proper section
  777. java-pkg_recordjavadoc()
  778. {
  779. debug-print-function ${FUNCNAME} $*
  780. # the find statement is important
  781. # as some packages include multiple trees of javadoc
  782. JAVADOC_PATH="$(find ${D}/usr/share/doc/ -name allclasses-frame.html -printf '%h:')"
  783. # remove $D - TODO: check this is ok with all cases of the above
  784. JAVADOC_PATH="${JAVADOC_PATH//${D}}"
  785. if [[ -n "${JAVADOC_PATH}" ]] ; then
  786. debug-print "javadocs found in ${JAVADOC_PATH%:}"
  787. java-pkg_do_write_
  788. else
  789. debug-print "No javadocs found"
  790. fi
  791. }
  792. # @FUNCTION: java-pkg_jar-from
  793. # @USAGE: [--build-only] [--with-dependencies] [--virtual] [--into dir] <package> [<package.jar>] [<destination.jar>]
  794. # @DESCRIPTION:
  795. # Makes a symlink to a jar from a certain package
  796. # A lot of java packages include dependencies in a lib/ directory
  797. # You can use this function to replace these bundled dependencies.
  798. # The dependency is recorded into package.env DEPEND line, unless "--build-only"
  799. # is passed as the very first argument, for jars that have to be present only
  800. # at build time and are not needed on runtime (junit testing etc).
  801. #
  802. # @CODE
  803. # Example: get all jars from xerces slot 2
  804. # java-pkg_jar-from xerces-2
  805. #
  806. # Example: get a specific jar from xerces slot 2
  807. # java-pkg_jar-from xerces-2 xml-apis.jar
  808. #
  809. # Example: get a specific jar from xerces slot 2, and name it diffrently
  810. # java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
  811. #
  812. # Example: get junit.jar which is needed only for building
  813. # java-pkg_jar-from --build-only junit junit.jar
  814. # @CODE
  815. #
  816. # @CODE
  817. # Parameters
  818. # --build-only - makes the jar(s) not added into package.env DEPEND line.
  819. # (assumed automatically when called inside src_test)
  820. # --with-dependencies - get jars also from requested package's dependencies
  821. # transitively.
  822. # --virtual - Packages passed to this function are to be handled as virtuals
  823. # and will not have individual jar dependencies recorded.
  824. # --into $dir - symlink jar(s) into $dir (must exist) instead of .
  825. # $1 - Package to get jars from, or comma-separated list of packages in
  826. # case other parameters are not used.
  827. # $2 - jar from package. If not specified, all jars will be used.
  828. # $3 - When a single jar is specified, destination filename of the
  829. # symlink. Defaults to the name of the jar.
  830. # @CODE
  831. # TODO could probably be cleaned up a little
  832. java-pkg_jar-from() {
  833. debug-print-function ${FUNCNAME} $*
  834. local build_only=""
  835. local destdir="."
  836. local deep=""
  837. local virtual=""
  838. local record_jar=""
  839. [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
  840. while [[ "${1}" == --* ]]; do
  841. if [[ "${1}" = "--build-only" ]]; then
  842. build_only="build"
  843. elif [[ "${1}" = "--with-dependencies" ]]; then
  844. deep="--with-dependencies"
  845. elif [[ "${1}" = "--virtual" ]]; then
  846. virtual="true"
  847. elif [[ "${1}" = "--into" ]]; then
  848. destdir="${2}"
  849. shift
  850. else
  851. die "java-pkg_jar-from called with unknown parameter: ${1}"
  852. fi
  853. shift
  854. done
  855. local target_pkg="${1}" target_jar="${2}" destjar="${3}"
  856. [[ -z ${target_pkg} ]] && die "Must specify a package"
  857. if [[ "${EAPI}" == "1" ]]; then
  858. target_pkg="${target_pkg//:/-}"
  859. fi
  860. # default destjar to the target jar
  861. [[ -z "${destjar}" ]] && destjar="${target_jar}"
  862. local error_msg="There was a problem getting the classpath for ${target_pkg}."
  863. local classpath
  864. classpath="$(java-config ${deep} --classpath=${target_pkg})"
  865. [[ $? != 0 ]] && die ${error_msg}
  866. # When we have commas this functions is called to bring jars from multiple
  867. # packages. This affects recording of dependencencies performed later
  868. # which expects one package only, so we do it here.
  869. if [[ ${target_pkg} = *,* ]]; then
  870. for pkg in ${target_pkg//,/ }; do
  871. java-pkg_ensure-dep "${build_only}" "${pkg}"
  872. [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
  873. done
  874. # setting this disables further record-jar_ calls later
  875. record_jar="true"
  876. else
  877. java-pkg_ensure-dep "${build_only}" "${target_pkg}"
  878. fi
  879. # Record the entire virtual as a dependency so that
  880. # no jars are missed.
  881. if [[ -z "${build_only}" && -n "${virtual}" ]]; then
  882. java-pkg_record-jar_ "${target_pkg}"
  883. # setting this disables further record-jars_ calls later
  884. record_jar="true"
  885. fi
  886. pushd ${destdir} > /dev/null \
  887. || die "failed to change directory to ${destdir}"
  888. local jar
  889. for jar in ${classpath//:/ }; do
  890. local jar_name=$(basename "${jar}")
  891. if [[ ! -f "${jar}" ]] ; then
  892. debug-print "${jar} from ${target_pkg} does not exist"
  893. die "Installation problems with jars in ${target_pkg} - is it installed?"
  894. fi
  895. # If no specific target jar was indicated, link it
  896. if [[ -z "${target_jar}" ]] ; then
  897. [[ -f "${target_jar}" ]] && rm "${target_jar}"
  898. ln -snf "${jar}" \
  899. || die "Failed to make symlink from ${jar} to ${jar_name}"
  900. if [[ -z "${record_jar}" ]]; then
  901. if [[ -z "${build_only}" ]]; then
  902. java-pkg_record-jar_ "${target_pkg}" "${jar}"
  903. else
  904. java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
  905. fi
  906. fi
  907. # otherwise, if the current jar is the target jar, link it
  908. elif [[ "${jar_name}" == "${target_jar}" ]] ; then
  909. [[ -f "${destjar}" ]] && rm "${destjar}"
  910. ln -snf "${jar}" "${destjar}" \
  911. || die "Failed to make symlink from ${jar} to ${destjar}"
  912. if [[ -z "${record_jar}" ]]; then
  913. if [[ -z "${build_only}" ]]; then
  914. java-pkg_record-jar_ "${target_pkg}" "${jar}"
  915. else
  916. java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
  917. fi
  918. fi
  919. popd > /dev/null || die
  920. return 0
  921. fi
  922. done
  923. popd > /dev/null || die
  924. # if no target was specified, we're ok
  925. if [[ -z "${target_jar}" ]] ; then
  926. return 0
  927. # otherwise, die bitterly
  928. else
  929. die "Failed to find ${target_jar:-jar} in ${target_pkg}"
  930. fi
  931. }
  932. # @FUNCTION: java-pkg_jarfrom
  933. # @DESCRIPTION:
  934. # See java-pkg_jar-from
  935. java-pkg_jarfrom() {
  936. java-pkg_jar-from "$@"
  937. }
  938. # @FUNCTION: java-pkg_getjars
  939. # @USAGE: [--build-only] [--with-dependencies] <package1>[,<package2>...]
  940. # @DESCRIPTION:
  941. # Get the classpath provided by any number of packages
  942. # Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
  943. # The providing packages are recorded as dependencies into package.env DEPEND
  944. # line, unless "--build-only" is passed as the very first argument, for jars
  945. # that have to be present only at build time and are not needed on runtime
  946. # (junit testing etc).
  947. #
  948. # @CODE
  949. # Example: Get the classpath for xerces-2 and xalan,
  950. # java-pkg_getjars xerces-2,xalan
  951. #
  952. # Example Return:
  953. # /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
  954. #
  955. #
  956. # Parameters:
  957. # --build-only - makes the jar(s) not added into package.env DEPEND line.
  958. # (assumed automatically when called inside src_test)
  959. # --with-dependencies - get jars also from requested package's dependencies
  960. # transitively.
  961. # $1 - list of packages to get jars from
  962. # (passed to java-config --classpath)
  963. # @CODE
  964. java-pkg_getjars() {
  965. debug-print-function ${FUNCNAME} $*
  966. local build_only=""
  967. local deep=""
  968. [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
  969. while [[ "${1}" == --* ]]; do
  970. if [[ "${1}" = "--build-only" ]]; then
  971. build_only="build"
  972. elif [[ "${1}" = "--with-dependencies" ]]; then
  973. deep="--with-dependencies"
  974. else
  975. die "java-pkg_jar-from called with unknown parameter: ${1}"
  976. fi
  977. shift
  978. done
  979. [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
  980. local pkgs="${1}"
  981. if [[ "${EAPI}" == "1" ]]; then
  982. pkgs="${pkgs//:/-}"
  983. fi
  984. jars="$(java-config ${deep} --classpath=${pkgs})"
  985. [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
  986. debug-print "${pkgs}:${jars}"
  987. for pkg in ${pkgs//,/ }; do
  988. java-pkg_ensure-dep "${build_only}" "${pkg}"
  989. done
  990. for pkg in ${pkgs//,/ }; do
  991. if [[ -z "${build_only}" ]]; then
  992. java-pkg_record-jar_ "${pkg}"
  993. else
  994. java-pkg_record-jar_ --build-only "${pkg}"
  995. fi
  996. done
  997. echo "${jars}"
  998. }
  999. # @FUNCTION: java-pkg_getjar
  1000. # @USAGE: [--build-only] [--virtual] <package> <jarfile>
  1001. # @DESCRIPTION:
  1002. # Get the complete path of a single jar from a package
  1003. # The providing package is recorded as runtime dependency into package.env
  1004. # DEPEND line, unless "--build-only" is passed as the very first argument, for
  1005. # jars that have to be present only at build time and are not needed on runtime
  1006. # (junit testing etc).
  1007. #
  1008. # @CODE
  1009. # Example:
  1010. # java-pkg_getjar xerces-2 xml-apis.jar
  1011. # returns
  1012. # /usr/share/xerces-2/lib/xml-apis.jar
  1013. #
  1014. # Parameters:
  1015. # --build-only - makes the jar not added into package.env DEPEND line.
  1016. # --virtual - Packages passed to this function are to be handled as virtuals
  1017. # and will not have individual jar dependencies recorded.
  1018. # $1 - package to use
  1019. # $2 - jar to get
  1020. # @CODE
  1021. java-pkg_getjar() {
  1022. debug-print-function ${FUNCNAME} $*
  1023. local build_only=""
  1024. local virtual=""
  1025. local record_jar=""
  1026. [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
  1027. while [[ "${1}" == --* ]]; do
  1028. if [[ "${1}" = "--build-only" ]]; then
  1029. build_only="build"
  1030. elif [[ "${1}" == "--virtual" ]]; then
  1031. virtual="true"
  1032. else
  1033. die "java-pkg_getjar called with unknown parameter: ${1}"
  1034. fi
  1035. shift
  1036. done
  1037. [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
  1038. local pkg="${1}" target_jar="${2}" jar
  1039. if [[ "${EAPI}" == "1" ]]; then
  1040. pkg="${pkg//:/-}"
  1041. fi
  1042. [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
  1043. [[ -z ${target_jar} ]] && die "Must specify jar to get"
  1044. local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
  1045. local classpath
  1046. classpath=$(java-config --classpath=${pkg})
  1047. [[ $? != 0 ]] && die ${error_msg}
  1048. java-pkg_ensure-dep "${build_only}" "${pkg}"
  1049. # Record the package(Virtual) as a dependency and then set build_only
  1050. # So that individual jars are not recorded.
  1051. if [[ -n "${virtual}" ]]; then
  1052. if [[ -z "${build_only}" ]]; then
  1053. java-pkg_record-jar_ "${pkg}"
  1054. else
  1055. java-pkg_record-jar_ --build-only "${pkg}"
  1056. fi
  1057. record_jar="true"
  1058. fi
  1059. for jar in ${classpath//:/ }; do
  1060. if [[ ! -f "${jar}" ]] ; then
  1061. die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
  1062. fi
  1063. if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
  1064. # Only record jars that aren't build-only
  1065. if [[ -z "${record_jar}" ]]; then
  1066. if [[ -z "${build_only}" ]]; then
  1067. java-pkg_record-jar_ "${pkg}" "${jar}"
  1068. else
  1069. java-pkg_record-jar_ --build-only "${pkg}" "${jar}"
  1070. fi
  1071. fi
  1072. echo "${jar}"
  1073. return 0
  1074. fi
  1075. done
  1076. die "Could not find ${target_jar} in ${pkg}"
  1077. return 1
  1078. }
  1079. # @FUNCTION: java-pkg_register-dependency
  1080. # @USAGE: <package>[,<package2>...] [<jarfile>]
  1081. # @DESCRIPTION:
  1082. # Registers runtime dependency on a package, list of packages, or a single jar
  1083. # from a package, into package.env DEPEND line. Can only be called in
  1084. # src_install phase.
  1085. # Intended for binary packages where you don't need to symlink the jars or get
  1086. # their classpath during build. As such, the dependencies only need to be
  1087. # specified in ebuild's RDEPEND, and should be omitted in DEPEND.
  1088. #
  1089. # @CODE
  1090. # Parameters:
  1091. # $1 - comma-separated list of packages, or a single package
  1092. # $2 - if param $1 is a single package, optionally specify the jar
  1093. # to depend on
  1094. #
  1095. # Examples:
  1096. # Record the dependency on whole xerces-2 and xalan,
  1097. # java-pkg_register-dependency xerces-2,xalan
  1098. #
  1099. # Record the dependency on ant.jar from ant-core
  1100. # java-pkg_register-dependency ant-core ant.jar
  1101. # @CODE
  1102. #
  1103. # Note: Passing both list of packages as the first parameter AND specifying the
  1104. # jar as the second is not allowed and will cause the function to die. We assume
  1105. # that there's more chance one passes such combination as a mistake, than that
  1106. # there are more packages providing identically named jar without class
  1107. # collisions.
  1108. java-pkg_register-dependency() {
  1109. debug-print-function ${FUNCNAME} $*
  1110. java-pkg_check-phase install
  1111. [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
  1112. local pkgs="${1}"
  1113. local jar="${2}"
  1114. [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
  1115. if [[ "${EAPI}" == "1" ]]; then
  1116. pkgs="${pkgs//:/-}"
  1117. fi
  1118. if [[ -z "${jar}" ]]; then
  1119. for pkg in ${pkgs//,/ }; do
  1120. java-pkg_ensure-dep runtime "${pkg}"
  1121. java-pkg_record-jar_ "${pkg}"
  1122. done
  1123. else
  1124. [[ ${pkgs} == *,* ]] && \
  1125. die "${FUNCNAME} called with both package list and jar name"
  1126. java-pkg_ensure-dep runtime "${pkgs}"
  1127. java-pkg_record-jar_ "${pkgs}" "${jar}"
  1128. fi
  1129. java-pkg_do_write_
  1130. }
  1131. # @FUNCTION: java-pkg_register-optional-dependency
  1132. # @USAGE: <package>[,<package2>...] [<jarfile>]
  1133. # @DESCRIPTION:
  1134. # Registers optional runtime dependency on a package, list of packages, or a
  1135. # single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
  1136. # called in src_install phase.
  1137. # Intended for packages that can use other packages when those are in classpath.
  1138. # Will be put on classpath by launcher if they are installed. Typical case is
  1139. # JDBC implementations for various databases. It's better than having USE flag
  1140. # for each implementation triggering hard dependency.
  1141. #
  1142. # @CODE
  1143. # Parameters:
  1144. # $1 - comma-separated list of packages, or a single package
  1145. # $2 - if param $1 is a single package, optionally specify the jar to depend on
  1146. #
  1147. # Example:
  1148. # Record the optional dependency on some jdbc providers
  1149. # java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
  1150. # @CODE
  1151. #
  1152. # Note: Passing both list of packages as the first parameter AND specifying the
  1153. # jar as the second is not allowed and will cause the function to die. We assume
  1154. # that there's more chance one passes such combination as a mistake, than that
  1155. # there are more packages providing identically named jar without class
  1156. # collisions.
  1157. java-pkg_register-optional-dependency() {
  1158. debug-print-function ${FUNCNAME} $*
  1159. java-pkg_check-phase install
  1160. [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
  1161. local pkgs="${1}"
  1162. local jar="${2}"
  1163. [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
  1164. if [[ "${EAPI}" == "1" ]]; then
  1165. pkgs="${pkgs//:/-}"
  1166. fi
  1167. if [[ -z "${jar}" ]]; then
  1168. for pkg in ${pkgs//,/ }; do
  1169. java-pkg_record-jar_ --optional "${pkg}"
  1170. done
  1171. else
  1172. [[ ${pkgs} == *,* ]] && \
  1173. die "${FUNCNAME} called with both package list and jar name"
  1174. java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
  1175. fi
  1176. java-pkg_do_write_
  1177. }
  1178. # @FUNCTION: java-pkg_register-environment-variable
  1179. # @USAGE: <name> <value>
  1180. # @DESCRIPTION:
  1181. # Register an arbitrary environment variable into package.env. The gjl launcher
  1182. # for this package or any package depending on this will export it into
  1183. # environement before executing java command.
  1184. # Must only be called in src_install phase.
  1185. JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
  1186. JAVA_PKG_EXTRA_ENV_VARS=""
  1187. java-pkg_register-environment-variable() {
  1188. debug-print-function ${FUNCNAME} $*
  1189. java-pkg_check-phase install
  1190. [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
  1191. echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
  1192. JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
  1193. java-pkg_do_write_
  1194. }
  1195. # @FUNCTION: java-pkg_get-bootclasspath
  1196. # @USAGE: <version>
  1197. # @DESCRIPTION:
  1198. # Returns classpath of a given bootclasspath-providing package version.
  1199. #
  1200. # @param $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath
  1201. # of the current JDK
  1202. java-pkg_get-bootclasspath() {
  1203. local version="${1}"
  1204. local bcp
  1205. case "${version}" in
  1206. auto)
  1207. bcp="$(java-config -g BOOTCLASSPATH)"
  1208. ;;
  1209. 1.5)
  1210. bcp="$(java-pkg_getjars --build-only gnu-classpath-0.98)"
  1211. ;;
  1212. *)
  1213. eerror "unknown parameter of java-pkg_get-bootclasspath"
  1214. die "unknown parameter of java-pkg_get-bootclasspath"
  1215. ;;
  1216. esac
  1217. echo "${bcp}"
  1218. }
  1219. # This function reads stdin, and based on that input, figures out how to
  1220. # populate jars from the filesystem.
  1221. # Need to figure out a good way of making use of this, ie be able to use a
  1222. # string that was built instead of stdin
  1223. # NOTE: this isn't quite ready for primetime.
  1224. #java-pkg_populate-jars() {
  1225. # local line
  1226. #
  1227. # read line
  1228. # while [[ -n "${line}" ]]; do
  1229. # # Ignore comments
  1230. # [[ ${line%%#*} == "" ]] && continue
  1231. #
  1232. # # get rid of any spaces
  1233. # line="${line// /}"
  1234. #
  1235. # # format: path=jarinfo
  1236. # local path=${line%%=*}
  1237. # local jarinfo=${line##*=}
  1238. #
  1239. # # format: jar@package
  1240. # local jar=${jarinfo%%@*}.jar
  1241. # local package=${jarinfo##*@}
  1242. # if [[ -n ${replace_only} ]]; then
  1243. # [[ ! -f $path ]] && die "No jar exists at ${path}"
  1244. # fi
  1245. # if [[ -n ${create_parent} ]]; then
  1246. # local parent=$(dirname ${path})
  1247. # mkdir -p "${parent}"
  1248. # fi
  1249. # java-pkg_jar-from "${package}" "${jar}" "${path}"
  1250. #
  1251. # read line
  1252. # done
  1253. #}
  1254. # @FUNCTION: java-pkg_find-normal-jars
  1255. # @USAGE: [<path/to/directory>]
  1256. # @DESCRIPTION:
  1257. # Find the files with suffix .jar file in the given directory (default: $WORKDIR)
  1258. java-pkg_find-normal-jars() {
  1259. local dir=$1
  1260. [[ "${dir}" ]] || dir="${WORKDIR}"
  1261. local found
  1262. for jar in $(find "${dir}" -name "*.jar" -type f); do
  1263. echo "${jar}"
  1264. found="true"
  1265. done
  1266. [[ "${found}" ]]
  1267. return $?
  1268. }
  1269. # @FUNCTION: java-pkg_ensure-no-bundled-jars
  1270. # @DESCRIPTION:
  1271. # Try to locate bundled jar files in ${WORKDIR} and die if found.
  1272. # This function should be called after WORKDIR has been populated with symlink
  1273. # to system jar files or bundled jars removed.
  1274. java-pkg_ensure-no-bundled-jars() {
  1275. debug-print-function ${FUNCNAME} $*
  1276. local bundled_jars=$(java-pkg_find-normal-jars)
  1277. if [[ -n ${bundled_jars} ]]; then
  1278. echo "Bundled jars found:"
  1279. local jar
  1280. for jar in ${bundled_jars}; do
  1281. echo $(pwd)${jar/./}
  1282. done
  1283. die "Bundled jars found!"
  1284. fi
  1285. }
  1286. # @FUNCTION: java-pkg_ensure-vm-version-sufficient
  1287. # @INTERNAL
  1288. # @DESCRIPTION:
  1289. # Checks if we have a sufficient VM and dies if we don't.
  1290. java-pkg_ensure-vm-version-sufficient() {
  1291. debug-print-function ${FUNCNAME} $*
  1292. if ! java-pkg_is-vm-version-sufficient; then
  1293. debug-print "VM is not suffient"
  1294. eerror "Current Java VM cannot build this package"
  1295. einfo "Please use java-config -S to set the correct one"
  1296. die "Active Java VM cannot build this package"
  1297. fi
  1298. }
  1299. # @FUNCTION: java-pkg_is-vm-version-sufficient
  1300. # @INTERNAL
  1301. # @DESCRIPTION:
  1302. # @RETURN: zero - VM is sufficient; non-zero - VM is not sufficient
  1303. java-pkg_is-vm-version-sufficient() {
  1304. debug-print-function ${FUNCNAME} $*
  1305. depend-java-query --is-sufficient "${DEPEND}" > /dev/null
  1306. return $?
  1307. }
  1308. # @FUNCTION: java-pkg_ensure-vm-version-eq
  1309. # @INTERNAL
  1310. # @DESCRIPTION:
  1311. # Die if the current VM is not equal to the argument passed.
  1312. #
  1313. # @param $@ - Desired VM version to ensure
  1314. java-pkg_ensure-vm-version-eq() {
  1315. debug-print-function ${FUNCNAME} $*
  1316. if ! java-pkg_is-vm-version-eq $@ ; then
  1317. debug-print "VM is not suffient"
  1318. eerror "This package requires a Java VM version = $@"
  1319. einfo "Please use java-config -S to set the correct one"
  1320. die "Active Java VM too old"
  1321. fi
  1322. }
  1323. # @FUNCTION: java-pkg_is-vm-version-eq
  1324. # @USAGE: <version>
  1325. # @INTERNAL
  1326. # @RETURN: zero - VM versions are equal; non-zero - VM version are not equal
  1327. java-pkg_is-vm-version-eq() {
  1328. debug-print-function ${FUNCNAME} $*
  1329. local needed_version="$@"
  1330. [[ -z "${needed_version}" ]] && die "need an argument"
  1331. local vm_version="$(java-pkg_get-vm-version)"
  1332. vm_version="$(get_version_component_range 1-2 "${vm_version}")"
  1333. needed_version="$(get_version_component_range 1-2 "${needed_version}")"
  1334. if [[ -z "${vm_version}" ]]; then
  1335. debug-print "Could not get JDK version from DEPEND"
  1336. return 1
  1337. else
  1338. if [[ "${vm_version}" == "${needed_version}" ]]; then
  1339. debug-print "Detected a JDK(${vm_version}) = ${needed_version}"
  1340. return 0
  1341. else
  1342. debug-print "Detected a JDK(${vm_version}) != ${needed_version}"
  1343. return 1
  1344. fi
  1345. fi
  1346. }
  1347. # @FUNCTION: java-pkg_ensure-vm-version-ge
  1348. # @INTERNAL
  1349. # @DESCRIPTION:
  1350. # Die if the current VM is not greater than the desired version
  1351. #
  1352. # @param $@ - VM version to compare current to
  1353. java-pkg_ensure-vm-version-ge() {
  1354. debug-print-function ${FUNCNAME} $*
  1355. if ! java-pkg_is-vm-version-ge "$@" ; then
  1356. debug-print "vm is not suffient"
  1357. eerror "This package requires a Java VM version >= $@"
  1358. einfo "Please use java-config -S to set the correct one"
  1359. die "Active Java VM too old"
  1360. fi
  1361. }
  1362. # @FUNCTION: java-pkg_is-vm-version-ge
  1363. # @INTERNAL
  1364. # @DESCRIPTION:
  1365. # @CODE
  1366. # Parameters:
  1367. # $@ - VM version to compare current VM to
  1368. # @CODE
  1369. # @RETURN: zero - current VM version is greater than checked version;
  1370. # non-zero - current VM version is not greater than checked version
  1371. java-pkg_is-vm-version-ge() {
  1372. debug-print-function ${FUNCNAME} $*
  1373. local needed_version=$@
  1374. local vm_version=$(java-pkg_get-vm-version)
  1375. if [[ -z "${vm_version}" ]]; then
  1376. debug-print "Could not get JDK version from DEPEND"
  1377. return 1
  1378. else
  1379. if version_is_at_least "${needed_version}" "${vm_version}"; then
  1380. debug-print "Detected a JDK(${vm_version}) >= ${needed_version}"
  1381. return 0
  1382. else
  1383. debug-print "Detected a JDK(${vm_version}) < ${needed_version}"
  1384. return 1
  1385. fi
  1386. fi
  1387. }
  1388. java-pkg_set-current-vm() {
  1389. export GENTOO_VM=${1}
  1390. }
  1391. java-pkg_get-current-vm() {
  1392. echo ${GENTOO_VM}
  1393. }
  1394. java-pkg_current-vm-matches() {
  1395. has $(java-pkg_get-current-vm) ${@}
  1396. return $?
  1397. }
  1398. # @FUNCTION: java-pkg_get-source
  1399. # @DESCRIPTION:
  1400. # Determines what source version should be used, for passing to -source.
  1401. # Unless you want to break things you probably shouldn't set _WANT_SOURCE
  1402. #
  1403. # @RETURN: string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
  1404. java-pkg_get-source() {
  1405. echo ${JAVA_PKG_WANT_SOURCE:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
  1406. }
  1407. # @FUNCTION: java-pkg_get-target
  1408. # @DESCRIPTION:
  1409. # Determines what target version should be used, for passing to -target.
  1410. # If you don't care about lower versions, you can set _WANT_TARGET to the
  1411. # version of your JDK.
  1412. #
  1413. # @RETURN: string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
  1414. java-pkg_get-target() {
  1415. echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
  1416. }
  1417. # @FUNCTION: java-pkg_get-javac
  1418. # @DESCRIPTION:
  1419. # Returns the compiler executable
  1420. java-pkg_get-javac() {
  1421. debug-print-function ${FUNCNAME} $*
  1422. java-pkg_init-compiler_
  1423. local compiler="${GENTOO_COMPILER}"
  1424. local compiler_executable
  1425. if [[ "${compiler}" = "javac" ]]; then
  1426. # nothing fancy needs to be done for javac
  1427. compiler_executable="javac"
  1428. else
  1429. # for everything else, try to determine from an env file
  1430. local compiler_env="/usr/share/java-config-2/compiler/${compiler}"
  1431. if [[ -f ${compiler_env} ]]; then
  1432. local old_javac=${JAVAC}
  1433. unset JAVAC
  1434. # try to get value of JAVAC
  1435. compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
  1436. export JAVAC=${old_javac}
  1437. if [[ -z ${compiler_executable} ]]; then
  1438. die "JAVAC is empty or undefined in ${compiler_env}"
  1439. fi
  1440. # check that it's executable
  1441. if [[ ! -x ${compiler_executable} ]]; then
  1442. die "${compiler_executable} doesn't exist, or isn't executable"
  1443. fi
  1444. else
  1445. die "Could not find environment file for ${compiler}"
  1446. fi
  1447. fi
  1448. echo ${compiler_executable}
  1449. }
  1450. # @FUNCTION: java-pkg_javac-args
  1451. # @DESCRIPTION:
  1452. # If an ebuild uses javac directly, instead of using ejavac, it should call this
  1453. # to know what -source/-target to use.
  1454. #
  1455. # @RETURN: string - arguments to pass to javac, complete with -target and -source
  1456. java-pkg_javac-args() {
  1457. debug-print-function ${FUNCNAME} $*
  1458. local want_source="$(java-pkg_get-source)"
  1459. local want_target="$(java-pkg_get-target)"
  1460. local source_str="-source ${want_source}"
  1461. local target_str="-target ${want_target}"
  1462. debug-print "want source: ${want_source}"
  1463. debug-print "want target: ${want_target}"
  1464. if [[ -z "${want_source}" || -z "${want_target}" ]]; then
  1465. die "Could not find valid -source/-target values for javac"
  1466. else
  1467. echo "${source_str} ${target_str}"
  1468. fi
  1469. }
  1470. # @FUNCTION: java-pkg_get-jni-cflags
  1471. # @DESCRIPTION:
  1472. # Echos the CFLAGS for JNI compilations
  1473. java-pkg_get-jni-cflags() {
  1474. local flags="-I${JAVA_HOME}/include"
  1475. local platform="linux"
  1476. use elibc_FreeBSD && platform="freebsd"
  1477. # TODO do a check that the directories are valid
  1478. flags="${flags} -I${JAVA_HOME}/include/${platform}"
  1479. echo ${flags}
  1480. }
  1481. java-pkg_ensure-gcj() {
  1482. # was enforcing sys-devel/gcc[gcj]
  1483. die "${FUNCNAME} was removed. Use use-deps available as of EAPI 2 instead. #261562"
  1484. }
  1485. java-pkg_ensure-test() {
  1486. # was enforcing USE=test if FEATURES=test
  1487. die "${FUNCNAME} was removed. Package mangers handle this already. #278965"
  1488. }
  1489. # @FUNCTION: java-pkg_register-ant-task
  1490. # @USAGE: [--version x.y] [<name>]
  1491. # @DESCRIPTION:
  1492. # Register this package as ant task, so that ant will load it when no specific
  1493. # ANT_TASKS are specified. Note that even without this registering, all packages
  1494. # specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
  1495. # packages, but can be also used by other ebuilds that used to symlink their
  1496. # .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
  1497. # compatibility.
  1498. #
  1499. # @CODE
  1500. # Parameters
  1501. # --version x.y Register only for ant version x.y (otherwise for any ant
  1502. # version). Used by the ant-* packages to prevent loading of mismatched
  1503. # ant-core ant tasks after core was updated, before the tasks are updated,
  1504. # without a need for blockers.
  1505. # $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
  1506. # @CODE
  1507. java-pkg_register-ant-task() {
  1508. local TASKS_DIR="tasks"
  1509. # check for --version x.y parameters
  1510. while [[ -n "${1}" && -n "${2}" ]]; do
  1511. local var="${1#--}"
  1512. local val="${2}"
  1513. if [[ "${var}" == "version" ]]; then
  1514. TASKS_DIR="tasks-${val}"
  1515. else
  1516. die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
  1517. fi
  1518. shift 2
  1519. done
  1520. local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
  1521. dodir /usr/share/ant/${TASKS_DIR}
  1522. touch "${ED}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
  1523. }
  1524. # @FUNCTION: java-pkg_ant-tasks-depend
  1525. # @INTERNAL
  1526. # @DESCRIPTION:
  1527. # Translates the WANT_ANT_TASKS variable into valid dependencies.
  1528. java-pkg_ant-tasks-depend() {
  1529. debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
  1530. if [[ -n "${WANT_ANT_TASKS}" ]]; then
  1531. local DEP=""
  1532. for i in ${WANT_ANT_TASKS}
  1533. do
  1534. if [[ ${i} = ant-* ]]; then
  1535. DEP="${DEP}dev-java/${i} "
  1536. elif [[ ${i} = */*:* ]]; then
  1537. DEP="${DEP}${i} "
  1538. else
  1539. echo "Invalid atom in WANT_ANT_TASKS: ${i}"
  1540. return 1
  1541. fi
  1542. done
  1543. echo ${DEP}
  1544. return 0
  1545. else
  1546. return 0
  1547. fi
  1548. }
  1549. # @FUNCTION: ejunit_
  1550. # @INTERNAL
  1551. # @DESCRIPTION:
  1552. # Internal Junit wrapper function. Makes it easier to run the tests and checks for
  1553. # dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
  1554. # @CODE
  1555. # Parameters:
  1556. # $1 - junit package (junit or junit-4)
  1557. # $2 - -cp or -classpath
  1558. # $3 - classpath; junit and recorded dependencies get appended
  1559. # $@ - the rest of the parameters are passed to java
  1560. # @CODE
  1561. ejunit_() {
  1562. debug-print-function ${FUNCNAME} $*
  1563. local pkgs
  1564. if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
  1565. for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
  1566. pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
  1567. done
  1568. fi
  1569. local junit=${1}
  1570. shift 1
  1571. local cp=$(java-pkg_getjars --with-dependencies ${junit}${pkgs})
  1572. if [[ ${1} = -cp || ${1} = -classpath ]]; then
  1573. cp="${2}:${cp}"
  1574. shift 2
  1575. else
  1576. cp=".:${cp}"
  1577. fi
  1578. local runner=junit.textui.TestRunner
  1579. if [[ "${junit}" == "junit-4" ]] ; then
  1580. runner=org.junit.runner.JUnitCore
  1581. fi
  1582. debug-print "Calling: java -cp \"${cp}\" -Djava.io.tmpdir=\"${T}\" -Djava.awt.headless=true ${runner} ${@}"
  1583. java -cp "${cp}" -Djava.io.tmpdir="${T}/" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
  1584. }
  1585. # @FUNCTION: ejunit
  1586. # @DESCRIPTION:
  1587. # Junit wrapper function. Makes it easier to run the tests and checks for
  1588. # dev-java/junit in DEPEND. Launches the tests using org.junit.runner.JUnitCore.
  1589. #
  1590. # @CODE
  1591. # Parameters:
  1592. # $1 - -cp or -classpath
  1593. # $2 - classpath; junit and recorded dependencies get appended
  1594. # $@ - the rest of the parameters are passed to java
  1595. #
  1596. # Examples:
  1597. # ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
  1598. # ejunit org.blinkenlights.jid3.test.AllTests
  1599. # ejunit org.blinkenlights.jid3.test.FirstTest org.blinkenlights.jid3.test.SecondTest
  1600. # @CODE
  1601. ejunit() {
  1602. debug-print-function ${FUNCNAME} $*
  1603. ejunit_ "junit" "${@}"
  1604. }
  1605. # @FUNCTION: ejunit4
  1606. # @DESCRIPTION:
  1607. # Junit4 wrapper function. Makes it easier to run the tests and checks for
  1608. # dev-java/junit:4 in DEPEND. Launches the tests using junit.textui.TestRunner.
  1609. #
  1610. # @CODE
  1611. # Parameters:
  1612. # $1 - -cp or -classpath
  1613. # $2 - classpath; junit and recorded dependencies get appended
  1614. # $@ - the rest of the parameters are passed to java
  1615. #
  1616. # Examples:
  1617. # ejunit4 -cp build/classes org.blinkenlights.jid3.test.AllTests
  1618. # ejunit4 org.blinkenlights.jid3.test.AllTests
  1619. # ejunit4 org.blinkenlights.jid3.test.FirstTest \
  1620. # org.blinkenlights.jid3.test.SecondTest
  1621. # @CODE
  1622. ejunit4() {
  1623. debug-print-function ${FUNCNAME} $*
  1624. ejunit_ "junit-4" "${@}"
  1625. }
  1626. # @FUNCTION: java-utils-2_src_prepare
  1627. # @DESCRIPTION:
  1628. # src_prepare Searches for bundled jars
  1629. # Don't call directly, but via java-pkg-2_src_prepare!
  1630. java-utils-2_src_prepare() {
  1631. case ${EAPI:-0} in
  1632. [0-5])
  1633. java-pkg_func-exists java_prepare && java_prepare ;;
  1634. *)
  1635. java-pkg_func-exists java_prepare &&
  1636. eqawarn "java_prepare is no longer called, define src_prepare instead."
  1637. eapply_user ;;
  1638. esac
  1639. # Check for files in JAVA_RM_FILES array.
  1640. if [[ ${JAVA_RM_FILES[@]} ]]; then
  1641. debug-print "$FUNCNAME: removing unneeded files"
  1642. java-pkg_rm_files "${JAVA_RM_FILES[@]}"
  1643. fi
  1644. if is-java-strict; then
  1645. echo "Searching for bundled jars:"
  1646. java-pkg_find-normal-jars || echo "None found."
  1647. echo "Searching for bundled classes (no output if none found):"
  1648. find "${WORKDIR}" -name "*.class"
  1649. echo "Search done."
  1650. fi
  1651. }
  1652. # @FUNCTION: java-utils-2_pkg_preinst
  1653. # @DESCRIPTION:
  1654. # pkg_preinst Searches for missing and unneeded dependencies
  1655. # Don't call directly, but via java-pkg-2_pkg_preinst!
  1656. java-utils-2_pkg_preinst() {
  1657. if is-java-strict; then
  1658. if [[ ! -e "${JAVA_PKG_ENV}" ]] || has ant-tasks ${INHERITED}; then
  1659. return
  1660. fi
  1661. if has_version dev-java/java-dep-check; then
  1662. local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
  1663. [[ ${output} ]] && ewarn "${output}"
  1664. else
  1665. eerror "Install dev-java/java-dep-check for dependency checking"
  1666. fi
  1667. fi
  1668. }
  1669. # @FUNCTION: eant
  1670. # @USAGE: <ant_build_target(s)>
  1671. # @DESCRIPTION:
  1672. # Ant wrapper function. Will use the appropriate compiler, based on user-defined
  1673. # compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
  1674. # variables:
  1675. #
  1676. # @CODE
  1677. # Variables:
  1678. # EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
  1679. # gentoo.classpath property. Be sure to call java-ant_rewrite-classpath in src_unpack.
  1680. # EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
  1681. # for build-time purposes, the dependency is not recorded to
  1682. # package.env!
  1683. # ANT_TASKS - used to determine ANT_TASKS before calling Ant.
  1684. # @CODE
  1685. eant() {
  1686. debug-print-function ${FUNCNAME} $*
  1687. if [[ ${EBUILD_PHASE} = compile ]]; then
  1688. java-ant-2_src_configure
  1689. fi
  1690. if ! has java-ant-2 ${INHERITED}; then
  1691. local msg="You should inherit java-ant-2 when using eant"
  1692. java-pkg_announce-qa-violation "${msg}"
  1693. fi
  1694. local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
  1695. java-pkg_init-compiler_
  1696. local compiler="${GENTOO_COMPILER}"
  1697. local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
  1698. local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
  1699. if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
  1700. die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
  1701. fi
  1702. if [[ ${compiler} != "javac" ]]; then
  1703. antflags="${antflags} -Dbuild.compiler=${build_compiler}"
  1704. # Figure out any extra stuff to put on the classpath for compilers aside
  1705. # from javac
  1706. # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
  1707. # java-config -p
  1708. local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
  1709. if [[ -n ${build_compiler_deps} ]]; then
  1710. antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
  1711. fi
  1712. fi
  1713. for arg in "${@}"; do
  1714. if [[ ${arg} = -lib ]]; then
  1715. if is-java-strict; then
  1716. eerror "You should not use the -lib argument to eant because it will fail"
  1717. eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
  1718. eerror "or ant properties to make dependencies available."
  1719. eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
  1720. eerror "split ant (>=dev-java/ant-core-1.7)."
  1721. die "eant -lib is deprecated/forbidden"
  1722. else
  1723. echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
  1724. echo "more info."
  1725. fi
  1726. fi
  1727. done
  1728. # parse WANT_ANT_TASKS for atoms
  1729. local want_ant_tasks
  1730. for i in ${WANT_ANT_TASKS}; do
  1731. if [[ ${i} = */*:* ]]; then
  1732. i=${i#*/}
  1733. i=${i%:0}
  1734. want_ant_tasks+="${i/:/-} "
  1735. else
  1736. want_ant_tasks+="${i} "
  1737. fi
  1738. done
  1739. # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
  1740. ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
  1741. # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
  1742. ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
  1743. # if ant-tasks is not set by ebuild or forced, use none
  1744. ANT_TASKS="${ANT_TASKS:-none}"
  1745. # at this point, ANT_TASKS should be "all", "none" or explicit list
  1746. if [[ "${ANT_TASKS}" == "all" ]]; then
  1747. einfo "Using all available ANT_TASKS"
  1748. elif [[ "${ANT_TASKS}" == "none" ]]; then
  1749. einfo "Disabling all optional ANT_TASKS"
  1750. else
  1751. einfo "Using following ANT_TASKS: ${ANT_TASKS}"
  1752. fi
  1753. export ANT_TASKS
  1754. [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
  1755. [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
  1756. local gcp="${EANT_GENTOO_CLASSPATH}"
  1757. local getjarsarg=""
  1758. if [[ ${EBUILD_PHASE} = "test" ]]; then
  1759. antflags="${antflags} -DJunit.present=true"
  1760. getjarsarg="--with-dependencies"
  1761. local re="\bant-junit4?([-:]\S+)?\b"
  1762. [[ ${ANT_TASKS} =~ ${re} ]] && gcp+=" ${BASH_REMATCH[0]}"
  1763. else
  1764. antflags="${antflags} -Dmaven.test.skip=true"
  1765. fi
  1766. local cp
  1767. for atom in ${gcp}; do
  1768. cp+=":$(java-pkg_getjars ${getjarsarg} ${atom})"
  1769. done
  1770. [[ ${EANT_NEEDS_TOOLS} ]] && cp+=":$(java-config --tools)"
  1771. [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && cp+=":${EANT_GENTOO_CLASSPATH_EXTRA}"
  1772. if [[ ${cp#:} ]]; then
  1773. # It seems ant does not like single quotes around ${cp}
  1774. antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
  1775. fi
  1776. [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
  1777. debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
  1778. ant ${antflags} "${@}" || die "eant failed"
  1779. }
  1780. # @FUNCTION: ejavac
  1781. # @USAGE: <javac_arguments>
  1782. # @DESCRIPTION:
  1783. # Javac wrapper function. Will use the appropriate compiler, based on
  1784. # /etc/java-config/compilers.conf
  1785. ejavac() {
  1786. debug-print-function ${FUNCNAME} $*
  1787. local compiler_executable
  1788. compiler_executable=$(java-pkg_get-javac)
  1789. local javac_args
  1790. javac_args="$(java-pkg_javac-args)"
  1791. if [[ -n ${JAVA_PKG_DEBUG} ]]; then
  1792. einfo "Verbose logging for \"${FUNCNAME}\" function"
  1793. einfo "Compiler executable: ${compiler_executable}"
  1794. einfo "Extra arguments: ${javac_args}"
  1795. einfo "Complete command:"
  1796. einfo "${compiler_executable} ${javac_args} ${@}"
  1797. fi
  1798. ebegin "Compiling"
  1799. ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
  1800. }
  1801. # @FUNCTION: ejavadoc
  1802. # @USAGE: <javadoc_arguments>
  1803. # @DESCRIPTION:
  1804. # javadoc wrapper function. Will set some flags based on the VM version
  1805. # due to strict javadoc rules in 1.8.
  1806. ejavadoc() {
  1807. debug-print-function ${FUNCNAME} $*
  1808. local javadoc_args=""
  1809. if java-pkg_is-vm-version-ge "1.8" ; then
  1810. javadoc_args="-Xdoclint:none"
  1811. fi
  1812. if [[ -n ${JAVA_PKG_DEBUG} ]]; then
  1813. einfo "Verbose logging for \"${FUNCNAME}\" function"
  1814. einfo "Javadoc executable: javadoc"
  1815. einfo "Extra arguments: ${javadoc_args}"
  1816. einfo "Complete command:"
  1817. einfo "javadoc ${javadoc_args} ${@}"
  1818. fi
  1819. ebegin "Generating JavaDoc"
  1820. javadoc ${javadoc_args} "${@}" || die "ejavadoc failed"
  1821. }
  1822. # @FUNCTION: java-pkg_filter-compiler
  1823. # @USAGE: <compiler(s)_to_filter>
  1824. # @DESCRIPTION:
  1825. # Used to prevent the use of some compilers. Should be used in src_compile.
  1826. # Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
  1827. java-pkg_filter-compiler() {
  1828. JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
  1829. }
  1830. # @FUNCTION: java-pkg_force-compiler
  1831. # @USAGE: <compiler(s)_to_force>
  1832. # @DESCRIPTION:
  1833. # Used to force the use of particular compilers. Should be used in src_compile.
  1834. # A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
  1835. # OutOfMemoryErrors that may come up.
  1836. java-pkg_force-compiler() {
  1837. JAVA_PKG_FORCE_COMPILER="$@"
  1838. }
  1839. # @FUNCTION: use_doc
  1840. # @DESCRIPTION:
  1841. #
  1842. # Helper function for getting ant to build javadocs. If the user has USE=doc,
  1843. # then 'javadoc' or the argument are returned. Otherwise, there is no return.
  1844. #
  1845. # The output of this should be passed to ant.
  1846. # @CODE
  1847. # Parameters:
  1848. # $@ - Option value to return. Defaults to 'javadoc'
  1849. #
  1850. # Examples:
  1851. # build javadocs by calling 'javadoc' target
  1852. # eant $(use_doc)
  1853. #
  1854. # build javadocs by calling 'apidoc' target
  1855. # eant $(use_doc apidoc)
  1856. # @CODE
  1857. # @RETURN string - Name of the target to create javadocs
  1858. use_doc() {
  1859. use doc && echo ${@:-javadoc}
  1860. }
  1861. # @FUNCTION: java-pkg_init
  1862. # @INTERNAL
  1863. # @DESCRIPTION:
  1864. # The purpose of this function, as the name might imply, is to initialize the
  1865. # Java environment. It ensures that that there aren't any environment variables
  1866. # that'll muss things up. It initializes some variables, which are used
  1867. # internally. And most importantly, it'll switch the VM if necessary.
  1868. #
  1869. # This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
  1870. # call it during each of the phases of the merge process.
  1871. java-pkg_init() {
  1872. debug-print-function ${FUNCNAME} $*
  1873. # Don't set up build environment if installing from binary. #206024 #258423
  1874. [[ "${MERGE_TYPE}" == "binary" ]] && return
  1875. # Also try Portage's nonstandard EMERGE_FROM for old EAPIs, if it doesn't
  1876. # work nothing is lost.
  1877. has ${EAPI:-0} 0 1 2 3 && [[ "${EMERGE_FROM}" == "binary" ]] && return
  1878. unset JAVAC
  1879. unset JAVA_HOME
  1880. java-config --help >/dev/null || {
  1881. eerror ""
  1882. eerror "Can't run java-config --help"
  1883. eerror "Have you upgraded python recently but haven't"
  1884. eerror "run python-updater yet?"
  1885. die "Can't run java-config --help"
  1886. }
  1887. # People do all kinds of weird things.
  1888. # https://forums.gentoo.org/viewtopic-p-3943166.html
  1889. local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
  1890. local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
  1891. if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
  1892. ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
  1893. ewarn "sun-jdk vms and and as such break configure scripts that"
  1894. ewarn "use it (for example app-office/openoffice) so we filter it out."
  1895. ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
  1896. ewarn "make.conf for example) to silence this warning or"
  1897. ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
  1898. fi
  1899. if [[ -z ${accept} ]]; then
  1900. # export _JAVA_OPTIONS= doesn't work because it will show up in java
  1901. # -version output
  1902. unset _JAVA_OPTIONS
  1903. # phase hooks make this run many times without this
  1904. I_WANT_GLOBAL_JAVA_OPTIONS="true"
  1905. fi
  1906. java-pkg_switch-vm
  1907. PATH=${JAVA_HOME}/bin:${PATH}
  1908. # TODO we will probably want to set JAVAC and JAVACFLAGS
  1909. # Do some QA checks
  1910. java-pkg_check-jikes
  1911. # Can't use unset here because Portage does not save the unset
  1912. # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
  1913. # When users have crazy classpaths some packages can fail to compile.
  1914. # and everything should work with empty CLASSPATH.
  1915. # This also helps prevent unexpected dependencies on random things
  1916. # from the CLASSPATH.
  1917. export CLASSPATH=
  1918. # Unset external ANT_ stuff
  1919. export ANT_TASKS=
  1920. export ANT_OPTS=
  1921. export ANT_RESPECT_JAVA_HOME=
  1922. }
  1923. # @FUNCTION: java-pkg-init-compiler_
  1924. # @INTERNAL
  1925. # @DESCRIPTION:
  1926. # This function attempts to figure out what compiler should be used. It does
  1927. # this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
  1928. # COMPILERS variable defined there.
  1929. # This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
  1930. #
  1931. # It will go through the list of compilers, and verify that it supports the
  1932. # target and source that are needed. If it is not suitable, then the next
  1933. # compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
  1934. # isn't done.
  1935. #
  1936. # Once the which compiler to use has been figured out, it is set to
  1937. # GENTOO_COMPILER.
  1938. #
  1939. # If you hadn't guessed, JAVA_PKG_FORCE_COMPILER is for testing only.
  1940. #
  1941. # If the user doesn't defined anything in JAVA_PKG_COMPILERS_CONF, or no
  1942. # suitable compiler was found there, then the default is to use javac provided
  1943. # by the current VM.
  1944. #
  1945. #
  1946. # @RETURN name of the compiler to use
  1947. java-pkg_init-compiler_() {
  1948. debug-print-function ${FUNCNAME} $*
  1949. if [[ -n ${GENTOO_COMPILER} ]]; then
  1950. debug-print "GENTOO_COMPILER already set"
  1951. return
  1952. fi
  1953. local compilers;
  1954. if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
  1955. compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
  1956. else
  1957. compilers=${JAVA_PKG_FORCE_COMPILER}
  1958. fi
  1959. debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
  1960. # Figure out if we should announce what compiler we're using
  1961. local compiler
  1962. for compiler in ${compilers}; do
  1963. debug-print "Checking ${compiler}..."
  1964. # javac should always be alright
  1965. if [[ ${compiler} = "javac" ]]; then
  1966. debug-print "Found javac... breaking"
  1967. export GENTOO_COMPILER="javac"
  1968. break
  1969. fi
  1970. if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
  1971. if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
  1972. einfo "Filtering ${compiler}" >&2
  1973. continue
  1974. fi
  1975. fi
  1976. # for non-javac, we need to make sure it supports the right target and
  1977. # source
  1978. local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
  1979. if [[ -f ${compiler_env} ]]; then
  1980. local desired_target="$(java-pkg_get-target)"
  1981. local desired_source="$(java-pkg_get-source)"
  1982. # Verify that the compiler supports target
  1983. local supported_target=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_TARGET})
  1984. if ! has ${desired_target} ${supported_target}; then
  1985. ewarn "${compiler} does not support -target ${desired_target}, skipping"
  1986. continue
  1987. fi
  1988. # Verify that the compiler supports source
  1989. local supported_source=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_SOURCE})
  1990. if ! has ${desired_source} ${supported_source}; then
  1991. ewarn "${compiler} does not support -source ${desired_source}, skipping"
  1992. continue
  1993. fi
  1994. # if you get here, then the compiler should be good to go
  1995. export GENTOO_COMPILER="${compiler}"
  1996. break
  1997. else
  1998. ewarn "Could not find configuration for ${compiler}, skipping"
  1999. ewarn "Perhaps it is not installed?"
  2000. continue
  2001. fi
  2002. done
  2003. # If it hasn't been defined already, default to javac
  2004. if [[ -z ${GENTOO_COMPILER} ]]; then
  2005. if [[ -n ${compilers} ]]; then
  2006. einfo "No suitable compiler found: defaulting to JDK default for compilation" >&2
  2007. else
  2008. # probably don't need to notify users about the default.
  2009. :;#einfo "Defaulting to javac for compilation" >&2
  2010. fi
  2011. if java-config -g GENTOO_COMPILER 2> /dev/null; then
  2012. export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
  2013. else
  2014. export GENTOO_COMPILER=javac
  2015. fi
  2016. else
  2017. einfo "Using ${GENTOO_COMPILER} for compilation" >&2
  2018. fi
  2019. }
  2020. # @FUNCTION: init_paths_
  2021. # @INTERNAL
  2022. # @DESCRIPTION:
  2023. # Initializes some variables that will be used. These variables are mostly used
  2024. # to determine where things will eventually get installed.
  2025. java-pkg_init_paths_() {
  2026. debug-print-function ${FUNCNAME} $*
  2027. local pkg_name
  2028. if [[ "${SLOT%/*}" == "0" ]] ; then
  2029. JAVA_PKG_NAME="${PN}"
  2030. else
  2031. JAVA_PKG_NAME="${PN}-${SLOT%/*}"
  2032. fi
  2033. JAVA_PKG_SHAREPATH="/usr/share/${JAVA_PKG_NAME}"
  2034. JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
  2035. JAVA_PKG_ENV="${ED}${JAVA_PKG_SHAREPATH}/package.env"
  2036. JAVA_PKG_VIRTUALS_PATH="/usr/share/java-config-2/virtuals"
  2037. JAVA_PKG_VIRTUAL_PROVIDER="${ED}${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
  2038. [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
  2039. [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="/usr/$(get_libdir)/${JAVA_PKG_NAME}"
  2040. [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
  2041. # TODO maybe only print once?
  2042. debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}"
  2043. debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}"
  2044. debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}"
  2045. debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}"
  2046. debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}"
  2047. }
  2048. # @FUNCTION: java-pkg_do_write_
  2049. # @INTERNAL
  2050. # @DESCRIPTION:
  2051. # Writes the package.env out to disk.
  2052. #
  2053. # TODO change to do-write, to match everything else
  2054. java-pkg_do_write_() {
  2055. debug-print-function ${FUNCNAME} $*
  2056. java-pkg_init_paths_
  2057. # Create directory for package.env
  2058. dodir "${JAVA_PKG_SHAREPATH}"
  2059. # Create package.env
  2060. (
  2061. echo "DESCRIPTION=\"${DESCRIPTION}\""
  2062. echo "GENERATION=\"2\""
  2063. echo "SLOT=\"${SLOT}\""
  2064. echo "CATEGORY=\"${CATEGORY}\""
  2065. echo "PVR=\"${PVR}\""
  2066. [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
  2067. [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
  2068. [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
  2069. [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
  2070. && echo "DEPEND=\"$(sort -u "${JAVA_PKG_DEPEND_FILE}" | tr '\n' ':')\""
  2071. [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
  2072. && echo "OPTIONAL_DEPEND=\"$(sort -u "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | tr '\n' ':')\""
  2073. echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
  2074. [[ -f "${JAVA_PKG_BUILD_DEPEND_FILE}" ]] \
  2075. && echo "BUILD_DEPEND=\"$(sort -u "${JAVA_PKG_BUILD_DEPEND_FILE}" | tr '\n' ':')\""
  2076. ) > "${JAVA_PKG_ENV}"
  2077. # register target/source
  2078. local target="$(java-pkg_get-target)"
  2079. local source="$(java-pkg_get-source)"
  2080. [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
  2081. [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
  2082. # register javadoc info
  2083. [[ -n ${JAVADOC_PATH} ]] && echo "JAVADOC_PATH=\"${JAVADOC_PATH}\"" \
  2084. >> ${JAVA_PKG_ENV}
  2085. # register source archives
  2086. [[ -n ${JAVA_SOURCES} ]] && echo "JAVA_SOURCES=\"${JAVA_SOURCES}\"" \
  2087. >> ${JAVA_PKG_ENV}
  2088. echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
  2089. [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
  2090. # extra env variables
  2091. if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
  2092. cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
  2093. # nested echo to remove leading/trailing spaces
  2094. echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
  2095. >> "${JAVA_PKG_ENV}" || die
  2096. fi
  2097. # Strip unnecessary leading and trailing colons
  2098. # TODO try to cleanup if possible
  2099. sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
  2100. }
  2101. # @FUNCTION: java-pkg_record-jar_
  2102. # @INTERNAL
  2103. # @DESCRIPTION:
  2104. # Record an (optional) dependency to the package.env
  2105. # @CODE
  2106. # Parameters:
  2107. # --optional - record dependency as optional
  2108. # --build - record dependency as build_only
  2109. # $1 - package to record
  2110. # $2 - (optional) jar of package to record
  2111. # @CODE
  2112. JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
  2113. JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
  2114. JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
  2115. java-pkg_record-jar_() {
  2116. debug-print-function ${FUNCNAME} $*
  2117. local depend_file="${JAVA_PKG_DEPEND_FILE}"
  2118. case "${1}" in
  2119. "--optional") depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"; shift;;
  2120. "--build-only") depend_file="${JAVA_PKG_BUILD_DEPEND_FILE}"; shift;;
  2121. esac
  2122. local pkg=${1} jar=${2} append
  2123. if [[ -z "${jar}" ]]; then
  2124. append="${pkg}"
  2125. else
  2126. append="$(basename ${jar})@${pkg}"
  2127. fi
  2128. echo "${append}" >> "${depend_file}"
  2129. }
  2130. # @FUNCTION: java-pkg_append_
  2131. # @INTERNAL
  2132. # @DESCRIPTION:
  2133. # Appends a value to a variable
  2134. #
  2135. # @CODE
  2136. # Parameters:
  2137. # $1 variable name to modify
  2138. # $2 value to append
  2139. #
  2140. # Examples:
  2141. # java-pkg_append_ CLASSPATH foo.jar
  2142. # @CODE
  2143. java-pkg_append_() {
  2144. debug-print-function ${FUNCNAME} $*
  2145. local var="${1}" value="${2}"
  2146. if [[ -z "${!var}" ]] ; then
  2147. export ${var}="${value}"
  2148. else
  2149. local oldIFS=${IFS} cur haveit
  2150. IFS=':'
  2151. for cur in ${!var}; do
  2152. if [[ ${cur} == ${value} ]]; then
  2153. haveit="yes"
  2154. break
  2155. fi
  2156. done
  2157. [[ -z ${haveit} ]] && export ${var}="${!var}:${value}"
  2158. IFS=${oldIFS}
  2159. fi
  2160. }
  2161. # @FUNCTION: java-pkg_expand_dir_
  2162. # @INTERNAL
  2163. # @DESCRIPTION:
  2164. # Gets the full path of the file/directory's parent.
  2165. # @CODE
  2166. # Parameters:
  2167. # $1 - file/directory to find parent directory for
  2168. # @CODE
  2169. # @RETURN: path to $1's parent directory
  2170. java-pkg_expand_dir_() {
  2171. pushd "$(dirname "${1}")" >/dev/null 2>&1 || die
  2172. pwd
  2173. popd >/dev/null 2>&1 || die
  2174. }
  2175. # @FUNCTION: java-pkg_func-exists
  2176. # @INTERNAL
  2177. # @DESCRIPTION:
  2178. # Does the indicated function exist?
  2179. # @RETURN: 0 - function is declared, 1 - function is undeclared
  2180. java-pkg_func-exists() {
  2181. declare -F ${1} > /dev/null
  2182. }
  2183. # @FUNCTION: java-pkg_setup-vm
  2184. # @INTERNAL
  2185. # @DESCRIPTION:
  2186. # Sets up the environment for a specific VM
  2187. java-pkg_setup-vm() {
  2188. debug-print-function ${FUNCNAME} $*
  2189. local vendor="$(java-pkg_get-vm-vendor)"
  2190. if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
  2191. addpredict "/dev/random"
  2192. elif [[ "${vendor}" == "ibm" ]]; then
  2193. addpredict "/proc/self/maps"
  2194. addpredict "/proc/cpuinfo"
  2195. addpredict "/proc/self/coredump_filter"
  2196. elif [[ "${vendor}" == "oracle" ]]; then
  2197. addpredict "/dev/random"
  2198. addpredict "/proc/self/coredump_filter"
  2199. elif [[ "${vendor}" == icedtea* ]] && java-pkg_is-vm-version-ge "1.7" ; then
  2200. addpredict "/dev/random"
  2201. addpredict "/proc/self/coredump_filter"
  2202. elif [[ "${vendor}" == "jrockit" ]]; then
  2203. addpredict "/proc/cpuinfo"
  2204. fi
  2205. }
  2206. # @FUNCTION: java-pkg_needs-vm
  2207. # @INTERNAL
  2208. # @DESCRIPTION:
  2209. # Does the current package depend on virtual/jdk or does it set
  2210. # JAVA_PKG_WANT_BUILD_VM?
  2211. #
  2212. # @RETURN: 0 - Package depends on virtual/jdk; 1 - Package does not depend on virtual/jdk
  2213. java-pkg_needs-vm() {
  2214. debug-print-function ${FUNCNAME} $*
  2215. if [[ -n "$(echo ${JAVA_PKG_NV_DEPEND:-${DEPEND}} | sed -e '\:virtual/jdk:!d')" ]]; then
  2216. return 0
  2217. fi
  2218. [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]] && return 0
  2219. return 1
  2220. }
  2221. # @FUNCTION: java-pkg_get-current-vm
  2222. # @INTERNAL
  2223. # @RETURN - The current VM being used
  2224. java-pkg_get-current-vm() {
  2225. java-config -f
  2226. }
  2227. # @FUNCTION: java-pkg_get-vm-vendor
  2228. # @INTERNAL
  2229. # @RETURN - The vendor of the current VM
  2230. java-pkg_get-vm-vendor() {
  2231. debug-print-function ${FUNCNAME} $*
  2232. local vm="$(java-pkg_get-current-vm)"
  2233. vm="${vm/-*/}"
  2234. echo "${vm}"
  2235. }
  2236. # @FUNCTION: java-pkg_get-vm-version
  2237. # @INTERNAL
  2238. # @RETURN - The version of the current VM
  2239. java-pkg_get-vm-version() {
  2240. debug-print-function ${FUNCNAME} $*
  2241. java-config -g PROVIDES_VERSION
  2242. }
  2243. # @FUNCTION: java-pkg_build-vm-from-handle
  2244. # @INTERNAL
  2245. # @DESCRIPTION:
  2246. # Selects a build vm from a list of vm handles. First checks for the system-vm
  2247. # beeing usable, then steps through the listed handles till a suitable vm is
  2248. # found.
  2249. #
  2250. # @RETURN - VM handle of an available JDK
  2251. java-pkg_build-vm-from-handle() {
  2252. debug-print-function ${FUNCNAME} "$*"
  2253. local vm
  2254. vm=$(java-pkg_get-current-vm 2>/dev/null)
  2255. if [[ $? -eq 0 ]]; then
  2256. if has ${vm} ${JAVA_PKG_WANT_BUILD_VM}; then
  2257. echo ${vm}
  2258. return 0
  2259. fi
  2260. fi
  2261. for vm in ${JAVA_PKG_WANT_BUILD_VM}; do
  2262. if java-config-2 --select-vm=${vm} 2>/dev/null; then
  2263. echo ${vm}
  2264. return 0
  2265. fi
  2266. done
  2267. eerror "${FUNCNAME}: No vm found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
  2268. return 1
  2269. }
  2270. # @FUNCTION: java-pkg_switch-vm
  2271. # @INTERNAL
  2272. # @DESCRIPTION:
  2273. # Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
  2274. # verify that the current VM is sufficient.
  2275. # Setup the environment for the VM being used.
  2276. java-pkg_switch-vm() {
  2277. debug-print-function ${FUNCNAME} $*
  2278. if java-pkg_needs-vm; then
  2279. # Use the VM specified by JAVA_PKG_FORCE_VM
  2280. if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
  2281. # If you're forcing the VM, I hope you know what your doing...
  2282. debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
  2283. export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
  2284. # if we're allowed to switch the vm...
  2285. elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
  2286. # if there is an explicit list of handles to choose from
  2287. if [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]]; then
  2288. debug-print "JAVA_PKG_WANT_BUILD_VM used: ${JAVA_PKG_WANT_BUILD_VM}"
  2289. GENTOO_VM=$(java-pkg_build-vm-from-handle)
  2290. if [[ $? != 0 ]]; then
  2291. eerror "${FUNCNAME}: No VM found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
  2292. die "${FUNCNAME}: Failed to determine VM for building"
  2293. fi
  2294. # JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET are required as
  2295. # they can't be deduced from handles.
  2296. if [[ -z "${JAVA_PKG_WANT_SOURCE}" ]]; then
  2297. eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_SOURCE"
  2298. die "Specify JAVA_PKG_WANT_SOURCE"
  2299. fi
  2300. if [[ -z "${JAVA_PKG_WANT_TARGET}" ]]; then
  2301. eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_TARGET"
  2302. die "Specify JAVA_PKG_WANT_TARGET"
  2303. fi
  2304. # otherwise determine a vm from dep string
  2305. else
  2306. debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
  2307. GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
  2308. if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
  2309. eerror "Unable to determine VM for building from dependencies:"
  2310. echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
  2311. die "Failed to determine VM for building."
  2312. fi
  2313. fi
  2314. export GENTOO_VM
  2315. # otherwise just make sure the current VM is sufficient
  2316. else
  2317. java-pkg_ensure-vm-version-sufficient
  2318. fi
  2319. debug-print "Using: $(java-config -f)"
  2320. java-pkg_setup-vm
  2321. export JAVA=$(java-config --java)
  2322. export JAVAC=$(java-config --javac)
  2323. JAVACFLAGS="$(java-pkg_javac-args)"
  2324. [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
  2325. export JAVACFLAGS
  2326. export JAVA_HOME="$(java-config -g JAVA_HOME)"
  2327. export JDK_HOME=${JAVA_HOME}
  2328. #TODO If you know a better solution let us know.
  2329. java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
  2330. local tann="${T}/announced-vm"
  2331. # With the hooks we should only get here once from pkg_setup but better safe than sorry
  2332. # if people have for example modified eclasses some where
  2333. if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
  2334. einfo "Using: $(java-config -f)"
  2335. [[ ! -f "${tann}" ]] && touch "${tann}"
  2336. fi
  2337. else
  2338. [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
  2339. fi
  2340. }
  2341. # @FUNCTION: java-pkg_die
  2342. # @INTERNAL
  2343. # @DESCRIPTION:
  2344. # Enhanced die for Java packages, which displays some information that may be
  2345. # useful for debugging bugs on bugzilla.
  2346. #register_die_hook java-pkg_die
  2347. if ! has java-pkg_die ${EBUILD_DEATH_HOOKS}; then
  2348. EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
  2349. fi
  2350. java-pkg_die() {
  2351. echo "!!! When you file a bug report, please include the following information:" >&2
  2352. echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
  2353. echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
  2354. echo "and of course, the output of emerge --info =${P}" >&2
  2355. }
  2356. # TODO document
  2357. # List jars in the source directory, ${S}
  2358. java-pkg_jar-list() {
  2359. if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
  2360. einfo "Linked Jars"
  2361. find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
  2362. einfo "Jars"
  2363. find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
  2364. einfo "Classes"
  2365. find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
  2366. fi
  2367. }
  2368. # @FUNCTION: java-pkg_verify-classes
  2369. # @INTERNAL
  2370. # @DESCRIPTION:
  2371. # Verify that the classes were compiled for the right source / target. Dies if
  2372. # not.
  2373. # @CODE
  2374. # $1 (optional) - the file to check, otherwise checks whole ${D}
  2375. # @CODE
  2376. java-pkg_verify-classes() {
  2377. #$(find ${D} -type f -name '*.jar' -o -name '*.class')
  2378. local version_verify="/usr/bin/class-version-verify.py"
  2379. if [[ ! -x "${version_verify}" ]]; then
  2380. version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
  2381. fi
  2382. if [[ ! -x "${version_verify}" ]]; then
  2383. ewarn "Unable to perform class version checks as"
  2384. ewarn "class-version-verify.py is unavailable"
  2385. ewarn "Please install dev-java/javatoolkit."
  2386. return
  2387. fi
  2388. local target=$(java-pkg_get-target)
  2389. local result
  2390. local log="${T}/class-version-verify.log"
  2391. if [[ -n "${1}" ]]; then
  2392. ${version_verify} -v -t ${target} "${1}" > "${log}"
  2393. result=$?
  2394. else
  2395. ebegin "Verifying java class versions (target: ${target})"
  2396. ${version_verify} -v -t ${target} -r "${D}" > "${log}"
  2397. result=$?
  2398. eend ${result}
  2399. fi
  2400. [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
  2401. if [[ ${result} != 0 ]]; then
  2402. eerror "Incorrect bytecode version found"
  2403. [[ -n "${1}" ]] && eerror "in file: ${1}"
  2404. eerror "See ${log} for more details."
  2405. die "Incorrect bytecode found"
  2406. fi
  2407. }
  2408. # @FUNCTION: java-pkg_ensure-dep
  2409. # @INTERNAL
  2410. # @DESCRIPTION:
  2411. # Check that a package being used in jarfrom, getjars and getjar is contained
  2412. # within DEPEND or RDEPEND with the correct SLOT. See this mail for details:
  2413. # https://archives.gentoo.org/gentoo-dev/message/dcb644f89520f4bbb61cc7bbe45fdf6e
  2414. # @CODE
  2415. # Parameters:
  2416. # $1 - empty - check both vars; "runtime" or "build" - check only
  2417. # RDEPEND, resp. DEPEND
  2418. # $2 - Package name and slot.
  2419. # @CODE
  2420. java-pkg_ensure-dep() {
  2421. debug-print-function ${FUNCNAME} $*
  2422. local limit_to="${1}"
  2423. local target_pkg="${2}"
  2424. local dev_error=""
  2425. # Transform into a regular expression to look for a matching package
  2426. # and SLOT. SLOTs don't have to be numeric so foo-bar could either
  2427. # mean foo-bar:0 or foo:bar. So you want to get your head around the
  2428. # line below?
  2429. #
  2430. # * The target package first has any dots escaped, e.g. foo-1.2
  2431. # becomes foo-1\.2.
  2432. #
  2433. # * sed then looks at the component following the last - or :
  2434. # character, or the whole string if there is no - or :
  2435. # character. It uses this to build a new regexp with two
  2436. # significant branches.
  2437. #
  2438. # * The first checks for the whole target package string, optionally
  2439. # followed by a version number, and then :0.
  2440. #
  2441. # * The second checks for the first part of the target package
  2442. # string, optionally followed by a version number, followed by the
  2443. # aforementioned component, treating that as a SLOT.
  2444. #
  2445. local stripped_pkg=/$(sed -r 's/[-:]?([^-:]+)$/(\0(-[^:]+)?:0|(-[^:]+)?:\1)/' <<< "${target_pkg//./\\.}")\\b
  2446. debug-print "Matching against: ${stripped_pkg}"
  2447. # Uncomment the lines below once we've dealt with more of these
  2448. # otherwise we'll be tempted to turn JAVA_PKG_STRICT off while
  2449. # getting hit with a wave of bug reports. :(
  2450. if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ $stripped_pkg ) ]]; then
  2451. dev_error="The ebuild is attempting to use ${target_pkg}, which is not "
  2452. dev_error+="declared with a SLOT in DEPEND."
  2453. # if is-java-strict; then
  2454. # die "${dev_error}"
  2455. # else
  2456. eqawarn "java-pkg_ensure-dep: ${dev_error}"
  2457. # eerror "Because you have ${target_pkg} installed,"
  2458. # eerror "the package will build without problems, but please"
  2459. # eerror "report this to https://bugs.gentoo.org."
  2460. # fi
  2461. elif [[ ${limit_to} != build && ! ( "${RDEPEND}${PDEPEND}" =~ ${stripped_pkg} ) ]]; then
  2462. dev_error="The ebuild is attempting to use ${target_pkg}, which is not "
  2463. dev_error+="declared with a SLOT in [RP]DEPEND and --build-only wasn't given."
  2464. # if is-java-strict; then
  2465. # die "${dev_error}"
  2466. # else
  2467. eqawarn "java-pkg_ensure-dep: ${dev_error}"
  2468. # eerror "The package will build without problems, but may fail to run"
  2469. # eerror "if you don't have ${target_pkg} installed,"
  2470. # eerror "so please report this to https://bugs.gentoo.org."
  2471. # fi
  2472. fi
  2473. }
  2474. java-pkg_check-phase() {
  2475. local phase=${1}
  2476. local funcname=${FUNCNAME[1]}
  2477. if [[ ${EBUILD_PHASE} != ${phase} ]]; then
  2478. local msg="${funcname} used outside of src_${phase}"
  2479. java-pkg_announce-qa-violation "${msg}"
  2480. fi
  2481. }
  2482. java-pkg_check-versioned-jar() {
  2483. local jar=${1}
  2484. if [[ ${jar} =~ ${PV} ]]; then
  2485. java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
  2486. fi
  2487. }
  2488. java-pkg_check-jikes() {
  2489. if has jikes ${IUSE}; then
  2490. java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
  2491. fi
  2492. }
  2493. java-pkg_announce-qa-violation() {
  2494. local nodie
  2495. if [[ ${1} == "--nodie" ]]; then
  2496. nodie="true"
  2497. shift
  2498. fi
  2499. echo "Java QA Notice: $@" >&2
  2500. increment-qa-violations
  2501. [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
  2502. }
  2503. increment-qa-violations() {
  2504. let "JAVA_PKG_QA_VIOLATIONS+=1"
  2505. export JAVA_PKG_QA_VIOLATIONS
  2506. }
  2507. is-java-strict() {
  2508. [[ -n ${JAVA_PKG_STRICT} ]]
  2509. return $?
  2510. }
  2511. # @FUNCTION: java-pkg_clean
  2512. # @DESCRIPTION:
  2513. # Java package cleaner function. This will remove all *.class and *.jar
  2514. # files, removing any bundled dependencies.
  2515. java-pkg_clean() {
  2516. if [[ -z "${JAVA_PKG_NO_CLEAN}" ]]; then
  2517. find "${@}" '(' -name '*.class' -o -name '*.jar' ')' -type f -delete -print || die
  2518. fi
  2519. }
  2520. # @FUNCTION: java-pkg_gen-cp
  2521. # @INTERNAL
  2522. # @DESCRIPTION:
  2523. # Java package generate classpath will create a classpath based on
  2524. # special variable CP_DEPEND in the ebuild.
  2525. #
  2526. # @CODE
  2527. # Parameters:
  2528. # $1 - classpath variable either EANT_GENTOO_CLASSPATH or JAVA_GENTOO_CLASSPATH
  2529. # @CODE
  2530. java-pkg_gen-cp() {
  2531. debug-print-function ${FUNCNAME} "${@}"
  2532. local atom
  2533. for atom in ${CP_DEPEND}; do
  2534. if [[ ${atom} =~ /(([[:alnum:]+_-]+)-[0-9]+(\.[0-9]+)*[a-z]?(_[[:alnum:]]+)?(-r[0-9]*)?|[[:alnum:]+_-]+):([[:alnum:]+_.-]+) ]]; then
  2535. atom=${BASH_REMATCH[2]:-${BASH_REMATCH[1]}}
  2536. [[ ${BASH_REMATCH[6]} != 0 ]] && atom+=-${BASH_REMATCH[6]}
  2537. local regex="(^|\s|,)${atom}($|\s|,)"
  2538. [[ ${!1} =~ ${regex} ]] || declare -g ${1}+=${!1:+,}${atom}
  2539. else
  2540. die "Invalid CP_DEPEND atom ${atom}, ensure a SLOT is included"
  2541. fi
  2542. done
  2543. }