Search in sources :

Example 81 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetArtifactsByChecksumSingleResultMd5.

@Test
public void testGetArtifactsByChecksumSingleResultMd5() throws Exception {
    ArtifactMetadata artifact = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    repository.save();
    assertEquals(Collections.singletonList(artifact), new ArrayList<>(repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_MD5)));
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 82 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetArtifactsByChecksumNoResult.

@Test
public void testGetArtifactsByChecksumNoResult() throws Exception {
    ArtifactMetadata artifact = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    Collection<ArtifactMetadata> artifactsByChecksum = repository.getArtifactsByChecksum(TEST_REPO_ID, "not checksum");
    assertThat(artifactsByChecksum).isNotNull().isEmpty();
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 83 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class RepositoryWalkingStatisticsProvider method walkRepository.

private void walkRepository(MetadataRepository metadataRepository, RepositoryStatistics stats, String repositoryId, String ns) throws MetadataResolutionException {
    for (String namespace : metadataRepository.getNamespaces(repositoryId, ns)) {
        walkRepository(metadataRepository, stats, repositoryId, ns + "." + namespace);
    }
    Collection<String> projects = metadataRepository.getProjects(repositoryId, ns);
    if (!projects.isEmpty()) {
        stats.setTotalGroupCount(stats.getTotalGroupCount() + 1);
        stats.setTotalProjectCount(stats.getTotalProjectCount() + projects.size());
        for (String project : projects) {
            for (String version : metadataRepository.getProjectVersions(repositoryId, ns, project)) {
                for (ArtifactMetadata artifact : metadataRepository.getArtifacts(repositoryId, ns, project, version)) {
                    stats.setTotalArtifactCount(stats.getTotalArtifactCount() + 1);
                    stats.setTotalArtifactFileSize(stats.getTotalArtifactFileSize() + artifact.getSize());
                    MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet(MavenArtifactFacet.FACET_ID);
                    if (facet != null) {
                        String type = facet.getType();
                        stats.setTotalCountForType(type, stats.getTotalCountForType(type) + 1);
                    }
                }
            }
        }
    }
}
Also used : MavenArtifactFacet(org.apache.archiva.metadata.model.maven2.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 84 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class CleanupReleasedSnapshotsRepositoryPurgeTest method testHigherSnapshotExistsInSameRepo.

@Test
public void testHigherSnapshotExistsInSameRepo() throws Exception {
    RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
    ManagedRepository managedRepository = repositoryRegistry.getManagedRepository(TEST_REPO_ID);
    repositoryRegistry.removeRepository(TEST_REPO_ID);
    repositoryRegistry.putRepository(getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME));
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-source-plugin";
    String projectVersion = "2.0.2";
    String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    Path vDir2 = repo.resolve(projectPath).resolve(projectName).resolve("2.0.3-SNAPSHOT");
    Path vDir3 = repo.resolve(projectPath).resolve(projectName).resolve("2.0.4-SNAPSHOT");
    // test listeners for the correct artifacts - no deletions
    listenerControl.replay();
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    List<ArtifactMetadata> m2 = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir2);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, "2.0.3-SNAPSHOT")).thenReturn(ml);
    List<ArtifactMetadata> m3 = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir3);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, "2.0.4-SNAPSHOT")).thenReturn(ml);
    repoPurge.process(CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO);
    listenerControl.verify();
    // Verify the metadataRepository invocations
    // No removal
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.0.3-SNAPSHOT"));
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.0.4-SNAPSHOT"));
    verify(metadataRepository, never()).removeArtifact(any(ArtifactMetadata.class), any(String.class));
    verify(metadataRepository, never()).removeArtifact(any(String.class), any(String.class), any(String.class), any(String.class), any(MetadataFacet.class));
    // check if the snapshot was not removed
    assertExists(projectRoot + "/2.0.3-SNAPSHOT");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.md5");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.sha1");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.md5");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.sha1");
    // check if the released version was not removed
    assertExists(projectRoot + "/2.0.4-SNAPSHOT");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.md5");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.sha1");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.md5");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.sha1");
    // check if metadata file was not updated (because nothing was removed)
    Path artifactMetadataFile = Paths.get(projectRoot + "/maven-metadata.xml");
    String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString(artifactMetadataFile, Charset.defaultCharset());
    String expectedVersions = "<expected><versions><version>2.0.3-SNAPSHOT</version>" + "<version>2.0.4-SNAPSHOT</version></versions></expected>";
    XMLAssert.assertXpathEvaluatesTo("2.0.4-SNAPSHOT", "//metadata/versioning/latest", metadataXml);
    XMLAssert.assertXpathsEqual("//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml);
    XMLAssert.assertXpathEvaluatesTo("20070427033345", "//metadata/versioning/lastUpdated", metadataXml);
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.repository.ManagedRepository) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 85 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class RepositoryPurgeConsumerTest method testReleasedSnapshotsWereCleaned.

@Test
public void testReleasedSnapshotsWereCleaned() throws Exception {
    KnownRepositoryContentConsumer repoPurgeConsumer = applicationContext.getBean("knownRepositoryContentConsumer#repo-purge-consumer-by-days-old", KnownRepositoryContentConsumer.class);
    org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
    ArtifactCleanupFeature acf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    acf.setDeleteReleasedSnapshots(true);
    addRepoToConfiguration("days-old", repoConfiguration);
    repoPurgeConsumer.beginScan(repoConfiguration, null);
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-plugin-plugin";
    String projectVersion = "2.3-SNAPSHOT";
    String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    repoPurgeConsumer.processFile(CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO);
    verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
    verify(metadataRepository, never()).removeArtifact(any(), any());
    // check if the snapshot was removed
    assertDeleted(projectRoot + "/2.3-SNAPSHOT");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1");
    // check if metadata file was updated
    Path artifactMetadataFile = Paths.get(projectRoot + "/maven-metadata.xml");
    String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString(artifactMetadataFile, Charset.defaultCharset());
    String expectedVersions = "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
    XMLAssert.assertXpathEvaluatesTo("2.3", "//metadata/versioning/latest", metadataXml);
    XMLAssert.assertXpathsEqual("//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml);
    XMLAssert.assertXpathEvaluatesTo("20070315032817", "//metadata/versioning/lastUpdated", metadataXml);
    removeRepoFromConfiguration("days-old", repoConfiguration);
}
Also used : Path(java.nio.file.Path) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

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