From: Brett Porter Date: Fri, 14 Mar 2008 07:15:16 +0000 (+0000) Subject: workaround the fact that load-on-start doesn't work with the spring integration ... X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4da871b7f9961a4f5e169e782587cabc22eaa3ca;p=archiva.git workaround the fact that load-on-start doesn't work with the spring integration (and this is better anyway) git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@637010 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaStartup.java b/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaStartup.java index 718db32f2..ee508b3c9 100644 --- a/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaStartup.java +++ b/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaStartup.java @@ -19,56 +19,54 @@ package org.apache.maven.archiva.web.startup; * under the License. */ +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.ServletException; + import org.apache.maven.archiva.common.ArchivaException; import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.codehaus.plexus.spring.PlexusToSpringUtils; +import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor; +import org.mortbay.jetty.webapp.WebAppContext; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; /** * ArchivaStartup - the startup of all archiva features in a deterministic order. * * @author Joakim Erdfelt * @version $Id$ - * - * @plexus.component - * role="org.apache.maven.archiva.web.startup.ArchivaStartup" - * role-hint="default" */ public class ArchivaStartup - extends AbstractLogEnabled - implements Initializable + implements ServletContextListener { - /** - * @plexus.requirement role-hint="default" - */ - private SecuritySynchronization securitySync; - - /** - * @plexus.requirement role-hint="default" - */ - private ResolverFactoryInit resolverFactory; - - /** - * @plexus.requirement role-hint="default" - */ - private ArchivaTaskScheduler taskScheduler; + public void contextDestroyed(ServletContextEvent arg0) { + } - public void initialize() - throws InitializationException - { - Banner.display( getLogger(), ArchivaVersion.determineVersion( this.getClass().getClassLoader() ) ); + public void contextInitialized(ServletContextEvent arg0) { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(arg0.getServletContext()); + + SecuritySynchronization securitySync = (SecuritySynchronization) wac.getBean(PlexusToSpringUtils.buildSpringId(SecuritySynchronization.class)); + ResolverFactoryInit resolverFactory = (ResolverFactoryInit) wac.getBean(PlexusToSpringUtils.buildSpringId(ResolverFactoryInit.class)); + ArchivaTaskScheduler taskScheduler = (ArchivaTaskScheduler) wac.getBean(PlexusToSpringUtils.buildSpringId(ArchivaTaskScheduler.class)); + TaskQueueExecutor databaseUpdateQueue = (TaskQueueExecutor) wac.getBean(PlexusToSpringUtils.buildSpringId(TaskQueueExecutor.class, "database-update")); + TaskQueueExecutor repositoryScanningQueue = (TaskQueueExecutor) wac.getBean(PlexusToSpringUtils.buildSpringId(TaskQueueExecutor.class, "repository-scanning")); + Banner banner = (Banner) wac.getBean(PlexusToSpringUtils.buildSpringId(Banner.class)); - try + try { securitySync.startup(); resolverFactory.startup(); taskScheduler.startup(); + banner.display(); } catch ( ArchivaException e ) { - throw new InitializationException( "Unable to properly startup archiva: " + e.getMessage(), e ); + throw new RuntimeException( "Unable to properly startup archiva: " + e.getMessage(), e ); } - } + } } diff --git a/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java b/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java index aedde96ff..eab7e45dc 100644 --- a/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java +++ b/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java @@ -224,15 +224,8 @@ public class Banner return injectVersion( decode( encodedBanner ), version ); } - public static void display( Logger logger, String version ) - { - String banner = getBanner( version ); - logger.info( StringUtils.repeat( "_", 25 ) + "\n" + banner ); - } - - public void initialize() - throws InitializationException - { - Banner.display( getLogger(), ArchivaVersion.determineVersion( this.getClass().getClassLoader() ) ); - } + public void display() { + String banner = getBanner( ArchivaVersion.determineVersion( this.getClass().getClassLoader() ) ); + getLogger().info( StringUtils.repeat( "_", 25 ) + "\n" + banner ); + } } diff --git a/springy/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml b/springy/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml index d03a07f82..8d42dcfd2 100644 --- a/springy/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml +++ b/springy/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml @@ -19,21 +19,6 @@ --> - - - org.apache.maven.archiva.web.startup.ArchivaStartup - default - - - org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor - database-update - - - org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor - repository-scanning - - - org.codehaus.plexus.registry.Registry diff --git a/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml b/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml index c59a0c109..f6b0fa81d 100644 --- a/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml +++ b/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml @@ -11,4 +11,4 @@ - \ No newline at end of file + diff --git a/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml b/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml index c67947e24..82d730be3 100644 --- a/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml +++ b/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml @@ -58,6 +58,10 @@ org.springframework.web.context.ContextLoaderListener + + + org.apache.maven.archiva.web.startup.ArchivaStartup + contextClass