Merge branch 2.0.0-m3 into feature/global_config_v2_endpoint

This commit is contained in:
Michael Behlendorf
2018-07-13 11:13:43 +02:00
71 changed files with 1990 additions and 955 deletions

View File

@@ -53,13 +53,9 @@ public interface HandlerBase<T extends TypedObject, E extends Exception>
/**
* Persists a new object.
*
*
* @param object to store
*
* @throws E
* @throws IOException
* @return The persisted object.
*/
public void create(T object) throws E, IOException;
public T create(T object) throws E;
/**
* Removes a persistent object.
@@ -70,7 +66,7 @@ public interface HandlerBase<T extends TypedObject, E extends Exception>
* @throws E
* @throws IOException
*/
public void delete(T object) throws E, IOException;
public void delete(T object) throws E;
/**
* Modifies a persistent object.
@@ -81,5 +77,5 @@ public interface HandlerBase<T extends TypedObject, E extends Exception>
* @throws E
* @throws IOException
*/
public void modify(T object) throws E, IOException;
public void modify(T object) throws E;
}

View File

@@ -33,7 +33,6 @@
package sonia.scm;
import java.io.IOException;
import java.util.Collection;
import java.util.Comparator;
@@ -56,9 +55,8 @@ public interface Manager<T extends ModelObject, E extends Exception>
* @param object to refresh
*
* @throws E
* @throws IOException
*/
void refresh(T object) throws E, IOException;
void refresh(T object) throws E;
//~--- get methods ----------------------------------------------------------

View File

@@ -35,7 +35,6 @@ package sonia.scm;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.Collection;
import java.util.Comparator;
@@ -78,16 +77,16 @@ public class ManagerDecorator<T extends ModelObject, E extends Exception>
* {@inheritDoc}
*/
@Override
public void create(T object) throws E, IOException
public T create(T object) throws E
{
decorated.create(object);
return decorated.create(object);
}
/**
* {@inheritDoc}
*/
@Override
public void delete(T object) throws E, IOException
public void delete(T object) throws E
{
decorated.delete(object);
}
@@ -105,7 +104,7 @@ public class ManagerDecorator<T extends ModelObject, E extends Exception>
* {@inheritDoc}
*/
@Override
public void modify(T object) throws E, IOException
public void modify(T object) throws E
{
decorated.modify(object);
}
@@ -114,7 +113,7 @@ public class ManagerDecorator<T extends ModelObject, E extends Exception>
* {@inheritDoc}
*/
@Override
public void refresh(T object) throws E, IOException
public void refresh(T object) throws E
{
decorated.refresh(object);
}

View File

@@ -53,5 +53,11 @@ public interface ModelObject
*
* @return unique id
*/
public String getId();
String getId();
void setLastModified(Long timestamp);
Long getCreationDate();
void setCreationDate(Long timestamp);
}

View File

