Search in sources :

Example 6 with IndexCreationFailedException

use of org.apache.archiva.indexer.IndexCreationFailedException in project archiva by apache.

the class MavenIndexManager method move.

@Override
public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException {
    if (context == null) {
        return null;
    }
    if (context.supports(IndexingContext.class)) {
        try {
            Path newPath = getIndexPath(repo);
            IndexingContext ctx = context.getBaseContext(IndexingContext.class);
            Path oldPath = ctx.getIndexDirectoryFile().toPath();
            if (oldPath.equals(newPath)) {
                // Nothing to do, if path does not change
                return context;
            }
            if (!Files.exists(oldPath)) {
                return createContext(repo);
            } else if (context.isEmpty()) {
                context.close();
                return createContext(repo);
            } else {
                context.close(false);
                Files.move(oldPath, newPath);
                return createContext(repo);
            }
        } catch (IOException e) {
            log.error("IOException while moving index directory {}", e.getMessage(), e);
            throw new IndexCreationFailedException("Could not recreated the index.", e);
        } catch (UnsupportedBaseContextException e) {
            throw new IndexCreationFailedException("The given context, is not a maven context.");
        }
    } else {
        throw new IndexCreationFailedException("Bad context type. This is not a maven context.");
    }
}
Also used : Path(java.nio.file.Path) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) IOException(java.io.IOException)

Example 7 with IndexCreationFailedException

use of org.apache.archiva.indexer.IndexCreationFailedException in project archiva by apache.

the class MavenIndexManager method createContext.

@Override
public ArchivaIndexingContext createContext(Repository repository) throws IndexCreationFailedException {
    log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType());
    if (repository.getType() != RepositoryType.MAVEN) {
        throw new UnsupportedRepositoryTypeException(repository.getType());
    }
    IndexingContext mvnCtx = null;
    try {
        if (repository instanceof RemoteRepository) {
            mvnCtx = createRemoteContext((RemoteRepository) repository);
        } else if (repository instanceof ManagedRepository) {
            mvnCtx = createManagedContext((ManagedRepository) repository);
        }
    } catch (IOException e) {
        log.error("IOException during context creation " + e.getMessage(), e);
        throw new IndexCreationFailedException("Could not create index context for repository " + repository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
    }
    MavenIndexContext context = new MavenIndexContext(repository, mvnCtx);
    return context;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) RemoteRepository(org.apache.archiva.repository.RemoteRepository) IOException(java.io.IOException) UnsupportedRepositoryTypeException(org.apache.archiva.repository.UnsupportedRepositoryTypeException)

Example 8 with IndexCreationFailedException

use of org.apache.archiva.indexer.IndexCreationFailedException in project archiva by apache.

the class RepositoryRegistry method createIndexingContext.

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);
        }
    }
}
Also used : IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) ArchivaIndexManager(org.apache.archiva.indexer.ArchivaIndexManager)

Example 9 with IndexCreationFailedException

use of org.apache.archiva.indexer.IndexCreationFailedException in project archiva by apache.

the class RepositoryRegistry method raise.

@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);
    }
}
Also used : IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexCreationEvent(org.apache.archiva.repository.features.IndexCreationEvent) ArchivaIndexManager(org.apache.archiva.indexer.ArchivaIndexManager)

Example 10 with IndexCreationFailedException

use of org.apache.archiva.indexer.IndexCreationFailedException in project archiva by apache.

the class ArchivaIndexManagerMock method createContext.

@Override
public ArchivaIndexingContext createContext(Repository repository) throws IndexCreationFailedException {
    log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType());
    if (repository.getType() != RepositoryType.MAVEN) {
        throw new UnsupportedRepositoryTypeException(repository.getType());
    }
    IndexingContext mvnCtx = null;
    try {
        if (repository instanceof RemoteRepository) {
            mvnCtx = createRemoteContext((RemoteRepository) repository);
        } else if (repository instanceof ManagedRepository) {
            mvnCtx = createManagedContext((ManagedRepository) repository);
        }
    } catch (IOException e) {
        log.error("IOException during context creation " + e.getMessage(), e);
        throw new IndexCreationFailedException("Could not create index context for repository " + repository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
    }
    MavenIndexContextMock context = new MavenIndexContextMock(repository, mvnCtx);
    return context;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) RemoteRepository(org.apache.archiva.repository.RemoteRepository) IOException(java.io.IOException) UnsupportedRepositoryTypeException(org.apache.archiva.repository.UnsupportedRepositoryTypeException)

Aggregations

IndexCreationFailedException (org.apache.archiva.indexer.IndexCreationFailedException)11 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)10 IOException (java.io.IOException)9 ManagedRepository (org.apache.archiva.repository.ManagedRepository)6 RemoteRepository (org.apache.archiva.repository.RemoteRepository)6 IndexingContext (org.apache.maven.index.context.IndexingContext)6 Path (java.nio.file.Path)3 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)3 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)3 EditableRepository (org.apache.archiva.repository.EditableRepository)3 Repository (org.apache.archiva.repository.Repository)3 UnsupportedRepositoryTypeException (org.apache.archiva.repository.UnsupportedRepositoryTypeException)3 ArchivaIndexManager (org.apache.archiva.indexer.ArchivaIndexManager)2 IndexCreationEvent (org.apache.archiva.repository.features.IndexCreationEvent)1