]> source.dussan.org Git - archiva.git/commitdiff
workaround the fact that load-on-start doesn't work with the spring integration ...
authorBrett Porter <brett@apache.org>
Fri, 14 Mar 2008 07:15:16 +0000 (07:15 +0000)
committerBrett Porter <brett@apache.org>
Fri, 14 Mar 2008 07:15:16 +0000 (07:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@637010 13f79535-47bb-0310-9956-ffa450edef68

springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaStartup.java
springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java
springy/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml
springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml
springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml

index 718db32f2021b1dce18ca38626c42006e6d231f3..ee508b3c9951f4f3d29e24c83f694cb7ccccd9f3 100644 (file)
@@ -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 <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  * @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 );
         }
-    }
+       }
 
 }
index aedde96ffc80ae1e7d3e850469adb1eec7c0b335..eab7e45dc90c907afbc3d3b2ae9b9bb10ad11245 100644 (file)
@@ -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 );
+       }
 }
index d03a07f82158e77a23938d83e8eff0faed406f84..8d42dcfd243441daf4ee3d3b2da501d79997e0e4 100644 (file)
   -->
 
 <plexus>
-  <load-on-start>
-    <component>
-      <role>org.apache.maven.archiva.web.startup.ArchivaStartup</role>
-      <role-hint>default</role-hint>
-    </component>
-    <component>
-      <role>org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor</role>
-      <role-hint>database-update</role-hint>
-    </component>
-    <component>
-      <role>org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor</role>
-      <role-hint>repository-scanning</role-hint>
-    </component>
-  </load-on-start>
-
   <components>
     <component>
       <role>org.codehaus.plexus.registry.Registry</role>
index c59a0c1090795d5f48e9c522a6e7afb6b042d562..f6b0fa81d33867469acbf81237bd3a5cbcb28926 100644 (file)
@@ -11,4 +11,4 @@
     <constructor-arg ref="cache#url-failures-cache" type="org.codehaus.plexus.cache.Cache"/>
   </bean>
 
-</beans>
\ No newline at end of file
+</beans>
index c67947e24df851edfa2e94080a85364c45dda5f2..82d730be37c9974a4391f84336fd2b3b6082314f 100644 (file)
   <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
+  <listener>
+    <!-- TODO: some Spring technique for this? -->
+       <listener-class>org.apache.maven.archiva.web.startup.ArchivaStartup</listener-class>
+  </listener>
 
   <context-param>
     <param-name>contextClass</param-name>