From 3779145ad51cb6ff423ff3eafd76bfa0bd90b24d Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Sun, 11 Jul 2010 04:23:27 +0000 Subject: [PATCH] [MRM-980] fix repo merger and update repo merger tests submitted by Patti Arachchige Eshan Sudharaka git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-MRM-980@962977 13f79535-47bb-0310-9956-ffa450edef68 --- .../merge/Maven2RepositoryMerger.java | 29 +++++++++-- .../merge/Maven2RepositoryMergerTest.java | 49 ++++++++++++++----- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java index b8bf53058..c1028137e 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java +++ b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java @@ -81,6 +81,11 @@ public class Maven2RepositoryMerger this.configuration = configuration; } + public void setMetadataRepository( MetadataRepository metadataRepository ) + { + this.metadataRepository = metadataRepository; + } + public void merge( String sourceRepoId, String targetRepoId ) throws Exception { @@ -144,11 +149,25 @@ public class Maven2RepositoryMerger // pom file copying String fileName = artifactMetadata.getProject() + "-" + artifactMetadata.getVersion() + ".pom"; - File sourcePomFile = - pathTranslator.toFile( new File( sourceRepoPath ), artifactMetadata.getId(), artifactMetadata.getProject(), - artifactMetadata.getVersion(), fileName ); - String relativePathToPomFile = sourcePomFile.getAbsolutePath().split( sourceRepoPath )[1]; - File targetPomFile = new File( targetRepoPath, relativePathToPomFile ); + // pom file copying + // TODO need to use path translator to get the pom file path +// String fileName = artifactMetadata.getProject() + "-" + artifactMetadata.getVersion() + ".pom"; +// +// File sourcePomFile = +// pathTranslator.toFile( new File( sourceRepoPath ), artifactMetadata.getId(), artifactMetadata.getProject(), +// artifactMetadata.getVersion(), fileName ); +// +// String relativePathToPomFile = sourcePomFile.getAbsolutePath().split( sourceRepoPath )[1]; +// File targetPomFile = new File( targetRepoPath, relativePathToPomFile ); + + //pom file copying (file path is taken with out using path translator) + + String index = artifactPath.substring( lastIndex + 1 ); + int last = index.lastIndexOf( '.' ); + File sourcePomFile = new File( sourceRepoPath, artifactPath.substring( 0, lastIndex ) + "/" + + artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" ); + File targetPomFile = new File( targetRepoPath, artifactPath.substring( 0, lastIndex ) + "/" + + artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" ); if ( !targetPomFile.exists() ) { diff --git a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java index b2baca3b0..6cf2e1e2a 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java +++ b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java @@ -23,23 +23,26 @@ import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.reports.RepositoryProblemFacet; -import org.mockito.MockitoAnnotations; +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; import org.junit.Before; +import java.util.List; +import java.util.ArrayList; + public class Maven2RepositoryMergerTest extends PlexusInSpringTestCase { - private static final String SOURCE_REPOSITORY_ID = "test-repository"; - - private static final String TARGET_REPOSITORY_ID = "target-repo"; - private static final String TEST_REPO_ID = "test"; - // private static final String TARGET_REPOSITORY_ID = "target-repo"; + private static final String TARGET_REPOSITORY_ID = "target-repo"; private Configuration config; @@ -59,31 +62,51 @@ public class Maven2RepositoryMergerTest throws Exception { super.setUp(); + MockitoAnnotations.initMocks( this ); + metadataRepository = mock( MetadataRepository.class ); + ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); Configuration c = new Configuration(); ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration(); testRepo.setId( TEST_REPO_ID ); testRepo.setLocation( getTestPath( "target/test-repository" ) ); - // testRepo.setLocation( "/boot/gsoc/apps/apache-archiva-1.4-SNAPSHOT/data/repositories/internal" ); + + RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration(); + List knownContentConsumers = new ArrayList(); + knownContentConsumers.add( "metadata-updater12" ); + repoScanConfig.setKnownContentConsumers( knownContentConsumers ); + c.setRepositoryScanning( repoScanConfig ); ManagedRepositoryConfiguration targetRepo = new ManagedRepositoryConfiguration(); targetRepo.setId( "target-rep" ); - targetRepo.setLocation( getTestPath( "src/test/resources/target-repo" ) ); + targetRepo.setLocation( getTestPath( "target" ) ); c.addManagedRepository( testRepo ); c.addManagedRepository( targetRepo ); configuration.save( c ); repositoryMerger = (Maven2RepositoryMerger) lookup( RepositoryMerger.class, "maven2" ); + repositoryMerger.setMetadataRepository( metadataRepository ); + } - metadataRepository = (MetadataRepository) lookup( MetadataRepository.class ); - + private List getArtifacts() + { + List metadata = new ArrayList(); + ArtifactMetadata artifact1 = new ArtifactMetadata(); + artifact1.setNamespace( "com.example.test" ); + artifact1.setProject( "test-artifact" ); + artifact1.setVersion( "1.0-SNAPSHOT" ); + artifact1.setProjectVersion( "1.0-SNAPSHOT" ); + artifact1.setId( "test-artifact-1.0-20100308.230825-1.jar" ); + + metadata.add( artifact1 ); + return metadata; } public void testMerge() throws Exception { + when( metadataRepository.getArtifacts( TEST_REPO_ID ) ).thenReturn( getArtifacts() ); repositoryMerger.merge( TEST_REPO_ID, "target-rep" ); - // assert( true , (metadataRepository.getArtifacts( TEST_REPO_ID ).size() > 0 ) ); - + verify( metadataRepository ).getArtifacts( TEST_REPO_ID ); } } \ No newline at end of file -- 2.39.5