/** * Resets the indexing context of a given repository. * * @param repo * @throws IndexUpdateFailedException */ @SuppressWarnings( "unchecked" ) public void resetIndexingContext(Repository repo) throws IndexUpdateFailedException { if (repo.hasIndex() && repo instanceof EditableRepository) { EditableRepository eRepo = (EditableRepository) repo; ArchivaIndexingContext newCtx = getIndexManager(repo.getType()).reset(repo.getIndexingContext()); eRepo.setIndexingContext(newCtx); } }
@Override public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException { ArchivaIndexingContext ctx; executeUpdateFunction(context, indexingContext -> { try { indexingContext.close(true); } catch (IOException e) { log.warn("Index close failed"); } try { FileUtils.deleteDirectory(Paths.get(context.getPath())); } catch (IOException e) { throw new IndexUpdateFailedException("Could not delete index files"); } }); try { Repository repo = context.getRepository(); ctx = createContext(context.getRepository()); if (repo instanceof EditableRepository) { ((EditableRepository)repo).setIndexingContext(ctx); } } catch (IndexCreationFailedException e) { throw new IndexUpdateFailedException("Could not create index"); } return ctx; }
private void createIndexingContext(EditableRepository editableRepo) throws RepositoryException { if (editableRepo.supportsFeature(IndexCreationFeature.class)) { ArchivaIndexManager idxManager = getIndexManager(editableRepo.getType()); try { editableRepo.setIndexingContext(idxManager.createContext(editableRepo)); idxManager.updateLocalIndexPath(editableRepo); } catch (IndexCreationFailedException e) { throw new RepositoryException("Could not create index for repository "+editableRepo.getId()+": "+e.getMessage(),e); } } }
@SuppressWarnings( "unchecked" ) @Override public <T> void raise(RepositoryEvent<T> event) { if (event instanceof IndexCreationEvent ) { if (managedRepositories.containsKey(event.getRepository().getId()) || remoteRepositories.containsKey(event.getRepository().getId())) { EditableRepository repo = (EditableRepository) event.getRepository(); if (repo != null && repo.getIndexingContext()!=null) { try { ArchivaIndexManager idxmgr = getIndexManager(repo.getType()); if (idxmgr != null) { ArchivaIndexingContext newCtx = idxmgr.move(repo.getIndexingContext(), repo); repo.setIndexingContext(newCtx); idxmgr.updateLocalIndexPath(repo); } } catch (IndexCreationFailedException e) { log.error("Could not move index to new directory {}", e.getMessage(), e); } } } } for(RepositoryEventListener listener : listeners) { listener.raise(event); } } }