Remove unnecessary interface

This commit is contained in:
René Pfeuffer
2019-03-29 10:36:55 +01:00
parent 1162536e21
commit ee219f2d59
5 changed files with 47 additions and 55 deletions

View File

@@ -15,15 +15,12 @@ public abstract class SimpleWorkdirFactory<R, C> implements WorkdirFactory<R, C>
private final File poolDirectory;
private final CloneProvider<R, C> cloneProvider;
public SimpleWorkdirFactory(CloneProvider<R, C> cloneProvider) {
this(new File(System.getProperty("java.io.tmpdir"), "scmm-work-pool"), cloneProvider);
public SimpleWorkdirFactory() {
this(new File(System.getProperty("java.io.tmpdir"), "scmm-work-pool"));
}
public SimpleWorkdirFactory(File poolDirectory, CloneProvider<R, C> cloneProvider) {
public SimpleWorkdirFactory(File poolDirectory) {
this.poolDirectory = poolDirectory;
this.cloneProvider = cloneProvider;
if (!poolDirectory.exists() && !poolDirectory.mkdirs()) {
throw new IllegalStateException("could not create pool directory " + poolDirectory);
}
@@ -33,17 +30,19 @@ public abstract class SimpleWorkdirFactory<R, C> implements WorkdirFactory<R, C>
public WorkingCopy<R> createWorkingCopy(C context) {
try {
File directory = createNewWorkdir();
ParentAndClone<R> parentAndClone = cloneProvider.cloneRepository(context, directory);
ParentAndClone<R> parentAndClone = cloneRepository(context, directory);
return new WorkingCopy<>(parentAndClone.getClone(), parentAndClone.getParent(), this::close, directory);
} catch (IOException e) {
throw new InternalRepositoryException(getRepository(context), "could not create temporary directory for clone of repository", e);
throw new InternalRepositoryException(getScmRepository(context), "could not clone repository in temporary directory", e);
}
}
protected abstract Repository getRepository(C context);
protected abstract Repository getScmRepository(C context);
protected abstract void closeRepository(R repository);
protected abstract ParentAndClone<R> cloneRepository(C context, File target) throws IOException;
private File createNewWorkdir() throws IOException {
return Files.createTempDirectory(poolDirectory.toPath(),"workdir").toFile();
}
@@ -56,11 +55,6 @@ public abstract class SimpleWorkdirFactory<R, C> implements WorkdirFactory<R, C>
}
}
@FunctionalInterface
protected interface CloneProvider<R, C> {
ParentAndClone<R> cloneRepository(C context, File target) throws IOException;
}
protected static class ParentAndClone<R> {
private final R parent;
private final R clone;