]> source.dussan.org Git - poi.git/commitdiff
[github-207] add SLF4JLogger
authorPJ Fanning <fanningpj@apache.org>
Thu, 17 Dec 2020 19:59:01 +0000 (19:59 +0000)
committerPJ Fanning <fanningpj@apache.org>
Thu, 17 Dec 2020 19:59:01 +0000 (19:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884568 13f79535-47bb-0310-9956-ffa450edef68

build.gradle
build.xml
osgi/pom.xml
src/java/org/apache/poi/util/SLF4JLogger.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java

index 68fd7f800f6f797f48a67a1efeae0a963729a770..91742edd99353fccdd1b63e91da92b55dd6d6564 100644 (file)
@@ -114,6 +114,7 @@ subprojects {
         japicmpversion = '4.1.2'
         junitVersion = '4.13.1'
         mockitoVersion = '3.6.0'
+        slf4jVersion = '1.7.30'
         xmlbeansVersion = '4.0.0'
     }
 
@@ -220,12 +221,14 @@ project('main') {
         compile 'commons-logging:commons-logging:1.2'
         compile 'org.apache.commons:commons-collections4:4.4'
         compile "org.apache.commons:commons-math3:${commonsMathVersion}"
+        compile "org.slf4j:slf4j-api:${slf4jVersion}"
         compile 'javax.activation:activation:1.1.1'
         compile 'com.zaxxer:SparseBitSet:1.2'
 
         testCompile "junit:junit:${junitVersion}"
         testCompile "org.mockito:mockito-core:${mockitoVersion}"
         testCompile 'org.reflections:reflections:0.9.12'
+        testRuntime "org.slf4j:slf4j-simple:${slf4jVersion}"
     }
 
     jar {
index c65c35664b2d0411d08ebdef7cee756415d1130b..4a9f81773a36fa4cf868859e78f23daaf114810a 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -118,8 +118,6 @@ under the License.
     </condition>
     <!-- Fix for strange woodstox references in gump build -->
     <property name="javax.xml.stream.XMLInputFactory" value="com.sun.xml.internal.stream.XMLInputFactoryImpl"/>
-    <!-- need to override POILogger property before commons logging works -->
-    <property name="org.apache.commons.logging.Log" value="org.apache.commons.logging.impl.Log4JLogger"/>
     <property name="tempdir" value="build/tmp"/>
 
     <!-- Main: -->
@@ -271,6 +269,7 @@ under the License.
     <dependency prefix="main.commons-collections4" artifact="org.apache.commons:commons-collections4:4.4" usage="main"/>
     <dependency prefix="main.commons-math3" artifact="org.apache.commons:commons-math3:3.6.1" usage="main"/>
     <dependency prefix="main.com.zaxxer" artifact="com.zaxxer:SparseBitSet:1.2" usage="main"/>
+    <dependency prefix="main.slf4j-api" artifact="org.slf4j:slf4j-api:1.7.30" usage="main"/>
 
     <dependency prefix="main.junit" artifact="junit:junit:4.13.1" usage="main-tests"/>
     <dependency prefix="main.jmh" artifact="org.openjdk.jmh:jmh-core:1.26" usage="main-tests"/>
@@ -281,6 +280,7 @@ under the License.
     <dependency prefix="main.byte-buddy" artifact="net.bytebuddy:byte-buddy:1.10.18" usage="main-tests"/>
     <dependency prefix="main.byte-buddy-agent" artifact="net.bytebuddy:byte-buddy-agent:1.10.18" usage="main-tests"/>
     <dependency prefix="main.objenesis" artifact="org.objenesis:objenesis:3.1" usage="main-tests"/>
+    <dependency prefix="main.slf4j-simple" artifact="org.slf4j:slf4j-api:1.7.30" usage="main-tests"/>
 
     <dependency prefix="main.ant" artifact="org.apache.ant:ant:1.10.9" usage="excelant"/>
     <dependency prefix="main.antlauncher" artifact="org.apache.ant:ant-launcher:1.10.9" usage="excelant"/>
@@ -289,7 +289,6 @@ under the License.
     <dependency prefix="dsig.xmlsec" artifact="org.apache.santuario:xmlsec:2.2.0" usage="ooxml-provided"/>
     <dependency prefix="dsig.bouncycastle-prov" artifact="org.bouncycastle:bcprov-jdk15on:1.67" usage="ooxml-provided"/>
     <dependency prefix="dsig.bouncycastle-pkix" artifact="org.bouncycastle:bcpkix-jdk15on:1.67" usage="ooxml-provided"/>
-    <dependency prefix="dsig.slf4j-api" artifact="org.slf4j:slf4j-api:1.7.30" usage="ooxml-provided"/>
     <!-- only used for signing the release - not used with the ooxml signatures -->
     <dependency prefix="dsig.bouncycastle-bcpg" artifact="org.bouncycastle:bcpg-jdk15on:1.67" usage="util"/>
 
@@ -310,7 +309,6 @@ under the License.
     <dependency prefix="ooxml.test.reflections" artifact="org.reflections:reflections:0.9.12" usage="ooxml-tests"/>
     <dependency prefix="ooxml.test.guava" artifact="com.google.guava:guava:30.0-jre" usage="ooxml-tests"/>
     <dependency prefix="ooxml.test.javassist" artifact="org.javassist:javassist:3.27.0-GA" usage="ooxml-tests"/>
-    <dependency prefix="ooxml.test.log4j" artifact="log4j:log4j:1.2.17" usage="ooxml-tests"/>
 
     <!-- coverage libs -->
     <dependency prefix="jacoco" artifact="org.jacoco:jacoco:0.8.6" usage="util" packaging="zip"/>
@@ -420,6 +418,7 @@ under the License.
         <pathelement location="${main.byte-buddy.jar}"/>
         <pathelement location="${main.byte-buddy-agent.jar}"/>
         <pathelement location="${main.objenesis.jar}"/>
+        <pathelement location="${main.slf4j-simple.jar}"/>
     </path>
 
     <path id="scratchpad.classpath">
@@ -431,7 +430,6 @@ under the License.
         <pathelement location="${dsig.xmlsec.jar}"/>
         <pathelement location="${dsig.bouncycastle-prov.jar}"/>
         <pathelement location="${dsig.bouncycastle-pkix.jar}"/>
-        <pathelement location="${dsig.slf4j-api.jar}"/>
     </path>
 
     <path id="ooxml.base.classpath">
@@ -441,7 +439,6 @@ under the License.
         <path refid="main.classpath"/>
         <pathelement location="${main.output.dir}"/>
         <pathelement location="${ooxml.test.guava.jar}"/>
-        <pathelement location="${ooxml.test.log4j.jar}"/>
         <!-- classes are omitted on test cases outside the xml-dsign area to avoid classpath poisioning -->
         <!--path refid="ooxml.xmlsec.classpath"/-->
         <!-- Used only for ExtractorFactory, see #57963 -->
@@ -476,7 +473,6 @@ under the License.
         <pathelement location="${ooxml.test.reflections.jar}"/>
         <pathelement location="${ooxml.test.guava.jar}"/>
         <pathelement location="${ooxml.test.javassist.jar}"/>
-        <pathelement location="${ooxml.test.log4j.jar}"/>
     </path>
 
     <path id="test.ooxml.lite.verify.classpath">
@@ -655,6 +651,8 @@ under the License.
                     <available file="${main.objenesis.jar}"/>
                     <available file="${main.ant.jar}"/>
                     <available file="${main.antlauncher.jar}"/>
+                    <available file="${main.slf4j-api.jar}"/>
+                    <available file="${main.slf4j-simple.jar}"/>
                     <available file="${asm.jar}"/>
                     <available file="${asm-commons.jar}"/>
                     <available file="${asm-tree.jar}"/>
@@ -664,7 +662,6 @@ under the License.
                     <available file="${dsig.bouncycastle-prov.jar}"/>
                     <available file="${dsig.bouncycastle-pkix.jar}"/>
                     <available file="${dsig.xmlsec.jar}"/>
-                    <available file="${dsig.slf4j-api.jar}"/>
                     <available file="${main.commons-collections4.jar}"/>
                     <available file="${main.commons-math3.jar}"/>
                     <available file="${main.com.zaxxer.jar}"/>
@@ -693,6 +690,8 @@ under the License.
         <downloadfile src="${main.objenesis.url}" dest="${main.objenesis.jar}"/>
         <downloadfile src="${main.ant.url}" dest="${main.ant.jar}"/>
         <downloadfile src="${main.antlauncher.url}" dest="${main.antlauncher.jar}"/>
+        <downloadfile src="${main.slf4j-api.url}" dest="${main.slf4j-api.jar}"/>
+        <downloadfile src="${main.slf4j-simple.url}" dest="${main.slf4j-simple.jar}"/>
         <downloadfile src="${asm.url}" dest="${asm.jar}"/>
         <downloadfile src="${asm-commons.url}" dest="${asm-commons.jar}"/>
         <downloadfile src="${asm-tree.url}" dest="${asm-tree.jar}"/>
@@ -711,7 +710,6 @@ under the License.
         <downloadfile src="${dsig.bouncycastle-prov.url}" dest="${dsig.bouncycastle-prov.jar}"/>
         <downloadfile src="${dsig.bouncycastle-pkix.url}" dest="${dsig.bouncycastle-pkix.jar}"/>
         <downloadfile src="${dsig.xmlsec.url}" dest="${dsig.xmlsec.jar}"/>
-        <downloadfile src="${dsig.slf4j-api.url}" dest="${dsig.slf4j-api.jar}"/>
     </target>
 
     <target name="check-ooxml-jars">
@@ -724,7 +722,6 @@ under the License.
                     <available file="${ooxml.test.reflections.jar}"/>
                     <available file="${ooxml.test.guava.jar}"/>
                     <available file="${ooxml.test.javassist.jar}"/>
-                    <available file="${ooxml.test.log4j.jar}"/>
                     <available file="${svg.xml-apis-ext.jar}"/>
                     <available file="${svg.batik-all.jar}"/>
                     <available file="${svg.xmlgraphics-commons.jar}"/>
@@ -745,7 +742,6 @@ under the License.
         <downloadfile src="${ooxml.test.reflections.url}" dest="${ooxml.test.reflections.jar}"/>
         <downloadfile src="${ooxml.test.guava.url}" dest="${ooxml.test.guava.jar}"/>
         <downloadfile src="${ooxml.test.javassist.url}" dest="${ooxml.test.javassist.jar}"/>
-        <downloadfile src="${ooxml.test.log4j.url}" dest="${ooxml.test.log4j.jar}"/>
         <downloadfile src="${svg.batik-all.url}" dest="${svg.batik-all.jar}"/>
         <downloadfile src="${svg.xml-apis-ext.url}" dest="${svg.xml-apis-ext.jar}"/>
         <downloadfile src="${svg.xmlgraphics-commons.url}" dest="${svg.xmlgraphics-commons.jar}"/>
@@ -1608,7 +1604,7 @@ under the License.
 
     <target name="test-integration" depends="compile-integration,-test-integration-check,jacocotask"
             unless="integration.test.notRequired">
-        <propertyreset name="org.apache.poi.util.POILogger" value="org.apache.poi.util.CommonsLogger"/>
+        <propertyreset name="org.apache.poi.util.POILogger" value="org.apache.poi.util.SLF4JLogger"/>
         <delete dir="build" includes="test-integration.log*"/>
 
         <path id="test-integration.modules">
@@ -2514,7 +2510,6 @@ org/apache/poi/schemas/ooxml/system/ooxml/rectaf36doctype.xsb
             </fileset>
             <auxClasspath path="${dsig.bouncycastle-pkix.jar}" />
             <auxClasspath path="${dsig.bouncycastle-prov.jar}" />
-            <auxClasspath path="${dsig.slf4j-api.jar}" />
             <auxClasspath path="${dsig.xmlsec.jar}" />
             <auxClasspath path="${ooxml.xsds.jar}" />
             <auxClasspath path="${ooxml.curvesapi.jar}" />
@@ -2524,6 +2519,8 @@ org/apache/poi/schemas/ooxml/system/ooxml/rectaf36doctype.xsb
             <auxClasspath path="${main.commons-math3.jar}" />
             <auxClasspath path="${main.commons-codec.jar}" />
             <auxClasspath path="${main.commons-logging.jar}" />
+            <auxClasspath path="${main.slf4j-api.jar}" />
+            <auxClasspath path="${main.slf4j-simple.jar}" />
             <auxClasspath path="${main.junit.jar}" />
             <auxClasspath path="${main.jmh.jar}"/>
             <auxClasspath path="${main.jmhAnnotation.jar}"/>
index 0d19cd3341cc926f519c257bc90c39c5738615b8..ce11df9228da37bdeb54bd3b751b63398eb11345 100644 (file)
@@ -87,6 +87,7 @@
                             org.apache.xml.security.*;resolution:=optional,
                             org.bouncycastle.*;resolution:=optional,
                             org.apache.commons.logging.*;resolution:=optional,
+                            org.slf4j.*;resolution:=optional,
                             !com.github.luben.zstd.*,
                             !org.tukaani.xz.*,
                             !org.brotli.dec.*,
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
-            <version>4.12</version>
+            <version>4.13.1</version>
         </dependency>
 
         <!-- Pax Exam -->
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
-            <version>1.7.25</version>
+            <version>1.7.30</version>
             <scope>test</scope>
         </dependency>
     </dependencies>
diff --git a/src/java/org/apache/poi/util/SLF4JLogger.java b/src/java/org/apache/poi/util/SLF4JLogger.java
new file mode 100644 (file)
index 0000000..236fc2c
--- /dev/null
@@ -0,0 +1,157 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An implementation of the {@link POILogger} using the
+ * SLF4J framework. Which itself can be configured to
+ * send log to various different log frameworks and even allows to create
+ * a small wrapper for custom log frameworks.
+ */
+public class SLF4JLogger implements POILogger
+{
+    private Logger log;
+
+    @Override
+    public void initialize(final String cat) {
+        this.log = LoggerFactory.getLogger(cat);
+    }
+
+    /**
+     * Log a message
+     *
+     * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
+     * @param obj1 The object to log.
+     */
+    @Override
+    public void _log(final int level, final Object obj1) {
+        switch (level) {
+            case FATAL:
+            case ERROR:
+                if (log.isErrorEnabled()) {
+                    log.error(obj1.toString());
+                }
+                break;
+            case WARN:
+                if (log.isWarnEnabled()) {
+                    log.warn(obj1.toString());
+                }
+                break;
+            case INFO:
+                if (log.isInfoEnabled()) {
+                    log.info(obj1.toString());
+                }
+                break;
+            case DEBUG:
+                if (log.isDebugEnabled()) {
+                    log.debug(obj1.toString());
+                }
+                break;
+            default:
+                if (log.isTraceEnabled()) {
+                    log.trace(obj1.toString());
+                }
+                break;
+        }
+    }
+
+    /**
+     * Log a message
+     *
+     * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
+     * @param obj1 The object to log.  This is converted to a string.
+     * @param exception An exception to be logged
+     */
+    @Override
+    public void _log(final int level, final Object obj1, final Throwable exception) {
+        switch (level) {
+            case FATAL:
+            case ERROR:
+                if (log.isErrorEnabled()) {
+                    if (obj1 != null) {
+                        log.error(obj1.toString(), exception);
+                    } else {
+                        log.error(exception.toString(), exception);
+                    }
+                }
+                break;
+            case WARN:
+                if (log.isWarnEnabled()) {
+                    if (obj1 != null) {
+                        log.warn(obj1.toString(), exception);
+                    } else {
+                        log.warn(exception.toString(), exception);
+                    }
+                }
+                break;
+            case INFO:
+                if (log.isInfoEnabled()) {
+                    if (obj1 != null) {
+                        log.info(obj1.toString(), exception);
+                    } else {
+                        log.info(exception.toString(), exception);
+                    }
+                }
+                break;
+            case DEBUG:
+                if (log.isDebugEnabled()) {
+                    if (obj1 != null) {
+                        log.debug(obj1.toString(), exception);
+                    } else {
+                        log.debug(exception.toString(), exception);
+                    }
+                }
+                break;
+            default:
+                if (log.isTraceEnabled()) {
+                    if (obj1 != null) {
+                        log.trace(obj1.toString(), exception);
+                    } else {
+                        log.trace(exception.toString(), exception);
+                    }
+                }
+                break;
+        }
+    }
+
+    /**
+     * Check if a logger is enabled to log at the specified level
+     *
+     * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
+     */
+    @Override
+    public boolean check(final int level)
+    {
+        switch (level) {
+            case FATAL:
+            case ERROR:
+                return log.isErrorEnabled();
+            case WARN:
+                return log.isWarnEnabled();
+            case INFO:
+                return log.isInfoEnabled();
+            case DEBUG:
+                return log.isDebugEnabled();
+            default:
+                return false;
+        }
+    }
+}
+
index de73c19c0a127d3d1dca023bac42e5c655a8c254..de378ec36230a37eda5c15b043657ce37ff85c70 100644 (file)
@@ -152,8 +152,8 @@ import org.w3c.dom.events.MutationEvent;
  * <p>To use SignatureInfo and its sibling classes, you'll need to have the following libs
  * in the classpath:</p>
  * <ul>
- * <li>BouncyCastle bcpkix and bcprov (tested against 1.65)</li>
- * <li>Apache Santuario "xmlsec" (tested against 2.1.5)</li>
+ * <li>BouncyCastle bcpkix and bcprov (tested against 1.67)</li>
+ * <li>Apache Santuario "xmlsec" (tested against 2.2.0)</li>
  * <li>and slf4j-api (tested against 1.7.30)</li>
  * </ul>
  */