Skip to content

Commit

Permalink
Merge pull request psi-probe#3246 from hazendaz/master
Browse files Browse the repository at this point in the history
Port some tomcat 10/11 changes forwards
  • Loading branch information
hazendaz authored Apr 24, 2024
2 parents fa7582e + aa070c4 commit 916031f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,10 @@
<enforceBytecodeVersion>
<maxJdkVersion>${java.version}</maxJdkVersion>
<ignoredScopes>test</ignoredScopes>
<excludes>
<!-- Openssl contains panama for jdk 22 or higher if enabled via listener 'org.apache.catalina.core.OpenSSLLifecycleListener' -->
<exclude>org.apache.tomcat:tomcat-coyote</exclude>
</excludes>
</enforceBytecodeVersion>
<requireJavaVersion>
<version>[17,18),[21,22),[22,23),[23,24)</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.catalina.WebResource;
import org.apache.catalina.WebResourceRoot;
import org.apache.catalina.deploy.NamingResourcesImpl;
import org.apache.jasper.EmbeddedServletOptions;
import org.apache.jasper.JspCompilationContext;
import org.apache.tomcat.util.descriptor.web.ApplicationParameter;
import org.apache.tomcat.util.descriptor.web.ContextResource;
Expand All @@ -55,6 +56,10 @@ class Tomcat10ContainerAdapterTest {
@Mock
Context context;

// * The embedded servlet options. */
@Mock
EmbeddedServletOptions options;

/**
* Creates the valve.
*/
Expand Down Expand Up @@ -112,8 +117,9 @@ void filterMappings() {
@Test
void createJspCompilationContext() {
final Tomcat10ContainerAdapter adapter = new Tomcat10ContainerAdapter();
JspCompilationContext jspContext = adapter.createJspCompilationContext("name", null, null, null,
ClassLoader.getSystemClassLoader());
Mockito.when(this.options.getGeneratedJspPackageName()).thenReturn("org.apache.jsp");
JspCompilationContext jspContext = adapter.createJspCompilationContext("name", this.options,
null, null, ClassLoader.getSystemClassLoader());
assertEquals("org.apache.jsp.name", jspContext.getFQCN());
}

Expand Down
4 changes: 0 additions & 4 deletions psi-probe-tomcat11/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@

<properties>
<tomcat.version>11.0.0-M19</tomcat.version>

<!-- Java Settings -->
<java.version>21</java.version>
<java.release.version>21</java.release.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.catalina.WebResource;
import org.apache.catalina.WebResourceRoot;
import org.apache.catalina.deploy.NamingResourcesImpl;
import org.apache.jasper.EmbeddedServletOptions;
import org.apache.jasper.JspCompilationContext;
import org.apache.tomcat.util.descriptor.web.ApplicationParameter;
import org.apache.tomcat.util.descriptor.web.ContextResource;
Expand Down Expand Up @@ -56,6 +57,10 @@ class Tomcat11ContainerAdapterTest {
@Mock
Context context;

// * The embedded servlet options. */
@Mock
EmbeddedServletOptions options;

/**
* Creates the valve.
*/
Expand Down Expand Up @@ -90,7 +95,8 @@ void canBoundToTomcat11() {
// TODO Not yet supported
@Disabled
@ParameterizedTest
@ValueSource(strings = {"Apache Tomcat (TomEE)/11.0", "NonStop(tm) Servlets For JavaServer Pages(tm) v11.0", "Vmware tc..../11.0"})
@ValueSource(strings = {"Apache Tomcat (TomEE)/11.0",
"NonStop(tm) Servlets For JavaServer Pages(tm) v11.0", "Vmware tc..../11.0"})
void canBoundTo(String container) {
final Tomcat11ContainerAdapter adapter = new Tomcat11ContainerAdapter();
assertTrue(adapter.canBoundTo(container));
Expand Down Expand Up @@ -123,8 +129,9 @@ void filterMappings() {
@Test
void createJspCompilationContext() {
final Tomcat11ContainerAdapter adapter = new Tomcat11ContainerAdapter();
JspCompilationContext jspContext = adapter.createJspCompilationContext("name", null, null, null,
ClassLoader.getSystemClassLoader());
Mockito.when(this.options.getGeneratedJspPackageName()).thenReturn("org.apache.jsp");
JspCompilationContext jspContext = adapter.createJspCompilationContext("name", this.options,
null, null, ClassLoader.getSystemClassLoader());
assertEquals("org.apache.jsp.name", jspContext.getFQCN());
}

Expand All @@ -136,7 +143,7 @@ void addContextResourceLink() {
NamingResourcesImpl namingResources = Mockito.mock(NamingResourcesImpl.class);
Mockito.when(context.getNamingResources()).thenReturn(namingResources);
Mockito.when(namingResources.findResourceLinks())
.thenReturn(new ContextResourceLink[]{new ContextResourceLink()});
.thenReturn(new ContextResourceLink[] {new ContextResourceLink()});

final Tomcat11ContainerAdapter adapter = new Tomcat11ContainerAdapter();
final List<ApplicationResource> list = new ArrayList<ApplicationResource>();
Expand All @@ -152,7 +159,7 @@ void addContextResource() {
NamingResourcesImpl namingResources = Mockito.mock(NamingResourcesImpl.class);
Mockito.when(context.getNamingResources()).thenReturn(namingResources);
Mockito.when(namingResources.findResources())
.thenReturn(new ContextResource[]{new ContextResource()});
.thenReturn(new ContextResource[] {new ContextResource()});

final Tomcat11ContainerAdapter adapter = new Tomcat11ContainerAdapter();
final List<ApplicationResource> list = new ArrayList<ApplicationResource>();
Expand All @@ -165,7 +172,7 @@ void addContextResource() {
*/
@Test
void applicationFilterMaps() {
Mockito.when(context.findFilterMaps()).thenReturn(new FilterMap[]{new FilterMap()});
Mockito.when(context.findFilterMaps()).thenReturn(new FilterMap[] {new FilterMap()});

final Tomcat11ContainerAdapter adapter = new Tomcat11ContainerAdapter();
assertEquals(0, adapter.getApplicationFilterMaps(context).size());
Expand All @@ -176,7 +183,7 @@ void applicationFilterMaps() {
*/
@Test
void applicationFilters() {
Mockito.when(context.findFilterDefs()).thenReturn(new FilterDef[]{new FilterDef()});
Mockito.when(context.findFilterDefs()).thenReturn(new FilterDef[] {new FilterDef()});

final Tomcat11ContainerAdapter adapter = new Tomcat11ContainerAdapter();
assertEquals(1, adapter.getApplicationFilters(context).size());
Expand All @@ -188,7 +195,7 @@ void applicationFilters() {
@Test
void applicationInitParams() {
Mockito.when(context.findApplicationParameters())
.thenReturn(new ApplicationParameter[]{new ApplicationParameter()});
.thenReturn(new ApplicationParameter[] {new ApplicationParameter()});

ServletContext servletContext = Mockito.mock(ServletContext.class);
Mockito.when(context.getServletContext()).thenReturn(servletContext);
Expand Down

0 comments on commit 916031f

Please sign in to comment.