use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testDeleteArtifact.
@Test
public void testDeleteArtifact() throws Exception {
ArtifactMetadata artifact = createArtifact();
artifact.addFacet(new TestMetadataFacet("value"));
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
assertThat(repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION)).containsExactly(artifact);
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact);
Collection<String> versions = repository.getProjectVersions(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
log.info("versions {}", versions);
assertThat(versions).isNotNull().isNotEmpty().hasSize(2).contains("1.0", "2.0");
repository.removeArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId());
versions = repository.getProjectVersions(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
log.info("versions {}", versions);
assertThat(versions).isNotNull().isNotEmpty().hasSize(1).contains("2.0");
assertThat(repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION)).isNotNull().isEmpty();
assertThat(repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0)).isNotEmpty().hasSize(1);
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testGetArtifactsByDateRangeLowerBound.
@Test
public void testGetArtifactsByDateRangeLowerBound() throws Exception {
ArtifactMetadata artifact = createArtifact();
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
repository.save();
Date date = new Date(artifact.getWhenGathered().getTime() - 10000);
List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange(TEST_REPO_ID, date, null);
assertEquals(Collections.singletonList(artifact), artifacts);
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testGetArtifactsByRepoIdMultipleCopies.
@Test
public void testGetArtifactsByRepoIdMultipleCopies() throws Exception {
ArtifactMetadata artifact = createArtifact();
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
ArtifactMetadata secondArtifact = createArtifact();
secondArtifact.setRepositoryId(OTHER_REPO_ID);
repository.updateArtifact(OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact);
repository.save();
// test it restricts to the appropriate repository
tryAssert(() -> assertEquals(Collections.singletonList(artifact), repository.getArtifacts(TEST_REPO_ID)));
tryAssert(() -> assertEquals(Collections.singletonList(secondArtifact), repository.getArtifacts(OTHER_REPO_ID)));
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testGetArtifactVersions.
@Test
public void testGetArtifactVersions() throws Exception {
ArtifactMetadata artifact1 = createArtifact();
String version1 = "1.0-20091212.012345-1";
artifact1.setId(artifact1.getProject() + "-" + version1 + ".jar");
artifact1.setVersion(version1);
ArtifactMetadata artifact2 = createArtifact();
String version2 = "1.0-20091212.123456-2";
artifact2.setId(artifact2.getProject() + "-" + version2 + ".jar");
artifact2.setVersion(version2);
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1);
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2);
Collection<String> versions = repository.getArtifactVersions(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
assertThat(versions).isNotNull().isNotEmpty().contains(version1, version2);
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class DefaultMetadataResolver method resolveArtifacts.
@Override
public Collection<ArtifactMetadata> resolveArtifacts(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
try {
MetadataRepository metadataRepository = session.getRepository();
Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts(repoId, namespace, projectId, projectVersion);
ExcludesFilter<String> filter = new ExcludesFilter<String>(createArtifactIdList(artifacts));
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion).filter(filter);
Collection<ArtifactMetadata> storageArtifacts = repositoryStorage.readArtifactsMetadata(readMetadataRequest);
if (storageArtifacts != null && !storageArtifacts.isEmpty()) {
log.debug("Resolved artifacts from storage: {}", storageArtifacts);
for (ArtifactMetadata artifact : storageArtifacts) {
try {
metadataRepository.updateArtifact(repoId, namespace, projectId, projectVersion, artifact);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
}
}
session.markDirty();
artifacts = new ArrayList<>(artifacts);
artifacts.addAll(storageArtifacts);
}
return artifacts;
} catch (RepositoryStorageRuntimeException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
}
}
Aggregations