mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 02:55:56 +01:00
Remove unnecessary interfaces
This commit is contained in:
@@ -41,10 +41,10 @@ import java.io.File;
|
||||
* implemented:
|
||||
*
|
||||
* <dl>
|
||||
* <dt>{@link #getInitializer(C)}</dt>
|
||||
* <dt>{@link #initialize(C, File, String)}</dt>
|
||||
* <dd>Creates a new clone of the repository for the given context in the given
|
||||
* directory with the given branch checked out (if branches are supported).</dd>
|
||||
* <dt>{@link #getReclaimer(C)}</dt>
|
||||
* <dt>{@link #reclaim(C, File, String)}</dt>
|
||||
* <dd>Reclaim the working directory with a already checked out clone of the
|
||||
* repository given in the context, so that the directory is not modified in
|
||||
* respect to the repository and the given branch is checked out (if branches
|
||||
@@ -215,19 +215,9 @@ public abstract class SimpleWorkingCopyFactory<R, W, C extends RepositoryProvide
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface WorkingCopyInitializer<R, W> {
|
||||
ParentAndClone<R, W> initialize(File target, String initialBranch);
|
||||
}
|
||||
protected abstract ParentAndClone<R, W> initialize(C context, File target, String initialBranch);
|
||||
|
||||
@FunctionalInterface
|
||||
public interface WorkingCopyReclaimer<R, W> {
|
||||
ParentAndClone<R, W> reclaim(File target, String initialBranch) throws ReclaimFailedException;
|
||||
}
|
||||
|
||||
protected abstract WorkingCopyInitializer<R, W> getInitializer(C context);
|
||||
|
||||
protected abstract WorkingCopyReclaimer<R, W> getReclaimer(C context);
|
||||
protected abstract ParentAndClone<R, W> reclaim(C context, File target, String initialBranch) throws ReclaimFailedException;
|
||||
|
||||
@SuppressWarnings("squid:S00112")
|
||||
// We do allow implementations to throw arbitrary exceptions here, so that we can handle them in closeCentral
|
||||
@@ -289,11 +279,11 @@ public abstract class SimpleWorkingCopyFactory<R, W, C extends RepositoryProvide
|
||||
}
|
||||
|
||||
public WorkingCopy<R, W> reclaim(File workdir) throws SimpleWorkingCopyFactory.ReclaimFailedException {
|
||||
return createWorkingCopyFromParentAndClone(getReclaimer(repositoryContext).reclaim(workdir, requestedBranch));
|
||||
return createWorkingCopyFromParentAndClone(SimpleWorkingCopyFactory.this.reclaim(repositoryContext, workdir, requestedBranch));
|
||||
}
|
||||
|
||||
public WorkingCopy<R, W> initialize(File workdir) {
|
||||
return createWorkingCopyFromParentAndClone(getInitializer(repositoryContext).initialize(workdir, requestedBranch));
|
||||
return createWorkingCopyFromParentAndClone(SimpleWorkingCopyFactory.this.initialize(repositoryContext, workdir, requestedBranch));
|
||||
}
|
||||
|
||||
public WorkingCopy<R, W> createWorkingCopyFromParentAndClone(ParentAndClone<R, W> parentAndClone) {
|
||||
|
||||
@@ -84,23 +84,20 @@ public class SimpleWorkingCopyFactoryTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WorkingCopyReclaimer<
|
||||
Closeable, Closeable> getReclaimer(Context context) {
|
||||
return (target, initialBranch) -> {throw new UnsupportedOperationException();};
|
||||
protected ParentAndClone<Closeable, Closeable> initialize(Context context, File target, String initialBranch) {
|
||||
initialBranchForLastCloneCall = initialBranch;
|
||||
return new ParentAndClone<>(parent, clone, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ParentAndClone<Closeable, Closeable> reclaim(Context context, File target, String initialBranch) throws ReclaimFailedException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeWorkingCopy(Closeable workingCopy) throws Exception {
|
||||
workingCopy.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WorkingCopyInitializer<Closeable, Closeable> getInitializer(Context context) {
|
||||
return (target, initialBranch) -> {
|
||||
initialBranchForLastCloneCall = initialBranch;
|
||||
return new ParentAndClone<>(parent, clone, target);
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.eclipse.jgit.lib.Repository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.work.SimpleWorkingCopyFactory;
|
||||
import sonia.scm.repository.work.SimpleWorkingCopyFactory.ParentAndClone;
|
||||
|
||||
import java.io.File;
|
||||
@@ -41,7 +40,7 @@ import java.io.IOException;
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
class GitWorkingCopyInitializer implements SimpleWorkingCopyFactory.WorkingCopyInitializer<Repository, Repository> {
|
||||
class GitWorkingCopyInitializer {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GitWorkingCopyInitializer.class);
|
||||
|
||||
@@ -53,7 +52,6 @@ class GitWorkingCopyInitializer implements SimpleWorkingCopyFactory.WorkingCopyI
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParentAndClone<Repository, Repository> initialize(File target, String initialBranch) {
|
||||
LOG.trace("clone repository {}", context.getRepository().getId());
|
||||
long start = System.nanoTime();
|
||||
|
||||
@@ -37,7 +37,7 @@ import sonia.scm.repository.work.SimpleWorkingCopyFactory.ParentAndClone;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
class GitWorkingCopyReclaimer implements SimpleWorkingCopyFactory.WorkingCopyReclaimer<Repository, Repository> {
|
||||
class GitWorkingCopyReclaimer {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GitWorkingCopyReclaimer.class);
|
||||
|
||||
@@ -47,7 +47,6 @@ class GitWorkingCopyReclaimer implements SimpleWorkingCopyFactory.WorkingCopyRec
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParentAndClone<Repository, Repository> reclaim(File target, String initialBranch) throws SimpleWorkingCopyFactory.ReclaimFailedException {
|
||||
LOG.trace("reclaim repository {}", context.getRepository().getId());
|
||||
long start = System.nanoTime();
|
||||
|
||||
@@ -26,18 +26,14 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.transport.ScmTransportProtocol;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.repository.GitWorkingCopyFactory;
|
||||
import sonia.scm.repository.work.WorkingCopyPool;
|
||||
import sonia.scm.repository.work.SimpleWorkingCopyFactory;
|
||||
import sonia.scm.repository.work.WorkingCopyPool;
|
||||
import sonia.scm.util.SystemUtil;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
|
||||
public class SimpleGitWorkingCopyFactory extends SimpleWorkingCopyFactory<Repository, Repository, GitContext> implements GitWorkingCopyFactory {
|
||||
|
||||
@Inject
|
||||
@@ -46,13 +42,13 @@ public class SimpleGitWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposi
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkingCopyInitializer<Repository, Repository> getInitializer(GitContext context) {
|
||||
return new GitWorkingCopyInitializer(this, context);
|
||||
public ParentAndClone<Repository, Repository> initialize(GitContext context, File target, String initialBranch) {
|
||||
return new GitWorkingCopyInitializer(this, context).initialize(target, initialBranch);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WorkingCopyReclaimer<Repository, Repository> getReclaimer(GitContext context) {
|
||||
return new GitWorkingCopyReclaimer(context);
|
||||
public ParentAndClone<Repository, Repository> reclaim(GitContext context, File target, String initialBranch) throws SimpleWorkingCopyFactory.ReclaimFailedException {
|
||||
return new GitWorkingCopyReclaimer(context).reclaim(target, initialBranch);
|
||||
}
|
||||
|
||||
String createScmTransportProtocolUri(File bareRepository) {
|
||||
|
||||
@@ -142,7 +142,7 @@ public class SimpleGitWorkingCopyFactoryTest extends AbstractGitCommandTestBase
|
||||
SimpleGitWorkingCopyFactory factory = new SimpleGitWorkingCopyFactory(new NoneCachingWorkingCopyPool(workdirProvider));
|
||||
File workdir = createExistingClone(factory);
|
||||
|
||||
factory.getReclaimer(createContext()).reclaim(workdir, "master");
|
||||
factory.reclaim(createContext(), workdir, "master");
|
||||
|
||||
assertBranchCheckedOutAndClean(workdir, "master");
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class SimpleGitWorkingCopyFactoryTest extends AbstractGitCommandTestBase
|
||||
SimpleGitWorkingCopyFactory factory = new SimpleGitWorkingCopyFactory(new NoneCachingWorkingCopyPool(workdirProvider));
|
||||
File workdir = createExistingClone(factory);
|
||||
|
||||
factory.getReclaimer(createContext()).reclaim(workdir, "test-branch");
|
||||
factory.reclaim(createContext(), workdir, "test-branch");
|
||||
|
||||
assertBranchCheckedOutAndClean(workdir, "test-branch");
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class SimpleGitWorkingCopyFactoryTest extends AbstractGitCommandTestBase
|
||||
File workdir = createExistingClone(factory);
|
||||
Git.open(workdir).rm().addFilepattern("a.txt").call();
|
||||
|
||||
factory.getReclaimer(createContext()).reclaim(workdir, "master");
|
||||
factory.reclaim(createContext(), workdir, "master");
|
||||
|
||||
assertBranchCheckedOutAndClean(workdir, "master");
|
||||
}
|
||||
@@ -174,7 +174,7 @@ public class SimpleGitWorkingCopyFactoryTest extends AbstractGitCommandTestBase
|
||||
File workdir = createExistingClone(factory);
|
||||
Files.delete(workdir.toPath().resolve("a.txt"));
|
||||
|
||||
factory.getReclaimer(createContext()).reclaim(workdir, "master");
|
||||
factory.reclaim(createContext(), workdir, "master");
|
||||
|
||||
assertBranchCheckedOutAndClean(workdir, "master");
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public class SimpleGitWorkingCopyFactoryTest extends AbstractGitCommandTestBase
|
||||
Files.createDirectories(newDirectory);
|
||||
Files.createFile(newDirectory.resolve("newFile"));
|
||||
|
||||
factory.getReclaimer(createContext()).reclaim(workdir, "master");
|
||||
factory.reclaim(createContext(), workdir, "master");
|
||||
|
||||
assertBranchCheckedOutAndClean(workdir, "master");
|
||||
}
|
||||
|
||||
@@ -55,8 +55,7 @@ public class SimpleHgWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposit
|
||||
this.hgRepositoryEnvironmentBuilder = hgRepositoryEnvironmentBuilder;
|
||||
}
|
||||
@Override
|
||||
public WorkingCopyInitializer<Repository, Repository> getInitializer(HgCommandContext context) {
|
||||
return (target, initialBranch) -> {
|
||||
public ParentAndClone<Repository, Repository> initialize(HgCommandContext context, File target, String initialBranch) {
|
||||
Repository centralRepository = openCentral(context);
|
||||
CloneCommand cloneCommand = CloneCommandFlags.on(centralRepository);
|
||||
if (initialBranch != null) {
|
||||
@@ -71,18 +70,10 @@ public class SimpleHgWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposit
|
||||
BaseRepository clone = Repository.open(target);
|
||||
|
||||
return new ParentAndClone<>(centralRepository, clone, target);
|
||||
};
|
||||
}
|
||||
|
||||
public Repository openCentral(HgCommandContext context) {
|
||||
BiConsumer<sonia.scm.repository.Repository, Map<String, String>> repositoryMapBiConsumer =
|
||||
(repository, environment) -> hgRepositoryEnvironmentBuilder.get().buildFor(repository, null, environment);
|
||||
return context.openWithSpecialEnvironment(repositoryMapBiConsumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WorkingCopyReclaimer<Repository, Repository> getReclaimer(HgCommandContext context) {
|
||||
return (target, initialBranch) -> {
|
||||
protected ParentAndClone<Repository, Repository> reclaim(HgCommandContext context, File target, String initialBranch) throws ReclaimFailedException {
|
||||
Repository centralRepository = openCentral(context);
|
||||
try {
|
||||
BaseRepository clone = Repository.open(target);
|
||||
@@ -94,7 +85,12 @@ public class SimpleHgWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposit
|
||||
} catch (ExecutionException | IOException e) {
|
||||
throw new ReclaimFailedException(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Repository openCentral(HgCommandContext context) {
|
||||
BiConsumer<sonia.scm.repository.Repository, Map<String, String>> repositoryMapBiConsumer =
|
||||
(repository, environment) -> hgRepositoryEnvironmentBuilder.get().buildFor(repository, null, environment);
|
||||
return context.openWithSpecialEnvironment(repositoryMapBiConsumer);
|
||||
}
|
||||
|
||||
private void delete(File directory, String unknownFile) throws IOException {
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.repository.SvnWorkingCopyFactory;
|
||||
import sonia.scm.repository.work.WorkingCopyPool;
|
||||
import sonia.scm.repository.work.SimpleWorkingCopyFactory;
|
||||
import sonia.scm.repository.work.WorkingCopyPool;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
@@ -39,13 +39,13 @@ public class SimpleSvnWorkingCopyFactory extends SimpleWorkingCopyFactory<File,
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WorkingCopyInitializer<File, File> getInitializer(SvnContext context) {
|
||||
return new SvnWorkingCopyInitializer(context);
|
||||
protected ParentAndClone<File, File> initialize(SvnContext context, File workingCopy, String initialBranch) {
|
||||
return new SvnWorkingCopyInitializer(context).initialize(workingCopy);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WorkingCopyReclaimer<File, File> getReclaimer(SvnContext context) {
|
||||
return new SvnWorkingCopyReclaimer(context);
|
||||
protected ParentAndClone<File, File> reclaim(SvnContext context, File target, String initialBranch) throws SimpleWorkingCopyFactory.ReclaimFailedException {
|
||||
return new SvnWorkingCopyReclaimer(context).reclaim(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,20 +30,18 @@ import org.tmatesoft.svn.core.wc2.SvnCheckout;
|
||||
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
|
||||
import org.tmatesoft.svn.core.wc2.SvnTarget;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.work.SimpleWorkingCopyFactory;
|
||||
import sonia.scm.repository.work.SimpleWorkingCopyFactory.ParentAndClone;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
class SvnWorkingCopyInitializer implements SimpleWorkingCopyFactory.WorkingCopyInitializer<File, File> {
|
||||
class SvnWorkingCopyInitializer {
|
||||
private final SvnContext context;
|
||||
|
||||
public SvnWorkingCopyInitializer(SvnContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParentAndClone<File, File> initialize(File workingCopy, String initialBranch) {
|
||||
public ParentAndClone<File, File> initialize(File workingCopy) {
|
||||
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
|
||||
|
||||
SVNURL source;
|
||||
|
||||
@@ -34,15 +34,14 @@ import java.io.File;
|
||||
|
||||
import static org.tmatesoft.svn.core.SVNDepth.INFINITY;
|
||||
|
||||
class SvnWorkingCopyReclaimer implements SimpleWorkingCopyFactory.WorkingCopyReclaimer<File, File> {
|
||||
class SvnWorkingCopyReclaimer {
|
||||
private final SvnContext context;
|
||||
|
||||
public SvnWorkingCopyReclaimer(SvnContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParentAndClone<File, File> reclaim(File target, String initialBranch) throws SimpleWorkingCopyFactory.ReclaimFailedException {
|
||||
public ParentAndClone<File, File> reclaim(File target) throws SimpleWorkingCopyFactory.ReclaimFailedException {
|
||||
SVNClientManager clientManager = SVNClientManager.newInstance();
|
||||
try {
|
||||
clientManager.getWCClient().doRevert(new File[] {target}, INFINITY, null);
|
||||
|
||||
Reference in New Issue
Block a user