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 04f191cc09b5c4f513b61d7cd0f3b56a1e3379da Author: Juan Pablo Santos RodrÃguez <[email protected]> AuthorDate: Thu Dec 2 17:01:59 2021 +0100 Setup CachingManager inside WikiEngine --- .../src/main/java/org/apache/wiki/WikiEngine.java | 61 ++++++++++++---------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java index d620239..5d8b64a 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java @@ -33,6 +33,7 @@ import org.apache.wiki.auth.AuthorizationManager; import org.apache.wiki.auth.UserManager; import org.apache.wiki.auth.acl.AclManager; import org.apache.wiki.auth.authorize.GroupManager; +import org.apache.wiki.cache.CachingManager; import org.apache.wiki.content.PageRenamer; import org.apache.wiki.diff.DifferenceManager; import org.apache.wiki.event.WikiEngineEvent; @@ -96,7 +97,7 @@ import java.util.stream.Collectors; public class WikiEngine implements Engine { private static final String ATTR_WIKIENGINE = "org.apache.wiki.WikiEngine"; - private static final Logger log = LogManager.getLogger( WikiEngine.class ); + private static final Logger LOG = LogManager.getLogger( WikiEngine.class ); /** Stores properties. */ private Properties m_properties; @@ -185,7 +186,7 @@ public class WikiEngine implements Engine { context.setAttribute( ATTR_WIKIENGINE, engine ); } catch( final Exception e ) { context.log( "ERROR: Failed to create a Wiki engine: " + e.getMessage() ); - log.error( "ERROR: Failed to create a Wiki engine, stacktrace follows ", e ); + LOG.error( "ERROR: Failed to create a Wiki engine, stacktrace follows ", e ); throw new InternalWikiException( "No wiki engine, check logs.", e ); } } @@ -207,7 +208,7 @@ public class WikiEngine implements Engine { * Do not use this method - use WikiEngine.getInstance() instead. * * @param context A ServletContext. - * @param appid An Application ID. This application is an unique random string which is used to recognize this WikiEngine. + * @param appid An Application ID. This application is a unique random string which is used to recognize this WikiEngine. * @param props The WikiEngine configuration. * @throws WikiException If the WikiEngine construction fails. */ @@ -224,7 +225,7 @@ public class WikiEngine implements Engine { try { // Note: May be null, if JSPWiki has been deployed in a WAR file. initialize( props ); - log.info( "Root path for this Wiki is: '" + m_rootPath + "'" ); + LOG.info( "Root path for this Wiki is: '{}'", m_rootPath ); } catch( final Exception e ) { final String msg = Release.APPNAME+": Unable to load and setup properties from jspwiki.properties. "+e.getMessage(); if ( context != null ) { @@ -241,25 +242,25 @@ public class WikiEngine implements Engine { m_startTime = new Date(); m_properties = props; - log.info( "*******************************************" ); - log.info( Release.APPNAME + " " + Release.getVersionString() + " starting. Whee!" ); + LOG.info( "*******************************************" ); + LOG.info( "{} {} starting. Whee!", Release.APPNAME, Release.getVersionString() ); fireEvent( WikiEngineEvent.INITIALIZING ); // begin initialization - log.debug( "Java version: " + System.getProperty( "java.runtime.version" ) ); - log.debug( "Java vendor: " + System.getProperty( "java.vm.vendor" ) ); - log.debug( "OS: " + System.getProperty( "os.name" ) + " " + System.getProperty( "os.version" ) + " " + System.getProperty( "os.arch" ) ); - log.debug( "Default server locale: " + Locale.getDefault() ); - log.debug( "Default server timezone: " + TimeZone.getDefault().getDisplayName( true, TimeZone.LONG ) ); + LOG.debug( "Java version: {}", System.getProperty( "java.runtime.version" ) ); + LOG.debug( "Java vendor: {}", System.getProperty( "java.vm.vendor" ) ); + LOG.debug( "OS: {} {} {}", System.getProperty( "os.name" ), System.getProperty( "os.version" ), System.getProperty( "os.arch" ) ); + LOG.debug( "Default server locale: {}", Locale.getDefault() ); + LOG.debug( "Default server timezone: {}", TimeZone.getDefault().getDisplayName( true, TimeZone.LONG ) ); if( m_servletContext != null ) { - log.info( "Servlet container: " + m_servletContext.getServerInfo() ); + LOG.info( "Servlet container: {}", m_servletContext.getServerInfo() ); if( m_servletContext.getMajorVersion() < 3 || ( m_servletContext.getMajorVersion() == 3 && m_servletContext.getMinorVersion() < 1 ) ) { throw new InternalWikiException( "JSPWiki requires a container which supports at least version 3.1 of Servlet specification" ); } } - log.debug( "Configuring WikiEngine..." ); + LOG.debug( "Configuring WikiEngine..." ); // Create and find the default working directory. m_workDir = TextUtil.getStringProperty( props, PROP_WORKDIR, null ); @@ -289,11 +290,11 @@ public class WikiEngine implements Engine { throw new WikiException( "jspwiki.workDir does not point to a directory: " + m_workDir ); } } catch( final SecurityException e ) { - log.fatal( "Unable to find or create the working directory: "+m_workDir, e ); + LOG.fatal( "Unable to find or create the working directory: {}", m_workDir, e ); throw new IllegalArgumentException( "Unable to find or create the working dir: " + m_workDir, e ); } - log.info( "JSPWiki working directory is '" + m_workDir + "'" ); + LOG.info( "JSPWiki working directory is '{}'", m_workDir ); m_saveUserInfo = TextUtil.getBooleanProperty( props, PROP_STOREUSERNAME, m_saveUserInfo ); m_useUTF8 = StandardCharsets.UTF_8.name().equals( TextUtil.getStringProperty( props, PROP_ENCODING, StandardCharsets.ISO_8859_1.name() ) ); @@ -311,6 +312,7 @@ public class WikiEngine implements Engine { initComponent( CommandResolver.class, this, props ); initComponent( urlclass.getName(), URLConstructor.class ); + initComponent( CachingManager.class, this, props ); initComponent( PageManager.class, this, props ); initComponent( PluginManager.class, this, props ); initComponent( DifferenceManager.class, this, props ); @@ -335,8 +337,8 @@ public class WikiEngine implements Engine { // RenderingManager depends on FilterManager events. initComponent( RenderingManager.class ); - // ReferenceManager has the side effect of loading all pages. Therefore after this point, all page attributes are available. - // initReferenceManager is indirectly using m_filterManager, therefore it has to be called after it was initialized. + // ReferenceManager has the side effect of loading all pages. Therefore, after this point, all page attributes are available. + // initReferenceManager is indirectly using m_filterManager, so it has to be called after it was initialized. initReferenceManager(); // Hook the different manager routines into the system. @@ -344,20 +346,20 @@ public class WikiEngine implements Engine { getManager( FilterManager.class ).addPageFilter( getManager( SearchManager.class ), -1002 ); } catch( final RuntimeException e ) { // RuntimeExceptions may occur here, even if they shouldn't. - log.fatal( "Failed to start managers.", e ); + LOG.fatal( "Failed to start managers.", e ); throw new WikiException( "Failed to start managers: " + e.getMessage(), e ); } catch( final ClassNotFoundException e ) { - log.fatal( "JSPWiki could not start, URLConstructor was not found: " + e.getMessage(), e ); + LOG.fatal( "JSPWiki could not start, URLConstructor was not found: {}", e.getMessage(), e ); throw new WikiException( e.getMessage(), e ); } catch( final InstantiationException e ) { - log.fatal( "JSPWiki could not start, URLConstructor could not be instantiated: " + e.getMessage(), e ); + LOG.fatal( "JSPWiki could not start, URLConstructor could not be instantiated: {}", e.getMessage(), e ); throw new WikiException( e.getMessage(), e ); } catch( final IllegalAccessException e ) { - log.fatal( "JSPWiki could not start, URLConstructor cannot be accessed: " + e.getMessage(), e ); + LOG.fatal( "JSPWiki could not start, URLConstructor cannot be accessed: {}", e.getMessage(), e ); throw new WikiException( e.getMessage(), e ); } catch( final Exception e ) { // Final catch-all for everything - log.fatal( "JSPWiki could not start, due to an unknown exception when starting.",e ); + LOG.fatal( "JSPWiki could not start, due to an unknown exception when starting.", e ); throw new WikiException( "Failed to start. Caused by: " + e.getMessage() + "; please check log files for better information.", e ); } @@ -367,7 +369,7 @@ public class WikiEngine implements Engine { initComponent( RSSGenerator.class, this, props ); } } catch( final Exception e ) { - log.error( "Unable to start RSS generator - JSPWiki will still work, but there will be no RSS feed.", e ); + LOG.error( "Unable to start RSS generator - JSPWiki will still work, but there will be no RSS feed.", e ); } final Map< String, String > extraComponents = ClassUtil.getExtraClassMappings(); @@ -375,17 +377,17 @@ public class WikiEngine implements Engine { fireEvent( WikiEngineEvent.INITIALIZED ); // initialization complete - log.info( "WikiEngine configured." ); + LOG.info( "WikiEngine configured." ); m_isConfigured = true; } void initExtraComponents( final Map< String, String > extraComponents ) { for( final Map.Entry< String, String > extraComponent : extraComponents.entrySet() ) { try { - log.info( "Registering on WikiEngine " + extraComponent.getKey() + " as " + extraComponent.getValue() ); + LOG.info( "Registering on WikiEngine {} as {}", extraComponent.getKey(), extraComponent.getValue() ); initComponent( extraComponent.getKey(), Class.forName( extraComponent.getValue() ) ); } catch( final Exception e ) { - log.error( "Unable to start " + extraComponent.getKey(), e ); + LOG.error( "Unable to start {}", extraComponent.getKey(), e ); } } } @@ -451,11 +453,11 @@ public class WikiEngine implements Engine { final URL url = m_servletContext.getResource( viewTemplate ); exists = url != null && StringUtils.isNotEmpty( url.getFile() ); } catch( final MalformedURLException e ) { - log.warn( "template not found with viewTemplate " + viewTemplate ); + LOG.warn( "template not found with viewTemplate {}", viewTemplate ); } } if( !exists ) { - log.warn( getTemplateDir() + " template not found, updating WikiEngine's default template to " + DEFAULT_TEMPLATE_NAME ); + LOG.warn( "{} template not found, updating WikiEngine's default template to {}", getTemplateDir(), DEFAULT_TEMPLATE_NAME ); m_templateDir = DEFAULT_TEMPLATE_NAME; } } @@ -480,7 +482,7 @@ public class WikiEngine implements Engine { } } catch( final ProviderException e ) { - log.fatal("PageProvider is unable to list pages: ", e); + LOG.fatal( "PageProvider is unable to list pages: ", e ); } catch( final Exception e ) { throw new WikiException( "Could not instantiate ReferenceManager: " + e.getMessage(), e ); } @@ -642,6 +644,7 @@ public class WikiEngine implements Engine { */ @Override public void shutdown() { + getManager( CachingManager.class ).shutdown(); fireEvent( WikiEngineEvent.SHUTDOWN ); getManager( FilterManager.class ).destroy(); WikiEventManager.shutdown();
