Remove dead code

This commit is contained in:
René Pfeuffer
2018-11-23 13:16:18 +01:00
parent 8b8240319b
commit aa596af880
7 changed files with 11 additions and 38 deletions

View File

@@ -86,7 +86,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
@Override @Override
public Repository create(Repository repository) { public Repository create(Repository repository) {
File directory = repositoryLocationResolver.getNativeDirectory(repository); File directory = initialRepositoryLocationResolver.getDefaultNativeDirectory(repository);
if (directory != null && directory.exists()) { if (directory != null && directory.exists()) {
throw new AlreadyExistsException(repository); throw new AlreadyExistsException(repository);
} }
@@ -161,11 +161,6 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
return directory; return directory;
} }
@Override
public File getInitialBaseDirectory() {
return initialRepositoryLocationResolver.getBaseDirectory();
}
@Override @Override
public String getVersionInformation() { public String getVersionInformation() {
return DEFAULT_VERSION_INFORMATION; return DEFAULT_VERSION_INFORMATION;

View File

@@ -30,15 +30,16 @@ public class InitialRepositoryLocationResolver {
this.context = context; this.context = context;
} }
File getBaseDirectory() {
return new File(context.getBaseDirectory(), DEFAULT_REPOSITORY_PATH);
}
File getDefaultDirectory(Repository repository) { File getDefaultDirectory(Repository repository) {
String initialRepoFolder = getRelativeRepositoryPath(repository); String initialRepoFolder = getRelativeRepositoryPath(repository);
return new File(context.getBaseDirectory(), initialRepoFolder); return new File(context.getBaseDirectory(), initialRepoFolder);
} }
File getDefaultNativeDirectory(Repository repository) {
String initialRepoFolder = getRelativeRepositoryPath(repository);
return new File(context.getBaseDirectory(), initialRepoFolder + "/data");
}
public String getRelativeRepositoryPath(Repository repository) { public String getRelativeRepositoryPath(Repository repository) {
return DEFAULT_REPOSITORY_PATH + File.separator + repository.getId(); return DEFAULT_REPOSITORY_PATH + File.separator + repository.getId();
} }

View File

@@ -11,10 +11,7 @@ import java.nio.file.Path;
public interface PathBasedRepositoryDAO extends RepositoryDAO { public interface PathBasedRepositoryDAO extends RepositoryDAO {
/** /**
* get the current path of the repository or create it * Get the current path of the repository. This works for existing repositories only, not for repositories that should be created.
*
* @param repository
* @return the current path of the repository
*/ */
Path getPath(Repository repository) ; Path getPath(Repository repository) ;
} }

View File

@@ -48,10 +48,4 @@ public interface RepositoryDirectoryHandler extends RepositoryHandler {
* @return the current directory of the given repository * @return the current directory of the given repository
*/ */
File getDirectory(Repository repository); File getDirectory(Repository repository);
/**
* get the initial directory of all repositories
* @return the initial directory of all repositories
*/
File getInitialBaseDirectory();
} }

View File

@@ -153,7 +153,10 @@ public class XmlRepositoryDAO
return context return context
.getBaseDirectory() .getBaseDirectory()
.toPath() .toPath()
.resolve(findExistingRepositoryPath(repository).map(RepositoryPath::getPath).orElse(initialRepositoryLocationResolver.getRelativeRepositoryPath(repository))); .resolve(
findExistingRepositoryPath(repository)
.map(RepositoryPath::getPath)
.orElseThrow(() -> new InternalRepositoryException(repository, "could not find base directory for repository")));
} }
@Override @Override

View File

@@ -104,19 +104,6 @@ public class XmlRepositoryDAOTest {
assertThat(path.toString()).isEqualTo("/tmp/path"); assertThat(path.toString()).isEqualTo("/tmp/path");
} }
@Test
public void shouldGetPathForNewRepository() {
when(db.getPaths()).thenReturn(emptyList());
InitialRepositoryLocationResolver initialRepositoryLocationResolver = new InitialRepositoryLocationResolver(context);
XmlRepositoryDAO dao = new XmlRepositoryDAO(storeFactory, initialRepositoryLocationResolver, context);
Repository newRepository = new Repository("id", "new", null, null);
Path path = dao.getPath(newRepository);
assertThat(path.toString()).isEqualTo(context.getBaseDirectory().getPath() + "/" + InitialRepositoryLocationResolver.DEFAULT_REPOSITORY_PATH + "/id");
}
@Test @Test
public void shouldFindRepositoryForRelativePath() { public void shouldFindRepositoryForRelativePath() {
new File(context.getBaseDirectory(), "relative/path/data").mkdirs(); new File(context.getBaseDirectory(), "relative/path/data").mkdirs();

View File

@@ -33,10 +33,6 @@ public class HgHookCallbackServletTest {
String path = "/tmp/hg/12345"; String path = "/tmp/hg/12345";
when(request.getParameter(PARAM_REPOSITORYPATH)).thenReturn(path); when(request.getParameter(PARAM_REPOSITORYPATH)).thenReturn(path);
File file = new File(path);
when(handler.getInitialBaseDirectory()).thenReturn(file);
servlet.doPost(request, response); servlet.doPost(request, response);
verify(response, never()).sendError(anyInt()); verify(response, never()).sendError(anyInt());