mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-30 03:09:13 +01:00
Remove function creep
This commit is contained in:
@@ -27,7 +27,6 @@ package sonia.scm.repository.work;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -49,13 +48,13 @@ public class CachingAllWorkingCopyPool implements WorkingCopyPool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, W, C extends RepositoryProvider> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W, C> workingCopyContext) {
|
||||
public <R, W> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W> workingCopyContext) {
|
||||
String id = workingCopyContext.getScmRepository().getId();
|
||||
File existingWorkdir = workdirs.remove(id);
|
||||
if (existingWorkdir != null) {
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
try {
|
||||
ParentAndClone<R, W> reclaimed = workingCopyContext.getReclaimer().reclaim(existingWorkdir, workingCopyContext.getRequestedBranch());
|
||||
ParentAndClone<R, W> reclaimed = workingCopyContext.reclaim(existingWorkdir);
|
||||
LOG.debug("reclaimed workdir for {} in path {} in {}", workingCopyContext.getScmRepository().getNamespaceAndName(), existingWorkdir, stopwatch.stop());
|
||||
return reclaimed;
|
||||
} catch (SimpleWorkingCopyFactory.ReclaimFailedException e) {
|
||||
@@ -66,17 +65,16 @@ public class CachingAllWorkingCopyPool implements WorkingCopyPool {
|
||||
return createNewWorkingCopy(workingCopyContext);
|
||||
}
|
||||
|
||||
private <R, W> ParentAndClone<R, W> createNewWorkingCopy(WorkingCopyContext<R, W, ?> workingCopyContext) {
|
||||
private <R, W> ParentAndClone<R, W> createNewWorkingCopy(WorkingCopyContext<R, W> workingCopyContext) {
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
File newWorkdir = workdirProvider.createNewWorkdir();
|
||||
SimpleWorkingCopyFactory.WorkingCopyInitializer<R, W> initializer = workingCopyContext.getInitializer();
|
||||
ParentAndClone<R, W> parentAndClone = initializer.initialize(newWorkdir, workingCopyContext.getRequestedBranch());
|
||||
ParentAndClone<R, W> parentAndClone = workingCopyContext.initialize(newWorkdir);
|
||||
LOG.debug("initialized new workdir for {} in path {} in {}", workingCopyContext.getScmRepository().getNamespaceAndName(), newWorkdir, stopwatch.stop());
|
||||
return parentAndClone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextClosed(WorkingCopyContext<?, ?, ?> workingCopyContext, File workdir) {
|
||||
public void contextClosed(WorkingCopyContext<?, ?> workingCopyContext, File workdir) {
|
||||
String id = workingCopyContext.getScmRepository().getId();
|
||||
File putResult = workdirs.putIfAbsent(id, workdir);
|
||||
if (putResult != null && putResult != workdir) {
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
package sonia.scm.repository.work;
|
||||
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -40,12 +39,12 @@ public class NoneCachingWorkingCopyPool implements WorkingCopyPool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, W, C extends RepositoryProvider> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W, C> context) {
|
||||
return context.getInitializer().initialize(workdirProvider.createNewWorkdir(), context.getRequestedBranch());
|
||||
public <R, W> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W> context) {
|
||||
return context.initialize(workdirProvider.createNewWorkdir());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextClosed(WorkingCopyContext<?, ?, ?> workingCopyContext, File workdir) {
|
||||
public void contextClosed(WorkingCopyContext<?, ?> workingCopyContext, File workdir) {
|
||||
IOUtil.deleteSilently(workdir);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,115 +55,109 @@ import java.io.File;
|
||||
* <dd>Closes resources allocated for the central repository.</dd>
|
||||
* </dl>
|
||||
* <pre>
|
||||
* ┌─────────────┐ ┌───────────────────────────┐ ┌───────────────┐ ┌───────────────┐
|
||||
* │ModifyCommand│ │SimpleGitWorkingCopyFactory│ │WorkingCopyPool│ │WorkdirProvider│
|
||||
* └──────┬──────┘ └─────────────┬─────────────┘ └───────┬───────┘ └───────┬───────┘
|
||||
* │ createWorkingCopy │ │ │
|
||||
* │──────────────────────────────>│ │ │
|
||||
* │ │ │ │
|
||||
* │ ────┐ │ │
|
||||
* │ │ createContext │ │
|
||||
* │ <───┘ │ │
|
||||
* │ │ │ │
|
||||
* │ │ create ┌─────────┐ │ │
|
||||
* │ │──────────────────────> │Reclaimer│ │ │
|
||||
* │ │ └────┬────┘ │ │
|
||||
* │ │ create │ ┌───────────┐ │ │
|
||||
* │ │───────────────────────────────────────────> │Initializer│ │ │
|
||||
* │ │ │ └─────┬─────┘ │ │
|
||||
* │ │ │getWorkingCopy │ │ │
|
||||
* │ │───────────────────────────────────────────────────────────────────────────>│ │
|
||||
* │ │ │ │ │ │
|
||||
* │ │ │ │ │ │
|
||||
* │ │ │ │ │ │
|
||||
* │ │ │ │ │ │
|
||||
* │ │ │ reclaim │ │
|
||||
* │ │ │<─────────────────────────────────────────────│ │
|
||||
* │ │ │ │ │ │
|
||||
* │ │ │ │ │ │
|
||||
* │ ╔══════╤════════════════╪═════════════════════════════╪═════════════════════╪════════════════════════╪══════════════════════════╪═════════════════╗
|
||||
* │ ║ ALT │ reclaim successful │ │ │ │ ║
|
||||
* │ ╟──────┘ │ │ │ │ │ ║
|
||||
* │ ║ │ │ │ │ │ ║
|
||||
* │ ║ │ │─────────────────────────────────────────────>│ │ ║
|
||||
* │ ╠═══════════════════════╪═════════════════════════════╪═════════════════════╪════════════════════════╪══════════════════════════╪═════════════════╣
|
||||
* │ ║ [reclaim fails; create new] │ │ │ │ ║
|
||||
* │ ║ │ ReclaimFailedException │ │ │ ║
|
||||
* │ ║ │───────────────────────────────────────────────────────────────────────────>│ │ ║
|
||||
* │ ║ │ │ │ │ │ ║
|
||||
* │ ║ │ │ │ │ createNewWorkdir │ ║
|
||||
* │ ║ │ │ │ │─────────────────────────>│ ║
|
||||
* │ ║ │ │ │ │ │ ║
|
||||
* │ ║ │ │ │ │ │ ║
|
||||
* │ ║ │ │ │ │<─────────────────────────│ ║
|
||||
* │ ║ │ │ │ │ │ ║
|
||||
* │ ║ │ │ │ initialize │ │ ║
|
||||
* │ ║ │ │ │<───────────────────────│ │ ║
|
||||
* │ ║ │ │ │ │ │ ║
|
||||
* │ ║ │ │ │ │ │ ║
|
||||
* │ ║ │ │ │───────────────────────>│ │ ║
|
||||
* │ ╚═══════════════════════╪═════════════════════════════╪═════════════════════╪════════════════════════╪══════════════════════════╪═════════════════╝
|
||||
* │ │ │ │ │ │
|
||||
* │ │ │ParentAndClone │ │ │
|
||||
* │ │<───────────────────────────────────────────────────────────────────────────│ │
|
||||
* │ │ │ │ │ │
|
||||
* │ │ │ │ │ │ ┌───────────┐
|
||||
* │ │────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────> │WorkingCopy│
|
||||
* │ │ │ │ │ │ └─────┬─────┘
|
||||
* │ WorkingCopy │ │ │ │ │ │
|
||||
* │<──────────────────────────────│ │ │ │ │ │
|
||||
* │ │ │ │ │ │ │
|
||||
* . . . . . . .
|
||||
* . . . . . . .
|
||||
* . . . . . . .
|
||||
* . . . . . . .
|
||||
* │ │ │ doWork │ │ │ │
|
||||
* │───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────>│
|
||||
* │ │ │ │ │ │ │
|
||||
* . . . . . . .
|
||||
* . . . . . . .
|
||||
* . . . . . . .
|
||||
* . . . . . . .
|
||||
* │ │ │ close │ │ │ │
|
||||
* │───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────>│
|
||||
* │ │ │ │ │ │ │
|
||||
* │ │ │ │ close │ │ │
|
||||
* │ │<───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
* │ │ │ │ │ │ │
|
||||
* │ ────┐ │ │ │ │ │
|
||||
* │ │ closeWorkingCopy │ │ │ │ │
|
||||
* │ <───┘ │ │ │ │ │
|
||||
* │ │ │ │ │ │ │
|
||||
* │ ────┐ │ │ │ │ │
|
||||
* │ │ closeRepository │ │ │ │ │
|
||||
* │ <───┘ │ │ │ │ │
|
||||
* │ │ │ │ │ │ │
|
||||
* │ │ │ contextClosed │ │ │ │
|
||||
* │ │───────────────────────────────────────────────────────────────────────────>│ │ │
|
||||
* ┌─────────────┐ ┌───────────────────────────┐ ┌───────────────┐ ┌───────────────┐
|
||||
* │ModifyCommand│ │SimpleGitWorkingCopyFactory│ │WorkingCopyPool│ │WorkdirProvider│
|
||||
* └──────┬──────┘ └─────────────┬─────────────┘ └───────┬───────┘ └───────┬───────┘
|
||||
* │ createWorkingCopy │ │ │
|
||||
* │──────────────────────────────>│ │ │
|
||||
* │ │ │ │
|
||||
* │ │ create ┌──────────────────┐ │ │
|
||||
* │ │──────────────────────> │WorkingCopyContext│ │ │
|
||||
* │ │ └────────┬─────────┘ │ │
|
||||
* │ │ getWorkingCopy │ │
|
||||
* │ │─────────────────────────────────────────────────────────────>│ │
|
||||
* │ │ │ │ │
|
||||
* │ │ │ │ │
|
||||
* │ │ │ │ │
|
||||
* │ │ │ │ │
|
||||
* │ │ │ reclaim │ │
|
||||
* │ │ │ <──────────────────────────│ │
|
||||
* │ │ │ │ │
|
||||
* │ │ │ │ │
|
||||
* │ │ ╔══════╤═══════════╪════════════════════════════╪══════════════════════════╪═════════════════╗
|
||||
* │ │ ║ ALT │ reclaim successful │ │ ║
|
||||
* │ │ ╟──────┘ │ │ │ ║
|
||||
* │ │ ║ │ │ │ ║
|
||||
* │ │ ║ │ ──────────────────────────>│ │ ║
|
||||
* │ │ ╠══════════════════╪════════════════════════════╪══════════════════════════╪═════════════════╣
|
||||
* │ │ ║ [reclaim fails; create new] │ │ ║
|
||||
* │ │ ║ │ ReclaimFailedException │ │ ║
|
||||
* │ │ ║ │ ──────────────────────────>│ │ ║
|
||||
* │ │ ║ │ │ │ ║
|
||||
* │ │ ║ │ │ createNewWorkdir │ ║
|
||||
* │ │ ║ │ │─────────────────────────>│ ║
|
||||
* │ │ ║ │ │ │ ║
|
||||
* │ │ ║ │ │ │ ║
|
||||
* │ │ ║ │ │<─────────────────────────│ ║
|
||||
* │ │ ║ │ │ │ ║
|
||||
* │ │ ║ │ initialize │ │ ║
|
||||
* │ │ ║ │ <──────────────────────────│ │ ║
|
||||
* │ │ ║ │ │ │ ║
|
||||
* │ │ ║ │ │ │ ║
|
||||
* │ │ ║ │ ──────────────────────────>│ │ ║
|
||||
* │ │ ╚══════════════════╪════════════════════════════╪══════════════════════════╪═════════════════╝
|
||||
* │ │ │ │ │
|
||||
* │ │ ParentAndClone │ │
|
||||
* │ │<─────────────────────────────────────────────────────────────│ │
|
||||
* │ │ │ │ │
|
||||
* │ │ │ │ │ ┌───────────┐
|
||||
* │ │──────────────────────────────────────────────────────────────────────────────────────────────────────────> │WorkingCopy│
|
||||
* │ │ │ │ │ └─────┬─────┘
|
||||
* │ WorkingCopy │ │ │ │ │
|
||||
* │<──────────────────────────────│ │ │ │ │
|
||||
* │ │ │ │ │ │
|
||||
* . . . . . .
|
||||
* . . . . . .
|
||||
* . . . . . .
|
||||
* . . . . . .
|
||||
* │ │ │ doWork │ │ │
|
||||
* │─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────>│
|
||||
* │ │ │ │ │ │
|
||||
* . . . . . .
|
||||
* . . . . . .
|
||||
* . . . . . .
|
||||
* . . . . . .
|
||||
* │ │ │ close │ │ │
|
||||
* │─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────>│
|
||||
* │ │ │ │ │ │
|
||||
* │ │ │ close │ │ │
|
||||
* │ │<─────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
* │ │ │ │ │ │
|
||||
* │ ────┐ │ │ │ │
|
||||
* │ │ closeWorkingCopy │ │ │ │
|
||||
* │ <───┘ │ │ │ │
|
||||
* │ │ │ │ │ │
|
||||
* │ ────┐ │ │ │ │
|
||||
* │ │ closeRepository │ │ │ │
|
||||
* │ <───┘ │ │ │ │
|
||||
* │ │ │ │ │ │
|
||||
* │ │ contextClosed │ │ │
|
||||
* │ │─────────────────────────────────────────────────────────────>│ │ │
|
||||
* ┌──────┴──────┐ ┌─────────────┴─────────────┐ ┌────────┴─────────┐ ┌───────┴───────┐ ┌───────┴───────┐ ┌─────┴─────┐
|
||||
* │ModifyCommand│ │SimpleGitWorkingCopyFactory│ │WorkingCopyContext│ │WorkingCopyPool│ │WorkdirProvider│ │WorkingCopy│
|
||||
* └─────────────┘ └───────────────────────────┘ └──────────────────┘ └───────────────┘ └───────────────┘ └───────────┘
|
||||
* </pre>
|
||||
* <img src="http://www.plantuml.com/plantuml/png/fPF1QiCm38RlVWgV0-a3U10wmZfss2ZTO6TZgqLCiOBjhCsUVeIcmKkPcx5RB7t_7qcsrY5g7xk6n3DRtFSrDursjgnUiMa97Z6-i_z0TwYvxJVQHFQzLD9uq16IbCZmMJDrjghPHJZ5l8tSWI6D3VYY67Kt14yE8sh2hyMI9BPb9dM051C7prqhttml8qj_BaVCD6KrrQakYAPumMNeZ84GzXs92IohIivi1520IRJNIE5k7BnqSCotSPgxgV5N6uq4zk5ae8t8xhhs8M3HRpr_eWK_3kq5ZcD2p82oci_isZEv1eNJjvZ2l_JlxBLLzYrjjGSNxvsjYTtoYowAF5hzs0sL5YfMgzLyTPAqiZoSRb66E43IQtvbHZn3B90dyNywxQ3bWCFvRvjbpYjV3nvMhC7Phg5l"/>
|
||||
* <img src="http://www.plantuml.com/plantuml/png/fPFHQlCm38Nl_HI-3gGFu1zCVyAwgutI3NPjRBM8ALQmdRNPqu_ITBX9yJ9sQUax9-H8MiTaGkfR4a_iS3yqtBR6krg_ODiHF69wu_2E_j1mDsoCJHm6gQGDO19aBL7WQospOiC-mIbLbRgOb9LPRSjCwW0v9Ww1-qw-Xa4cbW4i6Mp5H5Fh-TVLbJMKhZePUsiXndrFOgwejPOJOm4KuLkzDqZntvYCz72yQtAQcgZTHRynIE0UJXQwXEpl_uJ3i0tyWGx2cDup7CU6c02rdeQtA1ZqcD0GViBI4BoR6vVMHsrD09_-UzSG--NphweogcysMCcC4QlLQhhWMLivFhz-eYnnl4cbU2KZNY0MoBFw7vrsq774y_jt1sSlas_E7awimRk-fIy0"/>
|
||||
* @param <R> Type of central repository location
|
||||
* @param <W> Type of working copy for repository
|
||||
* @param <C> Type of repository context
|
||||
*/
|
||||
/*
|
||||
http://www.plantuml.com/plantuml/uml/fPF1QiCm38RlVWgV0-a3U10wmZfss2ZTO6TZgqLCiOBjhCsUVeIcmKkPcx5RB7t_7qcsrY5g7xk6n3DRtFSrDursjgnUiMa97Z6-i_z0TwYvxJVQHFQzLD9uq16IbCZmMJDrjghPHJZ5l8tSWI6D3VYY67Kt14yE8sh2hyMI9BPb9dM051C7prqhttml8qj_BaVCD6KrrQakYAPumMNeZ84GzXs92IohIivi1520IRJNIE5k7BnqSCotSPgxgV5N6uq4zk5ae8t8xhhs8M3HRpr_eWK_3kq5ZcD2p82oci_isZEv1eNJjvZ2l_JlxBLLzYrjjGSNxvsjYTtoYowAF5hzs0sL5YfMgzLyTPAqiZoSRb66E43IQtvbHZn3B90dyNywxQ3bWCFvRvjbpYjV3nvMhC7Phg5l
|
||||
http://www.plantuml.com/plantuml/uml/fPFHQlCm38Nl_HI-3gGFu1zCVyAwgutI3NPjRBM8ALQmdRNPqu_ITBX9yJ9sQUax9-H8MiTaGkfR4a_iS3yqtBR6krg_ODiHF69wu_2E_j1mDsoCJHm6gQGDO19aBL7WQospOiC-mIbLbRgOb9LPRSjCwW0v9Ww1-qw-Xa4cbW4i6Mp5H5Fh-TVLbJMKhZePUsiXndrFOgwejPOJOm4KuLkzDqZntvYCz72yQtAQcgZTHRynIE0UJXQwXEpl_uJ3i0tyWGx2cDup7CU6c02rdeQtA1ZqcD0GViBI4BoR6vVMHsrD09_-UzSG--NphweogcysMCcC4QlLQhhWMLivFhz-eYnnl4cbU2KZNY0MoBFw7vrsq774y_jt1sSlas_E7awimRk-fIy0
|
||||
@startuml
|
||||
ModifyCommand->SimpleGitWorkingCopyFactory : createWorkingCopy
|
||||
SimpleGitWorkingCopyFactory->SimpleGitWorkingCopyFactory:createContext
|
||||
SimpleGitWorkingCopyFactory-> Reclaimer**:create
|
||||
SimpleGitWorkingCopyFactory-> Initializer**:create
|
||||
SimpleGitWorkingCopyFactory-> WorkingCopyContext**:create
|
||||
SimpleGitWorkingCopyFactory->WorkingCopyPool:getWorkingCopy
|
||||
group Try to reclaim
|
||||
WorkingCopyPool->Reclaimer:reclaim
|
||||
WorkingCopyPool->WorkingCopyContext:reclaim
|
||||
alt reclaim successful
|
||||
Reclaimer->> WorkingCopyPool
|
||||
WorkingCopyContext->> WorkingCopyPool
|
||||
else reclaim fails; create new
|
||||
SimpleGitWorkingCopyFactory->x WorkingCopyPool:ReclaimFailedException
|
||||
WorkingCopyContext->x WorkingCopyPool:ReclaimFailedException
|
||||
WorkingCopyPool->WorkdirProvider:createNewWorkdir
|
||||
WorkdirProvider->>WorkingCopyPool
|
||||
WorkingCopyPool->Initializer:initialize
|
||||
Initializer->> WorkingCopyPool
|
||||
WorkingCopyPool->WorkingCopyContext:initialize
|
||||
WorkingCopyContext->> WorkingCopyPool
|
||||
end
|
||||
WorkingCopyPool->>SimpleGitWorkingCopyFactory:ParentAndClone
|
||||
SimpleGitWorkingCopyFactory->WorkingCopy**
|
||||
@@ -176,8 +170,7 @@ WorkingCopy->SimpleGitWorkingCopyFactory:close
|
||||
SimpleGitWorkingCopyFactory->SimpleGitWorkingCopyFactory:closeWorkingCopy
|
||||
SimpleGitWorkingCopyFactory->SimpleGitWorkingCopyFactory:closeRepository
|
||||
SimpleGitWorkingCopyFactory->WorkingCopyPool:contextClosed
|
||||
@enduml
|
||||
*/
|
||||
@enduml*/
|
||||
public abstract class SimpleWorkingCopyFactory<R, W, C extends RepositoryProvider> implements WorkingCopyFactory<R, W, C>, ServletContextListener {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SimpleWorkingCopyFactory.class);
|
||||
@@ -190,21 +183,21 @@ public abstract class SimpleWorkingCopyFactory<R, W, C extends RepositoryProvide
|
||||
|
||||
@Override
|
||||
public WorkingCopy<R, W> createWorkingCopy(C repositoryContext, String initialBranch) {
|
||||
WorkingCopyContext<R, W, C> workingCopyContext = createWorkingCopyContext(repositoryContext, initialBranch);
|
||||
WorkingCopyContext<R, W> workingCopyContext = createWorkingCopyContext(repositoryContext, initialBranch);
|
||||
WorkingCopyPool.ParentAndClone<R, W> parentAndClone = workingCopyPool.getWorkingCopy(workingCopyContext);
|
||||
return new WorkingCopy<>(parentAndClone.getClone(), parentAndClone.getParent(), () -> this.close(workingCopyContext, parentAndClone), parentAndClone.getDirectory());
|
||||
}
|
||||
|
||||
private WorkingCopyContext<R, W, C> createWorkingCopyContext(C repositoryContext, String initialBranch) {
|
||||
private WorkingCopyContext<R, W> createWorkingCopyContext(C repositoryContext, String initialBranch) {
|
||||
return new WorkingCopyContext<>(
|
||||
initialBranch,
|
||||
repositoryContext,
|
||||
repositoryContext.get(),
|
||||
getInitializer(repositoryContext),
|
||||
getReclaimer(repositoryContext)
|
||||
);
|
||||
}
|
||||
|
||||
private void close(WorkingCopyContext<R, W, C> workingCopyContext, WorkingCopyPool.ParentAndClone<R, W> parentAndClone) {
|
||||
private void close(WorkingCopyContext<R, W> workingCopyContext, WorkingCopyPool.ParentAndClone<R, W> parentAndClone) {
|
||||
try {
|
||||
closeWorkingCopy(parentAndClone.getClone());
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -25,38 +25,31 @@
|
||||
package sonia.scm.repository.work;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
|
||||
public class WorkingCopyContext<R, W, C extends RepositoryProvider> {
|
||||
import java.io.File;
|
||||
|
||||
public class WorkingCopyContext<R, W> {
|
||||
private final String requestedBranch;
|
||||
private final C context;
|
||||
private final Repository repository;
|
||||
private final SimpleWorkingCopyFactory.WorkingCopyInitializer<R, W> initializer;
|
||||
private final SimpleWorkingCopyFactory.WorkingCopyReclaimer<R, W> reclaimer;
|
||||
|
||||
public WorkingCopyContext(String requestedBranch, C context, SimpleWorkingCopyFactory.WorkingCopyInitializer<R, W> initializer, SimpleWorkingCopyFactory.WorkingCopyReclaimer<R, W> reclaimer) {
|
||||
public WorkingCopyContext(String requestedBranch, Repository repository, SimpleWorkingCopyFactory.WorkingCopyInitializer<R, W> initializer, SimpleWorkingCopyFactory.WorkingCopyReclaimer<R, W> reclaimer) {
|
||||
this.requestedBranch = requestedBranch;
|
||||
this.context = context;
|
||||
this.repository = repository;
|
||||
this.initializer = initializer;
|
||||
this.reclaimer = reclaimer;
|
||||
}
|
||||
|
||||
public Repository getScmRepository() {
|
||||
return context.get();
|
||||
return repository;
|
||||
}
|
||||
|
||||
public String getRequestedBranch() {
|
||||
return requestedBranch;
|
||||
public WorkingCopyPool.ParentAndClone<R, W> reclaim(File workdir) throws SimpleWorkingCopyFactory.ReclaimFailedException {
|
||||
return reclaimer.reclaim(workdir, requestedBranch);
|
||||
}
|
||||
|
||||
public C getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public SimpleWorkingCopyFactory.WorkingCopyInitializer<R, W> getInitializer() {
|
||||
return initializer;
|
||||
}
|
||||
|
||||
public SimpleWorkingCopyFactory.WorkingCopyReclaimer<R, W> getReclaimer() {
|
||||
return reclaimer;
|
||||
public WorkingCopyPool.ParentAndClone<R, W> initialize(File workdir) {
|
||||
return initializer.initialize(workdir, requestedBranch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,12 @@
|
||||
|
||||
package sonia.scm.repository.work;
|
||||
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface WorkingCopyPool {
|
||||
<R, W, C extends RepositoryProvider> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W, C> context);
|
||||
<R, W> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W> context);
|
||||
|
||||
void contextClosed(WorkingCopyContext<?, ?, ?> workingCopyContext, File workdir);
|
||||
void contextClosed(WorkingCopyContext<?, ?> workingCopyContext, File workdir);
|
||||
|
||||
void shutdown();
|
||||
|
||||
@@ -46,15 +44,15 @@ public interface WorkingCopyPool {
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
public R getParent() {
|
||||
R getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public W getClone() {
|
||||
W getClone() {
|
||||
return clone;
|
||||
}
|
||||
|
||||
public File getDirectory() {
|
||||
File getDirectory() {
|
||||
return directory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
@@ -55,20 +54,14 @@ class CachingAllWorkingCopyPoolTest {
|
||||
CachingAllWorkingCopyPool cachingAllWorkingCopyPool;
|
||||
|
||||
@Mock
|
||||
WorkingCopyContext<Object, Path, RepositoryProvider> workingCopyContext;
|
||||
@Mock
|
||||
SimpleWorkingCopyFactory.WorkingCopyInitializer<Object, Path> initializer;
|
||||
@Mock
|
||||
SimpleWorkingCopyFactory.WorkingCopyReclaimer<Object, Path> reclaimer;
|
||||
WorkingCopyContext<Object, Path> workingCopyContext;
|
||||
|
||||
@BeforeEach
|
||||
void initContext() throws SimpleWorkingCopyFactory.ReclaimFailedException {
|
||||
lenient().when(workingCopyContext.getInitializer()).thenReturn(initializer);
|
||||
lenient().when(workingCopyContext.getReclaimer()).thenReturn(reclaimer);
|
||||
|
||||
lenient().when(initializer.initialize(any(), any()))
|
||||
lenient().when(workingCopyContext.initialize(any()))
|
||||
.thenAnswer(invocationOnMock -> new WorkingCopyPool.ParentAndClone<>(null, null, invocationOnMock.getArgument(0, File.class)));
|
||||
lenient().when(reclaimer.reclaim(any(), any()))
|
||||
lenient().when(workingCopyContext.reclaim(any()))
|
||||
.thenAnswer(invocationOnMock -> new WorkingCopyPool.ParentAndClone<>(null, null, invocationOnMock.getArgument(0, File.class)));
|
||||
}
|
||||
|
||||
@@ -79,7 +72,7 @@ class CachingAllWorkingCopyPoolTest {
|
||||
|
||||
WorkingCopyPool.ParentAndClone<?, ?> workdir = cachingAllWorkingCopyPool.getWorkingCopy(workingCopyContext);
|
||||
|
||||
verify(initializer).initialize(temp.toFile(), null);
|
||||
verify(workingCopyContext).initialize(temp.toFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,8 +84,8 @@ class CachingAllWorkingCopyPoolTest {
|
||||
cachingAllWorkingCopyPool.contextClosed(workingCopyContext, firstWorkdir.getDirectory());
|
||||
WorkingCopyPool.ParentAndClone<?, ?> secondWorkdir = cachingAllWorkingCopyPool.getWorkingCopy(workingCopyContext);
|
||||
|
||||
verify(initializer).initialize(temp.toFile(), null);
|
||||
verify(reclaimer).reclaim(temp.toFile(), null);
|
||||
verify(workingCopyContext).initialize(temp.toFile());
|
||||
verify(workingCopyContext).reclaim(temp.toFile());
|
||||
assertThat(secondWorkdir.getDirectory()).isEqualTo(temp.toFile());
|
||||
}
|
||||
|
||||
@@ -112,9 +105,9 @@ class CachingAllWorkingCopyPoolTest {
|
||||
cachingAllWorkingCopyPool.contextClosed(workingCopyContext, firstWorkdir.getDirectory());
|
||||
cachingAllWorkingCopyPool.contextClosed(workingCopyContext, secondWorkdir.getDirectory());
|
||||
|
||||
verify(reclaimer, never()).reclaim(any(), any());
|
||||
verify(initializer).initialize(firstDirectory, null);
|
||||
verify(initializer).initialize(secondDirectory, null);
|
||||
verify(workingCopyContext, never()).reclaim(any());
|
||||
verify(workingCopyContext).initialize(firstDirectory);
|
||||
verify(workingCopyContext).initialize(secondDirectory);
|
||||
assertThat(firstWorkdir.getDirectory()).isNotEqualTo(secondWorkdir.getDirectory());
|
||||
assertThat(firstWorkdir.getDirectory()).exists();
|
||||
assertThat(secondWorkdir.getDirectory()).doesNotExist();
|
||||
|
||||
@@ -61,13 +61,13 @@ public class SimpleWorkingCopyFactoryTest {
|
||||
WorkdirProvider workdirProvider = new WorkdirProvider(temporaryFolder.newFolder());
|
||||
WorkingCopyPool configurableTestWorkingCopyPool = new WorkingCopyPool() {
|
||||
@Override
|
||||
public <R, W, C extends RepositoryProvider> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W, C> context) {
|
||||
public <R, W> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W> context) {
|
||||
workdir = workdirProvider.createNewWorkdir();
|
||||
return context.getInitializer().initialize(workdir, context.getRequestedBranch());
|
||||
return context.initialize(workdir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextClosed(WorkingCopyContext<?, ?, ?> createWorkdirContext, File workdir) {
|
||||
public void contextClosed(WorkingCopyContext<?, ?> createWorkdirContext, File workdir) {
|
||||
if (!workdirIsCached) {
|
||||
IOUtil.deleteSilently(workdir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user