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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations