use of org.apache.archiva.repository.Repository in project archiva by apache.
the class MavenRepositorySearch method addIndexingContexts.
/**
* @param selectedRepos
* @return indexing contextId used
*/
private List<String> addIndexingContexts(List<String> selectedRepos) {
Set<String> indexingContextIds = new HashSet<>();
for (String repo : selectedRepos) {
try {
Repository rRepo = repositoryRegistry.getRepository(repo);
if (rRepo != null) {
if (rRepo.getType().equals(RepositoryType.MAVEN)) {
assert rRepo.getIndexingContext() != null;
IndexingContext context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);
if (context.isSearchable()) {
indexingContextIds.addAll(getRemoteIndexingContextIds(repo));
indexingContextIds.add(context.getId());
} else {
log.warn("indexingContext with id {} not searchable", rRepo.getId());
}
}
} else {
log.warn("Repository '{}' not found in configuration.", repo);
}
} catch (RepositorySearchException e) {
log.warn("RepositorySearchException occured while accessing index of repository '{}' : {}", repo, e.getMessage());
continue;
} catch (UnsupportedBaseContextException e) {
log.error("Fatal situation: Maven repository without IndexingContext found.");
continue;
}
}
return new ArrayList<>(indexingContextIds);
}
use of org.apache.archiva.repository.Repository in project archiva by apache.
the class ArchivaIndexManagerMock method reset.
@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;
}
use of org.apache.archiva.repository.Repository in project archiva by apache.
the class RepositoryGroupAdminTest method addAndDeleteGroup.
@Test
public void addAndDeleteGroup() throws Exception {
try {
Repository repo = repositoryRegistry.getRepository("test-new-one");
if (repo != null) {
repositoryRegistry.removeRepository(repo);
}
repo = repositoryRegistry.getRepository("test-new-two");
if (repo != null) {
repositoryRegistry.removeRepository(repo);
}
ManagedRepository managedRepositoryOne = getTestManagedRepository("test-new-one", Paths.get(APPSERVER_BASE_PATH, "test-new-one").toString());
ManagedRepository managedRepositoryTwo = getTestManagedRepository("test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two").toString());
managedRepositoryAdmin.addManagedRepository(managedRepositoryOne, false, getFakeAuditInformation());
managedRepositoryAdmin.addManagedRepository(managedRepositoryTwo, false, getFakeAuditInformation());
RepositoryGroup repositoryGroup = new RepositoryGroup("repo-group-one", Arrays.asList("test-new-one", "test-new-two"));
// repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", null);
mockAuditListener.clearEvents();
repositoryGroupAdmin.addRepositoryGroup(repositoryGroup, getFakeAuditInformation());
assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().size());
assertEquals("repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get(0).getId());
assertEquals(2, repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories().size());
assertEquals(Arrays.asList("test-new-one", "test-new-two"), repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories());
// verify if default values were saved
assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexTtl());
assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexPath());
repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", getFakeAuditInformation());
assertEquals(0, repositoryGroupAdmin.getRepositoriesGroups().size());
assertEquals(2, mockAuditListener.getAuditEvents().size());
assertEquals(AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get(0).getAction());
assertEquals(AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get(1).getAction());
} finally {
mockAuditListener.clearEvents();
repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-one"));
repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-two"));
}
}
use of org.apache.archiva.repository.Repository in project archiva by apache.
the class ArchivaRepositoryRegistryTest method validateRepository.
@Test
void validateRepository() {
Repository repo = repositoryRegistry.getRepository("internal");
assertNotNull(repo);
assertTrue(repositoryRegistry.validateRepository(repo).isValid());
}
use of org.apache.archiva.repository.Repository in project archiva by apache.
the class ArchivaIndexManagerMock method reset.
@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(context.getPath().getFilePath());
} 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;
}
Aggregations