Remove superfluous exception class

This commit is contained in:
René Pfeuffer
2020-05-14 21:42:00 +02:00
parent 3c808bf171
commit d6b618f0ec
10 changed files with 18 additions and 68 deletions

View File

@@ -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.InternalRepositoryException;
import sonia.scm.repository.RepositoryProvider;
import sonia.scm.util.IOUtil;
@@ -64,14 +63,10 @@ public class CachingAllWorkingCopyPool implements WorkingCopyPool {
deleteWorkdir(existingWorkdir);
}
}
try {
return createNewWorkingCopy(workingCopyContext);
} catch (WorkingCopyFailedException e) {
throw new InternalRepositoryException(workingCopyContext.getScmRepository(), "failed to create working copy", e);
}
return createNewWorkingCopy(workingCopyContext);
}
private <R, W> ParentAndClone<R, W> createNewWorkingCopy(WorkingCopyContext<R, W, ?> workingCopyContext) throws WorkingCopyFailedException {
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();

View File

@@ -40,7 +40,7 @@ public class NoneCachingWorkingCopyPool implements WorkingCopyPool {
}
@Override
public <R, W, C extends RepositoryProvider> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W, C> context) throws WorkingCopyFailedException {
public <R, W, C extends RepositoryProvider> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W, C> context) {
return context.getInitializer().initialize(workdirProvider.createNewWorkdir(), context.getRequestedBranch());
}

View File

@@ -191,13 +191,9 @@ public abstract class SimpleWorkingCopyFactory<R, W, C extends RepositoryProvide
@Override
public WorkingCopy<R, W> createWorkingCopy(C repositoryContext, String initialBranch) {
try {
WorkingCopyContext<R, W, C> 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());
} catch (WorkingCopyFailedException e) {
throw new InternalRepositoryException(repositoryContext.get(), "could not create working copy for repository in temporary directory", e);
}
WorkingCopyContext<R, W, C> 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) {
@@ -239,7 +235,7 @@ public abstract class SimpleWorkingCopyFactory<R, W, C extends RepositoryProvide
@FunctionalInterface
public interface WorkingCopyInitializer<R, W> {
WorkingCopyPool.ParentAndClone<R, W> initialize(File target, String initialBranch) throws WorkingCopyFailedException;
WorkingCopyPool.ParentAndClone<R, W> initialize(File target, String initialBranch);
}
@FunctionalInterface

View File

@@ -1,39 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.work;
public class WorkingCopyFailedException extends Exception {
public WorkingCopyFailedException(String message) {
super(message);
}
public WorkingCopyFailedException(Throwable cause) {
super(cause);
}
public WorkingCopyFailedException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -29,7 +29,7 @@ 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) throws WorkingCopyFailedException;
<R, W, C extends RepositoryProvider> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W, C> context);
void contextClosed(WorkingCopyContext<?, ?, ?> workingCopyContext, File workdir);

View File

