From e46495ea9a2e027d33c6fbab9abc19351e745f64 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sun, 17 Mar 2024 20:17:53 +0100 Subject: [PATCH 1/2] Remove deprecated dependencies to satisfy security scanners This is a PoC on how to remove deprecated libraries from the POM file (or move them to the `test` scope) to appease some primitive security scanners. The trick is to extract classes/methods from the Avalon, LogKit and Log4j 1.x libraries that are used in the Commons Logging code and put them in an additional source code directory `src/main/dummy`. **Remark:** The source files in `src/main/dummy` are **not** included in the any Commons Logging artifact. They are only used by the compiler to include the correct signatures in the class files. --- pom.xml | 67 +++++++++++++++- .../avalon/framework/logger/Logger.java | 55 ++++++++++++++ src/main/dummy/org/apache/log/Hierarchy.java | 33 ++++++++ src/main/dummy/org/apache/log/Logger.java | 76 +++++++++++++++++++ src/main/dummy/org/apache/log4j/Category.java | 35 +++++++++ src/main/dummy/org/apache/log4j/Level.java | 32 ++++++++ src/main/dummy/org/apache/log4j/Logger.java | 28 +++++++ src/main/dummy/org/apache/log4j/Priority.java | 24 ++++++ .../commons/logging/impl/Log4JLogger.java | 4 +- 9 files changed, 349 insertions(+), 5 deletions(-) create mode 100644 src/main/dummy/org/apache/avalon/framework/logger/Logger.java create mode 100644 src/main/dummy/org/apache/log/Hierarchy.java create mode 100644 src/main/dummy/org/apache/log/Logger.java create mode 100644 src/main/dummy/org/apache/log4j/Category.java create mode 100644 src/main/dummy/org/apache/log4j/Level.java create mode 100644 src/main/dummy/org/apache/log4j/Logger.java create mode 100644 src/main/dummy/org/apache/log4j/Priority.java diff --git a/pom.xml b/pom.xml index d230f67f9..2ccb407e6 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,49 @@ under the License. clean verify apache-rat:check japicmp:cmp javadoc:javadoc checkstyle:check pmd:check + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-dummy-sources + + add-source + + generate-sources + + + src/main/dummy + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + + + none + + org/apache/commons/logging/** + + + + + + + + org/apache/commons/logging/** + + + + + + --ignore-missing-deps + --multi-release=9 + @@ -522,13 +583,13 @@ under the License. avalon-framework avalon-framework 4.1.5 - true + test org.apache.logging.log4j log4j-1.2-api ${log4j2.version} - true + test org.apache.logging.log4j @@ -540,7 +601,7 @@ under the License. logkit logkit 2.0 - true + test org.slf4j diff --git a/src/main/dummy/org/apache/avalon/framework/logger/Logger.java b/src/main/dummy/org/apache/avalon/framework/logger/Logger.java new file mode 100644 index 000000000..8ab942a9b --- /dev/null +++ b/src/main/dummy/org/apache/avalon/framework/logger/Logger.java @@ -0,0 +1,55 @@ +/* + * 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.avalon.framework.logger; + +/** + * This is a dummy class used to compile {@link org.apache.commons.logging.impl.AvalonLogger}, without depending on + * the deprecated Avalon library. + */ +public interface Logger { + void debug(String var1); + + void debug(String var1, Throwable var2); + + boolean isDebugEnabled(); + + void info(String var1); + + void info(String var1, Throwable var2); + + boolean isInfoEnabled(); + + void warn(String var1); + + void warn(String var1, Throwable var2); + + boolean isWarnEnabled(); + + void error(String var1); + + void error(String var1, Throwable var2); + + boolean isErrorEnabled(); + + void fatalError(String var1); + + void fatalError(String var1, Throwable var2); + + boolean isFatalErrorEnabled(); + + Logger getChildLogger(String var1); +} diff --git a/src/main/dummy/org/apache/log/Hierarchy.java b/src/main/dummy/org/apache/log/Hierarchy.java new file mode 100644 index 000000000..5806469a0 --- /dev/null +++ b/src/main/dummy/org/apache/log/Hierarchy.java @@ -0,0 +1,33 @@ +/* + * 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.log; + +/** + * This is a dummy class used to compile {@link org.apache.commons.logging.impl.LogKitLogger}, without depending on + * the deprecated LogKit library. + */ +public class Hierarchy { + + public static Hierarchy getDefaultHierarchy() { + return null; + } + + public Logger getLoggerFor(String ignored) { + return null; + } + +} diff --git a/src/main/dummy/org/apache/log/Logger.java b/src/main/dummy/org/apache/log/Logger.java new file mode 100644 index 000000000..f2930e57c --- /dev/null +++ b/src/main/dummy/org/apache/log/Logger.java @@ -0,0 +1,76 @@ +/* + * 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.log; + +/** + * This is a dummy class used to compile {@link org.apache.commons.logging.impl.LogKitLogger}, without depending on the + * deprecated LogKit library. + */ +public class Logger { + + public final boolean isDebugEnabled() { + return false; + } + + public final void debug(final String message, final Throwable throwable) { + } + + public final void debug(final String message) { + } + + public final boolean isInfoEnabled() { + return false; + } + + public final void info(final String message, final Throwable throwable) { + } + + public final void info(final String message) { + } + + public final boolean isWarnEnabled() { + return false; + } + + public final void warn(final String message, final Throwable throwable) { + } + + public final void warn(final String message) { + } + + public final boolean isErrorEnabled() { + return false; + } + + public final void error(final String message, final Throwable throwable) { + } + + public final void error(final String message) { + + } + + public final boolean isFatalErrorEnabled() { + return false; + } + + public final void fatalError(final String message, final Throwable throwable) { + } + + public final void fatalError(final String message) { + } + +} diff --git a/src/main/dummy/org/apache/log4j/Category.java b/src/main/dummy/org/apache/log4j/Category.java new file mode 100644 index 000000000..37d3c337f --- /dev/null +++ b/src/main/dummy/org/apache/log4j/Category.java @@ -0,0 +1,35 @@ +/* + * 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.log4j; + +/** + * This is a dummy class used to compile {@link org.apache.commons.logging.impl.Log4JLogger}, without depending on the + * deprecated Log4j 1.x library. + */ +public class Category { + + public final String getName() { + return null; + } + + public void log(final String fqcn, final Priority priority, final Object message, final Throwable t) { + } + + public boolean isEnabledFor(final Priority level) { + return false; + } +} diff --git a/src/main/dummy/org/apache/log4j/Level.java b/src/main/dummy/org/apache/log4j/Level.java new file mode 100644 index 000000000..855e8115c --- /dev/null +++ b/src/main/dummy/org/apache/log4j/Level.java @@ -0,0 +1,32 @@ +/* + * 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.log4j; + +import java.io.Serializable; + +/** + * This is a dummy class used to compile {@link org.apache.commons.logging.impl.Log4JLogger}, without depending on the + * deprecated Log4j 1.x library. + */ +public class Level extends Priority implements Serializable { + public static final Level FATAL = null; + public static final Level ERROR = null; + public static final Level WARN = null; + public static final Level INFO = null; + public static final Level DEBUG = null; + public static final Level TRACE = null; +} diff --git a/src/main/dummy/org/apache/log4j/Logger.java b/src/main/dummy/org/apache/log4j/Logger.java new file mode 100644 index 000000000..2e3f8b565 --- /dev/null +++ b/src/main/dummy/org/apache/log4j/Logger.java @@ -0,0 +1,28 @@ +/* + * 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.log4j; + +/** + * This is a dummy class used to compile {@link org.apache.commons.logging.impl.Log4JLogger}, without depending on the + * deprecated Log4j 1.x library. + */ +public class Logger extends Category { + + public static Logger getLogger(final String name) { + return null; + } +} diff --git a/src/main/dummy/org/apache/log4j/Priority.java b/src/main/dummy/org/apache/log4j/Priority.java new file mode 100644 index 000000000..ddd5637e0 --- /dev/null +++ b/src/main/dummy/org/apache/log4j/Priority.java @@ -0,0 +1,24 @@ +/* + * 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.log4j; + +/** + * This is a dummy class used to compile {@link org.apache.commons.logging.impl.Log4JLogger}, without depending on the + * deprecated Log4j 1.x library. + */ +public class Priority { +} diff --git a/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java b/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java index 0cabd4b59..f780882a2 100644 --- a/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java +++ b/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java @@ -236,7 +236,7 @@ public void info(final Object message, final Throwable t) { */ @Override public boolean isDebugEnabled() { - return getLogger().isDebugEnabled(); + return getLogger().isEnabledFor(Level.DEBUG); } /** @@ -260,7 +260,7 @@ public boolean isFatalEnabled() { */ @Override public boolean isInfoEnabled() { - return getLogger().isInfoEnabled(); + return getLogger().isEnabledFor(Level.INFO); } /** From 544ba3be8173204d6e7079764ad975d39ee770a5 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sun, 17 Mar 2024 21:21:05 +0100 Subject: [PATCH 2/2] Fix Animal Sniffer failure --- pom.xml | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2ccb407e6..f44da84b5 100644 --- a/pom.xml +++ b/pom.xml @@ -582,7 +582,7 @@ under the License. avalon-framework avalon-framework - 4.1.5 + ${avalon.version} test @@ -600,7 +600,7 @@ under the License. logkit logkit - 2.0 + ${logkit.version} test @@ -725,8 +725,10 @@ under the License. 3.2.1 filesystem + 4.1.5 2.23.1 1.3.14 + 2.0 2.0.12 1.13.0 @@ -741,6 +743,45 @@ under the License. 2024-01-01T00:00:00Z + + + + animal-sniffer + + (,9) + + src/site/resources/profile.noanimal + + + + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + + + checkAPIcompatibility + + + + org.apache.avalon.framework.logger.* + org.apache.log.* + org.apache.log4j.* + + + + + + + + + + + baliuka