use of org.apache.archiva.repository.Repository in project archiva by apache.
the class MavenRepositoryProvider method getRepositoryGroupConfiguration.
@Override
public RepositoryGroupConfiguration getRepositoryGroupConfiguration(RepositoryGroup repositoryGroup) throws RepositoryException {
if (repositoryGroup.getType() != RepositoryType.MAVEN) {
throw new RepositoryException("The given repository group is not of MAVEN type");
}
RepositoryGroupConfiguration cfg = new RepositoryGroupConfiguration();
cfg.setId(repositoryGroup.getId());
cfg.setName(repositoryGroup.getName());
if (repositoryGroup.supportsFeature(IndexCreationFeature.class)) {
IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature(IndexCreationFeature.class);
cfg.setMergedIndexPath(indexCreationFeature.getIndexPath().toString());
}
cfg.setMergedIndexTtl(repositoryGroup.getMergedIndexTTL());
cfg.setRepositories(repositoryGroup.getRepositories().stream().map(Repository::getId).collect(Collectors.toList()));
cfg.setCronExpression(repositoryGroup.getSchedulingDefinition());
return cfg;
}
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 ArchivaRepositoryRegistryTest method getRepository.
@Test
public void getRepository() throws Exception {
Repository repo = repositoryRegistry.getRepository("internal");
assertNotNull(repo);
assertEquals("internal", repo.getId());
assertEquals("Archiva Managed Internal Repository", repo.getName());
assertEquals("This is internal repository.", repo.getDescription());
assertEquals("default", repo.getLayout());
assertEquals("0 0 * * * ?", repo.getSchedulingDefinition());
assertTrue(repo instanceof ManagedRepository);
assertTrue(repo.hasIndex());
assertTrue(repo.isScanned());
assertEquals(RepositoryType.MAVEN, repo.getType());
}
use of org.apache.archiva.repository.Repository in project archiva by apache.
the class DefaultFileUploadService method save.
@Override
public Boolean save(String repositoryId, String groupId, String artifactId, String version, String packaging, boolean generatePom) throws ArchivaRestServiceException {
repositoryId = StringUtils.trim(repositoryId);
groupId = StringUtils.trim(groupId);
artifactId = StringUtils.trim(artifactId);
version = StringUtils.trim(version);
packaging = StringUtils.trim(packaging);
checkParamChars("repositoryId", repositoryId);
checkParamChars("groupId", groupId);
checkParamChars("artifactId", artifactId);
checkParamChars("version", version);
checkParamChars("packaging", packaging);
List<FileMetadata> fileMetadatas = getSessionFilesList();
if (fileMetadatas == null || fileMetadatas.isEmpty()) {
return Boolean.FALSE;
}
org.apache.archiva.repository.ManagedRepository repository = repositoryRegistry.getManagedRepository(repositoryId);
if (repository == null) {
// TODO i18n ?
throw new ArchivaRestServiceException("Cannot find managed repository with id " + repositoryId, Response.Status.BAD_REQUEST.getStatusCode(), null);
}
if (VersionUtil.isSnapshot(version) && !repository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)) {
// TODO i18n ?
throw new ArchivaRestServiceException("Managed repository with id " + repositoryId + " do not accept snapshots", Response.Status.BAD_REQUEST.getStatusCode(), null);
}
// get from the session file with groupId/artifactId
Iterator<FileMetadata> iterator = fileMetadatas.stream().filter(fileMetadata -> fileMetadata != null && !fileMetadata.isPomFile()).iterator();
boolean pomGenerated = false;
while (iterator.hasNext()) {
FileMetadata fileMetadata = iterator.next();
log.debug("fileToAdd: {}", fileMetadata);
saveFile(repositoryId, fileMetadata, generatePom && !pomGenerated, groupId, artifactId, version, packaging);
pomGenerated = true;
deleteFile(fileMetadata.getServerFileName());
}
iterator = fileMetadatas.stream().filter(fileMetadata -> fileMetadata != null && fileMetadata.isPomFile()).iterator();
while (iterator.hasNext()) {
FileMetadata fileMetadata = iterator.next();
log.debug("fileToAdd: {}", fileMetadata);
savePomFile(repositoryId, fileMetadata, groupId, artifactId, version, packaging);
deleteFile(fileMetadata.getServerFileName());
}
return Boolean.TRUE;
}
use of org.apache.archiva.repository.Repository in project archiva by apache.
the class DefaultFileUploadService method getMetadata.
private ArchivaRepositoryMetadata getMetadata(StorageAsset metadataFile) throws RepositoryMetadataException {
ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
if (metadataFile.exists()) {
Repository repo = repositoryRegistry.getRepositoryOfAsset(metadataFile);
RepositoryType type = repo == null ? RepositoryType.MAVEN : repo.getType();
MetadataReader metadataReader = repositoryRegistry.getMetadataReader(type);
metadata = metadataReader.read(metadataFile);
}
return metadata;
}
Aggregations