Skip to content

Commit 1785561

Browse files
committed
Added EntierpriseEditionVersion enum.
ServletContextHandler now sets ENVIRONMENT using above enum.
1 parent 0872c75 commit 1785561

7 files changed

Lines changed: 66 additions & 12 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// ========================================================================
3+
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
4+
//
5+
// This program and the accompanying materials are made available under the
6+
// terms of the Eclipse Public License v. 2.0 which is available at
7+
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
8+
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
//
10+
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
11+
// ========================================================================
12+
//
13+
14+
package org.eclipse.jetty.ee.common;
15+
16+
public enum EnterpriseEditionVersion
17+
{
18+
ee10(10),
19+
ee11(11);
20+
21+
public static final EnterpriseEditionVersion currentVersion = initEnterpriseEditionVersion();
22+
23+
public static EnterpriseEditionVersion getEnterpriseEditionVersion()
24+
{
25+
return currentVersion;
26+
}
27+
28+
private final int version;
29+
30+
EnterpriseEditionVersion(int version)
31+
{
32+
this.version = version;
33+
}
34+
35+
public int version()
36+
{
37+
return version;
38+
}
39+
40+
private static EnterpriseEditionVersion initEnterpriseEditionVersion()
41+
{
42+
try
43+
{
44+
return switch (ServletApiVersion.getServletApiVersion())
45+
{
46+
case v6_0 -> ee10;
47+
case v6_1 -> ee11;
48+
default -> null;
49+
};
50+
}
51+
catch (Throwable e)
52+
{
53+
throw new RuntimeException(e);
54+
}
55+
}
56+
}

jetty-ee/jetty-ee-common/src/main/java/org/eclipse/jetty/ee/common/ServletApiVersion.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ public enum ServletApiVersion
2727
v6_0("6.0"),
2828
v6_1("6.1");
2929

30-
public static ServletApiVersion currentVersion = initServletApiVersion();
30+
public static final ServletApiVersion currentVersion = initServletApiVersion();
3131

32-
private static Logger LOG = LoggerFactory.getLogger(ServletApiVersion.class);
3332
private final String version;
3433
private final int major;
3534
private final int minor;
@@ -85,7 +84,7 @@ public static ServletApiVersion initServletApiVersion()
8584
}
8685
return ServletApiVersion.from(specificationVersion);
8786
}
88-
catch (ClassNotFoundException e)
87+
catch (ClassNotFoundException | NoClassDefFoundError e)
8988
{
9089
throw new IllegalStateException("Cannot detect servlet API version", e);
9190
}

jetty-ee/jetty-ee-common/src/main/java/org/eclipse/jetty/ee/common/WebsocketApiVersion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public enum WebsocketApiVersion
2626
v2_1("2.1"),
2727
v2_2("2.2");
2828

29-
public static WebsocketApiVersion currentVersion = initWebsocketApiVersion();
29+
public static final WebsocketApiVersion currentVersion = initWebsocketApiVersion();
3030

3131
private static Logger LOG = LoggerFactory.getLogger(WebsocketApiVersion.class);
3232
private final String version;
@@ -84,7 +84,7 @@ public static WebsocketApiVersion initWebsocketApiVersion()
8484
}
8585
return WebsocketApiVersion.from(specificationVersion);
8686
}
87-
catch (ClassNotFoundException e)
87+
catch (ClassNotFoundException | NoClassDefFoundError e)
8888
{
8989
throw new IllegalStateException("Cannot detect websocket API version", e);
9090
}

jetty-ee/jetty-ee-osgi/jetty-ee-osgi-boot/src/main/java/org/eclipse/jetty/ee/osgi/boot/EEActivator.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
import org.eclipse.jetty.ee.common.EnterpriseEditionVersion;
2425
import org.eclipse.jetty.ee.common.ServletApiVersion;
2526
import org.eclipse.jetty.ee.common.WebAppClassLoader;
2627
import org.eclipse.jetty.ee.webapp.Configuration;
@@ -55,11 +56,7 @@ public class EEActivator extends AbstractEEActivator
5556
{
5657
private static final Logger LOG = LoggerFactory.getLogger(EEActivator.class);
5758

58-
public static final String ENVIRONMENT = switch (ServletApiVersion.getServletApiVersion()){
59-
case v6_0 -> "ee10";
60-
case v6_1 -> "ee11";
61-
default -> null;
62-
};
59+
public static final String ENVIRONMENT = EnterpriseEditionVersion.getEnterpriseEditionVersion().name();
6360

6461
@Override
6562
public String getEnvironment()

jetty-ee/jetty-ee-servlet/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
requires static java.security.jgss;
3434
// Only required if using JDBCLoginService.
3535
requires static java.sql;
36+
requires org.eclipse.jetty.ee.common;
3637

3738
exports org.eclipse.jetty.ee.servlet;
3839
exports org.eclipse.jetty.ee.servlet.listener;

jetty-ee/jetty-ee-servlet/src/main/java/org/eclipse/jetty/ee/servlet/ServletContextHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import jakarta.servlet.http.HttpSessionBindingListener;
6969
import jakarta.servlet.http.HttpSessionIdListener;
7070
import jakarta.servlet.http.HttpSessionListener;
71+
import org.eclipse.jetty.ee.common.EnterpriseEditionVersion;
7172
import org.eclipse.jetty.ee.servlet.ServletContextResponse.EncodingFrom;
7273
import org.eclipse.jetty.ee.servlet.ServletContextResponse.OutputType;
7374
import org.eclipse.jetty.ee.servlet.security.ConstraintAware;
@@ -132,7 +133,7 @@
132133
public class ServletContextHandler extends ContextHandler
133134
{
134135
private static final Logger LOG = LoggerFactory.getLogger(ServletContextHandler.class);
135-
public static final Environment ENVIRONMENT = Environment.ensure("ee", ServletContextHandler.class);
136+
public static final Environment ENVIRONMENT = Environment.ensure(EnterpriseEditionVersion.getEnterpriseEditionVersion().name(), ServletContextHandler.class);
136137
/**
137138
* @deprecated Use {@link ServletContextHandler#ENVIRONMENT} instead.
138139
*/

jetty-ee/jetty-ee-webapp/src/main/java/org/eclipse/jetty/ee/webapp/WebDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static XmlParser newParser(boolean validating)
9797

9898
protected static void addDescriptorCatalog(XmlParser xmlParser) throws IllegalStateException
9999
{
100-
String catalogName = "catalog-%s.xml".formatted(ServletContextHandler.ENVIRONMENT.getName());
100+
String catalogName = "catalog-ee.xml";
101101
URL url = WebDescriptor.class.getResource(catalogName);
102102
if (url == null)
103103
throw new IllegalStateException("Catalog not found: %s/%s".formatted(WebDescriptor.class.getPackageName(), catalogName));

0 commit comments

Comments
 (0)