@@ -42,15 +42,9 @@ package sonia.scm.group;
public class GroupAlreadyExistsException extends GroupException
{
/** Field description */
private static final long serialVersionUID = 4042878550219750430L;
/**
* Constructs a new instance.
*
* @param message exception message
*/
public GroupAlreadyExistsException(String message) {
super(message);
public GroupAlreadyExistsException(Group group) {
super(group.getName() + " group already exists");
}
}

View File

@@ -52,39 +52,7 @@ public class GroupNotFoundException extends GroupException
* Constructs a new GroupNotFoundException.
*
*/
public GroupNotFoundException() {}
/**
* Constructs a new GroupNotFoundException.
*
*
* @param message message for the exception
*/
public GroupNotFoundException(String message)
{
super(message);
}
/**
* Constructs a new GroupNotFoundException.
*
*
* @param throwable root cause
*/
public GroupNotFoundException(Throwable throwable)
{
super(throwable);
}
/**
* Constructs a new GroupNotFoundException.
*
*
* @param message message for the exception
* @param throwable root cause
*/
public GroupNotFoundException(String message, Throwable throwable)
{
super(message, throwable);
public GroupNotFoundException(Group group) {
super("group " + group.getName() + " does not exist");
}
}

View File

@@ -38,23 +38,20 @@ package sonia.scm.repository;
import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
import com.google.common.io.Resources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.ConfigurationException;
import sonia.scm.io.CommandResult;
import sonia.scm.io.ExtendedCommand;
import sonia.scm.io.FileSystem;
import sonia.scm.store.ConfigurationStoreFactory;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.net.URL;
import sonia.scm.store.ConfigurationStoreFactory;
//~--- JDK imports ------------------------------------------------------------
/**
*
@@ -108,8 +105,8 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
* @throws RepositoryException
*/
@Override
public void create(Repository repository)
throws RepositoryException, IOException
public Repository create(Repository repository)
throws RepositoryException
{
File directory = getDirectory(repository);
@@ -125,6 +122,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
fileSystem.create(directory);
create(repository, directory);
postCreate(repository, directory);
return repository;
}
catch (Exception ex)
{
@@ -137,11 +135,16 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
directory);
}
fileSystem.destroy(directory);
try {
fileSystem.destroy(directory);
} catch (IOException e) {
logger.error("could not delete directory after failed repository creation: {}", directory, e);
}
}
Throwables.propagateIfPossible(ex, RepositoryException.class,
IOException.class);
Throwables.propagateIfPossible(ex, RepositoryException.class);
// This point will never be reached
return null;
}
}
@@ -173,14 +176,17 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
* @throws RepositoryException
*/
@Override
public void delete(Repository repository)
throws RepositoryException, IOException
public void delete(Repository repository) throws RepositoryException
{
File directory = getDirectory(repository);
if (directory.exists())
{
fileSystem.destroy(directory);
try {
fileSystem.destroy(directory);
} catch (IOException e) {
throw new RepositoryException("could not delete repository", e);
}
cleanupEmptyDirectories(config.getRepositoryDirectory(),
directory.getParentFile());
}
@@ -232,8 +238,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
* @throws RepositoryException
*/
@Override
public void modify(Repository repository)
throws RepositoryException, IOException
public void modify(Repository repository) throws RepositoryException
{
// nothing todo

View File

@@ -37,23 +37,17 @@ import com.github.sdorra.ssp.PermissionObject;
import com.github.sdorra.ssp.StaticPermissions;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import sonia.scm.BasicPropertiesAware;
import sonia.scm.ModelObject;
import sonia.scm.util.HttpUtil;
import sonia.scm.util.Util;
import sonia.scm.util.ValidationUtil;
import javax.xml.bind.annotation.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Source code repository.
*
@@ -207,6 +201,10 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
return name;
}
public String getNamespace() {
return namespace;
}
/**
* Returns the access permissions of the {@link Repository}.
*

View File

@@ -38,13 +38,12 @@ package sonia.scm.repository;
import sonia.scm.Type;
import sonia.scm.TypeManager;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Collection;
import java.util.Optional;
//~--- JDK imports ------------------------------------------------------------
/**
* The central class for managing {@link Repository} objects.
@@ -149,4 +148,11 @@ public interface RepositoryManager
*/
@Override
public RepositoryHandler getHandler(String type);
default Optional<Repository> getByNamespace(String namespace, String name) {
return getAll()
.stream()
.filter(r -> r.getName().equals(name) && r.getNamespace().equals(namespace))
.findFirst();
}
}

View File

@@ -38,13 +38,11 @@ package sonia.scm.repository;
import sonia.scm.ManagerDecorator;
import sonia.scm.Type;
//~--- JDK imports ------------------------------------------------------------
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
//~--- JDK imports ------------------------------------------------------------
/**
* Decorator for {@link RepositoryManager}.
@@ -92,19 +90,10 @@ public class RepositoryManagerDecorator
//~--- get methods ----------------------------------------------------------
/**
* {@inheritDoc}
*
*
* @param type
* @param name
*
* @return
*/
@Override
public Repository get(String type, String name)
public Repository get(String namespace, String name)
{
return decorated.get(type, name);
return decorated.get(namespace, name);
}
/**

View File

@@ -52,17 +52,11 @@ public class RepositoryNotFoundException extends RepositoryException
* error detail message.
*
*/
public RepositoryNotFoundException() {}
public RepositoryNotFoundException(Repository repository) {
super("repository " + repository.getName() + "/" + repository.getNamespace() + " does not exist");
}
/**
* Constructs a new {@link RepositoryNotFoundException} with the specified
* error detail message.
*
*
* @param message error detail message
*/
public RepositoryNotFoundException(String message)
{
super(message);
public RepositoryNotFoundException(String repositoryId) {
super("repository with id " + repositoryId + " does not exist");
}
}

