Search in sources :

Example 11 with MavenArtifactFacet

use of org.apache.archiva.maven.metadata.model.MavenArtifactFacet in project archiva by apache.

the class Maven2RepositoryMetadataResolverTest method testGetArtifactMetadataSnapshots.

@Test
public void testGetArtifactMetadataSnapshots() throws Exception {
    Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL));
    List<ArtifactMetadata> artifacts = new ArrayList<>(testArtifacts);
    Collections.sort(artifacts, new Comparator<ArtifactMetadata>() {

        @Override
        public int compare(ArtifactMetadata o1, ArtifactMetadata o2) {
            return o1.getId().compareTo(o2.getId());
        }
    });
    assertEquals(6, artifacts.size());
    ArtifactMetadata artifactMetadata = artifacts.get(0);
    assertEquals("test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId());
    MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    assertEquals(1, facet.getBuildNumber());
    assertEquals("20100308.230825", facet.getTimestamp());
    assertNull(facet.getClassifier());
    assertEquals("jar", facet.getType());
    artifactMetadata = artifacts.get(1);
    assertEquals("test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId());
    facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    assertEquals(1, facet.getBuildNumber());
    assertEquals("20100308.230825", facet.getTimestamp());
    assertNull(facet.getClassifier());
    assertEquals("pom", facet.getType());
    artifactMetadata = artifacts.get(2);
    assertEquals("test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId());
    facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    assertEquals(2, facet.getBuildNumber());
    assertEquals("20100310.014828", facet.getTimestamp());
    assertEquals("javadoc", facet.getClassifier());
    assertEquals("javadoc", facet.getType());
    artifactMetadata = artifacts.get(3);
    assertEquals("test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId());
    facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    assertEquals(2, facet.getBuildNumber());
    assertEquals("20100310.014828", facet.getTimestamp());
    assertEquals("sources", facet.getClassifier());
    assertEquals("java-source", facet.getType());
    artifactMetadata = artifacts.get(4);
    assertEquals("test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId());
    facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    assertEquals(2, facet.getBuildNumber());
    assertEquals("20100310.014828", facet.getTimestamp());
    assertNull(facet.getClassifier());
    assertEquals("jar", facet.getType());
    artifactMetadata = artifacts.get(5);
    assertEquals("test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId());
    facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    assertEquals(2, facet.getBuildNumber());
    assertEquals("20100310.014828", facet.getTimestamp());
    assertNull(facet.getClassifier());
    assertEquals("pom", facet.getType());
}
Also used : ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ArrayList(java.util.ArrayList) MavenArtifactFacet(org.apache.archiva.maven.metadata.model.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 12 with MavenArtifactFacet

use of org.apache.archiva.maven.metadata.model.MavenArtifactFacet in project archiva by apache.

the class RepositoryWalkingStatisticsProvider method walkRepository.

private void walkRepository(RepositorySession repositorySession, MetadataRepository metadataRepository, RepositoryStatistics stats, String repositoryId, String ns) throws MetadataResolutionException {
    for (String namespace : metadataRepository.getChildNamespaces(repositorySession, repositoryId, ns)) {
        walkRepository(repositorySession, metadataRepository, stats, repositoryId, ns + "." + namespace);
    }
    Collection<String> projects = metadataRepository.getProjects(repositorySession, 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(repositorySession, repositoryId, ns, project)) {
                for (ArtifactMetadata artifact : metadataRepository.getArtifacts(repositorySession, 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.maven.metadata.model.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Aggregations

MavenArtifactFacet (org.apache.archiva.maven.metadata.model.MavenArtifactFacet)12 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)10 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)3 Test (org.junit.Test)3 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)2 LayoutException (org.apache.archiva.repository.content.LayoutException)2 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)2 URL (java.net.URL)1 Path (java.nio.file.Path)1 DateFormat (java.text.DateFormat)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1 Artifact (org.apache.archiva.maven.model.Artifact)1 RepositoryListener (org.apache.archiva.metadata.audit.RepositoryListener)1 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)1