Search in sources :

Example 26 with ArtifactMetadata

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

the class Maven2RepositoryMetadataResolverTest method testGetArtifactMetadataSnapshotsMRM1859.

@Test
public void testGetArtifactMetadataSnapshotsMRM1859() throws Exception {
    Path repoDir = Paths.get("target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT");
    URL url = Thread.currentThread().getContextClassLoader().getResource("resolver-status.properties");
    Path resFile = Paths.get(url.toURI());
    Path destFile = repoDir.resolve(resFile.getFileName());
    Files.copy(resFile, destFile, StandardCopyOption.REPLACE_EXISTING);
    URL url2 = Thread.currentThread().getContextClassLoader().getResource("test01.properties");
    Path resFile2 = Paths.get(url2.toURI());
    Path destFile2 = repoDir.resolve(resFile2.getFileName());
    Files.copy(resFile2, destFile2, StandardCopyOption.REPLACE_EXISTING);
    try {
        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());
    } finally {
        Files.delete(destFile);
        Files.delete(destFile2);
    }
}
Also used : Path(java.nio.file.Path) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ArrayList(java.util.ArrayList) MavenArtifactFacet(org.apache.archiva.metadata.model.maven2.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) URL(java.net.URL) Test(org.junit.Test)

Example 27 with ArtifactMetadata

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

the class DuplicateArtifactsConsumerTest method createMetadata.

private static ArtifactMetadata createMetadata(String version) {
    ArtifactMetadata artifact = new ArtifactMetadata();
    artifact.setId(TEST_PROJECT + "-" + version + ".jar");
    artifact.setNamespace(TEST_NAMESPACE);
    artifact.setProject(TEST_PROJECT);
    artifact.setProjectVersion(version);
    artifact.setVersion(version);
    artifact.setRepositoryId(TEST_REPO);
    return artifact;
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 28 with ArtifactMetadata

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

the class RepositoryStatisticsManagerTest method createArtifact.

private ArtifactMetadata createArtifact(String namespace, String projectId, String projectVersion, String type) {
    ArtifactMetadata metadata = new ArtifactMetadata();
    metadata.setRepositoryId(TEST_REPO_ID);
    metadata.setId(projectId + "-" + projectVersion + "." + type);
    metadata.setProject(projectId);
    metadata.setSize(12345L);
    metadata.setProjectVersion(projectVersion);
    metadata.setVersion(projectVersion);
    metadata.setNamespace(namespace);
    MavenArtifactFacet facet = new MavenArtifactFacet();
    facet.setType(type);
    metadata.addFacet(facet);
    return metadata;
}
Also used : MavenArtifactFacet(org.apache.archiva.metadata.model.maven2.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 29 with ArtifactMetadata

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

the class CassandraMetadataRepository method mapArtifactMetadataToArtifact.

/**
 * Attach metadata to each of the  ArtifactMetadata objects
 */
private List<ArtifactMetadata> mapArtifactMetadataToArtifact(QueryResult<OrderedRows<String, String, String>> result, List<ArtifactMetadata> artifactMetadatas) {
    if (result.get() == null || result.get().getCount() < 1) {
        return artifactMetadatas;
    }
    final List<MetadataFacetModel> metadataFacetModels = new ArrayList<>(result.get().getCount());
    for (Row<String, String, String> row : result.get()) {
        ColumnSlice<String, String> columnSlice = row.getColumnSlice();
        MetadataFacetModel metadataFacetModel = new MetadataFacetModel();
        metadataFacetModel.setFacetId(getStringValue(columnSlice, FACET_ID.toString()));
        metadataFacetModel.setName(getStringValue(columnSlice, NAME.toString()));
        metadataFacetModel.setValue(getStringValue(columnSlice, VALUE.toString()));
        metadataFacetModel.setKey(getStringValue(columnSlice, KEY.toString()));
        metadataFacetModel.setProjectVersion(getStringValue(columnSlice, PROJECT_VERSION.toString()));
        metadataFacetModels.add(metadataFacetModel);
    }
    for (final ArtifactMetadata artifactMetadata : artifactMetadatas) {
        Iterable<MetadataFacetModel> metadataFacetModelIterable = Iterables.filter(metadataFacetModels, new Predicate<MetadataFacetModel>() {

            @Override
            public boolean apply(MetadataFacetModel metadataFacetModel) {
                if (metadataFacetModel != null) {
                    return StringUtils.equals(artifactMetadata.getVersion(), metadataFacetModel.getProjectVersion());
                }
                return false;
            }
        });
        Iterator<MetadataFacetModel> iterator = metadataFacetModelIterable.iterator();
        Map<String, List<MetadataFacetModel>> metadataFacetValuesPerFacetId = new HashMap<>();
        while (iterator.hasNext()) {
            MetadataFacetModel metadataFacetModel = iterator.next();
            List<MetadataFacetModel> values = metadataFacetValuesPerFacetId.get(metadataFacetModel.getName());
            if (values == null) {
                values = new ArrayList<>();
                metadataFacetValuesPerFacetId.put(metadataFacetModel.getFacetId(), values);
            }
            values.add(metadataFacetModel);
        }
        for (Map.Entry<String, List<MetadataFacetModel>> entry : metadataFacetValuesPerFacetId.entrySet()) {
            MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(entry.getKey());
            if (metadataFacetFactory != null) {
                List<MetadataFacetModel> facetModels = entry.getValue();
                if (!facetModels.isEmpty()) {
                    MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet();
                    Map<String, String> props = new HashMap<>(facetModels.size());
                    for (MetadataFacetModel metadataFacetModel : facetModels) {
                        props.put(metadataFacetModel.getKey(), metadataFacetModel.getValue());
                    }
                    metadataFacet.fromProperties(props);
                    artifactMetadata.addFacet(metadataFacet);
                }
            }
        }
    }
    return artifactMetadatas;
}
Also used : MetadataFacetModel(org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) MailingList(org.apache.archiva.metadata.model.MailingList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Map(java.util.Map) HashMap(java.util.HashMap)

Example 30 with ArtifactMetadata

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

the class CassandraMetadataRepository method mapArtifactMetadataStringColumnSlice.

protected ArtifactMetadata mapArtifactMetadataStringColumnSlice(ColumnSlice<String, String> columnSlice) {
    ArtifactMetadata artifactMetadata = new ArtifactMetadata();
    artifactMetadata.setNamespace(getStringValue(columnSlice, NAMESPACE_ID.toString()));
    artifactMetadata.setSize(getAsLongValue(columnSlice, SIZE.toString()));
    artifactMetadata.setId(getStringValue(columnSlice, ID.toString()));
    artifactMetadata.setFileLastModified(getAsLongValue(columnSlice, FILE_LAST_MODIFIED.toString()));
    artifactMetadata.setMd5(getStringValue(columnSlice, MD5.toString()));
    artifactMetadata.setProject(getStringValue(columnSlice, PROJECT.toString()));
    artifactMetadata.setProjectVersion(getStringValue(columnSlice, PROJECT_VERSION.toString()));
    artifactMetadata.setRepositoryId(getStringValue(columnSlice, REPOSITORY_NAME.toString()));
    artifactMetadata.setSha1(getStringValue(columnSlice, SHA1.toString()));
    artifactMetadata.setVersion(getStringValue(columnSlice, VERSION.toString()));
    Long whenGathered = getAsLongValue(columnSlice, WHEN_GATHERED.toString());
    if (whenGathered != null) {
        artifactMetadata.setWhenGathered(new Date(whenGathered));
    }
    return artifactMetadata;
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Date(java.util.Date)

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