use of org.apache.archiva.filter.Filter in project archiva by apache.
the class Maven2RepositoryStorage method isProjectVersion.
private boolean isProjectVersion(StorageAsset dir) {
final String artifactId = dir.getParent().getName();
final String projectVersion = dir.getName();
// check if there is a POM artifact file to ensure it is a version directory
Predicate<StorageAsset> filter;
if (VersionUtil.isSnapshot(projectVersion)) {
filter = new PomFilenameFilter(artifactId, projectVersion);
} else {
final String pomFile = artifactId + "-" + projectVersion + ".pom";
filter = new PomFileFilter(pomFile);
}
if (dir.list().stream().filter(f -> !f.isContainer()).anyMatch(filter)) {
return true;
}
// if a metadata file is present, check if this is the "version" directory, marking it as a project version
ArchivaRepositoryMetadata metadata = readMetadata(dir);
if (metadata != null && projectVersion.equals(metadata.getVersion())) {
return true;
}
return false;
}
use of org.apache.archiva.filter.Filter in project archiva by apache.
the class Maven2RepositoryStorage method listProjects.
@Override
public Collection<String> listProjects(String repoId, String namespace, Filter<String> filter) throws RepositoryStorageRuntimeException {
StorageAsset dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace);
if (!(dir.exists() && dir.isContainer())) {
return Collections.emptyList();
}
// scan all directories in the namespace, and only include those that are known to be projects
final Predicate<StorageAsset> dFilter = new DirectoryFilter(filter);
return dir.list().stream().filter(dFilter).filter(path -> isProject(path, filter)).map(path -> path.getName().toString()).sorted().collect(Collectors.toList());
}
use of org.apache.archiva.filter.Filter in project archiva by apache.
the class Maven2RepositoryStorage method listNamespaces.
@Override
public Collection<String> listNamespaces(String repoId, String namespace, Filter<String> filter) throws RepositoryStorageRuntimeException {
StorageAsset dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace);
if (!(dir.exists()) && !dir.isContainer()) {
return Collections.emptyList();
}
// scan all the directories which are potential namespaces. Any directories known to be projects are excluded
Predicate<StorageAsset> dFilter = new DirectoryFilter(filter);
return dir.list().stream().filter(dFilter).filter(path -> !isProject(path, filter)).map(path -> path.getName().toString()).sorted().collect(Collectors.toList());
}
use of org.apache.archiva.filter.Filter in project archiva by apache.
the class Maven2RepositoryStorage method readArtifactsMetadata.
@Override
public Collection<ArtifactMetadata> readArtifactsMetadata(ReadMetadataRequest readMetadataRequest) throws RepositoryStorageRuntimeException {
StorageAsset dir = pathTranslator.toFile(getRepositoryBasedir(readMetadataRequest.getRepositoryId()), readMetadataRequest.getNamespace(), readMetadataRequest.getProjectId(), readMetadataRequest.getProjectVersion());
if (!(dir.exists() && dir.isContainer())) {
return Collections.emptyList();
}
// all files that are not metadata and not a checksum / signature are considered artifacts
final Predicate<StorageAsset> dFilter = new ArtifactDirectoryFilter(readMetadataRequest.getFilter());
// Returns a map TRUE -> (success values), FALSE -> (Exceptions)
Map<Boolean, List<Try<ArtifactMetadata>>> result = dir.list().stream().filter(dFilter).map(path -> {
try {
return Try.success(getArtifactFromFile(readMetadataRequest.getRepositoryId(), readMetadataRequest.getNamespace(), readMetadataRequest.getProjectId(), readMetadataRequest.getProjectVersion(), path));
} catch (Exception e) {
log.debug("Could not create metadata for {}: {}", path, e.getMessage(), e);
return Try.<ArtifactMetadata>failure(e);
}
}).collect(Collectors.groupingBy(Try::isSuccess));
if (result.containsKey(Boolean.FALSE) && result.get(Boolean.FALSE).size() > 0 && (!result.containsKey(Boolean.TRUE) || result.get(Boolean.TRUE).size() == 0)) {
log.error("Could not get artifact metadata. Directory: {}. Number of errors {}.", dir, result.get(Boolean.FALSE).size());
Try<ArtifactMetadata> failure = result.get(Boolean.FALSE).get(0);
log.error("Sample exception {}", failure.getError().getMessage(), failure.getError());
throw new RepositoryStorageRuntimeException(readMetadataRequest.getRepositoryId(), "Could not retrieve metadata of the files");
} else {
if (!result.containsKey(Boolean.TRUE) || result.get(Boolean.TRUE) == null) {
return Collections.emptyList();
}
return result.get(Boolean.TRUE).stream().map(tr -> tr.get()).collect(Collectors.toList());
}
}
Aggregations