]> source.dussan.org Git - archiva.git/commitdiff
take care of too old repository
authorolivier lamy <olamy@apache.org>
Tue, 15 Aug 2017 09:55:54 +0000 (19:55 +1000)
committerolivier lamy <olamy@apache.org>
Tue, 15 Aug 2017 09:55:54 +0000 (19:55 +1000)
Signed-off-by: olivier lamy <olamy@apache.org>
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java

index 7ba503cfb5e87774533557a5adb2f5c51f29f40d..f7662ba255febcb9f12022e4681defedc03630ff 100644 (file)
@@ -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 );
         }
index bf8d88b1873faf2e379873c98e2086660c8c36c3..01f733767d4d64af97deb80003b0c1dd988f3929 100644 (file)
@@ -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 );
         }