You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2020/03/31 17:41:13 UTC
[jspwiki] 01/14: Move WikiSPIServletContextListener to new
jspwiki-bootstrap module
This is an automated email from the ASF dual-hosted git repository.
juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 9980e7a4eef9552c69f3229cb1f1b0f37e791da2
Author: juanpablo <ju...@apache.org>
AuthorDate: Tue Mar 31 19:12:36 2020 +0200
Move WikiSPIServletContextListener to new jspwiki-bootstrap module
this module will be responsible for the wiki's initial procedures:
* locating + and instantiating the Wiki SPI implementation to be used
* log configuration
preparing the migration to log4j2, log4j loads only if present on classpath (which, right now, is always)
---
.../api/spi/WikiSPIServletContextListener.java | 20 -----
.../test/java/org/apache/wiki/api/ReleaseTest.java | 0
jspwiki-bootstrap/pom.xml | 92 ++++++++++++++++++++++
.../bootstrap/WikiSPIServletContextListener.java | 75 ++++++++++++++++++
.../java/org/apache/wiki/bootstrap/package.html | 42 ++++++++++
.../WikiSPIServletContextListenerTest.java | 65 +++++++++++++++
.../apache/wiki/bootstrap/spi/AclsSPITestImpl.java | 20 +++++
.../wiki/bootstrap/spi/ContentsSPITestImpl.java | 21 +++++
.../wiki/bootstrap/spi/ContextSPITestImpl.java | 34 ++++++++
.../wiki/bootstrap/spi/EngineSPITestImpl.java | 16 ++++
.../wiki/bootstrap/spi/SessionSPITestImpl.java | 26 ++++++
.../services/org.apache.wiki.api.spi.AclsSPI | 1 +
.../services/org.apache.wiki.api.spi.ContentsSPI | 1 +
.../services/org.apache.wiki.api.spi.ContextSPI | 1 +
.../services/org.apache.wiki.api.spi.EngineSPI | 1 +
.../services/org.apache.wiki.api.spi.SessionSPI | 1 +
.../src/test/resources/ini/jspwiki.properties | 5 ++
17 files changed, 401 insertions(+), 20 deletions(-)
diff --git a/jspwiki-api/src/main/java/org/apache/wiki/api/spi/WikiSPIServletContextListener.java b/jspwiki-api/src/main/java/org/apache/wiki/api/spi/WikiSPIServletContextListener.java
deleted file mode 100644
index 233aac9..0000000
--- a/jspwiki-api/src/main/java/org/apache/wiki/api/spi/WikiSPIServletContextListener.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.wiki.api.spi;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-
-public class WikiSPIServletContextListener implements ServletContextListener {
-
- /** {@inheritDoc} */
- @Override
- public void contextInitialized( final ServletContextEvent sce ) {
- Wiki.init( sce.getServletContext() );
- }
-
- /** {@inheritDoc} */
- @Override
- public void contextDestroyed( final ServletContextEvent sce ) {
- }
-
-}
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/api/ReleaseTest.java b/jspwiki-api/src/test/java/org/apache/wiki/api/ReleaseTest.java
similarity index 100%
rename from jspwiki-main/src/test/java/org/apache/wiki/api/ReleaseTest.java
rename to jspwiki-api/src/test/java/org/apache/wiki/api/ReleaseTest.java
diff --git a/jspwiki-bootstrap/pom.xml b/jspwiki-bootstrap/pom.xml
new file mode 100644
index 0000000..480a7f2
--- /dev/null
+++ b/jspwiki-bootstrap/pom.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.apache.jspwiki</groupId>
+ <artifactId>jspwiki-builder</artifactId>
+ <version>2.11.0.M7-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jspwiki-bootstrap</artifactId>
+ <name>Apache JSPWiki bootstrapping procedures</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jspwiki-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jspwiki-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>javax.servlet.jsp-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/jspwiki-bootstrap/src/main/java/org/apache/wiki/bootstrap/WikiSPIServletContextListener.java b/jspwiki-bootstrap/src/main/java/org/apache/wiki/bootstrap/WikiSPIServletContextListener.java
new file mode 100644
index 0000000..172c140
--- /dev/null
+++ b/jspwiki-bootstrap/src/main/java/org/apache/wiki/bootstrap/WikiSPIServletContextListener.java
@@ -0,0 +1,75 @@
+/*
+ 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.wiki.bootstrap;
+
+import org.apache.log4j.PropertyConfigurator;
+import org.apache.wiki.api.spi.Wiki;
+import org.apache.wiki.util.ClassUtil;
+import org.apache.wiki.util.TextUtil;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import java.util.Properties;
+
+
+public class WikiSPIServletContextListener implements ServletContextListener {
+
+ /** {@inheritDoc} */
+ @Override
+ public void contextInitialized( final ServletContextEvent sce ) {
+ final Properties properties = initWikiSPIs( sce );
+ initWikiLoggingFramework( properties );
+ }
+
+ /**
+ * Locate and init JSPWiki SPIs' implementations
+ *
+ * @param sce associated servlet context.
+ * @return JSPWiki configuration properties.
+ */
+ Properties initWikiSPIs( final ServletContextEvent sce ) {
+ return Wiki.init( sce.getServletContext() );
+ }
+
+ /**
+ * Initialize the logging framework(s). By default we try to load the log config statements from jspwiki.properties,
+ * unless the property jspwiki.use.external.logconfig=true, in that case we let the logging framework figure out the
+ * logging configuration.
+ *
+ * <p>For Log4J, we only try to initialize it if its present on classpath</p>
+ *
+ * @param properties JSPWiki configuration properties.
+ * @return {@code true} if configuration was read from jspwiki.properties, {@code false} otherwise.
+ */
+ boolean initWikiLoggingFramework( final Properties properties ) {
+ final String useExternalLogConfig = TextUtil.getStringProperty( properties,"jspwiki.use.external.logconfig","false" );
+ if( useExternalLogConfig.equals( "false" ) ) {
+ if( ClassUtil.exists( "org.apache.log4j.Logger" ) ) {
+ PropertyConfigurator.configure( properties );
+ }
+ }
+ return useExternalLogConfig.equals( "false" );
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void contextDestroyed( final ServletContextEvent sce ) {
+ }
+
+}
diff --git a/jspwiki-bootstrap/src/main/java/org/apache/wiki/bootstrap/package.html b/jspwiki-bootstrap/src/main/java/org/apache/wiki/bootstrap/package.html
new file mode 100644
index 0000000..29d351d
--- /dev/null
+++ b/jspwiki-bootstrap/src/main/java/org/apache/wiki/bootstrap/package.html
@@ -0,0 +1,42 @@
+<!--
+ 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.
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>JSPWiki's Bootstrapping facilities</title>
+</head>
+<body>
+JSPWiki's Bootstrapping procedures package.
+
+This package holds all the classes needed to bootstrap JSPWiki, prior to Engine creation:
+<ul>
+ <li>JSPWiki's SPIs implementation location</li>
+ <li>Log configuration</li>
+</ul>
+
+All of these tasks are done through a dedicated Servlet Context Listener.
+
+<h3>Package Specification</h3>
+
+<h3>Related Documentation</h3>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/WikiSPIServletContextListenerTest.java b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/WikiSPIServletContextListenerTest.java
new file mode 100644
index 0000000..7193f46
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/WikiSPIServletContextListenerTest.java
@@ -0,0 +1,65 @@
+/*
+ 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.wiki.bootstrap;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import java.util.Properties;
+
+
+@ExtendWith( MockitoExtension.class )
+public class WikiSPIServletContextListenerTest {
+
+ @Mock
+ ServletContext sc;
+
+ @Test
+ public void testWikiInit() {
+ final ServletContextEvent sce = new ServletContextEvent( sc );
+ final WikiSPIServletContextListener listener = new WikiSPIServletContextListener();
+ final Properties properties = listener.initWikiSPIs( sce );
+
+ Assertions.assertEquals( 5, properties.size() );
+ }
+
+ @Test
+ public void testLoggingFrameworkInit() {
+ final WikiSPIServletContextListener listener = new WikiSPIServletContextListener();
+ final Properties properties = new Properties();
+
+ Assertions.assertTrue( listener.initWikiLoggingFramework( properties ) );
+ properties.setProperty( "jspwiki.use.external.logconfig", "true" );
+ Assertions.assertFalse( listener.initWikiLoggingFramework( properties ) );
+ }
+
+ @Test
+ public void testServletContextListenerLifeCycle() {
+ final ServletContextEvent sce = new ServletContextEvent( sc );
+ final WikiSPIServletContextListener listener = new WikiSPIServletContextListener();
+ Assertions.assertDoesNotThrow( () -> listener.contextInitialized( sce ) );
+ Assertions.assertDoesNotThrow( () -> listener.contextDestroyed( sce ) );
+ }
+
+}
diff --git a/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/AclsSPITestImpl.java b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/AclsSPITestImpl.java
new file mode 100644
index 0000000..f9c9766
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/AclsSPITestImpl.java
@@ -0,0 +1,20 @@
+package org.apache.wiki.bootstrap.spi;
+
+import org.apache.wiki.api.core.Acl;
+import org.apache.wiki.api.core.AclEntry;
+import org.apache.wiki.api.spi.AclsSPI;
+
+
+public class AclsSPITestImpl implements AclsSPI {
+
+ @Override
+ public Acl acl() {
+ return null;
+ }
+
+ @Override
+ public AclEntry entry() {
+ return null;
+ }
+
+}
diff --git a/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/ContentsSPITestImpl.java b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/ContentsSPITestImpl.java
new file mode 100644
index 0000000..4f14dfa
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/ContentsSPITestImpl.java
@@ -0,0 +1,21 @@
+package org.apache.wiki.bootstrap.spi;
+
+import org.apache.wiki.api.core.Attachment;
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.core.Page;
+import org.apache.wiki.api.spi.ContentsSPI;
+
+
+public class ContentsSPITestImpl implements ContentsSPI {
+
+ @Override
+ public Attachment attachment( final Engine engine, final String parentPage, final String fileName ) {
+ return null;
+ }
+
+ @Override
+ public Page page( final Engine engine, final String name ) {
+ return null;
+ }
+
+}
diff --git a/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/ContextSPITestImpl.java b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/ContextSPITestImpl.java
new file mode 100644
index 0000000..3b4caa9
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/ContextSPITestImpl.java
@@ -0,0 +1,34 @@
+package org.apache.wiki.bootstrap.spi;
+
+import org.apache.wiki.api.core.Command;
+import org.apache.wiki.api.core.Context;
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.core.Page;
+import org.apache.wiki.api.spi.ContextSPI;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+public class ContextSPITestImpl implements ContextSPI {
+
+ @Override
+ public Context create( final Engine engine, final Page page ) {
+ return null;
+ }
+
+ @Override
+ public Context create( final Engine engine, final HttpServletRequest request, final Command command ) {
+ return null;
+ }
+
+ @Override
+ public Context create( final Engine engine, final HttpServletRequest request, final Page page ) {
+ return null;
+ }
+
+ @Override
+ public Context create( final Engine engine, final HttpServletRequest request, final String requestContext ) {
+ return null;
+ }
+
+}
diff --git a/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/EngineSPITestImpl.java b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/EngineSPITestImpl.java
new file mode 100644
index 0000000..6c45c71
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/EngineSPITestImpl.java
@@ -0,0 +1,16 @@
+package org.apache.wiki.bootstrap.spi;
+
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.spi.EngineSPI;
+
+import javax.servlet.ServletContext;
+import java.util.Properties;
+
+
+public class EngineSPITestImpl implements EngineSPI {
+
+ @Override
+ public Engine find( final ServletContext context, final Properties props ) {
+ return null;
+ }
+}
diff --git a/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/SessionSPITestImpl.java b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/SessionSPITestImpl.java
new file mode 100644
index 0000000..48848cd
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/java/org/apache/wiki/bootstrap/spi/SessionSPITestImpl.java
@@ -0,0 +1,26 @@
+package org.apache.wiki.bootstrap.spi;
+
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.core.Session;
+import org.apache.wiki.api.spi.SessionSPI;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+public class SessionSPITestImpl implements SessionSPI {
+
+ @Override
+ public void remove( final Engine engine, final HttpServletRequest request ) {
+
+ }
+
+ @Override
+ public Session find( final Engine engine, final HttpServletRequest request ) {
+ return null;
+ }
+
+ @Override
+ public Session guest( final Engine engine ) {
+ return null;
+ }
+}
diff --git a/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.AclsSPI b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.AclsSPI
new file mode 100644
index 0000000..a93fecc
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.AclsSPI
@@ -0,0 +1 @@
+org.apache.wiki.bootstrap.spi.AclsSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContentsSPI b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContentsSPI
new file mode 100644
index 0000000..6a070b3
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContentsSPI
@@ -0,0 +1 @@
+org.apache.wiki.bootstrap.spi.ContentsSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContextSPI b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContextSPI
new file mode 100644
index 0000000..79f6b80
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContextSPI
@@ -0,0 +1 @@
+org.apache.wiki.bootstrap.spi.ContextSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.EngineSPI b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.EngineSPI
new file mode 100644
index 0000000..dfb923c
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.EngineSPI
@@ -0,0 +1 @@
+org.apache.wiki.bootstrap.spi.EngineSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.SessionSPI b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.SessionSPI
new file mode 100644
index 0000000..060877d
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/resources/META-INF/services/org.apache.wiki.api.spi.SessionSPI
@@ -0,0 +1 @@
+org.apache.wiki.bootstrap.spi.SessionSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-bootstrap/src/test/resources/ini/jspwiki.properties b/jspwiki-bootstrap/src/test/resources/ini/jspwiki.properties
new file mode 100644
index 0000000..ee5bae0
--- /dev/null
+++ b/jspwiki-bootstrap/src/test/resources/ini/jspwiki.properties
@@ -0,0 +1,5 @@
+jspwiki.provider.impl.acls=org.apache.wiki.bootstrap.spi.AclsSPITestImpl
+jspwiki.provider.impl.contents=org.apache.wiki.bootstrap.spi.ContentsSPITestImpl
+jspwiki.provider.impl.context=org.apache.wiki.bootstrap.spi.ContextSPITestImpl
+jspwiki.provider.impl.engine=org.apache.wiki.bootstrap.spi.EngineSPITestImpl
+jspwiki.provider.impl.session=org.apache.wiki.bootstrap.spi.SessionSPITestImpl
\ No newline at end of file