You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rz...@apache.org on 2026/10/13 07:52:31 UTC
(tomee) 03/18: Log webapp jars skipped by the scan exclusion list (#3069)
This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch tomee-10.x
in repository https://gitbox.apache.org/repos/asf/tomee.git
commit 07c28448ea3ede0928ae159d2cd87f6bd65af486
Author: Richard Zowalla <rz...@apache.org>
AuthorDate: Tue Oct 13 08:47:20 2026 +0200
Log webapp jars skipped by the scan exclusion list (#3069)
Annotations of such jars (including security ones) were dropped silently.
(cherry picked from commit 3d61320135b892ff1f522d4ea28f83cd31a65819)
---
.../apache/openejb/config/DeploymentLoader.java | 46 +++++++++++++++-
.../apache/openejb/config/NewLoaderLogicTest.java | 63 ++++++++++++++++++++++
2 files changed, 108 insertions(+), 1 deletion(-)
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java b/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
index 2fb22ae0b1..2c32244be8 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
@@ -1150,7 +1150,51 @@ public class DeploymentLoader implements DeploymentFilterable {
} catch (final MalformedURLException e) {
return Arrays.asList(webUrls);
}
- return urls.getUrls();
+
+ final List<URL> scannable = urls.getUrls();
+ final Collection<String> excludedWebappJars = builtinExcludedWebappJars(webUrls, scannable, excludeFilter);
+ if (!excludedWebappJars.isEmpty()) {
+ LOGGER.info("Application jars not scanned for annotations (e.g. @WebServlet, @ServletSecurity, @RolesAllowed)"
+ + " because their name matches a container scan exclusion prefix: " + excludedWebappJars
+ + ". To scan them, set the system property openejb.additional.include to the listed prefix"
+ + " (this re-enables scanning of every jar with that prefix and needs a restart)");
+ }
+ return scannable;
+ }
+
+ // webapp jars dropped by the container exclusion list, reported as "jar (prefix 'p')";
+ // jars excluded by WEB-INF/exclusions.list or custom filters are explicit so not reported
+ static Collection<String> builtinExcludedWebappJars(final URL[] webUrls, final List<URL> scannable, final Filter excludeFilter) {
+ final Set<String> kept = new HashSet<>();
+ for (final URL url : scannable) {
+ kept.add(url.toExternalForm());
+ }
+
+ final Collection<String> excluded = new ArrayList<>();
+ for (final URL url : webUrls) {
+ if (kept.contains(url.toExternalForm())) {
+ continue;
+ }
+ try {
+ final File file = URLs.toFile(url);
+ if (!file.getAbsolutePath().replace('\\', '/').contains("/WEB-INF/")) {
+ continue;
+ }
+ final String name = NameFiltering.filter(file).getName();
+ if (excludeFilter != null && excludeFilter.accept(name)) {
+ continue;
+ }
+ for (final String prefix : NewLoaderLogic.getExclusions()) {
+ if (name.startsWith(prefix) || prefix.endsWith("-") && name.equals(prefix.substring(0, prefix.length() - 1) + ".jar")) {
+ excluded.add(file.getName() + " (prefix '" + prefix + "')");
+ break;
+ }
+ }
+ } catch (final IllegalArgumentException iae) {
+ // no-op
+ }
+ }
+ return excluded;
}
public static void addBeansXmls(final WebModule webModule) {
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/config/NewLoaderLogicTest.java b/container/openejb-core/src/test/java/org/apache/openejb/config/NewLoaderLogicTest.java
index cfa01bfd3e..f62892fe84 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/config/NewLoaderLogicTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/config/NewLoaderLogicTest.java
@@ -16,8 +16,21 @@
*/
package org.apache.openejb.config;
+import org.apache.openejb.util.LogCategory;
import org.junit.Test;
+import java.io.File;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -31,4 +44,54 @@ public class NewLoaderLogicTest {
assertFalse(NewLoaderLogic.skip("openejb-noexclude.jar"));
assertFalse(NewLoaderLogic.skip("business-foo-1.2.3.jar"));
}
+
+ @Test
+ public void reportWebappJarsDroppedByContainerExclusions() throws Exception {
+ final File base = new File("target/NewLoaderLogicTest");
+ final File lib = new File(base, "app/WEB-INF/lib");
+ final URL collidingAppJar = new File(lib, "ant-reporting-web.jar").toURI().toURL();
+ final URL appJar = new File(lib, "business.jar").toURI().toURL();
+ final URL explicitlyExcludedAppJar = new File(lib, "internal-tools.jar").toURI().toURL();
+ final URL containerJar = new File(base, "tomee/lib/ant-1.10.15.jar").toURI().toURL();
+ final URL[] webUrls = {collidingAppJar, appJar, explicitlyExcludedAppJar, containerJar};
+
+ final File exclusions = new File(base, "app/WEB-INF/exclusions.list");
+ exclusions.getParentFile().mkdirs();
+ Files.write(exclusions.toPath(), "internal-\n".getBytes(StandardCharsets.UTF_8));
+
+ final List<LogRecord> records = new ArrayList<>();
+ final Handler handler = new Handler() {
+ @Override
+ public void publish(final LogRecord record) {
+ records.add(record);
+ }
+
+ @Override
+ public void flush() {
+ // no-op
+ }
+
+ @Override
+ public void close() {
+ // no-op
+ }
+ };
+ final Logger logger = Logger.getLogger(LogCategory.OPENEJB_STARTUP_CONFIG.getName());
+ logger.addHandler(handler);
+ try {
+ final List<URL> scannable = DeploymentLoader.filterWebappUrls(webUrls, null, exclusions.toURI().toURL());
+ assertEquals(Collections.singletonList(appJar), scannable);
+ } finally {
+ logger.removeHandler(handler);
+ }
+
+ final List<String> messages = new ArrayList<>();
+ for (final LogRecord record : records) {
+ if (record.getMessage().startsWith("Application jars not scanned")) {
+ messages.add(record.getMessage());
+ }
+ }
+ assertEquals(1, messages.size());
+ assertTrue(messages.get(0), messages.get(0).contains("[ant-reporting-web.jar (prefix 'ant-')]"));
+ }
}