@Test public void testMergeWithOutConflictArtifacts() throws Exception { String sourceRepoId = "source-repo"; ArtifactMetadata artifact1 = new ArtifactMetadata(); artifact1.setNamespace( "org.testng" ); artifact1.setProject( "testng" ); artifact1.setVersion( "5.8" ); artifact1.setProjectVersion( "5.8" ); artifact1.setId( "testng-5.8-jdk15.jar" ); artifact1.setRepositoryId( sourceRepoId ); List<ArtifactMetadata> sourceRepoArtifactsList = getArtifacts(); sourceRepoArtifactsList.add( artifact1 ); List<ArtifactMetadata> targetRepoArtifactsList = getArtifacts(); Configuration c = new Configuration(); ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration(); testRepo.setId( TEST_REPO_ID ); testRepo.setLocation( "target/test-repository" ); String sourceRepo = "src/test/resources/test-repository-with-conflict-artifacts"; ManagedRepositoryConfiguration testRepoWithConflicts = new ManagedRepositoryConfiguration(); testRepoWithConflicts.setId( sourceRepoId ); testRepoWithConflicts.setLocation( sourceRepo ); RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration(); List<String> knownContentConsumers = new ArrayList<>(); knownContentConsumers.add( "metadata-updater" ); repoScanConfig.setKnownContentConsumers( knownContentConsumers ); c.setRepositoryScanning( repoScanConfig ); c.addManagedRepository( testRepo ); c.addManagedRepository( testRepoWithConflicts ); configuration.save( c ); Path targetRepoFile = Paths.get( "/target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar" ); targetRepoFile.toFile().setReadOnly(); when(metadataRepository.getArtifacts(session, sourceRepoId)).thenReturn(sourceRepoArtifactsList); when(metadataRepository.getArtifacts(session, TEST_REPO_ID)).thenReturn(targetRepoArtifactsList); assertEquals(1, repositoryMerger.getConflictingArtifacts(metadataRepository, sourceRepoId, TEST_REPO_ID).size()); verify(metadataRepository).getArtifacts(session, TEST_REPO_ID); }
@Override public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo, String targetRepo ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { TreeSet<ArtifactMetadata> targetArtifacts = new TreeSet<>(META_COMPARATOR); targetArtifacts.addAll(metadataRepository.getArtifacts(session , targetRepo )); TreeSet<ArtifactMetadata> sourceArtifacts = new TreeSet<>(META_COMPARATOR); sourceArtifacts.addAll(metadataRepository.getArtifacts(session , sourceRepo )); sourceArtifacts.retainAll(targetArtifacts); return new ArrayList<>(sourceArtifacts); } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } }
Maven2RepositoryMerger implements RepositoryMerger { @Override public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo, String targetRepo ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { TreeSet<ArtifactMetadata> targetArtifacts = new TreeSet<>(META_COMPARATOR); targetArtifacts.addAll(metadataRepository.getArtifacts(session , targetRepo )); TreeSet<ArtifactMetadata> sourceArtifacts = new TreeSet<>(META_COMPARATOR); sourceArtifacts.addAll(metadataRepository.getArtifacts(session , sourceRepo )); sourceArtifacts.retainAll(targetArtifacts); return new ArrayList<>(sourceArtifacts); } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } } }
Maven2RepositoryMerger implements RepositoryMerger { @Override public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo, String targetRepo ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { TreeSet<ArtifactMetadata> targetArtifacts = new TreeSet<>(META_COMPARATOR); targetArtifacts.addAll(metadataRepository.getArtifacts(session , targetRepo )); TreeSet<ArtifactMetadata> sourceArtifacts = new TreeSet<>(META_COMPARATOR); sourceArtifacts.addAll(metadataRepository.getArtifacts(session , sourceRepo )); sourceArtifacts.retainAll(targetArtifacts); return new ArrayList<>(sourceArtifacts); } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } } @Inject  Maven2RepositoryMerger(
        @Named (value = "archivaConfiguration#default") ArchivaConfiguration archivaConfiguration,
        @Named (value = "repositoryPathTranslator#maven2") RepositoryPathTranslator repositoryPathTranslator ); }
Maven2RepositoryMerger implements RepositoryMerger { @Override public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo, String targetRepo ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { TreeSet<ArtifactMetadata> targetArtifacts = new TreeSet<>(META_COMPARATOR); targetArtifacts.addAll(metadataRepository.getArtifacts(session , targetRepo )); TreeSet<ArtifactMetadata> sourceArtifacts = new TreeSet<>(META_COMPARATOR); sourceArtifacts.addAll(metadataRepository.getArtifacts(session , sourceRepo )); sourceArtifacts.retainAll(targetArtifacts); return new ArrayList<>(sourceArtifacts); } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } } @Inject  Maven2RepositoryMerger(
        @Named (value = "archivaConfiguration#default") ArchivaConfiguration archivaConfiguration,
        @Named (value = "repositoryPathTranslator#maven2") RepositoryPathTranslator repositoryPathTranslator ); void setConfiguration( ArchivaConfiguration configuration ); @Override boolean supportsRepository( RepositoryType type ); @Override void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId ); @Override void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId,
                       Filter<ArtifactMetadata> filter ); @Override List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
                                                           String targetRepo ); RepositorySessionFactory getRepositorySessionFactory( ); void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory ); }
Maven2RepositoryMerger implements RepositoryMerger { @Override public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo, String targetRepo ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { TreeSet<ArtifactMetadata> targetArtifacts = new TreeSet<>(META_COMPARATOR); targetArtifacts.addAll(metadataRepository.getArtifacts(session , targetRepo )); TreeSet<ArtifactMetadata> sourceArtifacts = new TreeSet<>(META_COMPARATOR); sourceArtifacts.addAll(metadataRepository.getArtifacts(session , sourceRepo )); sourceArtifacts.retainAll(targetArtifacts); return new ArrayList<>(sourceArtifacts); } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } } @Inject  Maven2RepositoryMerger(
        @Named (value = "archivaConfiguration#default") ArchivaConfiguration archivaConfiguration,
        @Named (value = "repositoryPathTranslator#maven2") RepositoryPathTranslator repositoryPathTranslator ); void setConfiguration( ArchivaConfiguration configuration ); @Override boolean supportsRepository( RepositoryType type ); @Override void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId ); @Override void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId,
                       Filter<ArtifactMetadata> filter ); @Override List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
                                                           String targetRepo ); RepositorySessionFactory getRepositorySessionFactory( ); void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory );  }