1 package org.apache.archiva.webdav.util;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
22 import org.apache.maven.index.NexusIndexer;
23 import org.apache.maven.index.context.IndexingContext;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.context.ApplicationContext;
27 import org.springframework.stereotype.Service;
28 import org.springframework.web.context.WebApplicationContext;
29 import org.springframework.web.context.support.WebApplicationContextUtils;
31 import javax.annotation.PostConstruct;
32 import javax.annotation.PreDestroy;
33 import javax.inject.Inject;
34 import javax.servlet.ServletContextEvent;
35 import javax.servlet.ServletContextListener;
38 * @author Olivier Lamy
41 public class MavenIndexerCleaner
42 implements ServletContextListener
44 Logger log = LoggerFactory.getLogger( getClass() );
47 private PlexusSisuBridge plexusSisuBridge;
50 private ApplicationContext applicationContext;
53 public void startup() throws Exception
55 plexusSisuBridge = applicationContext.getBean( PlexusSisuBridge.class );
60 public void shutdown()
67 public void contextInitialized( ServletContextEvent servletContextEvent )
71 WebApplicationContext wacu =
72 WebApplicationContextUtils.getRequiredWebApplicationContext( servletContextEvent.getServletContext() );
73 plexusSisuBridge = wacu.getBean( PlexusSisuBridge.class );
79 log.error( e.getMessage(), e );
80 throw new RuntimeException( e.getMessage(), e );
84 public void contextDestroyed( ServletContextEvent servletContextEvent )
93 log.error( e.getMessage(), e );
94 throw new RuntimeException( e.getMessage(), e );
98 public void cleanupIndex( )
101 log.info( "cleanup IndexingContext" );
102 NexusIndexer nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
103 for ( IndexingContext context : nexusIndexer.getIndexingContexts().values() )
105 nexusIndexer.removeIndexingContext( context, true );