1 package org.apache.archiva.indexer.merger;
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.archiva.common.plexusbridge.PlexusSisuBridgeException;
23 import org.apache.maven.index.NexusIndexer;
24 import org.apache.maven.index.context.IndexingContext;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.scheduling.annotation.Scheduled;
28 import org.springframework.stereotype.Service;
30 import javax.inject.Inject;
31 import java.io.IOException;
32 import java.util.Date;
35 * @author Olivier Lamy
39 public class TemporaryGroupIndexCleaner
41 private Logger log = LoggerFactory.getLogger( getClass() );
44 private IndexMerger indexMerger;
46 private NexusIndexer indexer;
49 public TemporaryGroupIndexCleaner( PlexusSisuBridge plexusSisuBridge )
50 throws PlexusSisuBridgeException
52 indexer = plexusSisuBridge.lookup( NexusIndexer.class );
56 @Scheduled( fixedDelay = 900000 )
57 public void cleanTemporaryIndex()
59 for ( TemporaryGroupIndex temporaryGroupIndex : indexMerger.getTemporaryGroupIndexes() )
61 // cleanup files older than 60 minutes 3600000
62 if ( new Date().getTime() - temporaryGroupIndex.getCreationTime() > 3600000 )
66 IndexingContext context = indexer.getIndexingContexts().get( temporaryGroupIndex.getIndexId() );
67 if ( context != null )
69 indexer.removeIndexingContext( context, true );
73 indexMerger.cleanTemporaryGroupIndex( temporaryGroupIndex );
75 indexMerger.getTemporaryGroupIndexes().remove( temporaryGroupIndex );
76 log.debug( "remove directory {}", temporaryGroupIndex.getDirectory() );
78 catch ( IOException e )
80 log.warn( "failed to remove directory:" + temporaryGroupIndex.getDirectory(), e );