From 0b94298d7cdb44c41203077c40a1ffc233d36378 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 3 Nov 2011 23:45:37 +0000 Subject: [PATCH] ensure we cleanup Maven IndexingContext on shutdown git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197355 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-rest-services/pom.xml | 2 +- .../services/utils/MavenIndexerCleaner.java | 54 +++++++++++++++++++ .../META-INF/spring-context-test.xml | 17 ++++-- 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/MavenIndexerCleaner.java diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml index 6c2331e29..e7724a178 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml @@ -29,7 +29,7 @@ Archiva Web :: REST support :: Services - + 7.0.21 false diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/MavenIndexerCleaner.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/MavenIndexerCleaner.java new file mode 100644 index 000000000..c2453c8eb --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/MavenIndexerCleaner.java @@ -0,0 +1,54 @@ +package org.apache.archiva.rest.services.utils; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; +import org.apache.maven.index.NexusIndexer; +import org.apache.maven.index.context.IndexingContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +/** + * @author Olivier Lamy + */ +@Service +public class MavenIndexerCleaner +{ + Logger log = LoggerFactory.getLogger( getClass() ); + + @Inject + private PlexusSisuBridge plexusSisuBridge; + + @PreDestroy + public void shutdown() + throws Exception + { + + log.info( "cleanup IndexingContext" ); + NexusIndexer nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); + for ( IndexingContext context : nexusIndexer.getIndexingContexts().values() ) + { + nexusIndexer.removeIndexingContext( context, true ); + } + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml index c96d355c2..5e0337b10 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml @@ -20,8 +20,18 @@ --> + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.0.xsd + http://cxf.apache.org/jaxrs + http://cxf.apache.org/schemas/jaxrs.xsd" default-lazy-init="true"> + + + @@ -36,7 +46,7 @@ - + @@ -57,7 +67,8 @@ - + -- 2.39.5