Incorporate comments from peer review

This commit is contained in:
René Pfeuffer
2018-11-07 16:10:32 +01:00
parent 176cda36dc
commit f7348d8882
4 changed files with 40 additions and 8 deletions

View File

@@ -89,7 +89,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
throw new AlreadyExistsException(repository);
}
checkPath(directory);
checkPath(directory, repository);
try {
fileSystem.create(directory);
@@ -259,7 +259,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
* @param directory repository target directory
* @throws RuntimeException when the parent directory already is a repository
*/
private void checkPath(File directory) {
private void checkPath(File directory, Repository repository) {
File repositoryDirectory = config.getRepositoryDirectory();
File parent = directory.getParentFile();
@@ -267,7 +267,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
logger.trace("check {} for existing repository", parent);
if (isRepository(parent)) {
throw new RuntimeException("parent path " + parent + " is a repository");
throw new InternalRepositoryException(repository, "parent path " + parent + " is a repository");
}
parent = parent.getParentFile();

View File

@@ -15,6 +15,10 @@ public class InternalRepositoryException extends ExceptionWithContext {
this(context.build(), message, cause);
}
public InternalRepositoryException(Repository repository, String message) {
this(ContextEntry.ContextBuilder.entity(repository), message, null);
}
public InternalRepositoryException(Repository repository, String message, Exception cause) {
this(ContextEntry.ContextBuilder.entity(repository), message, cause);
}

View File

@@ -38,6 +38,7 @@ package sonia.scm.repository.api;
import com.github.legman.ReferenceType;
import com.github.legman.Subscribe;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -154,6 +155,37 @@ public final class RepositoryServiceFactory
//~--- methods --------------------------------------------------------------
/**
* Creates a new RepositoryService for the given repository.
*
*
* @param repositoryId id of the repository
*
* @return a implementation of RepositoryService
* for the given type of repository
*
* @throws NotFoundException if no repository
* with the given id is available
* @throws RepositoryServiceNotFoundException if no repository service
* implementation for this kind of repository is available
* @throws IllegalArgumentException if the repository id is null or empty
* @throws ScmSecurityException if current user has not read permissions
* for that repository
*/
public RepositoryService create(String repositoryId) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(repositoryId),
"a non empty repositoryId is required");
Repository repository = repositoryManager.get(repositoryId);
if (repository == null)
{
throw new NotFoundException(Repository.class, repositoryId);
}
return create(repository);
}
/**
* Creates a new RepositoryService for the given repository.
*