use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.
the class Maven2RepositoryStorage method listNamespaces.
@Override
public Collection<String> listNamespaces(String repoId, String namespace, Filter<String> filter) throws RepositoryStorageRuntimeException {
Path dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace);
if (!(Files.exists(dir) && Files.isDirectory(dir))) {
return Collections.emptyList();
}
// scan all the directories which are potential namespaces. Any directories known to be projects are excluded
Predicate<Path> dFilter = new DirectoryFilter(filter);
try (Stream<Path> stream = Files.list(dir)) {
return stream.filter(dFilter).filter(path -> !isProject(path, filter)).map(path -> path.getFileName().toString()).sorted().collect(Collectors.toList());
} catch (IOException e) {
LOGGER.error("Could not read directory {}: {}", dir, e.getMessage(), e);
return Collections.emptyList();
}
}
use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.
the class DefaultMetadataResolver method resolveProjectVersion.
@Override
public ProjectVersionMetadata resolveProjectVersion(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
MetadataRepository metadataRepository = session.getRepository();
ProjectVersionMetadata metadata = metadataRepository.getProjectVersion(repoId, namespace, projectId, projectVersion);
// may then work here and be more efficient than always trying again)
if (metadata == null || metadata.isIncomplete()) {
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion).browsingRequest(true);
metadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
log.debug("Resolved project version metadata from storage: {}", metadata);
// eg. maven projects should be able to process parent here
if (!metadata.getDependencies().isEmpty()) {
ProjectVersionReference ref = new ProjectVersionReference();
ref.setNamespace(namespace);
ref.setProjectId(projectId);
ref.setProjectVersion(projectVersion);
ref.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
}
try {
for (RepositoryListener listener : listeners) {
listener.addArtifact(session, repoId, namespace, projectId, metadata);
}
metadataRepository.updateProjectVersion(repoId, namespace, projectId, metadata);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
}
session.markDirty();
} catch (RepositoryStorageMetadataInvalidException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
} catch (RepositoryStorageMetadataNotFoundException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
// no need to rethrow - return null
} catch (RepositoryStorageRuntimeException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
}
}
return metadata;
}
use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.
the class DefaultMetadataResolver method resolveProjects.
@Override
public Collection<String> resolveProjects(RepositorySession session, String repoId, String namespace) throws MetadataResolutionException {
try {
MetadataRepository metadataRepository = session.getRepository();
Collection<String> projects = metadataRepository.getProjects(repoId, namespace);
Collection<String> exclusions = new ArrayList<>(projects);
String cacheKey = repoId + "-" + namespace;
Collection<String> namespaces = namespacesCache.get(cacheKey);
if (namespaces == null) {
namespaces = metadataRepository.getNamespaces(repoId, namespace);
namespacesCache.put(cacheKey, namespaces);
}
exclusions.addAll(namespaces);
Collection<String> storageProjects = repositoryStorage.listProjects(repoId, namespace, new ExcludesFilter<>(exclusions));
if (storageProjects != null && !storageProjects.isEmpty()) {
log.debug("Resolved projects from storage: {}", storageProjects);
for (String projectId : storageProjects) {
ProjectMetadata projectMetadata = repositoryStorage.readProjectMetadata(repoId, namespace, projectId);
if (projectMetadata != null) {
try {
metadataRepository.updateProject(repoId, projectMetadata);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
}
}
}
session.markDirty();
projects = new ArrayList<>(projects);
projects.addAll(storageProjects);
}
return projects;
} catch (RepositoryStorageRuntimeException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.
the class DefaultMetadataResolver method resolveProjectVersions.
@Override
public Collection<String> resolveProjectVersions(RepositorySession session, String repoId, String namespace, String projectId) throws MetadataResolutionException {
try {
MetadataRepository metadataRepository = session.getRepository();
Collection<String> projectVersions = metadataRepository.getProjectVersions(repoId, namespace, projectId);
Collection<String> storageProjectVersions = repositoryStorage.listProjectVersions(repoId, namespace, projectId, new ExcludesFilter<String>(projectVersions));
if (storageProjectVersions != null && !storageProjectVersions.isEmpty()) {
log.debug("Resolved project versions from storage: {}", storageProjectVersions);
for (String projectVersion : storageProjectVersions) {
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion);
ProjectVersionMetadata versionMetadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
for (RepositoryListener listener : listeners) {
listener.addArtifact(session, repoId, namespace, projectId, versionMetadata);
}
metadataRepository.updateProjectVersion(repoId, namespace, projectId, versionMetadata);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
} catch (RepositoryStorageMetadataInvalidException e) {
log.warn("Not update project in metadata repository due to an error resolving it from storage: {}", e.getMessage());
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
} catch (RepositoryStorageMetadataNotFoundException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
}
}
session.markDirty();
projectVersions = new ArrayList<>(projectVersions);
projectVersions.addAll(storageProjectVersions);
}
return projectVersions;
} catch (RepositoryStorageRuntimeException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411Test method testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed.
@Test
public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed() throws Exception {
testRepo.setSnapshots(false);
configuration.save(c);
repositoryRegistry.reload();
assertFalse(c.getManagedRepositories().get(0).isSnapshots());
copyTestArtifactWithParent("target/test-classes/com/example/test/test-snapshot-artifact-module-a", "target/test-repository/com/example/test/test-snapshot-artifact-module-a");
try {
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a", "1.1-SNAPSHOT"));
fail("Should not be found");
} catch (RepositoryStorageRuntimeException e) {
}
List<String> paths = new ArrayList<>();
paths.add("target/test-repository/com/example/test/test-snapshot-artifact-module-a");
paths.add("target/test-repository/com/example/test/test-snapshot-artifact-root");
deleteTestArtifactWithParent(paths);
}
Aggregations