Search in sources :

Example 1 with IncludesFilter

use of org.apache.archiva.metadata.repository.filter.IncludesFilter 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 2 with IncludesFilter

use of org.apache.archiva.metadata.repository.filter.IncludesFilter in project archiva by apache.

the class DefaultMergeRepositoriesService method mergeWithOutSnapshots.

private void mergeWithOutSnapshots(MetadataRepository metadataRepository, List<ArtifactMetadata> sourceArtifacts, String sourceRepoId, String repoid) throws RepositoryMergerException {
    List<ArtifactMetadata> artifactsWithOutSnapshots = new ArrayList<>();
    for (ArtifactMetadata metadata : sourceArtifacts) {
        if (VersionUtil.isSnapshot(metadata.getProjectVersion())) // if ( metadata.getProjectVersion().contains( VersionUtil.SNAPSHOT ) )
        {
            artifactsWithOutSnapshots.add(metadata);
        } else {
            triggerAuditEvent(repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
        }
    }
    sourceArtifacts.removeAll(artifactsWithOutSnapshots);
    Filter<ArtifactMetadata> artifactListWithOutSnapShots = new IncludesFilter<ArtifactMetadata>(sourceArtifacts);
    repositoryMerger.merge(metadataRepository, sourceRepoId, repoid, artifactListWithOutSnapShots);
}
Also used : IncludesFilter(org.apache.archiva.metadata.repository.filter.IncludesFilter) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Aggregations

ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)2 IncludesFilter (org.apache.archiva.metadata.repository.filter.IncludesFilter)2 ArrayList (java.util.ArrayList)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)1 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)1 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)1