1 |
commit: faa407032918b43fafe7d4e1de85dde4d30ba4f2 |
2 |
Author: Zhang Zongyu <zzy2529420793 <AT> gmail <DOT> com> |
3 |
AuthorDate: Tue Aug 25 16:30:09 2020 +0000 |
4 |
Commit: Miroslav Šulc <fordfrog <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Aug 30 16:01:54 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=faa40703 |
7 |
|
8 |
java-pkg-simple.eclass and java-utils-2.eclass: features and enhancements |
9 |
|
10 |
1) support java resources |
11 |
2) support java main class and launcher |
12 |
3) enable java-pkg-simple_src_test() |
13 |
4) support binary jars (both for resolve circular deps and for pkgdiff test) |
14 |
|
15 |
Signed-off-by: Zhang Zongyu <zzy2529420793 <AT> gmail.com> |
16 |
Signed-off-by: Miroslav Šulc <fordfrog <AT> gentoo.org> |
17 |
|
18 |
eclass/java-pkg-simple.eclass | 379 ++++++++++++++++++++++++++++++++++++++---- |
19 |
eclass/java-utils-2.eclass | 38 +++++ |
20 |
2 files changed, 388 insertions(+), 29 deletions(-) |
21 |
|
22 |
diff --git a/eclass/java-pkg-simple.eclass b/eclass/java-pkg-simple.eclass |
23 |
index 0b16cd5d40f..bfec305123f 100644 |
24 |
--- a/eclass/java-pkg-simple.eclass |
25 |
+++ b/eclass/java-pkg-simple.eclass |
26 |
@@ -22,11 +22,30 @@ if ! has java-pkg-2 ${INHERITED}; then |
27 |
eerror "java-pkg-simple eclass can only be inherited AFTER java-pkg-2" |
28 |
fi |
29 |
|
30 |
-EXPORT_FUNCTIONS src_compile src_install |
31 |
+EXPORT_FUNCTIONS src_compile src_install src_test |
32 |
|
33 |
# We are only interested in finding all java source files, wherever they may be. |
34 |
S="${WORKDIR}" |
35 |
|
36 |
+# handle dependencies for testing frameworks |
37 |
+if has test ${JAVA_PKG_IUSE}; then |
38 |
+ local test_deps |
39 |
+ for framework in ${JAVA_TESTING_FRAMEWORKS}; do |
40 |
+ case ${framework} in |
41 |
+ junit) |
42 |
+ test_deps+=" dev-java/junit:0";; |
43 |
+ junit-4) |
44 |
+ test_deps+=" dev-java/junit:4";; |
45 |
+ pkgdiff) |
46 |
+ test_deps+=" amd64? ( dev-util/pkgdiff |
47 |
+ dev-util/japi-compliance-checker )";; |
48 |
+ testng) |
49 |
+ test_deps+=" dev-java/testng:0";; |
50 |
+ esac |
51 |
+ done |
52 |
+ [[ ${test_deps} ]] && DEPEND="test? ( ${test_deps} )" |
53 |
+fi |
54 |
+ |
55 |
# @ECLASS-VARIABLE: JAVA_GENTOO_CLASSPATH |
56 |
# @DEFAULT_UNSET |
57 |
# @DESCRIPTION: |
58 |
@@ -45,17 +64,46 @@ S="${WORKDIR}" |
59 |
# Extra list of colon separated path elements to be put on the |
60 |
# classpath when compiling sources. |
61 |
|
62 |
+# @ECLASS-VARIABLE: JAVA_CLASSPATH_EXTRA |
63 |
+# @DEFAULT_UNSET |
64 |
+# @DESCRIPTION: |
65 |
+# An extra comma or space separated list of java packages |
66 |
+# that are needed only during compiling sources. |
67 |
+ |
68 |
+# @ECLASS-VARIABLE: JAVA_NEEDS_TOOLS |
69 |
+# @DEFAULT_UNSET |
70 |
+# @DESCRIPTION: |
71 |
+# add tools.jar to the gentoo.classpath. Should only be used |
72 |
+# for build-time purposes, the dependency is not recorded to |
73 |
+# package.env. |
74 |
+ |
75 |
# @ECLASS-VARIABLE: JAVA_SRC_DIR |
76 |
# @DEFAULT_UNSET |
77 |
# @DESCRIPTION: |
78 |
-# Directories relative to ${S} which contain the sources of the |
79 |
-# application. The default of "" will be treated mostly as ${S} |
80 |
-# itself. For the generated source package (if source is listed in |
81 |
+# An array of directories relative to ${S} which contain the sources |
82 |
+# of the application. If you set ${JAVA_SRC_DIR} to a string it works |
83 |
+# as well. The default value "" means it will get all source files |
84 |
+# inside ${S}. |
85 |
+# For the generated source package (if source is listed in |
86 |
# ${JAVA_PKG_IUSE}), it is important that these directories are |
87 |
# actually the roots of the corresponding source trees. |
88 |
# |
89 |
# @CODE |
90 |
-# JAVA_SRC_DIR="src/java/org/gentoo" |
91 |
+# JAVA_SRC_DIR=( "impl/src/main/java/" |
92 |
+# "arquillian/weld-ee-container/src/main/java/" |
93 |
+# ) |
94 |
+# @CODE |
95 |
+ |
96 |
+# @DESCRIPTION: |
97 |
+# @ECLASS-VARIABLE: JAVA_RESOURCE_DIRS |
98 |
+# @DEFAULT_UNSET |
99 |
+# @DESCRIPTION: |
100 |
+# An array of directories relative to ${S} which contain the |
101 |
+# resources of the application. If you do not set the variable, |
102 |
+# there will be no resources added to the compiled jar file. |
103 |
+# |
104 |
+# @CODE |
105 |
+# JAVA_RESOURCE_DIRS=("src/java/resources/") |
106 |
# @CODE |
107 |
|
108 |
# @ECLASS-VARIABLE: JAVA_ENCODING |
109 |
@@ -68,6 +116,17 @@ S="${WORKDIR}" |
110 |
# @DESCRIPTION: |
111 |
# Additional arguments to be passed to javac. |
112 |
|
113 |
+# @ECLASS-VARIABLE: JAVA_MAIN_CLASS |
114 |
+# @DEFAULT_UNSET |
115 |
+# @DESCRIPTION: |
116 |
+# If the java has a main class, you are going to set the |
117 |
+# variable so that we can generate a proper MANIFEST.MF |
118 |
+# and create a launcher. |
119 |
+# |
120 |
+# @CODE |
121 |
+# JAVA_MAIN_CLASS="org.gentoo.java.ebuilder.Main" |
122 |
+# @CODE |
123 |
+ |
124 |
# @ECLASS-VARIABLE: JAVADOC_ARGS |
125 |
# @DEFAULT_UNSET |
126 |
# @DESCRIPTION: |
127 |
@@ -78,34 +137,217 @@ S="${WORKDIR}" |
128 |
# The name of the jar file to create and install. |
129 |
: ${JAVA_JAR_FILENAME:=${PN}.jar} |
130 |
|
131 |
+# @ECLASS-VARIABLE: JAVA_BINJAR_FILENAME |
132 |
+# @DEFAULT_UNSET |
133 |
+# @DESCRIPTION: |
134 |
+# The name of the binary jar file to be installed if |
135 |
+# USE FLAG 'binary' is set. |
136 |
+ |
137 |
+# @ECLASS-VARIABLE: JAVA_LAUNCHER_FILENAME |
138 |
+# @DESCRIPTION: |
139 |
+# If ${JAVA_MAIN_CLASS} is set, we will create a launcher to |
140 |
+# execute the jar, and ${JAVA_LAUNCHER_FILENAME} will be the |
141 |
+# name of the script. |
142 |
+: ${JAVA_LAUNCHER_FILENAME:=${PN}-${SLOT}} |
143 |
+ |
144 |
+# @ECLASS-VARIABLE: JAVA_TESTING_FRAMEWORKS |
145 |
+# @DEFAULT_UNSET |
146 |
+# @DESCRIPTION: |
147 |
+# A space separated list that defines which tests it should launch |
148 |
+# during src_test. |
149 |
+# |
150 |
+# @CODE |
151 |
+# JAVA_TESTING_FRAMEWORKS="junit pkgdiff" |
152 |
+# @CODE |
153 |
+ |
154 |
+# @ECLASS-VARIABLE: JAVA_TEST_EXCLUDES |
155 |
+# @DEFAULT_UNSET |
156 |
+# @DESCRIPTION: |
157 |
+# A array of classes that should not be executed during src_test(). |
158 |
+# |
159 |
+# @CODE |
160 |
+# JAVA_TEST_EXCLUDES=( "net.sf.cglib.CodeGenTestCase" "net.sf.cglib.TestAll" ) |
161 |
+# @CODE |
162 |
+ |
163 |
+# @ECLASS-VARIABLE: JAVA_TEST_GENTOO_CLASSPATH |
164 |
+# @DEFAULT_UNSET |
165 |
+# @DESCRIPTION: |
166 |
+# The extra classpath we need while compiling and running the |
167 |
+# source code for testing. |
168 |
+ |
169 |
+# @ECLASS-VARIABLE: JAVA_TEST_SRC_DIR |
170 |
+# @DEFAULT_UNSET |
171 |
+# @DESCRIPTION: |
172 |
+# An array of directories relative to ${S} which contain the |
173 |
+# sources for testing. It is almost equivalent to |
174 |
+# ${JAVA_SRC_DIR} in src_test. |
175 |
+ |
176 |
+# @ECLASS-VARIABLE: JAVA_TEST_RESOURCE_DIRS |
177 |
+# @DEFAULT_UNSET |
178 |
+# @DESCRIPTION: |
179 |
+# It is almost equivalent to ${JAVA_RESOURCE_DIRS} in src_test. |
180 |
+ |
181 |
+# @FUNCTION: java-pkg-simple_getclasspath |
182 |
+# @USAGE: java-pkg-simple_getclasspath [--runtime-only] |
183 |
+# @INTERNAL |
184 |
+# @DESCRIPTION: |
185 |
+# Get proper ${classpath} from ${JAVA_GENTOO_CLASSPATH_EXTRA}, |
186 |
+# ${JAVA_NEEDS_TOOLS}, ${JAVA_CLASSPATH_EXTRA} and |
187 |
+# ${JAVA_GENTOO_CLASSPATH}. We use it inside |
188 |
+# java-pkg-simple_src_compile and java-pkg-simple_src_test. |
189 |
+# |
190 |
+# Note that if you need to define a "classpath" variable before |
191 |
+# calling this function. |
192 |
+java-pkg-simple_getclasspath() { |
193 |
+ debug-print-function ${FUNCNAME} $* |
194 |
+ |
195 |
+ local denpendency |
196 |
+ local deep_jars="--with-dependencies" |
197 |
+ local buildonly_jars="--build-only" |
198 |
+ |
199 |
+ # the extra classes that are not installed by portage |
200 |
+ classpath+=":${JAVA_GENTOO_CLASSPATH_EXTRA}" |
201 |
+ |
202 |
+ # whether we need tools.jar |
203 |
+ [[ ${JAVA_NEEDS_TOOLS} ]] && classpath+=":$(java-config --tools)" |
204 |
+ |
205 |
+ # the extra classes that are installed by portage |
206 |
+ for dependency in ${JAVA_CLASSPATH_EXTRA}; do |
207 |
+ classpath="${classpath}:$(java-pkg_getjars ${buildonly_jars}\ |
208 |
+ ${deep_jars} ${dependency})" |
209 |
+ done |
210 |
+ |
211 |
+ # add test dependencies if USE FLAG 'test' is set |
212 |
+ if has test ${JAVA_PKG_IUSE} && use test; then |
213 |
+ for dependency in ${JAVA_TEST_GENTOO_CLASSPATH}; do |
214 |
+ classpath="${classpath}:$(java-pkg_getjars ${buildonly_jars}\ |
215 |
+ ${deep_jars} ${dependency})" |
216 |
+ done |
217 |
+ fi |
218 |
+ |
219 |
+ # add the RUNTIME dependencies |
220 |
+ for dependency in ${JAVA_GENTOO_CLASSPATH}; do |
221 |
+ classpath="${classpath}:$(java-pkg_getjars ${deep_jars} ${dependency})" |
222 |
+ done |
223 |
+ |
224 |
+ # purify classpath |
225 |
+ while [[ $classpath = *::* ]]; do classpath="${classpath//::/:}"; done |
226 |
+ classpath=${classpath%:} |
227 |
+ classpath=${classpath#:} |
228 |
+ |
229 |
+ debug-print "CLASSPATH=${classpath}" |
230 |
+} |
231 |
+ |
232 |
+# @FUNCTION: java-pkg-simple_test_with_pkgdiff_ |
233 |
+# @INTERNAL |
234 |
+# @DESCRIPTION: |
235 |
+# use japi-compliance-checker the ensure the compabitily of \*.class files, |
236 |
+# Besides, use pkgdiff to ensure the compabilty of resources. |
237 |
+java-pkg-simple_test_with_pkgdiff_() { |
238 |
+ debug-print-function ${FUNCNAME} $* |
239 |
+ |
240 |
+ if [[ ! ${ARCH} == "amd64" ]]; then |
241 |
+ elog "For architectures other than amd64, "\ |
242 |
+ "the pkgdiff test is currently unavailable "\ |
243 |
+ "because 'dev-util/japi-compliance-checker "\ |
244 |
+ "and 'dev-util/pkgdiff' do not support those architectures." |
245 |
+ return |
246 |
+ fi |
247 |
+ |
248 |
+ local report1=${PN}-japi-compliance-checker.html |
249 |
+ local report2=${PN}-pkgdiff.html |
250 |
+ |
251 |
+ # pkgdiff test |
252 |
+ if [[ -f "${DISTDIR}/${JAVA_BINJAR_FILENAME}" ]]; then |
253 |
+ # pkgdiff cannot deal with symlinks, so this is a workaround |
254 |
+ cp "${DISTDIR}/${JAVA_BINJAR_FILENAME}" ./ \ |
255 |
+ || die "Cannot copy binjar file to ${S}." |
256 |
+ |
257 |
+ # japi-compliance-checker |
258 |
+ japi-compliance-checker ${JAVA_BINJAR_FILENAME} ${JAVA_JAR_FILENAME}\ |
259 |
+ --lib=${PN} -v1 ${PV}-bin -v2 ${PV} -report-path ${report1}\ |
260 |
+ --binary\ |
261 |
+ || die "japi-compliance-checker returns $?,"\ |
262 |
+ "check the report in ${S}/${report1}" |
263 |
+ |
264 |
+ # ignore META-INF since it does not matter |
265 |
+ # ignore classes because japi-compilance checker will take care of it |
266 |
+ pkgdiff ${JAVA_BINJAR_FILENAME} ${JAVA_JAR_FILENAME}\ |
267 |
+ -vnum1 ${PV}-bin -vnum2 ${PV}\ |
268 |
+ -skip-pattern "META-INF|.class$"\ |
269 |
+ -name ${PN} -report-path ${report2}\ |
270 |
+ || die "pkgdiff returns $?, check the report in ${S}/${report2}" |
271 |
+ fi |
272 |
+} |
273 |
+ |
274 |
+# @FUNCTION: java-pkg-simple_prepend_resources |
275 |
+# @USAGE: java-pkg-simple_prepend-resources <${classes}> <"${RESOURCE_DIRS[@]}"> |
276 |
+# @INTERNAL |
277 |
+# @DESCRIPTION: |
278 |
+# Copy things under "${JAVA_RESOURCE_DIRS[@]}" or "${JAVA_TEST_RESOURCE_DIRS[@]}" |
279 |
+# to ${classes}, so that `jar` will package resources together with classes. |
280 |
+# |
281 |
+# Note that you need to define a "classes" variable before calling |
282 |
+# this function. |
283 |
+java-pkg-simple_prepend_resources() { |
284 |
+ debug-print-function ${FUNCNAME} $* |
285 |
+ |
286 |
+ local destination="${1}" |
287 |
+ shift 1 |
288 |
+ |
289 |
+ # return if there is no resource dirs defined |
290 |
+ [[ "$@" ]] || return |
291 |
+ local resources=("${@}") |
292 |
+ |
293 |
+ # add resources directory to classpath |
294 |
+ for resource in "${resources[@]}"; do |
295 |
+ cp -rT "${resource:-.}" "${destination}"\ |
296 |
+ || die "Could copy resources to ${destination}" |
297 |
+ done |
298 |
+} |
299 |
+ |
300 |
# @FUNCTION: java-pkg-simple_src_compile |
301 |
# @DESCRIPTION: |
302 |
# src_compile for simple bare source java packages. Finds all *.java |
303 |
# sources in ${JAVA_SRC_DIR}, compiles them with the classpath |
304 |
# calculated from ${JAVA_GENTOO_CLASSPATH}, and packages the resulting |
305 |
-# classes to ${JAVA_JAR_FILENAME}. |
306 |
+# classes to a single ${JAVA_JAR_FILENAME}. If the file |
307 |
+# target/META-INF/MANIFEST.MF exists, it is used as the manifest of the |
308 |
+# created jar. |
309 |
+# |
310 |
+# If USE FLAG 'binary' exists and is set, it will just copy |
311 |
+# ${JAVA_BINJAR_FILENAME} to ${S} and skip the rest of src_compile. |
312 |
java-pkg-simple_src_compile() { |
313 |
local sources=sources.lst classes=target/classes apidoc=target/api |
314 |
|
315 |
# auto generate classpath |
316 |
java-pkg_gen-cp JAVA_GENTOO_CLASSPATH |
317 |
|
318 |
+ # do not compile if we decide to install binary jar |
319 |
+ if has binary ${JAVA_PKG_IUSE} && use binary; then |
320 |
+ # register the runtime dependencies |
321 |
+ for dependency in ${JAVA_GENTOO_CLASSPATH//,/ }; do |
322 |
+ java-pkg_record-jar_ ${dependency} |
323 |
+ done |
324 |
+ |
325 |
+ cp "${DISTDIR}"/${JAVA_BINJAR_FILENAME} ${JAVA_JAR_FILENAME}\ |
326 |
+ || die "Could not copy the binary jar file to ${S}" |
327 |
+ return 0 |
328 |
+ fi |
329 |
+ |
330 |
# gather sources |
331 |
- find ${JAVA_SRC_DIR:-*} -name \*.java > ${sources} |
332 |
+ find "${JAVA_SRC_DIR[@]}" -name \*.java > ${sources} |
333 |
+ |
334 |
+ # create the target directory |
335 |
mkdir -p ${classes} || die "Could not create target directory" |
336 |
|
337 |
# compile |
338 |
- local classpath="${JAVA_GENTOO_CLASSPATH_EXTRA}" dependency |
339 |
- for dependency in ${JAVA_GENTOO_CLASSPATH}; do |
340 |
- classpath="${classpath}:$(java-pkg_getjars ${dependency})" \ |
341 |
- || die "getjars failed for ${dependency}" |
342 |
- done |
343 |
- while [[ $classpath = *::* ]]; do classpath="${classpath//::/:}"; done |
344 |
- classpath=${classpath%:} |
345 |
- classpath=${classpath#:} |
346 |
- debug-print "CLASSPATH=${classpath}" |
347 |
- ejavac -d ${classes} -encoding ${JAVA_ENCODING} \ |
348 |
- ${classpath:+-classpath ${classpath}} ${JAVAC_ARGS} \ |
349 |
+ local classpath="" |
350 |
+ java-pkg-simple_getclasspath |
351 |
+ java-pkg-simple_prepend_resources ${classes} "${JAVA_RESOURCE_DIRS[@]}" |
352 |
+ |
353 |
+ ejavac -d ${classes} -encoding ${JAVA_ENCODING}\ |
354 |
+ ${classpath:+-classpath ${classpath}} ${JAVAC_ARGS}\ |
355 |
@${sources} |
356 |
|
357 |
# javadoc |
358 |
@@ -118,25 +360,33 @@ java-pkg-simple_src_compile() { |
359 |
fi |
360 |
|
361 |
# package |
362 |
- local jar_args="cf ${JAVA_JAR_FILENAME}" |
363 |
+ local jar_args |
364 |
if [[ -e ${classes}/META-INF/MANIFEST.MF ]]; then |
365 |
jar_args="cfm ${JAVA_JAR_FILENAME} ${classes}/META-INF/MANIFEST.MF" |
366 |
+ elif [[ ${JAVA_MAIN_CLASS} ]]; then |
367 |
+ jar_args="cfe ${JAVA_JAR_FILENAME} ${JAVA_MAIN_CLASS}" |
368 |
+ else |
369 |
+ jar_args="cf ${JAVA_JAR_FILENAME}" |
370 |
fi |
371 |
jar ${jar_args} -C ${classes} . || die "jar failed" |
372 |
} |
373 |
|
374 |
# @FUNCTION: java-pkg-simple_src_install |
375 |
# @DESCRIPTION: |
376 |
-# src_install for simple single jar java packages. Simply packages the |
377 |
-# contents from the target directory and installs it as |
378 |
-# ${JAVA_JAR_FILENAME}. If the file target/META-INF/MANIFEST.MF exists, |
379 |
-# it is used as the manifest of the created jar. |
380 |
+# src_install for simple single jar java packages. Simply installs |
381 |
+# ${JAVA_JAR_FILENAME}. It will also install a launcher if |
382 |
+# ${JAVA_MAIN_CLASS} is set. |
383 |
java-pkg-simple_src_install() { |
384 |
local sources=sources.lst classes=target/classes apidoc=target/api |
385 |
|
386 |
- # main jar |
387 |
+ # install the jar file that we need |
388 |
java-pkg_dojar ${JAVA_JAR_FILENAME} |
389 |
|
390 |
+ # install a wrapper if ${JAVA_MAIN_CLASS} is defined |
391 |
+ if [[ ${JAVA_MAIN_CLASS} ]]; then |
392 |
+ java-pkg_dolauncher "${JAVA_LAUNCHER_FILENAME}" --main ${JAVA_MAIN_CLASS} |
393 |
+ fi |
394 |
+ |
395 |
# javadoc |
396 |
if has doc ${JAVA_PKG_IUSE} && use doc; then |
397 |
java-pkg_dojavadoc ${apidoc} |
398 |
@@ -145,12 +395,10 @@ java-pkg-simple_src_install() { |
399 |
# dosrc |
400 |
if has source ${JAVA_PKG_IUSE} && use source; then |
401 |
local srcdirs="" |
402 |
- if [[ ${JAVA_SRC_DIR} ]]; then |
403 |
+ if [[ "${JAVA_SRC_DIR[@]}" ]]; then |
404 |
local parent child |
405 |
- for parent in ${JAVA_SRC_DIR}; do |
406 |
- for child in ${parent}/*; do |
407 |
- srcdirs="${srcdirs} ${child}" |
408 |
- done |
409 |
+ for parent in "${JAVA_SRC_DIR[@]}"; do |
410 |
+ srcdirs="${srcdirs} ${parent}" |
411 |
done |
412 |
else |
413 |
# take all directories actually containing any sources |
414 |
@@ -159,3 +407,76 @@ java-pkg-simple_src_install() { |
415 |
java-pkg_dosrc ${srcdirs} |
416 |
fi |
417 |
} |
418 |
+ |
419 |
+# @FUNCTION: java-pkg-simple_src_test |
420 |
+# @DESCRIPTION: |
421 |
+# src_test for simple single java jar file. |
422 |
+# It will perform test with frameworks that are defined in |
423 |
+# ${JAVA_TESTING_FRAMEWORKS}. |
424 |
+java-pkg-simple_src_test() { |
425 |
+ local test_sources=test_sources.lst classes=target/test-classes |
426 |
+ local tests_to_run classpath |
427 |
+ |
428 |
+ # do not continue if the USE FLAG 'test' is explicitly unset |
429 |
+ # or no ${JAVA_TESTING_FRSerializingCAMEWORKS} specified |
430 |
+ if ! has test ${JAVA_PKG_IUSE}; then |
431 |
+ return |
432 |
+ elif ! use test; then |
433 |
+ return |
434 |
+ elif [[ ! "${JAVA_TESTING_FRAMEWORKS}" ]]; then |
435 |
+ return |
436 |
+ fi |
437 |
+ |
438 |
+ # create the target directory |
439 |
+ mkdir -p ${classes} || die "Could not create target directory for testing" |
440 |
+ |
441 |
+ # get classpath |
442 |
+ classpath="${classes}:${JAVA_JAR_FILENAME}" |
443 |
+ java-pkg-simple_getclasspath |
444 |
+ java-pkg-simple_prepend_resources ${classes} "${JAVA_TEST_RESOURCE_DIRS[@]}" |
445 |
+ |
446 |
+ # gathering sources for testing |
447 |
+ find "${JAVA_TEST_SRC_DIR[@]}" -name \*.java > ${test_sources} |
448 |
+ |
449 |
+ # compile |
450 |
+ [[ -s ${test_sources} ]] && ejavac -d ${classes} ${JAVAC_ARGS} \ |
451 |
+ -encoding ${JAVA_ENCODING} ${classpath:+-classpath ${classpath}} \ |
452 |
+ @${test_sources} |
453 |
+ |
454 |
+ # grab a set of tests that testing framework will run |
455 |
+ tests_to_run=$(find "${classes}" -type f\ |
456 |
+ \( -name "*Test.class"\ |
457 |
+ -o -name "Test*.class"\ |
458 |
+ -o -name "*Tests.class"\ |
459 |
+ -o -name "*TestCase.class" \)\ |
460 |
+ ! -name "*Abstract*"\ |
461 |
+ ! -name "*BaseTest*"\ |
462 |
+ ! -name "*TestTypes*"\ |
463 |
+ ! -name "*TestUtils*"\ |
464 |
+ ! -name "*\$*") |
465 |
+ tests_to_run=${tests_to_run//"${classes}"\/} |
466 |
+ tests_to_run=${tests_to_run//.class} |
467 |
+ tests_to_run=${tests_to_run//\//.} |
468 |
+ |
469 |
+ # exclude extra test classes, usually corner cases |
470 |
+ # that the code above cannot handle |
471 |
+ for class in "${JAVA_TEST_EXCLUDES[@]}"; do |
472 |
+ tests_to_run=${tests_to_run//${class}} |
473 |
+ done |
474 |
+ |
475 |
+ # launch test |
476 |
+ for framework in ${JAVA_TESTING_FRAMEWORKS}; do |
477 |
+ case ${framework} in |
478 |
+ junit) |
479 |
+ ejunit -classpath "${classpath}" ${tests_to_run};; |
480 |
+ junit-4) |
481 |
+ ejunit4 -classpath "${classpath}" ${tests_to_run};; |
482 |
+ pkgdiff) |
483 |
+ java-pkg-simple_test_with_pkgdiff_;; |
484 |
+ testng) |
485 |
+ etestng -classpath "${classpath}" ${tests_to_run};; |
486 |
+ *) |
487 |
+ elog "No suitable function found for framework ${framework}" |
488 |
+ esac |
489 |
+ done |
490 |
+} |
491 |
|
492 |
diff --git a/eclass/java-utils-2.eclass b/eclass/java-utils-2.eclass |
493 |
index 29f13e031f4..a33962f114d 100644 |
494 |
--- a/eclass/java-utils-2.eclass |
495 |
+++ b/eclass/java-utils-2.eclass |
496 |
@@ -1861,6 +1861,44 @@ ejunit4() { |
497 |
ejunit_ "junit-4" "${@}" |
498 |
} |
499 |
|
500 |
+# @FUNCTION: etestng |
501 |
+# @USAGE: etestng_ [-cp $classpath] <test classes> |
502 |
+# @INTERNAL |
503 |
+# @DESCRIPTION: |
504 |
+# Testng wrapper function. Makes it easier to run the tests. |
505 |
+# Launches the tests using org.testng.TestNG. |
506 |
+# |
507 |
+# @CODE |
508 |
+# $1 - -cp or -classpath |
509 |
+# $2 - the classpath passed to it |
510 |
+# $@ - test classes for testng to run. |
511 |
+# @CODE |
512 |
+etestng() { |
513 |
+ debug-print-function ${FUNCNAME} $* |
514 |
+ |
515 |
+ local runner=org.testng.TestNG |
516 |
+ local cp=$(java-pkg_getjars --with-dependencies testng) |
517 |
+ local tests |
518 |
+ |
519 |
+ if [[ ${1} = -cp || ${1} = -classpath ]]; then |
520 |
+ cp="${cp}:${2}" |
521 |
+ shift 2 |
522 |
+ else |
523 |
+ cp="${cp}:." |
524 |
+ fi |
525 |
+ |
526 |
+ for test in ${@}; do |
527 |
+ tests+="${test}," |
528 |
+ done |
529 |
+ |
530 |
+ debug-print "java -cp \"${cp}\" -Djava.io.tmpdir=\"${T}\""\ |
531 |
+ "-Djava.awt.headless=true ${runner}"\ |
532 |
+ "-usedefaultlisteners false -testclass ${tests}" |
533 |
+ java -cp "${cp}" -Djava.io.tmpdir=\"${T}\" -Djava.awt.headless=true\ |
534 |
+ ${runner} -usedefaultlisteners false -testclass ${tests}\ |
535 |
+ || die "Running TestNG failed." |
536 |
+} |
537 |
+ |
538 |
# @FUNCTION: java-utils-2_src_prepare |
539 |
# @DESCRIPTION: |
540 |
# src_prepare Searches for bundled jars |