use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class NewVersionsOfArtifactRssFeedProcessor method processNewVersionsOfArtifact.
private SyndFeed processNewVersionsOfArtifact(String groupId, String artifactId, MetadataRepository metadataRepository) throws FeedException {
List<ArtifactMetadata> artifacts = new ArrayList<>();
try {
for (String repoId : metadataRepository.getRepositories()) {
Collection<String> versions = metadataRepository.getProjectVersions(repoId, groupId, artifactId);
for (String version : versions) {
artifacts.addAll(metadataRepository.getArtifacts(repoId, groupId, artifactId, version));
}
}
} catch (MetadataRepositoryException e) {
throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
} catch (MetadataResolutionException e) {
throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
}
long tmp = 0;
RssFeedEntry entry = null;
List<RssFeedEntry> entries = new ArrayList<>();
String description = "";
int idx = 0;
for (ArtifactMetadata artifact : artifacts) {
long whenGathered = artifact.getWhenGathered().getTime();
if (tmp != whenGathered) {
if (entry != null) {
entry.setDescription(description);
entries.add(entry);
entry = null;
}
entry = new RssFeedEntry(this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date(whenGathered));
entry.setPublishedDate(artifact.getWhenGathered());
description = this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() + " | ";
} else {
description = description + artifact.getId() + " | ";
}
if (idx == (artifacts.size() - 1)) {
entry.setDescription(description);
entries.add(entry);
}
tmp = whenGathered;
idx++;
}
String key = groupId + ":" + artifactId;
return generator.generateFeed(getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key + "\' found during repository scan.", entries);
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class NewArtifactsRssFeedProcessorTest method testProcess.
@SuppressWarnings("unchecked")
@Test
public void testProcess() throws Exception {
List<ArtifactMetadata> newArtifacts = new ArrayList<>();
Date whenGathered = Calendar.getInstance().getTime();
newArtifacts.add(createArtifact("artifact-one", "1.0", whenGathered));
newArtifacts.add(createArtifact("artifact-one", "1.1", whenGathered));
newArtifacts.add(createArtifact("artifact-one", "2.0", whenGathered));
newArtifacts.add(createArtifact("artifact-two", "1.0.1", whenGathered));
newArtifacts.add(createArtifact("artifact-two", "1.0.2", whenGathered));
newArtifacts.add(createArtifact("artifact-two", "1.0.3-SNAPSHOT", whenGathered));
newArtifacts.add(createArtifact("artifact-three", "2.0-SNAPSHOT", whenGathered));
newArtifacts.add(createArtifact("artifact-four", "1.1-beta-2", whenGathered));
metadataRepository.setArtifactsByDateRange(newArtifacts);
Map<String, String> reqParams = new HashMap<>();
reqParams.put(RssFeedProcessor.KEY_REPO_ID, TEST_REPO);
SyndFeed feed = newArtifactsProcessor.process(reqParams, metadataRepository);
// check that the date used in the call is close to the one passed (5 seconds difference at most)
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.add(Calendar.DATE, -30);
assertTrue((metadataRepository.getFrom().getTime() - cal.getTimeInMillis()) < 1000 * 5);
assertEquals(null, metadataRepository.getTo());
assertEquals(TEST_REPO, metadataRepository.getRepoId());
assertTrue(feed.getTitle().equals("New Artifacts in Repository 'test-repo'"));
assertTrue(feed.getDescription().equals("New artifacts found in repository 'test-repo' during repository scan."));
assertTrue(feed.getLanguage().equals("en-us"));
assertTrue(feed.getPublishedDate().equals(whenGathered));
List<SyndEntry> entries = feed.getEntries();
assertEquals(entries.size(), 1);
assertTrue(entries.get(0).getTitle().equals("New Artifacts in Repository 'test-repo' as of " + whenGathered));
assertTrue(entries.get(0).getPublishedDate().equals(whenGathered));
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class DefaultMergeRepositoriesService method doMerge.
protected void doMerge(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
MetadataRepository metadataRepository = repositorySession.getRepository();
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
if (repository.isReleases() && !repository.isSnapshots()) {
mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
} else {
repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId);
for (ArtifactMetadata metadata : sourceArtifacts) {
triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
}
}
doScanRepository(targetRepositoryId, false);
} catch (MetadataRepositoryException e) {
throw new ArchivaRestServiceException(e.getMessage(), e);
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(e.getMessage(), e);
} finally {
repositorySession.close();
}
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class DefaultMergeRepositoriesService method mergeBySkippingConflicts.
public void mergeBySkippingConflicts(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
List<ArtifactMetadata> conflictSourceArtifacts = repositoryMerger.getConflictingArtifacts(repositorySession.getRepository(), sourceRepositoryId, targetRepositoryId);
MetadataRepository metadataRepository = repositorySession.getRepository();
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
sourceArtifacts.removeAll(conflictSourceArtifacts);
ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
if (repository.isReleases() && !repository.isSnapshots()) {
mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
} else {
Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(sourceArtifacts);
repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId, artifactsWithOutConflicts);
for (ArtifactMetadata metadata : sourceArtifacts) {
triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
}
}
doScanRepository(targetRepositoryId, false);
} catch (MetadataRepositoryException e) {
throw new ArchivaRestServiceException(e.getMessage(), e);
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(e.getMessage(), e);
} finally {
repositorySession.close();
}
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class NewVersionsOfArtifactRssFeedProcessorTest method createArtifact.
private ArtifactMetadata createArtifact(Date whenGathered, String version) {
ArtifactMetadata artifact = new ArtifactMetadata();
artifact.setNamespace(GROUP_ID);
artifact.setProject(ARTIFACT_ID);
artifact.setProjectVersion(version);
artifact.setVersion(version);
artifact.setRepositoryId(TEST_REPO);
artifact.setId(ARTIFACT_ID + "-" + version + ".jar");
artifact.setWhenGathered(whenGathered);
return artifact;
}
Aggregations