View File

@@ -37,37 +37,26 @@ 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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.HandlerEventType;
import sonia.scm.cache.Cache;
import sonia.scm.cache.CacheManager;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.PostReceiveRepositoryHookEvent;
import sonia.scm.repository.PreProcessorUtil;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryCacheKeyPredicate;
import sonia.scm.repository.RepositoryEvent;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryNotFoundException;
import sonia.scm.repository.RepositoryPermissions;
import sonia.scm.event.ScmEventBus;
import sonia.scm.repository.*;
import sonia.scm.repository.spi.RepositoryServiceProvider;
import sonia.scm.repository.spi.RepositoryServiceResolver;
import sonia.scm.security.ScmSecurityException;
//~--- JDK imports ------------------------------------------------------------
import java.util.Set;
import sonia.scm.event.ScmEventBus;
import sonia.scm.repository.ClearRepositoryCacheEvent;
//~--- JDK imports ------------------------------------------------------------
/**
* The {@link RepositoryServiceFactory} is the entrypoint of the repository api.
@@ -179,8 +168,7 @@ public final class RepositoryServiceFactory
if (repository == null)
{
throw new RepositoryNotFoundException(
"could not find a repository with id ".concat(repositoryId));
throw new RepositoryNotFoundException(repositoryId);
}
return create(repository);

View File

@@ -30,12 +30,10 @@ package sonia.scm.security;
import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.subject.SimplePrincipalCollection;
import sonia.scm.group.Group;
import sonia.scm.group.GroupException;
import sonia.scm.group.GroupManager;
@@ -46,9 +44,6 @@ import sonia.scm.user.UserException;
import sonia.scm.user.UserManager;
import sonia.scm.web.security.AdministrationContext;
import java.io.IOException;
import java.util.Collection;
/**
@@ -134,7 +129,7 @@ public final class SyncingRealmHelper {
groupManager.create(group);
}
}
catch (GroupException | IOException ex) {
catch (GroupException ex) {
throw new AuthenticationException("could not store group", ex);
}
});
@@ -155,7 +150,7 @@ public final class SyncingRealmHelper {
userManager.create(user);
}
}
catch (UserException | IOException ex) {
catch (UserException ex) {
throw new AuthenticationException("could not store user", ex);
}
});

View File

@@ -41,19 +41,11 @@ package sonia.scm.user;
public class UserAlreadyExistsException extends UserException
{
/** Field description */
private static final long serialVersionUID = 9182294539718090814L;
//~--- constructors ---------------------------------------------------------
/**
* Constructs a new instance.
*
* @param message message of exception
* @since 1.5
*/
public UserAlreadyExistsException(String message)
{
super(message);
public UserAlreadyExistsException(User user) {
super(user.getName() + " user already exists");
}
}

View File

@@ -51,39 +51,7 @@ public class UserNotFoundException extends UserException
* Constructs a new UserNotFoundException.
*
*/
public UserNotFoundException() {}
/**
* Constructs a new UserNotFoundException.
*
*
* @param message message for the exception
*/
public UserNotFoundException(String message)
{
super(message);
}
/**
* Constructs a new UserNotFoundException.
*
*
* @param throwable root cause
*/
public UserNotFoundException(Throwable throwable)
{
super(throwable);
}
/**
* Constructs a new UserNotFoundException.
*
*
* @param message message for the exception
* @param throwable root cause
*/
public UserNotFoundException(String message, Throwable throwable)
{
super(message, throwable);
public UserNotFoundException(User user) {
super("user " + user.getName() + " does not exist");
}
}

View File

@@ -14,8 +14,10 @@ public class VndMediaType {
public static final String USER = PREFIX + "user" + SUFFIX;
public static final String GROUP = PREFIX + "group" + SUFFIX;
public static final String REPOSITORY = PREFIX + "repository" + SUFFIX;
public static final String USER_COLLECTION = PREFIX + "userCollection" + SUFFIX;
public static final String GROUP_COLLECTION = PREFIX + "groupCollection" + SUFFIX;
public static final String REPOSITORY_COLLECTION = PREFIX + "repositoryCollection" + SUFFIX;
public static final String GLOBAL_CONFIG = PREFIX + "global_config" + SUFFIX;