This is an automated email from the ASF dual-hosted git repository.
jungm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/main by this push:
new a108225c50 TOMEE-4710 - drop patching catalina.jar (#2947)
a108225c50 is described below
commit a108225c50de59fccd07b4b6a23f737413bd3f12
Author: Markus Jung <[email protected]>
AuthorDate: Fri Sep 25 21:05:28 2026 +0200
TOMEE-4710 - drop patching catalina.jar (#2947)
---
tomee/apache-tomee/pom.xml | 8 --
.../java/org/apache/catalina/util/ServerInfo.java | 148 ---------------------
.../java/org/apache/tomee/installer/Installer.java | 60 +++++++--
3 files changed, 52 insertions(+), 164 deletions(-)
diff --git a/tomee/apache-tomee/pom.xml b/tomee/apache-tomee/pom.xml
index a5198ea65d..7074ee322c 100644
--- a/tomee/apache-tomee/pom.xml
+++ b/tomee/apache-tomee/pom.xml
@@ -156,14 +156,6 @@
<scope>runtime</scope>
</dependency>
- <!-- needed to compile in intellij for tomcat patches -->
- <dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>tomcat-catalina</artifactId>
- <version>${tomcat.version}</version>
- <scope>provided</scope>
- </dependency>
-
<!-- needed for BOM generation -->
<dependency>
<groupId>org.projectlombok</groupId>
diff --git
a/tomee/apache-tomee/src/patch/java/org/apache/catalina/util/ServerInfo.java
b/tomee/apache-tomee/src/patch/java/org/apache/catalina/util/ServerInfo.java
deleted file mode 100644
index 54adbf2b44..0000000000
--- a/tomee/apache-tomee/src/patch/java/org/apache/catalina/util/ServerInfo.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * 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.catalina.util;
-
-
-import java.io.InputStream;
-import java.util.Properties;
-
-import org.apache.tomcat.util.ExceptionUtils;
-
-
-/**
- * Simple utility module to make it easy to plug in the server identifier
- * when integrating Tomcat.
- *
- * @author Craig R. McClanahan
- */
-public class ServerInfo {
-
-
- // ------------------------------------------------------- Static Variables
-
-
- /**
- * The server information String with which we identify ourselves.
- */
- private static final String serverInfo;
-
- /**
- * The server built String.
- */
- private static final String serverBuilt;
-
- /**
- * The server's version number String.
- */
- private static final String serverNumber;
-
- static {
-
- String info = null;
- String built = null;
- String number = null;
-
- Properties props = new Properties();
- try (InputStream is = ServerInfo.class.getResourceAsStream
- ("/org/apache/catalina/util/ServerInfo.properties")) {
- props.load(is);
- info = props.getProperty("server.info");
- built = props.getProperty("server.built");
- number = props.getProperty("server.number");
- } catch (Throwable t) {
- ExceptionUtils.handleThrowable(t);
- }
- if (info == null || info.equals("Apache Tomcat/@VERSION@")) {
- info = "Apache Tomcat/10.0.x-dev";
- }
- if (built == null || built.equals("@VERSION_BUILT@")) {
- built = "unknown";
- }
- if (number == null || number.equals("@VERSION_NUMBER@")) {
- number = "10.0.x";
- }
-
- // TOMEE-4014 - PATCH START
- try {
- final Class<?> systemInstanceClass =
Class.forName("org.apache.openejb.loader.SystemInstance");
- final Class<?> optionsClass =
Class.forName("org.apache.openejb.loader.Options");
- final Object systemInstance =
systemInstanceClass.getDeclaredMethod("get").invoke(null);
- final Object optionsInstance =
systemInstanceClass.getDeclaredMethod("getOptions").invoke(systemInstance);
-
- final boolean keepServerInfo = (boolean)
optionsClass.getDeclaredMethod("get", String.class,
boolean.class).invoke(optionsInstance, "tomee.keep-server-info", false);
-
- if (!keepServerInfo) {
- final int slash = info.indexOf('/');
- final Class<?> versionClass =
Class.forName("org.apache.openejb.util.OpenEjbVersion");
- final Object instance =
versionClass.getDeclaredMethod("get").invoke(null);
- final String tomeeVersion = (String)
versionClass.getDeclaredMethod("getVersion").invoke(instance);
-
- info = info.substring(0, slash) + " (TomEE)" +
info.substring(slash) + " (" + tomeeVersion + ")";
- }
- } catch (Throwable t) {
- // ignore
- t.printStackTrace();
- }
- // TOMEE-4014 - PATCH END
-
- serverInfo = info;
- serverBuilt = built;
- serverNumber = number;
- }
-
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * @return the server identification for this version of Tomcat.
- */
- public static String getServerInfo() {
- return serverInfo;
- }
-
- /**
- * @return the server built time for this version of Tomcat.
- */
- public static String getServerBuilt() {
- return serverBuilt;
- }
-
- /**
- * @return the server's version number.
- */
- public static String getServerNumber() {
- return serverNumber;
- }
-
- public static void main(String args[]) {
- System.out.println("Server version: " + getServerInfo());
- System.out.println("Server built: " + getServerBuilt());
- System.out.println("Server number: " + getServerNumber());
- System.out.println("OS Name: " +
- System.getProperty("os.name"));
- System.out.println("OS Version: " +
- System.getProperty("os.version"));
- System.out.println("Architecture: " +
- System.getProperty("os.arch"));
- System.out.println("JVM Version: " +
- System.getProperty("java.runtime.version"));
- System.out.println("JVM Vendor: " +
- System.getProperty("java.vm.vendor"));
- }
-
-}
\ No newline at end of file
diff --git
a/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
b/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
index 435fe9b7d3..fd1055a79c 100644
--- a/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
+++ b/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
@@ -16,14 +16,17 @@
*/
package org.apache.tomee.installer;
+import org.apache.openejb.loader.IO;
import org.apache.openejb.loader.Options;
import org.apache.openejb.loader.SystemInstance;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import java.util.function.Function;
import java.util.jar.JarFile;
@@ -138,6 +141,7 @@ public class Installer implements InstallerInterface {
commentDeploymentDir();
installConfigFiles(true);
+ installServerInfo();
removeTomcatLibJar("annotations-api.jar");
// addJavaeeInEndorsed();
@@ -174,6 +178,49 @@ public class Installer implements InstallerInterface {
}
}
+ // Tomcat reads its server info from
org/apache/catalina/util/ServerInfo.properties, and the lib/ directory comes
+ // before lib/catalina.jar in common.loader, so this copy with the TomEE
version shows up in the startup log,
+ // ServletContext#getServerInfo(), error pages and "catalina.sh version"
+ private void installServerInfo() {
+ final String serverInfoPath =
"org/apache/catalina/util/ServerInfo.properties";
+ final File serverInfoFile = new File(paths.getCatalinaLibDir(),
serverInfoPath);
+ if (serverInfoFile.exists()) {
+ return;
+ }
+
+ try (final JarFile catalinaJar = new JarFile(new
File(paths.getCatalinaLibDir(), "catalina.jar"))) {
+ final String tomcatServerInfo = Installers.readEntry(catalinaJar,
serverInfoPath, alerts);
+ if (tomcatServerInfo == null) {
+ return;
+ }
+
+ final Properties tomcatServerInfoProperties = new Properties();
+ tomcatServerInfoProperties.load(new
StringReader(tomcatServerInfo));
+ final String info =
tomcatServerInfoProperties.getProperty("server.info");
+ final int slash = info == null ? -1 : info.indexOf('/');
+ if (slash < 0) {
+ return;
+ }
+
+ // not OpenEjbVersion, it uses the context classloader which
doesn't see openejb-core during the build
+ final String tomeeVersion =
IO.readProperties(Installer.class.getClassLoader().getResourceAsStream("openejb-version.properties"),
new Properties())
+ .getProperty("version");
+ final String tomeeInfo = info.substring(0, slash) + " (TomEE)" +
info.substring(slash) + " (" + tomeeVersion + ")";
+
+ if (!serverInfoFile.getParentFile().isDirectory() &&
!serverInfoFile.getParentFile().mkdirs()) {
+ alerts.addWarning("Unable to create " +
serverInfoFile.getParentFile().getAbsolutePath());
+ return;
+ }
+ if (Installers.writeAll(serverInfoFile,
tomcatServerInfo.replace("server.info=" + info,
+ "# Overrides server.info of catalina.jar, remove this file
to report plain Apache Tomcat\n" +
+ "server.info=" + tomeeInfo), alerts)) {
+ alerts.addInfo("Add TomEE server info to lib");
+ }
+ } catch (final IOException e) {
+ alerts.addWarning("Unable to add TomEE server info to lib: " +
e.getMessage());
+ }
+ }
+
private void removeTomcatLibJar(final String name) {
final File jar = new File(paths.getCatalinaLibDir(), name);
removeJar(jar);
@@ -587,12 +634,9 @@ public class Installer implements InstallerInterface {
"\n" +
"# ----- Execute The Requested Command");
- newCatalinaSh = newCatalinaSh.replace(" \"$_RUNJAVA\" \\\n" +
- " -classpath \"$CATALINA_HOME/lib/catalina.jar\" \\\n" +
- " org.apache.catalina.util.ServerInfo",
- " eval \"\\\"$_RUNJAVA\\\"\" \"$JAVA_OPTS\" \\\n" +
- " -classpath
\"\\\"$CATALINA_HOME/lib/catalina.jar:$CATALINA_HOME/lib/openejb-core-"+
properties.get("tomee.version") + ".jar\\\"\" \\\n" +
- " org.apache.catalina.util.ServerInfo");
+ // "catalina.sh version" should see
lib/org/apache/catalina/util/ServerInfo.properties like common.loader does
+ newCatalinaSh = newCatalinaSh.replace("-classpath
\"\\\"$CATALINA_HOME/bin/tomcat-juli.jar:$CATALINA_HOME/lib/*\\\"\"",
+ "-classpath
\"\\\"$CATALINA_BASE/lib:$CATALINA_HOME/lib:$CATALINA_HOME/bin/tomcat-juli.jar:$CATALINA_HOME/lib/*\\\"\"");
// overwrite the catalina.sh file
if (Installers.writeAll(paths.getCatalinaShFile(), newCatalinaSh,
alerts)) {
@@ -644,8 +688,8 @@ public class Installer implements InstallerInterface {
"\r\n" +
"rem ----- Execute The Requested Command");
- newCatalinaBat = newCatalinaBat.replace("%_EXECJAVA% %JAVA_OPTS%
-classpath \"%CATALINA_HOME%\\lib\\catalina.jar\"
org.apache.catalina.util.ServerInfo",
- "%_EXECJAVA% %JAVA_OPTS% -classpath
\"%CATALINA_HOME%\\lib\\catalina.jar;%CATALINA_HOME%\\lib\\openejb-core-" +
properties.get("tomee.version") + ".jar\" org.apache.catalina.util.ServerInfo");
+ newCatalinaBat = newCatalinaBat.replace("-classpath
\"%CATALINA_HOME%\\bin\\tomcat-juli.jar;%CATALINA_HOME%\\lib\\*\"",
+ "-classpath
\"%CATALINA_BASE%\\lib;%CATALINA_HOME%\\lib;%CATALINA_HOME%\\bin\\tomcat-juli.jar;%CATALINA_HOME%\\lib\\*\"");
// overwrite the catalina.bat file
if (Installers.writeAll(paths.getCatalinaBatFile(), newCatalinaBat,
alerts)) {