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.lucene.store.Lock;
23 import org.apache.lucene.store.LockReleaseFailedException;
24 import org.apache.lucene.store.NativeFSLockFactory;
25 import org.apache.maven.index.NexusIndexer;
26 import org.apache.maven.index.context.IndexingContext;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.context.ApplicationContext;
30 import org.springframework.stereotype.Service;
31 import org.springframework.web.context.WebApplicationContext;
32 import org.springframework.web.context.support.WebApplicationContextUtils;
34 import javax.annotation.PostConstruct;
35 import javax.annotation.PreDestroy;
36 import javax.inject.Inject;
37 import javax.servlet.ServletContextEvent;
38 import javax.servlet.ServletContextListener;
42 * @author Olivier Lamy
45 public class MavenIndexerCleaner
46 implements ServletContextListener
48 Logger log = LoggerFactory.getLogger( getClass() );
51 private PlexusSisuBridge plexusSisuBridge;
54 private ApplicationContext applicationContext;
60 plexusSisuBridge = applicationContext.getBean( PlexusSisuBridge.class );
65 public void shutdown()
72 public void contextInitialized( ServletContextEvent servletContextEvent )
76 WebApplicationContext wacu =
77 WebApplicationContextUtils.getRequiredWebApplicationContext( servletContextEvent.getServletContext() );
78 plexusSisuBridge = wacu.getBean( PlexusSisuBridge.class );
84 log.error( e.getMessage(), e );
85 throw new RuntimeException( e.getMessage(), e );
89 public void contextDestroyed( ServletContextEvent servletContextEvent )
98 log.error( e.getMessage(), e );
99 throw new RuntimeException( e.getMessage(), e );
103 public void cleanupIndex()
106 log.info( "cleanup IndexingContext" );
107 NexusIndexer nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
108 for ( IndexingContext context : nexusIndexer.getIndexingContexts().values() )
110 nexusIndexer.removeIndexingContext( context, true );