use of org.apache.archiva.metadata.model.ProjectMetadata in project archiva by apache.
the class ArchivaMetadataCreationConsumer method processFile.
@Override
public void processFile(String path) throws ConsumerException {
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
// note that we do minimal processing including checksums and POM information for performance of
// the initial scan. Any request for this information will be intercepted and populated on-demand
// or picked up by subsequent scans
ArtifactMetadata artifact = repositoryStorage.readArtifactMetadataFromPath(repoId, path);
ProjectMetadata project = new ProjectMetadata();
project.setNamespace(artifact.getNamespace());
project.setId(artifact.getProject());
String projectVersion = VersionUtil.getBaseVersion(artifact.getVersion());
MetadataRepository metadataRepository = repositorySession.getRepository();
boolean createVersionMetadata = false;
// FIXME: maybe not too efficient since it may have already been read and stored for this artifact
ProjectVersionMetadata versionMetadata = null;
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(artifact.getNamespace()).projectId(artifact.getProject()).projectVersion(projectVersion);
versionMetadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
createVersionMetadata = true;
} catch (RepositoryStorageMetadataNotFoundException e) {
log.warn("Missing or invalid POM for artifact:{} (repository:{}); creating empty metadata", path, repoId);
versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId(projectVersion);
versionMetadata.setIncomplete(true);
createVersionMetadata = true;
} catch (RepositoryStorageMetadataInvalidException e) {
log.warn("Error occurred resolving POM for artifact:{} (repository:{}); message: {}", new Object[] { path, repoId, e.getMessage() });
}
// read the metadata and update it if it is newer or doesn't exist
artifact.setWhenGathered(whenGathered);
metadataRepository.updateArtifact(repoId, project.getNamespace(), project.getId(), projectVersion, artifact);
if (createVersionMetadata) {
metadataRepository.updateProjectVersion(repoId, project.getNamespace(), project.getId(), versionMetadata);
}
metadataRepository.updateProject(repoId, project);
repositorySession.save();
} catch (MetadataRepositoryException e) {
log.warn("Error occurred persisting metadata for artifact:{} (repository:{}); message: {}", path, repoId, e.getMessage(), e);
repositorySession.revert();
} catch (RepositoryStorageRuntimeException e) {
log.warn("Error occurred persisting metadata for artifact:{} (repository:{}); message: {}", path, repoId, e.getMessage(), e);
repositorySession.revert();
} finally {
repositorySession.close();
}
}
use of org.apache.archiva.metadata.model.ProjectMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testDeleteRepository.
@Test
public void testDeleteRepository() throws Exception {
repository.updateNamespace(TEST_REPO_ID, TEST_NAMESPACE);
ProjectMetadata project1 = new ProjectMetadata();
project1.setNamespace(TEST_NAMESPACE);
project1.setId("project1");
repository.updateProject(TEST_REPO_ID, project1);
ProjectMetadata project2 = new ProjectMetadata();
project2.setNamespace(TEST_NAMESPACE);
project2.setId("project2");
repository.updateProject(TEST_REPO_ID, project2);
ArtifactMetadata artifact1 = createArtifact();
artifact1.setProject("project1");
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1);
ArtifactMetadata artifact2 = createArtifact();
artifact2.setProject("project2");
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2);
repository.save();
List<ArtifactMetadata> expected = Arrays.asList(artifact1, artifact2);
Collections.sort(expected, new ArtifactMetadataComparator());
tryAssert(() -> {
List<ArtifactMetadata> actual = new ArrayList<>(repository.getArtifactsByDateRange(TEST_REPO_ID, null, null));
Collections.sort(actual, new ArtifactMetadataComparator());
assertEquals(expected, actual);
});
repository.removeRepository(TEST_REPO_ID);
assertTrue(repository.getArtifacts(TEST_REPO_ID).isEmpty());
assertTrue(repository.getRootNamespaces(TEST_REPO_ID).isEmpty());
}
use of org.apache.archiva.metadata.model.ProjectMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testGetProjectOnly.
@Test
public void testGetProjectOnly() throws Exception {
assertNull(repository.getProject(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT));
assertThat(repository.getRootNamespaces(TEST_REPO_ID)).isNotNull().isEmpty();
ProjectMetadata project = new ProjectMetadata();
project.setId(TEST_PROJECT);
project.setNamespace(TEST_NAMESPACE);
repository.updateProject(TEST_REPO_ID, project);
project = repository.getProject(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
assertEquals(TEST_PROJECT, project.getId());
assertEquals(TEST_NAMESPACE, project.getNamespace());
// test that namespace is also constructed
Collection<String> namespaces = repository.getRootNamespaces(TEST_REPO_ID);
assertThat(namespaces).isNotNull().isNotEmpty().contains(TEST_NAMESPACE).hasSize(1);
}
use of org.apache.archiva.metadata.model.ProjectMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method createProject.
private static ProjectMetadata createProject(String ns) {
ProjectMetadata project = new ProjectMetadata();
project.setId(TEST_PROJECT);
project.setNamespace(ns);
return project;
}
use of org.apache.archiva.metadata.model.ProjectMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testGetArtifactOnly.
@Test
public void testGetArtifactOnly() throws Exception {
assertThat(new ArrayList<>(repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION))).isNotNull().isEmpty();
assertThat(repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION)).isNull();
assertThat(repository.getProject(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT)).isNull();
assertThat(repository.getRootNamespaces(TEST_REPO_ID)).isNotNull().isEmpty();
ArtifactMetadata metadata = createArtifact();
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
Collection<ArtifactMetadata> artifacts = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
// assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
assertThat(artifacts).containsExactly(metadata);
// test that namespace, project and project version is also constructed
assertThat(repository.getRootNamespaces(TEST_REPO_ID)).isNotNull().isNotEmpty().contains(TEST_NAMESPACE).hasSize(1);
ProjectMetadata projectMetadata = repository.getProject(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
assertEquals(TEST_PROJECT, projectMetadata.getId());
assertEquals(TEST_NAMESPACE, projectMetadata.getNamespace());
ProjectVersionMetadata projectVersionMetadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
assertEquals(TEST_PROJECT_VERSION, projectVersionMetadata.getId());
}
Aggregations