Search in sources :

Example 16 with ArtifactMetadata

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

Example 17 with ArtifactMetadata

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

Example 18 with ArtifactMetadata

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

Example 19 with ArtifactMetadata

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

Example 20 with ArtifactMetadata

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);
    }
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ExcludesFilter(org.apache.archiva.metadata.repository.filter.ExcludesFilter) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Aggregations

ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)96 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)23 Path (java.nio.file.Path)20 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)17 Date (java.util.Date)15 HashSet (java.util.HashSet)11 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)10 MavenArtifactFacet (org.apache.archiva.metadata.model.maven2.MavenArtifactFacet)9 HashMap (java.util.HashMap)8 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)8 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)7 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)7 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)7 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)7 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)7 Node (javax.jcr.Node)6 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)6 IOException (java.io.IOException)5 RepositoryException (javax.jcr.RepositoryException)5