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");
}
org.apache.archiva.repository.storage.util.StorageUtil.deleteRecursively(context.getPath());
});
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 RepositoryGroup method of.
public static RepositoryGroup of(org.apache.archiva.repository.RepositoryGroup modelObj) {
RepositoryGroup result = new RepositoryGroup();
MergeConfiguration mergeConfig = new MergeConfiguration();
result.setMergeConfiguration(mergeConfig);
result.setId(modelObj.getId());
result.setName(modelObj.getName());
result.setLocation(modelObj.getLocation().toString());
result.setRepositories(modelObj.getRepositories().stream().map(Repository::getId).collect(Collectors.toList()));
if (modelObj.supportsFeature(IndexCreationFeature.class)) {
IndexCreationFeature icf = modelObj.getFeature(IndexCreationFeature.class);
mergeConfig.setMergedIndexPath(icf.getIndexPath().toString());
mergeConfig.setMergedIndexTtlMinutes(modelObj.getMergedIndexTTL());
mergeConfig.setIndexMergeSchedule(modelObj.getSchedulingDefinition());
}
return result;
}
use of org.apache.archiva.repository.Repository in project archiva by apache.
the class DefaultMavenManagedRepositoryService method addManagedRepository.
@Override
public MavenManagedRepository addManagedRepository(MavenManagedRepository managedRepository) throws ArchivaRestServiceException {
final String repoId = managedRepository.getId();
if (StringUtils.isEmpty(repoId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_INVALID_ID, repoId), 422);
}
Repository repo = repositoryRegistry.getRepository(repoId);
if (repo != null) {
httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(repoId).build().toString());
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ID_EXISTS, repoId), 303);
}
try {
repositoryRegistry.putRepository(mapper.map(managedRepository));
httpServletResponse.setStatus(201);
return mapper.reverseMap(repositoryRegistry.getManagedRepository(repoId));
} catch (RepositoryException e) {
log.error("Could not create repository: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ADD_FAILED, repoId));
}
}
use of org.apache.archiva.repository.Repository in project archiva by apache.
the class DefaultIndexMerger method buildMergedIndex.
@Override
public ArchivaIndexingContext buildMergedIndex(IndexMergerRequest indexMergerRequest) throws IndexMergerException {
String groupId = indexMergerRequest.getGroupId();
if (runningGroups.contains(groupId)) {
log.info("skip build merge remote indexes for id: '{}' as already running", groupId);
return null;
}
runningGroups.add(groupId);
StopWatch stopWatch = new StopWatch();
try {
stopWatch.reset();
stopWatch.start();
StorageAsset mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();
Repository destinationRepository = repositoryRegistry.getRepository(indexMergerRequest.getGroupId());
ArchivaIndexManager idxManager = repositoryRegistry.getIndexManager(destinationRepository.getType());
List<ArchivaIndexingContext> sourceContexts = indexMergerRequest.getRepositoriesIds().stream().map(id -> repositoryRegistry.getRepository(id).getIndexingContext()).collect(Collectors.toList());
try {
ArchivaIndexingContext result = idxManager.mergeContexts(destinationRepository, sourceContexts, indexMergerRequest.isPackIndex());
if (indexMergerRequest.isTemporary()) {
String tempRepoId = destinationRepository.getId() + System.currentTimeMillis();
temporaryGroupIndexes.add(new TemporaryGroupIndex(mergedIndexDirectory, tempRepoId, groupId, indexMergerRequest.getMergedIndexTtl()));
temporaryContextes.add(result);
}
return result;
} catch (IndexCreationFailedException e) {
throw new IndexMergerException("Index merging failed " + e.getMessage(), e);
}
} finally {
stopWatch.stop();
log.info("merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), stopWatch.getTime());
runningGroups.remove(groupId);
}
}
use of org.apache.archiva.repository.Repository in project archiva by apache.
the class ArchivaRepositoryRegistryTest method removeRepository.
@Test
public void removeRepository() throws Exception {
assertEquals(5, repositoryRegistry.getRepositories().size());
Repository repo = repositoryRegistry.getRepository("snapshots");
repositoryRegistry.removeRepository(repo);
assertEquals(4, repositoryRegistry.getRepositories().size());
assertTrue(repositoryRegistry.getRepositories().stream().noneMatch(rep -> rep.getId().equals("snapshots")));
archivaConfiguration.reload();
repositoryRegistry.reload();
assertEquals(4, repositoryRegistry.getRepositories().size());
}
Aggregations