commit:     de2db80524e6e55868462ac22d89c48ff37e341a
Author:     Yuan Liao <liaoyuan <AT> gmail <DOT> com>
AuthorDate: Sat Feb 26 02:59:49 2022 +0000
Commit:     Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
CommitDate: Sat Feb 26 08:48:25 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=de2db805

dev-java/commons-logging: Let build.xml accept log4j-12-api as Log4j 1.2

Closes: https://bugs.gentoo.org/834036
Signed-off-by: Yuan Liao <liaoyuan <AT> gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/24352
Signed-off-by: Miroslav Šulc <fordfrog <AT> gentoo.org>

 ...1.2-r4.ebuild => commons-logging-1.2-r5.ebuild} | 48 ++++++++++++++++++----
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/dev-java/commons-logging/commons-logging-1.2-r4.ebuild 
b/dev-java/commons-logging/commons-logging-1.2-r5.ebuild
similarity index 53%
rename from dev-java/commons-logging/commons-logging-1.2-r4.ebuild
rename to dev-java/commons-logging/commons-logging-1.2-r5.ebuild
index d32f9e36c65e..cfe4860720b9 100644
--- a/dev-java/commons-logging/commons-logging-1.2-r4.ebuild
+++ b/dev-java/commons-logging/commons-logging-1.2-r5.ebuild
@@ -22,7 +22,11 @@ RESTRICT="!test? ( test ) !servletapi? ( test )"
 CDEPEND="
        avalon-logkit? ( dev-java/avalon-logkit:2.0 )
        avalon-framework? ( dev-java/avalon-framework:4.2 )
-       log4j? ( dev-java/log4j-12-api:2 )
+       log4j? (
+               dev-java/log4j-12-api:2
+               dev-java/log4j-api:2
+               dev-java/log4j-core:2
+       )
        servletapi? ( dev-java/tomcat-servlet-api:4.0 )"
 
 RDEPEND="
@@ -38,7 +42,6 @@ S="${WORKDIR}/${P}-src"
 
 EANT_BUILD_TARGET="compile"
 JAVA_ANT_REWRITE_CLASSPATH="yes"
-JAVA_ANT_CLASSPATH_TAGS="javac javadoc"
 JAVA_ANT_IGNORE_SYSTEM_CLASSES="yes"
 
 DOCS=( RELEASE-NOTES.txt PROPOSAL.html )
@@ -55,20 +58,41 @@ src_prepare() {
 
        if use avalon-framework; then
                echo "avalon-framework.jar=$(java-pkg_getjars 
avalon-framework-4.2)" >> build.properties || die
-               EANT_GENTOO_CLASSPATH+=" avalon-framework-4.2"
        fi
        if use avalon-logkit; then
                echo "logkit.jar=$(java-pkg_getjars avalon-logkit-2.0)" >> 
build.properties || die
-               EANT_GENTOO_CLASSPATH+=" avalon-logkit-2.0"
        fi
        if use log4j; then
-               echo "log4j12.jar=$(java-pkg_getjars 
log4j-12-api-2,log4j-core-2)" >> build.properties || die
-               EANT_GENTOO_CLASSPATH+=" log4j-12-api-2 log4j-core-2"
+               # log4j12.jar can only contain path to one single file because
+               # build.xml decides whether the Log4JLogger should be built with
+               # <available file="${log4j12.jar}" property="log4j12.present"/>,
+               # and a value that contains multiple file paths will cause the
+               # test to return a negative result.  However, classes from 
multiple
+               # Log4j 2 JARs are needed to compile the sources.  So, we 
combine
+               # them into a single JAR on the go.
+               # https://bugs.gentoo.org/834036
+               mkdir -p "${T}/log4j-2" ||
+                       die "Failed to create temporary directory for Log4j 2 
classes"
+               pushd "${T}/log4j-2" > /dev/null ||
+                       die "Failed to enter temporary directory for Log4j 2 
classes"
+
+               local jar="$(java-config -j)"
+               local dep
+               for dep in log4j-{12-api,api,core}; do
+                       # Assuming SLOT="2" for Log4j 2 dependencies
+                       "${jar}" -xf "$(java-pkg_getjar "${dep}-2" 
"${dep}.jar")" ||
+                               die "Failed to extract files from ${dep}-2 
installed on system"
+               done
+               "${jar}" -cf log4j-2.jar . || die "Failed to create JAR for 
Log4j"
+
+               popd > /dev/null ||
+                       die "Failed to leave temporary directory for Log4j 2 
classes"
+
+               echo "log4j12.jar=${T}/log4j-2/log4j-2.jar" >> build.properties 
|| die
        fi
 
        if use servletapi; then
                echo "servletapi.jar=$(java-pkg_getjar tomcat-servlet-api-4.0 
servlet-api.jar)" >> build.properties || die
-               EANT_GENTOO_CLASSPATH+=" tomcat-servlet-api-4.0"
        fi
 }
 
@@ -84,5 +108,15 @@ src_install() {
 }
 
 src_test() {
+       # Do not run Log4j tests because these tests use an Appender to verify
+       # logging correctness.  The log4j-12-api bridge no longer supports 
using an
+       # Appender for verifications since the methods for adding an Appender in
+       # the bridge "are largely no-ops".  This means an Appender's state would
+       # never be changed by log4j-12-api after new messages are logged.  The 
test
+       # cases, however, expect changes to the Appender's state in such an 
event,
+       # so they would fail with log4j-12-api.
+       # https://logging.apache.org/log4j/log4j-2.8/log4j-1.2-api/index.html
+       sed -i -e "/^log4j12\.jar=/d" build.properties ||
+               die "Failed to skip Log4j tests by modifying build.properties"
        java-pkg-2_src_test
 }

Reply via email to