mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-10-31 10:35:56 +01:00 
			
		
		
		
	Refactor the repository store implementation in order to store repositories in specific paths.
This commit is contained in:
		| @@ -7,15 +7,12 @@ import lombok.NoArgsConstructor; | ||||
| import lombok.Setter; | ||||
| import sonia.scm.repository.Compatibility; | ||||
|  | ||||
| import java.io.File; | ||||
|  | ||||
| @NoArgsConstructor | ||||
| @Getter | ||||
| @Setter | ||||
| public class SvnConfigDto extends HalRepresentation { | ||||
|  | ||||
|   private boolean disabled; | ||||
|   private File repositoryDirectory; | ||||
|  | ||||
|   private boolean enabledGZip; | ||||
|   private Compatibility compatibility; | ||||
|   | ||||
| @@ -85,9 +85,9 @@ public class SvnRepositoryHandler | ||||
|  | ||||
|   @Inject | ||||
|   public SvnRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem, | ||||
|     HookEventFacade eventFacade) | ||||
|                               HookEventFacade eventFacade, RepositoryLocationResolver repositoryLocationResolver) | ||||
|   { | ||||
|     super(storeFactory, fileSystem); | ||||
|     super(storeFactory, fileSystem, repositoryLocationResolver); | ||||
|  | ||||
|     // register logger | ||||
|     SVNDebugLog.setDefaultLog(new SVNKitLogger()); | ||||
|   | ||||
| @@ -7,8 +7,6 @@ import org.mockito.runners.MockitoJUnitRunner; | ||||
| import sonia.scm.repository.Compatibility; | ||||
| import sonia.scm.repository.SvnConfig; | ||||
|  | ||||
| import java.io.File; | ||||
|  | ||||
| import static org.junit.Assert.assertEquals; | ||||
| import static org.junit.Assert.assertTrue; | ||||
|  | ||||
| @@ -24,7 +22,6 @@ public class SvnConfigDtoToSvnConfigMapperTest { | ||||
|     SvnConfig config = mapper.map(dto); | ||||
|  | ||||
|     assertTrue(config.isDisabled()); | ||||
|     assertEquals("repository/directory", config.getRepositoryDirectory().getPath()); | ||||
|  | ||||
|     assertEquals(Compatibility.PRE15, config.getCompatibility()); | ||||
|     assertTrue(config.isEnabledGZip()); | ||||
| @@ -33,7 +30,6 @@ public class SvnConfigDtoToSvnConfigMapperTest { | ||||
|   private SvnConfigDto createDefaultDto() { | ||||
|     SvnConfigDto configDto = new SvnConfigDto(); | ||||
|     configDto.setDisabled(true); | ||||
|     configDto.setRepositoryDirectory(new File("repository/directory")); | ||||
|     configDto.setCompatibility(Compatibility.PRE15); | ||||
|     configDto.setEnabledGZip(true); | ||||
|  | ||||
|   | ||||
| @@ -81,7 +81,6 @@ public class SvnConfigResourceTest { | ||||
|     ObjectNode responseJson = new ObjectMapper().readValue(responseString, ObjectNode.class); | ||||
|  | ||||
|     assertTrue(responseString.contains("\"disabled\":false")); | ||||
|     assertTrue(responseJson.get("repositoryDirectory").asText().endsWith("repository/directory")); | ||||
|     assertTrue(responseString.contains("\"self\":{\"href\":\"/v2/config/svn")); | ||||
|     assertTrue(responseString.contains("\"update\":{\"href\":\"/v2/config/svn")); | ||||
|   } | ||||
| @@ -150,7 +149,6 @@ public class SvnConfigResourceTest { | ||||
|   private SvnConfig createConfiguration() { | ||||
|     SvnConfig config = new SvnConfig(); | ||||
|     config.setDisabled(false); | ||||
|     config.setRepositoryDirectory(new File("repository/directory")); | ||||
|     return config; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -61,7 +61,6 @@ public class SvnConfigToSvnConfigDtoMapperTest { | ||||
|     SvnConfigDto dto = mapper.map(config); | ||||
|  | ||||
|     assertTrue(dto.isDisabled()); | ||||
|     assertEquals("repository/directory", dto.getRepositoryDirectory().getPath()); | ||||
|  | ||||
|     assertEquals(Compatibility.PRE15, dto.getCompatibility()); | ||||
|     assertTrue(dto.isEnabledGZip()); | ||||
| @@ -84,7 +83,6 @@ public class SvnConfigToSvnConfigDtoMapperTest { | ||||
|   private SvnConfig createConfiguration() { | ||||
|     SvnConfig config = new SvnConfig(); | ||||
|     config.setDisabled(true); | ||||
|     config.setRepositoryDirectory(new File("repository/directory")); | ||||
|  | ||||
|     config.setCompatibility(Compatibility.PRE15); | ||||
|     config.setEnabledGZip(true); | ||||
|   | ||||
| @@ -43,6 +43,7 @@ import sonia.scm.store.ConfigurationStore; | ||||
| import sonia.scm.store.ConfigurationStoreFactory; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.nio.file.Path; | ||||
|  | ||||
| import static org.junit.Assert.assertEquals; | ||||
| import static org.junit.Assert.assertTrue; | ||||
| @@ -72,6 +73,9 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase { | ||||
|  | ||||
|   private HookEventFacade facade = new HookEventFacade(repositoryManagerProvider, hookContextFactory); | ||||
|  | ||||
|   RepositoryLocationResolver repositoryLocationResolver ; | ||||
|   private Path repoDir; | ||||
|  | ||||
|   @Override | ||||
|   protected void checkDirectory(File directory) { | ||||
|     File format = new File(directory, "format"); | ||||
| @@ -87,16 +91,22 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase { | ||||
|  | ||||
|   @Override | ||||
|   protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory, | ||||
|                                                       File directory) { | ||||
|     SvnRepositoryHandler handler = new SvnRepositoryHandler(factory, | ||||
|       new DefaultFileSystem(), null); | ||||
|                                                       File directory) throws RepositoryPathNotFoundException { | ||||
|  | ||||
|  | ||||
|     DefaultFileSystem fileSystem = new DefaultFileSystem(); | ||||
|     PathBasedRepositoryDAO repoDao = mock(PathBasedRepositoryDAO.class); | ||||
|  | ||||
|     repositoryLocationResolver = new RepositoryLocationResolver(repoDao, new InitialRepositoryLocationResolver(contextProvider,fileSystem)); | ||||
|     SvnRepositoryHandler handler = new SvnRepositoryHandler(factory, | ||||
|       new DefaultFileSystem(), null, repositoryLocationResolver); | ||||
|  | ||||
|     repoDir = directory.toPath(); | ||||
|     when(repoDao.getPath(any())).thenReturn(repoDir); | ||||
|     handler.init(contextProvider); | ||||
|  | ||||
|     SvnConfig config = new SvnConfig(); | ||||
|  | ||||
|     config.setRepositoryDirectory(directory); | ||||
|  | ||||
|     // TODO fix event bus exception | ||||
|     handler.setConfig(config); | ||||
|  | ||||
| @@ -107,15 +117,14 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase { | ||||
|   public void getDirectory() { | ||||
|     when(factory.getStore(any(), any())).thenReturn(store); | ||||
|     SvnRepositoryHandler repositoryHandler = new SvnRepositoryHandler(factory, | ||||
|       new DefaultFileSystem(), facade); | ||||
|       new DefaultFileSystem(), facade, repositoryLocationResolver); | ||||
|  | ||||
|     SvnConfig svnConfig = new SvnConfig(); | ||||
|     svnConfig.setRepositoryDirectory(new File("/path")); | ||||
|     repositoryHandler.setConfig(svnConfig); | ||||
|  | ||||
|     Repository repository = new Repository("id", "svn", "Space", "Name"); | ||||
|  | ||||
|     File path = repositoryHandler.getDirectory(repository); | ||||
|     assertEquals("/path/id", path.getAbsolutePath()); | ||||
|     assertEquals(repoDir.toString()+File.separator+InitialRepositoryLocationResolver.REPOSITORIES_NATIVE_DIRECTORY, path.getAbsolutePath()); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user