mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
Incorporate comments from peer review
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user