@@ -62,7 +62,7 @@ class CachingAllWorkingCopyPoolTest {
SimpleWorkingCopyFactory.WorkingCopyReclaimer<Object, Path> reclaimer;
@BeforeEach
void initContext() throws SimpleWorkingCopyFactory.ReclaimFailedException, WorkingCopyFailedException {
void initContext() throws SimpleWorkingCopyFactory.ReclaimFailedException {
lenient().when(workingCopyContext.getInitializer()).thenReturn(initializer);
lenient().when(workingCopyContext.getReclaimer()).thenReturn(reclaimer);
@@ -73,7 +73,7 @@ class CachingAllWorkingCopyPoolTest {
}
@Test
void shouldCreateNewWorkdirForTheFirstRequest(@TempDir Path temp) throws WorkingCopyFailedException {
void shouldCreateNewWorkdirForTheFirstRequest(@TempDir Path temp) {
when(workingCopyContext.getScmRepository()).thenReturn(REPOSITORY);
when(workdirProvider.createNewWorkdir()).thenReturn(temp.toFile());
@@ -83,7 +83,7 @@ class CachingAllWorkingCopyPoolTest {
}
@Test
void shouldCreateWorkdirOnlyOnceForTheSameRepository(@TempDir Path temp) throws SimpleWorkingCopyFactory.ReclaimFailedException, WorkingCopyFailedException {
void shouldCreateWorkdirOnlyOnceForTheSameRepository(@TempDir Path temp) throws SimpleWorkingCopyFactory.ReclaimFailedException {
when(workingCopyContext.getScmRepository()).thenReturn(REPOSITORY);
when(workdirProvider.createNewWorkdir()).thenReturn(temp.toFile());
@@ -97,7 +97,7 @@ class CachingAllWorkingCopyPoolTest {
}
@Test
void shouldCacheOnlyOneWorkdirForRepository(@TempDir Path temp) throws SimpleWorkingCopyFactory.ReclaimFailedException, WorkingCopyFailedException {
void shouldCacheOnlyOneWorkdirForRepository(@TempDir Path temp) throws SimpleWorkingCopyFactory.ReclaimFailedException {
when(workingCopyContext.getScmRepository()).thenReturn(REPOSITORY);
File firstDirectory = temp.resolve("first").toFile();
firstDirectory.mkdirs();

View File

@@ -61,7 +61,7 @@ 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) throws WorkingCopyFailedException {
public <R, W, C extends RepositoryProvider> ParentAndClone<R, W> getWorkingCopy(WorkingCopyContext<R, W, C> context) {
workdir = workdirProvider.createNewWorkdir();
return context.getInitializer().initialize(workdir, context.getRequestedBranch());
}

View File

@@ -33,7 +33,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.work.SimpleWorkingCopyFactory;
import sonia.scm.repository.work.WorkingCopyFailedException;
import sonia.scm.repository.work.WorkingCopyPool;
import java.io.File;
@@ -55,7 +54,7 @@ class GitWorkingCopyInitializer implements SimpleWorkingCopyFactory.WorkingCopyI
}
@Override
public WorkingCopyPool.ParentAndClone<Repository, Repository> initialize(File target, String initialBranch) throws WorkingCopyFailedException {
public WorkingCopyPool.ParentAndClone<Repository, Repository> initialize(File target, String initialBranch) {
LOG.trace("clone repository {}", context.getRepository().getId());
long start = System.nanoTime();
try {

View File

@@ -32,8 +32,8 @@ import com.aragost.javahg.commands.PullCommand;
import com.aragost.javahg.commands.StatusCommand;
import com.aragost.javahg.commands.UpdateCommand;
import com.aragost.javahg.commands.flags.CloneCommandFlags;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.work.SimpleWorkingCopyFactory;
import sonia.scm.repository.work.WorkingCopyFailedException;
import sonia.scm.repository.work.WorkingCopyPool;
import sonia.scm.repository.work.WorkingCopyPool.ParentAndClone;
import sonia.scm.util.IOUtil;
@@ -66,7 +66,7 @@ public class SimpleHgWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposit
try {
cloneCommand.execute(target.getAbsolutePath());
} catch (IOException e) {
throw new WorkingCopyFailedException(e);
throw new InternalRepositoryException(context.getScmRepository(), "could not clone repository", e);
}
BaseRepository clone = Repository.open(target);
@@ -108,7 +108,7 @@ public class SimpleHgWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposit
}
@Override
protected void closeWorkingCopy(Repository workingCopy) throws Exception {
protected void closeWorkingCopy(Repository workingCopy) {
workingCopy.close();
}

View File

@@ -31,7 +31,6 @@ 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.WorkingCopyFailedException;
import sonia.scm.repository.work.WorkingCopyPool;
import java.io.File;
@@ -44,7 +43,7 @@ class SvnWorkingCopyInitializer implements SimpleWorkingCopyFactory.WorkingCopyI
}
@Override
public WorkingCopyPool.ParentAndClone<File, File> initialize(File workingCopy, String initialBranch) throws WorkingCopyFailedException {
public WorkingCopyPool.ParentAndClone<File, File> initialize(File workingCopy, String initialBranch) {
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
SVNURL source;