use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class Maven2RepositoryStorage method readArtifactsMetadata.
@Override
public Collection<ArtifactMetadata> readArtifactsMetadata(ReadMetadataRequest readMetadataRequest) throws RepositoryStorageRuntimeException {
Path dir = pathTranslator.toFile(getRepositoryBasedir(readMetadataRequest.getRepositoryId()), readMetadataRequest.getNamespace(), readMetadataRequest.getProjectId(), readMetadataRequest.getProjectVersion());
if (!(Files.exists(dir) && Files.isDirectory(dir))) {
return Collections.emptyList();
}
// all files that are not metadata and not a checksum / signature are considered artifacts
final Predicate<Path> dFilter = new ArtifactDirectoryFilter(readMetadataRequest.getFilter());
try (Stream<Path> stream = Files.list(dir)) {
// Returns a map TRUE -> (success values), FALSE -> (Exceptions)
Map<Boolean, List<Try<ArtifactMetadata>>> result = stream.filter(dFilter).map(path -> {
try {
return Try.success(getArtifactFromFile(readMetadataRequest.getRepositoryId(), readMetadataRequest.getNamespace(), readMetadataRequest.getProjectId(), readMetadataRequest.getProjectVersion(), path));
} catch (Exception e) {
LOGGER.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)) {
LOGGER.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);
LOGGER.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());
}
} catch (IOException e) {
LOGGER.error("Could not read directory {}: {}", dir, e.getMessage(), e);
}
return Collections.emptyList();
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class Maven2RepositoryStorage method getArtifactFromFile.
private ArtifactMetadata getArtifactFromFile(String repoId, String namespace, String projectId, String projectVersion, Path file) throws IOException {
ArtifactMetadata metadata = pathTranslator.getArtifactFromId(repoId, namespace, projectId, projectVersion, file.getFileName().toString());
populateArtifactMetadataFromFile(metadata, file);
return metadata;
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method deleteSnapshotVersion.
@Test
public void deleteSnapshotVersion() throws Exception {
ArtifactMetadata artifactOne = createArtifact();
artifactOne.setVersion("2.0-20120618.214127-1");
artifactOne.setProjectVersion("2.0-SNAPSHOT");
artifactOne.addFacet(new TestMetadataFacet("value"));
artifactOne.setId(TEST_PROJECT + "-" + "2.0-20120618.214127-1" + "." + "jar");
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactOne);
ArtifactMetadata artifactTwo = createArtifact();
artifactTwo.setVersion("2.0-20120618.214135-2");
artifactTwo.setProjectVersion("2.0-SNAPSHOT");
artifactTwo.addFacet(new TestMetadataFacet("value"));
artifactTwo.setId(TEST_PROJECT + "-" + "2.0-20120618.214135-2" + "." + "jar");
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactTwo);
Collection<ArtifactMetadata> artifactMetadatas = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT");
assertThat(artifactMetadatas).isNotNull().isNotEmpty().hasSize(2);
log.info("artifactMetadatas: {}", artifactMetadatas);
repository.removeArtifact(artifactOne, "2.0-SNAPSHOT");
artifactMetadatas = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT");
assertThat(artifactMetadatas).isNotNull().isNotEmpty().hasSize(1);
repository.removeArtifact(artifactTwo, "2.0-SNAPSHOT");
artifactMetadatas = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT");
assertThat(artifactMetadatas).isNotNull().isEmpty();
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testGetArtifactsByProjectVersionMetadata.
@Test
public void testGetArtifactsByProjectVersionMetadata() throws Exception {
createArtifactWithGenericMetadataFacet(10);
Collection<ArtifactMetadata> artifactsByMetadata = repository.getArtifactsByProjectVersionMetadata(TEST_METADATA_KEY, TEST_METADATA_VALUE, TEST_REPO_ID);
assertThat(artifactsByMetadata).hasSize(1);
ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator().next();
assertThat(artifactMetadata.getId()).isEqualTo("projectId-1.0.jar");
assertThat(artifactMetadata.getSha1()).isEqualTo(TEST_SHA1);
assertThat(artifactMetadata.getRepositoryId()).isEqualTo(TEST_REPO_ID);
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testGetArtifactsByDateRangeLowerBoundOutOfRange.
@Test
public void testGetArtifactsByDateRangeLowerBoundOutOfRange() throws Exception {
ArtifactMetadata artifact = createArtifact();
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
Date date = new Date(artifact.getWhenGathered().getTime() + 10000);
List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange(TEST_REPO_ID, date, null);
assertThat(artifacts).isNotNull().isEmpty();
}
Aggregations