Search in sources :

Example 51 with ArtifactMetadata

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);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) RssFeedEntry(org.apache.archiva.rss.RssFeedEntry) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) Date(java.util.Date) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 52 with ArtifactMetadata

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));
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) HashMap(java.util.HashMap) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Date(java.util.Date) Test(org.junit.Test)

Example 53 with ArtifactMetadata

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();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 54 with ArtifactMetadata

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();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) IncludesFilter(org.apache.archiva.metadata.repository.filter.IncludesFilter) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 55 with ArtifactMetadata

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;
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

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