From: olivier lamy Date: Tue, 15 Aug 2017 09:55:54 +0000 (+1000) Subject: take care of too old repository X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2351414ee6698951bef41e8dee63b09a9754cf3f;p=archiva.git take care of too old repository Signed-off-by: olivier lamy --- diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java index 7ba503cfb..f7662ba25 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java @@ -46,6 +46,7 @@ import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; +import org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -638,24 +639,33 @@ public class DefaultManagedRepositoryAdmin if ( context == null ) { - context = indexer.addIndexingContext( repository.getId(), repository.getId(), repositoryDirectory, - indexDirectory, - repositoryDirectory.toURI().toURL().toExternalForm(), - indexDirectory.toURI().toURL().toString(), indexCreators ); + try + { + context = indexer.addIndexingContext( repository.getId(), repository.getId(), repositoryDirectory, + indexDirectory, + repositoryDirectory.toURI().toURL().toExternalForm(), + indexDirectory.toURI().toURL().toString(), indexCreators ); - context.setSearchable( repository.isScanned() ); + context.setSearchable( repository.isScanned() ); + } + catch ( IndexFormatTooOldException e ) + { + // existing index with an old lucene format so we need to delete it!!! + // delete it first then recreate it. + log.warn( "the index of repository {} is too old we have to delete and recreate it", // + repository.getId() ); + FileUtils.deleteDirectory( indexDirectory ); + context = indexer.addIndexingContext( repository.getId(), repository.getId(), repositoryDirectory, + indexDirectory, + repositoryDirectory.toURI().toURL().toExternalForm(), + indexDirectory.toURI().toURL().toString(), indexCreators ); + + context.setSearchable( repository.isScanned() ); + } } return context; } - catch ( MalformedURLException e ) - { - throw new RepositoryAdminException( e.getMessage(), e ); - } - catch ( IOException e ) - { - throw new RepositoryAdminException( e.getMessage(), e ); - } - catch ( UnsupportedExistingLuceneIndexException e ) + catch ( IOException| UnsupportedExistingLuceneIndexException e ) { throw new RepositoryAdminException( e.getMessage(), e ); } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java index bf8d88b18..01f733767 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java @@ -23,16 +23,19 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; import org.apache.archiva.admin.repository.AbstractRepositoryAdmin; +import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ProxyConnectorConfiguration; import org.apache.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.archiva.configuration.RepositoryCheckPath; import org.apache.archiva.metadata.model.facets.AuditEvent; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; +import org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; @@ -304,19 +307,28 @@ public class DefaultRemoteRepositoryAdmin { indexDirectory.mkdirs(); } - return indexer.addIndexingContext( contextKey, remoteRepository.getId(), repoDir, indexDirectory, - remoteRepository.getUrl(), calculateIndexRemoteUrl( remoteRepository ), - indexCreators ); - } - catch ( MalformedURLException e ) - { - throw new RepositoryAdminException( e.getMessage(), e ); - } - catch ( IOException e ) - { - throw new RepositoryAdminException( e.getMessage(), e ); + + try + { + + return indexer.addIndexingContext( contextKey, remoteRepository.getId(), repoDir, indexDirectory, + remoteRepository.getUrl(), calculateIndexRemoteUrl( remoteRepository ), + indexCreators ); + } + catch ( IndexFormatTooOldException e ) + { + // existing index with an old lucene format so we need to delete it!!! + // delete it first then recreate it. + log.warn( "the index of repository {} is too old we have to delete and recreate it", // + remoteRepository.getId() ); + FileUtils.deleteDirectory( indexDirectory ); + return indexer.addIndexingContext( contextKey, remoteRepository.getId(), repoDir, indexDirectory, + remoteRepository.getUrl(), calculateIndexRemoteUrl( remoteRepository ), + indexCreators ); + + } } - catch ( UnsupportedExistingLuceneIndexException e ) + catch ( IOException | UnsupportedExistingLuceneIndexException e ) { throw new RepositoryAdminException( e.getMessage(), e ); }