Search in sources :

Example 6 with ProjectMetadata

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();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) RepositoryStorageMetadataInvalidException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) RepositoryStorageMetadataNotFoundException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 7 with ProjectMetadata

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());
}
Also used : ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 8 with ProjectMetadata

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);
}
Also used : ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Test(org.junit.Test)

Example 9 with ProjectMetadata

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;
}
Also used : ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata)

Example 10 with ProjectMetadata

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());
}
Also used : ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Aggregations

ProjectMetadata (org.apache.archiva.metadata.model.ProjectMetadata)14 Test (org.junit.Test)6 OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)3 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)3 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)3 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)3 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)3 Namespace (org.apache.archiva.metadata.repository.cassandra.model.Namespace)3 ArrayList (java.util.ArrayList)2 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)2 ArtifactMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel)2 ProjectVersionMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel)2 Repository (org.apache.archiva.metadata.repository.cassandra.model.Repository)2 RepositoryStorageRuntimeException (org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 Properties (java.util.Properties)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1