@Test public void testMerge() throws Exception { String targetRepoPath = "target/test-repository-target"; Path mergedArtifact = Paths.get( targetRepoPath, "com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar" ); Path mavenMetadata = Paths.get( targetRepoPath, "com/example/test/test-artifact/maven-metadata.xml" ); Path pom = Paths.get( targetRepoPath, "com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom" ); for (Path testArtifact : new Path[] { mergedArtifact, mavenMetadata, pom }) { Files.deleteIfExists(testArtifact); } assertFalse( "Artifact file exists already", Files.exists(mergedArtifact) ); assertFalse( "Metadata file exists already", Files.exists(mavenMetadata) ); assertFalse( "Pom File exists already", Files.exists(pom) ); Configuration c = new Configuration(); ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration(); testRepo.setId( TEST_REPO_ID ); testRepo.setLocation( "target/test-repository" ); RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration(); List<String> knownContentConsumers = new ArrayList<>(); knownContentConsumers.add( "metadata-updater12" ); repoScanConfig.setKnownContentConsumers( knownContentConsumers ); c.setRepositoryScanning( repoScanConfig ); ManagedRepositoryConfiguration targetRepo = new ManagedRepositoryConfiguration(); targetRepo.setId( "target-rep" ); targetRepo.setLocation( targetRepoPath ); c.addManagedRepository( testRepo ); c.addManagedRepository( targetRepo ); configuration.save( c ); when(metadataRepository.getArtifacts(session, TEST_REPO_ID)).thenReturn(getArtifacts()); repositoryMerger.merge(metadataRepository, TEST_REPO_ID, "target-rep"); verify(metadataRepository).getArtifacts(session, TEST_REPO_ID); assertTrue( Files.exists(mergedArtifact) ); assertTrue( Files.exists(mavenMetadata) ); assertTrue( Files.exists(pom) ); }
@Override public void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts(session , sourceRepoId ); for ( ArtifactMetadata artifactMetadata : artifactsInSourceRepo ) { artifactMetadata.setRepositoryId( targetRepoId ); createFolderStructure( sourceRepoId, targetRepoId, artifactMetadata ); } } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( IOException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( RepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } }
Maven2RepositoryMerger implements RepositoryMerger { @Override public void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts(session , sourceRepoId ); for ( ArtifactMetadata artifactMetadata : artifactsInSourceRepo ) { artifactMetadata.setRepositoryId( targetRepoId ); createFolderStructure( sourceRepoId, targetRepoId, artifactMetadata ); } } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( IOException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( RepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } } }
Maven2RepositoryMerger implements RepositoryMerger { @Override public void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts(session , sourceRepoId ); for ( ArtifactMetadata artifactMetadata : artifactsInSourceRepo ) { artifactMetadata.setRepositoryId( targetRepoId ); createFolderStructure( sourceRepoId, targetRepoId, artifactMetadata ); } } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( IOException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( RepositoryException 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 void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts(session , sourceRepoId ); for ( ArtifactMetadata artifactMetadata : artifactsInSourceRepo ) { artifactMetadata.setRepositoryId( targetRepoId ); createFolderStructure( sourceRepoId, targetRepoId, artifactMetadata ); } } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( IOException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( RepositoryException 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 void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts(session , sourceRepoId ); for ( ArtifactMetadata artifactMetadata : artifactsInSourceRepo ) { artifactMetadata.setRepositoryId( targetRepoId ); createFolderStructure( sourceRepoId, targetRepoId, artifactMetadata ); } } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( IOException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } catch ( RepositoryException 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 );  }