use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class FileMetadataRepository method getArtifacts.
@Override
public Collection<ArtifactMetadata> getArtifacts(String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
try {
Map<String, ArtifactMetadata> artifacts = new HashMap<>();
Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
for (Map.Entry entry : properties.entrySet()) {
String name = (String) entry.getKey();
StringTokenizer tok = new StringTokenizer(name, ":");
if (tok.hasMoreTokens() && "artifact".equals(tok.nextToken())) {
String field = tok.nextToken();
String id = tok.nextToken();
ArtifactMetadata artifact = artifacts.get(id);
if (artifact == null) {
artifact = new ArtifactMetadata();
artifact.setRepositoryId(repoId);
artifact.setNamespace(namespace);
artifact.setProject(projectId);
artifact.setProjectVersion(projectVersion);
artifact.setVersion(projectVersion);
artifact.setId(id);
artifacts.put(id, artifact);
}
String value = (String) entry.getValue();
if ("updated".equals(field)) {
artifact.setFileLastModified(Long.parseLong(value));
} else if ("size".equals(field)) {
artifact.setSize(Long.valueOf(value));
} else if ("whenGathered".equals(field)) {
artifact.setWhenGathered(new Date(Long.parseLong(value)));
} else if ("version".equals(field)) {
artifact.setVersion(value);
} else if ("md5".equals(field)) {
artifact.setMd5(value);
} else if ("sha1".equals(field)) {
artifact.setSha1(value);
} else if ("facetIds".equals(field)) {
if (value.length() > 0) {
String propertyPrefix = "artifact:facet:" + id + ":";
for (String facetId : value.split(",")) {
MetadataFacetFactory factory = metadataFacetFactories.get(facetId);
if (factory == null) {
log.error("Attempted to load unknown artifact metadata facet: {}", facetId);
} else {
MetadataFacet facet = factory.createMetadataFacet();
String prefix = propertyPrefix + facet.getFacetId();
Map<String, String> map = new HashMap<>();
for (Object key : new ArrayList<>(properties.keySet())) {
String property = (String) key;
if (property.startsWith(prefix)) {
map.put(property.substring(prefix.length() + 1), properties.getProperty(property));
}
}
facet.fromProperties(map);
artifact.addFacet(facet);
}
}
}
updateArtifactFacets(artifact, properties);
}
}
}
return artifacts.values();
} catch (IOException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class FileMetadataRepository method getArtifactsByDateRange.
@Override
public List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime) throws MetadataRepositoryException {
try {
// TODO: this is quite slow - if we are to persist with this repository implementation we should build an index
// of this information (eg. in Lucene, as before)
List<ArtifactMetadata> artifacts = new ArrayList<>();
for (String ns : getRootNamespaces(repoId)) {
getArtifactsByDateRange(artifacts, repoId, ns, startTime, endTime);
}
artifacts.sort(new ArtifactComparator());
return artifacts;
} catch (MetadataResolutionException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class JcrMetadataRepository method getArtifactsByDateRange.
@Override
public List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime) throws MetadataRepositoryException {
List<ArtifactMetadata> artifacts;
String q = getArtifactQuery(repoId);
if (startTime != null) {
q += " AND [whenGathered] >= $start";
}
if (endTime != null) {
q += " AND [whenGathered] <= $end";
}
try {
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
ValueFactory valueFactory = getJcrSession().getValueFactory();
if (startTime != null) {
query.bindValue("start", valueFactory.createValue(createCalendar(startTime)));
}
if (endTime != null) {
query.bindValue("end", valueFactory.createValue(createCalendar(endTime)));
}
QueryResult result = query.execute();
artifacts = new ArrayList<>();
for (Node n : JcrUtils.getNodes(result)) {
artifacts.add(getArtifactFromNode(repoId, n));
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
return artifacts;
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class Maven2RepositoryMetadataResolverTest method testGetArtifactsTimestampedSnapshots.
@Test
public void testGetArtifactsTimestampedSnapshots() throws Exception {
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(storage.readArtifactsMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT", ALL)));
assertEquals(1, artifacts.size());
ArtifactMetadata artifact = artifacts.get(0);
assertEquals("missing-metadata-1.0-20091101.112233-1.pom", artifact.getId());
assertEquals("com.example.test", artifact.getNamespace());
assertEquals("missing-metadata", artifact.getProject());
assertEquals("1.0-20091101.112233-1", artifact.getVersion());
assertEquals(TEST_REPO_ID, artifact.getRepositoryId());
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class Maven2RepositoryMetadataResolverTest method testGetArtifactMetadata.
@Test
public void testGetArtifactMetadata() throws Exception {
Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata(new ReadMetadataRequest(TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL));
List<ArtifactMetadata> artifacts = new ArrayList<>(springArtifacts);
Collections.sort(artifacts, new Comparator<ArtifactMetadata>() {
@Override
public int compare(ArtifactMetadata o1, ArtifactMetadata o2) {
return o1.getId().compareTo(o2.getId());
}
});
assertEquals(3, artifacts.size());
ArtifactMetadata artifactMetadata = artifacts.get(0);
assertEquals("plexus-spring-1.2-sources.jar", artifactMetadata.getId());
MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
assertEquals(0, facet.getBuildNumber());
assertNull(facet.getTimestamp());
assertEquals("sources", facet.getClassifier());
assertEquals("java-source", facet.getType());
artifactMetadata = artifacts.get(1);
assertEquals("plexus-spring-1.2.jar", artifactMetadata.getId());
facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
assertEquals(0, facet.getBuildNumber());
assertNull(facet.getTimestamp());
assertNull(facet.getClassifier());
assertEquals("jar", facet.getType());
artifactMetadata = artifacts.get(2);
assertEquals("plexus-spring-1.2.pom", artifactMetadata.getId());
facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
assertEquals(0, facet.getBuildNumber());
assertNull(facet.getTimestamp());
assertNull(facet.getClassifier());
assertEquals("pom", facet.getType());
}
Aggregations