mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
merge with 2.0.0-m3
This commit is contained in:
124
Jenkinsfile
vendored
124
Jenkinsfile
vendored
@@ -1,47 +1,107 @@
|
||||
#!groovy
|
||||
@Library('github.com/cloudogu/ces-build-lib@ac17d45')
|
||||
|
||||
// Keep the version in sync with the one used in pom.xml in order to get correct syntax completion.
|
||||
@Library('github.com/cloudogu/ces-build-lib@9aadeeb')
|
||||
import com.cloudogu.ces.cesbuildlib.*
|
||||
|
||||
node() { // No specific label
|
||||
|
||||
properties([
|
||||
// Keep only the last 10 build to preserve space
|
||||
buildDiscarder(logRotator(numToKeepStr: '10')),
|
||||
// Don't run concurrent builds for a branch, because they use the same workspace directory
|
||||
disableConcurrentBuilds()
|
||||
])
|
||||
// Change this as when we go back to default - necessary for proper SonarQube analysis
|
||||
mainBranch = "2.0.0-m3"
|
||||
|
||||
String defaultEmailRecipients = env.EMAIL_SCM_RECIPIENTS
|
||||
properties([
|
||||
// Keep only the last 10 build to preserve space
|
||||
buildDiscarder(logRotator(numToKeepStr: '10')),
|
||||
])
|
||||
|
||||
catchError {
|
||||
catchError {
|
||||
|
||||
Maven mvn = new MavenWrapper(this)
|
||||
Maven mvn = setupMavenBuild()
|
||||
// Maven build specified it must be 1.8.0-101 or newer
|
||||
def javaHome = tool 'JDK-1.8.0-101+'
|
||||
|
||||
stage('Checkout') {
|
||||
checkout scm
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
mvn 'clean install -DskipTests -DperformRelease'
|
||||
archive '**/target/*.jar,**/target/*.zip'
|
||||
}
|
||||
|
||||
stage('Unit Test') {
|
||||
mvn 'test -Dsonia.scm.test.skip.hg=true'
|
||||
}
|
||||
|
||||
stage('SonarQube') {
|
||||
def sonarQube = new SonarQube(this, 'ces-sonar')
|
||||
|
||||
sonarQube.analyzeWith(mvn)
|
||||
withEnv(["JAVA_HOME=${javaHome}", "PATH=${env.JAVA_HOME}/bin:${env.PATH}"]) {
|
||||
|
||||
stage('Checkout') {
|
||||
checkout scm
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
mvn 'clean install -DskipTests'
|
||||
}
|
||||
|
||||
stage('Unit Test') {
|
||||
mvn 'test -Dsonia.scm.test.skip.hg=true'
|
||||
}
|
||||
|
||||
stage('SonarQube') {
|
||||
|
||||
def sonarQube = new SonarQube(this, 'sonarcloud.io')
|
||||
|
||||
analyzeWith(mvn)
|
||||
|
||||
if (!sonarQube.waitForQualityGateWebhookToBeCalled()) {
|
||||
currentBuild.result = 'UNSTABLE'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Archive Unit and integration test results, if any
|
||||
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/surefire-reports/TEST-*.xml,**/target/jest-reports/TEST-*.xml'
|
||||
// Archive Unit and integration test results, if any
|
||||
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/surefire-reports/TEST-*.xml,**/target/jest-reports/TEST-*.xml'
|
||||
|
||||
// Find maven warnings and visualize in job
|
||||
warnings consoleParsers: [[parserName: 'Maven']], canRunOnFailed: true
|
||||
// Find maven warnings and visualize in job
|
||||
warnings consoleParsers: [[parserName: 'Maven']], canRunOnFailed: true
|
||||
|
||||
mailIfStatusChanged(defaultEmailRecipients)
|
||||
mailIfStatusChanged(commitAuthorEmail)
|
||||
}
|
||||
|
||||
String mainBranch
|
||||
|
||||
Maven setupMavenBuild() {
|
||||
Maven mvn = new MavenWrapper(this)
|
||||
|
||||
if (mainBranch.equals(env.BRANCH_NAME)) {
|
||||
// Release starts javadoc, which takes very long, so do only for certain branches
|
||||
mvn.additionalArgs += ' -DperformRelease'
|
||||
// JDK8 is more strict, we should fix this before the next release. Right now, this is just not the focus, yet.
|
||||
mvn.additionalArgs += ' -Dmaven.javadoc.failOnError=false'
|
||||
}
|
||||
return mvn
|
||||
}
|
||||
|
||||
void analyzeWith(Maven mvn) {
|
||||
|
||||
withSonarQubeEnv('sonarcloud.io') {
|
||||
|
||||
String mvnArgs = "${env.SONAR_MAVEN_GOAL} " +
|
||||
"-Dsonar.host.url=${env.SONAR_HOST_URL} " +
|
||||
"-Dsonar.login=${env.SONAR_AUTH_TOKEN} "
|
||||
|
||||
if (isPullRequest()) {
|
||||
echo "Analysing SQ in PR mode"
|
||||
mvnArgs += "-Dsonar.pullrequest.base=${env.CHANGE_TARGET} " +
|
||||
"-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} " +
|
||||
"-Dsonar.pullrequest.key=${env.CHANGE_ID} " +
|
||||
"-Dsonar.pullrequest.provider=bitbucketcloud " +
|
||||
"-Dsonar.pullrequest.bitbucketcloud.owner=sdorra " +
|
||||
"-Dsonar.pullrequest.bitbucketcloud.repository=scm-manager "
|
||||
} else {
|
||||
mvnArgs += " -Dsonar.branch.name=${env.BRANCH_NAME} "
|
||||
if (!mainBranch.equals(env.BRANCH_NAME)) {
|
||||
// Avoid exception "The main branch must not have a target" on main branch
|
||||
mvnArgs += " -Dsonar.branch.target=${mainBranch} "
|
||||
}
|
||||
}
|
||||
mvn "${mvnArgs}"
|
||||
}
|
||||
}
|
||||
|
||||
String getCommitAuthorComplete() {
|
||||
new Sh(this).returnStdOut 'hg log --branch . --limit 1 --template "{author}"'
|
||||
}
|
||||
|
||||
String getCommitAuthorEmail() {
|
||||
def matcher = getCommitAuthorComplete() =~ "<(.*?)>"
|
||||
matcher ? matcher[0][1] : ""
|
||||
}
|
||||
|
||||
23
pom.xml
23
pom.xml
@@ -146,9 +146,30 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<!-- Dependency used in Jenkinsfile. Including this in maven provides code completion in Jenkinsfile. -->
|
||||
<groupId>com.github.cloudogu</groupId>
|
||||
<artifactId>ces-build-lib</artifactId>
|
||||
<!-- Keep this version in sync with the one used in Jenkinsfile -->
|
||||
<version>9aadeeb</version>
|
||||
<!-- Don't ship this dependency with the app -->
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
@@ -254,7 +275,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<configuration>
|
||||
<useStandardDocletOptions>true</useStandardDocletOptions>
|
||||
<charset>${project.build.sourceEncoding}</charset>
|
||||
@@ -439,7 +459,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.8.1</version>
|
||||
<configuration>
|
||||
<doclet>org.jboss.apiviz.APIviz</doclet>
|
||||
<docletArtifact>
|
||||
|
||||
@@ -159,7 +159,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<configuration>
|
||||
<useStandardDocletOptions>true</useStandardDocletOptions>
|
||||
<charset>${project.build.sourceEncoding}</charset>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 name The name (aka id) of the group
|
||||
*/
|
||||
public GroupAlreadyExistsException(String name) {
|
||||
super(name + " group already exists");
|
||||
public GroupAlreadyExistsException(Group group) {
|
||||
super(group.getName() + " group already exists");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class GroupNotFoundException extends GroupException
|
||||
* Constructs a new GroupNotFoundException.
|
||||
*
|
||||
*/
|
||||
public GroupNotFoundException() {
|
||||
super("group does not exists");
|
||||
public GroupNotFoundException(Group group) {
|
||||
super("group " + group.getName() + " does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,8 +177,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);
|
||||
|
||||
@@ -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 name The name (aka id) of the user
|
||||
* @since 1.5
|
||||
*/
|
||||
public UserAlreadyExistsException(String name)
|
||||
{
|
||||
super(name + " user already exists");
|
||||
public UserAlreadyExistsException(User user) {
|
||||
super(user.getName() + " user already exists");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class UserNotFoundException extends UserException
|
||||
* Constructs a new UserNotFoundException.
|
||||
*
|
||||
*/
|
||||
public UserNotFoundException() {
|
||||
super("user does not exists");
|
||||
public UserNotFoundException(User user) {
|
||||
super("user " + user.getName() + " does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@
|
||||
<sonar.issue.ignore.multicriteria>e1</sonar.issue.ignore.multicriteria>
|
||||
<sonar.issue.ignore.multicriteria.e1.ruleKey>javascript:S3827</sonar.issue.ignore.multicriteria.e1.ruleKey>
|
||||
<sonar.issue.ignore.multicriteria.e1.resourceKey>**.js</sonar.issue.ignore.multicriteria.e1.resourceKey>
|
||||
<sonar.exclusions>src/main/webapp/resources/extjs/**,src/main/webapp/resources/moment/**,src/main/webapp/resources/syntaxhighlighter/**</sonar.exclusions>
|
||||
<sonar.exclusions>src/main/webapp**</sonar.exclusions>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
|
||||
68
scm-webapp/src/main/java/sonia/scm/ManagerDaoAdapter.java
Normal file
68
scm-webapp/src/main/java/sonia/scm/ManagerDaoAdapter.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package sonia.scm;
|
||||
|
||||
import com.github.sdorra.ssp.PermissionCheck;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ManagerDaoAdapter<T extends ModelObject, E extends Exception> {
|
||||
|
||||
private final GenericDAO<T> dao;
|
||||
private final Function<T, E> notFoundException;
|
||||
private final Function<T, E> alreadyExistsException;
|
||||
|
||||
public ManagerDaoAdapter(GenericDAO<T> dao, Function<T, E> notFoundException, Function<T, E> alreadyExistsException) {
|
||||
this.dao = dao;
|
||||
this.notFoundException = notFoundException;
|
||||
this.alreadyExistsException = alreadyExistsException;
|
||||
}
|
||||
|
||||
public void modify(T object, Function<T, PermissionCheck> permissionCheck, AroundHandler<T, E> beforeUpdate, AroundHandler<T, E> afterUpdate) throws E {
|
||||
T notModified = dao.get(object.getId());
|
||||
if (notModified != null) {
|
||||
permissionCheck.apply(notModified).check();
|
||||
AssertUtil.assertIsValid(object);
|
||||
|
||||
beforeUpdate.handle(notModified);
|
||||
|
||||
object.setLastModified(System.currentTimeMillis());
|
||||
object.setCreationDate(notModified.getCreationDate());
|
||||
|
||||
dao.modify(object);
|
||||
|
||||
afterUpdate.handle(notModified);
|
||||
} else {
|
||||
throw notFoundException.apply(object);
|
||||
}
|
||||
}
|
||||
|
||||
public T create(T newObject, Supplier<PermissionCheck> permissionCheck, AroundHandler<T, E> beforeCreate, AroundHandler<T, E> afterCreate) throws E {
|
||||
permissionCheck.get().check();
|
||||
AssertUtil.assertIsValid(newObject);
|
||||
if (dao.contains(newObject)) {
|
||||
throw alreadyExistsException.apply(newObject);
|
||||
}
|
||||
newObject.setCreationDate(System.currentTimeMillis());
|
||||
beforeCreate.handle(newObject);
|
||||
dao.add(newObject);
|
||||
afterCreate.handle(newObject);
|
||||
return newObject;
|
||||
}
|
||||
|
||||
public void delete(T toDelete, Supplier<PermissionCheck> permissionCheck, AroundHandler<T, E> beforeDelete, AroundHandler<T, E> afterDelete) throws E {
|
||||
permissionCheck.get().check();
|
||||
if (dao.contains(toDelete)) {
|
||||
beforeDelete.handle(toDelete);
|
||||
dao.delete(toDelete);
|
||||
afterDelete.handle(toDelete);
|
||||
} else {
|
||||
throw notFoundException.apply(toDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface AroundHandler<T extends ModelObject, E extends Exception> {
|
||||
void handle(T notModified) throws E;
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.ManagerDaoAdapter;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.TransformFilter;
|
||||
import sonia.scm.search.SearchRequest;
|
||||
@@ -84,6 +85,10 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
public DefaultGroupManager(GroupDAO groupDAO)
|
||||
{
|
||||
this.groupDAO = groupDAO;
|
||||
this.managerDaoAdapter = new ManagerDaoAdapter<>(
|
||||
groupDAO,
|
||||
GroupNotFoundException::new,
|
||||
GroupAlreadyExistsException::new);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -101,79 +106,34 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param group
|
||||
*
|
||||
* @throws GroupException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public Group create(Group group) throws GroupException
|
||||
{
|
||||
public Group create(Group group) throws GroupException {
|
||||
String type = group.getType();
|
||||
|
||||
if (Util.isEmpty(type))
|
||||
{
|
||||
if (Util.isEmpty(type)) {
|
||||
group.setType(groupDAO.getType());
|
||||
}
|
||||
|
||||
String name = group.getName();
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("create group {} of type {}", name,
|
||||
group.getType());
|
||||
}
|
||||
|
||||
GroupPermissions.create().check();
|
||||
|
||||
if (groupDAO.contains(name))
|
||||
{
|
||||
throw new GroupAlreadyExistsException(name);
|
||||
}
|
||||
logger.info("create group {} of type {}", group.getName(), group.getType());
|
||||
|
||||
removeDuplicateMembers(group);
|
||||
group.setCreationDate(System.currentTimeMillis());
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, group);
|
||||
groupDAO.add(group);
|
||||
fireEvent(HandlerEventType.CREATE, group);
|
||||
return group;
|
||||
|
||||
return managerDaoAdapter.create(
|
||||
group,
|
||||
GroupPermissions::create,
|
||||
newGroup -> fireEvent(HandlerEventType.BEFORE_CREATE, newGroup),
|
||||
newGroup -> fireEvent(HandlerEventType.CREATE, newGroup)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param group
|
||||
*
|
||||
* @throws GroupException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void delete(Group group) throws GroupException
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("delete group {} of type {}", group.getName(),
|
||||
group.getType());
|
||||
}
|
||||
|
||||
String name = group.getName();
|
||||
GroupPermissions.delete().check(name);
|
||||
|
||||
if (groupDAO.contains(name))
|
||||
{
|
||||
fireEvent(HandlerEventType.BEFORE_DELETE, group);
|
||||
groupDAO.delete(group);
|
||||
fireEvent(HandlerEventType.DELETE, group);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new GroupNotFoundException();
|
||||
}
|
||||
public void delete(Group group) throws GroupException {
|
||||
logger.info("delete group {} of type {}", group.getName(), group.getType());
|
||||
managerDaoAdapter.delete(
|
||||
group,
|
||||
() -> GroupPermissions.delete(group.getName()),
|
||||
toDelete -> fireEvent(HandlerEventType.BEFORE_DELETE, toDelete),
|
||||
toDelete -> fireEvent(HandlerEventType.DELETE, toDelete)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,31 +155,18 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void modify(Group group) throws GroupException
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("modify group {} of type {}", group.getName(),
|
||||
group.getType());
|
||||
}
|
||||
public void modify(Group group) throws GroupException {
|
||||
logger.info("modify group {} of type {}", group.getName(), group.getType());
|
||||
|
||||
String name = group.getName();
|
||||
GroupPermissions.modify().check(name);
|
||||
|
||||
Group notModified = groupDAO.get(name);
|
||||
if (notModified != null)
|
||||
{
|
||||
removeDuplicateMembers(group);
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, group, notModified);
|
||||
group.setLastModified(System.currentTimeMillis());
|
||||
group.setCreationDate(notModified.getCreationDate());
|
||||
groupDAO.modify(group);
|
||||
fireEvent(HandlerEventType.MODIFY, group, notModified);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new GroupNotFoundException();
|
||||
}
|
||||
managerDaoAdapter.modify(
|
||||
group,
|
||||
GroupPermissions::modify,
|
||||
notModified -> {
|
||||
removeDuplicateMembers(group);
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, group, notModified);
|
||||
},
|
||||
notModified -> fireEvent(HandlerEventType.MODIFY, group, notModified)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +192,7 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
|
||||
if (fresh == null)
|
||||
{
|
||||
throw new GroupNotFoundException();
|
||||
throw new GroupNotFoundException(group);
|
||||
}
|
||||
|
||||
fresh.copyProperties(group);
|
||||
@@ -458,4 +405,5 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
|
||||
/** Field description */
|
||||
private GroupDAO groupDAO;
|
||||
private final ManagerDaoAdapter<Group, GroupException> managerDaoAdapter;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.ArgumentIsInvalidException;
|
||||
import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.ManagerDaoAdapter;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
@@ -90,6 +91,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
private final Set<Type> types;
|
||||
private RepositoryMatcher repositoryMatcher;
|
||||
private NamespaceStrategy namespaceStrategy;
|
||||
private final ManagerDaoAdapter<Repository, RepositoryException> managerDaoAdapter;
|
||||
|
||||
|
||||
@Inject
|
||||
@@ -116,6 +118,10 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
for (RepositoryHandler handler : handlerSet) {
|
||||
addHandler(contextProvider, handler);
|
||||
}
|
||||
managerDaoAdapter = new ManagerDaoAdapter<>(
|
||||
repositoryDAO,
|
||||
RepositoryNotFoundException::new,
|
||||
RepositoryAlreadyExistsException::create);
|
||||
}
|
||||
|
||||
|
||||
@@ -128,64 +134,47 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
}
|
||||
}
|
||||
|
||||
public Repository create(Repository repository, boolean initRepository)
|
||||
throws RepositoryException {
|
||||
logger.info("create repository {} of type {}", repository.getName(), repository.getType());
|
||||
|
||||
RepositoryPermissions.create().check();
|
||||
|
||||
repository.setNamespace(namespaceStrategy.getNamespace());
|
||||
logger.info("setting namespace of new repository {} to {}", repository.getName(), repository.getNamespace());
|
||||
|
||||
AssertUtil.assertIsValid(repository);
|
||||
|
||||
if (repositoryDAO.contains(repository.getNamespaceAndName())) {
|
||||
throw RepositoryAlreadyExistsException.create(repository);
|
||||
}
|
||||
|
||||
repository.setId(keyGenerator.createKey());
|
||||
repository.setCreationDate(System.currentTimeMillis());
|
||||
|
||||
if (initRepository) {
|
||||
getHandler(repository).create(repository);
|
||||
}
|
||||
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, repository);
|
||||
repositoryDAO.add(repository);
|
||||
fireEvent(HandlerEventType.CREATE, repository);
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository create(Repository repository)
|
||||
throws RepositoryException {
|
||||
public Repository create(Repository repository) throws RepositoryException {
|
||||
return create(repository, true);
|
||||
}
|
||||
|
||||
public Repository create(Repository repository, boolean initRepository) throws RepositoryException {
|
||||
repository.setId(keyGenerator.createKey());
|
||||
repository.setNamespace(namespaceStrategy.getNamespace());
|
||||
|
||||
logger.info("create repository {} of type {} in namespace {}", repository.getName(), repository.getType(), repository.getNamespace());
|
||||
|
||||
return managerDaoAdapter.create(
|
||||
repository,
|
||||
RepositoryPermissions::create,
|
||||
newRepository -> {
|
||||
if (initRepository) {
|
||||
getHandler(newRepository).create(newRepository);
|
||||
}
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, newRepository);
|
||||
},
|
||||
newRepository -> fireEvent(HandlerEventType.CREATE, newRepository)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Repository repository)
|
||||
throws RepositoryException {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("delete repository {} of type {}", repository.getName(),
|
||||
repository.getType());
|
||||
}
|
||||
public void delete(Repository repository) throws RepositoryException {
|
||||
logger.info("delete repository {} of type {}", repository.getName(), repository.getType());
|
||||
managerDaoAdapter.delete(
|
||||
repository,
|
||||
() -> RepositoryPermissions.delete(repository),
|
||||
this::preDelete,
|
||||
toDelete -> fireEvent(HandlerEventType.DELETE, toDelete)
|
||||
);
|
||||
}
|
||||
|
||||
RepositoryPermissions.delete(repository).check();
|
||||
|
||||
if (configuration.isEnableRepositoryArchive() && !repository.isArchived()) {
|
||||
throw new RepositoryIsNotArchivedException(
|
||||
"Repository could not deleted, because it is not archived.");
|
||||
}
|
||||
|
||||
if (repositoryDAO.contains(repository)) {
|
||||
fireEvent(HandlerEventType.BEFORE_DELETE, repository);
|
||||
getHandler(repository).delete(repository);
|
||||
repositoryDAO.delete(repository);
|
||||
fireEvent(HandlerEventType.DELETE, repository);
|
||||
} else {
|
||||
throw new RepositoryNotFoundException(
|
||||
"repository ".concat(repository.getName()).concat(" not found"));
|
||||
private void preDelete(Repository toDelete) throws RepositoryException {
|
||||
if (configuration.isEnableRepositoryArchive() && !toDelete.isArchived()) {
|
||||
throw new RepositoryIsNotArchivedException("Repository could not deleted, because it is not archived.");
|
||||
}
|
||||
fireEvent(HandlerEventType.BEFORE_DELETE, toDelete);
|
||||
getHandler(toDelete).delete(toDelete);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -199,29 +188,18 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modify(Repository repository)
|
||||
throws RepositoryException {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("modify repository {} of type {}", repository.getName(),
|
||||
repository.getType());
|
||||
}
|
||||
public void modify(Repository repository) throws RepositoryException {
|
||||
logger.info("modify repository {} of type {}", repository.getName(), repository.getType());
|
||||
|
||||
AssertUtil.assertIsValid(repository);
|
||||
|
||||
Repository oldRepository = repositoryDAO.get(repository.getNamespaceAndName());
|
||||
|
||||
if (oldRepository != null) {
|
||||
RepositoryPermissions.modify(oldRepository).check();
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, repository, oldRepository);
|
||||
repository.setLastModified(System.currentTimeMillis());
|
||||
repository.setCreationDate(oldRepository.getCreationDate());
|
||||
getHandler(repository).modify(repository);
|
||||
repositoryDAO.modify(repository);
|
||||
fireEvent(HandlerEventType.MODIFY, repository, oldRepository);
|
||||
} else {
|
||||
throw new RepositoryNotFoundException(
|
||||
"repository ".concat(repository.getName()).concat(" not found"));
|
||||
}
|
||||
managerDaoAdapter.modify(
|
||||
repository,
|
||||
RepositoryPermissions::modify,
|
||||
notModified -> {
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, repository, notModified);
|
||||
getHandler(repository).modify(repository);
|
||||
},
|
||||
notModified -> fireEvent(HandlerEventType.MODIFY, repository, notModified)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -235,8 +213,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
if (fresh != null) {
|
||||
fresh.copyProperties(repository);
|
||||
} else {
|
||||
throw new RepositoryNotFoundException(
|
||||
"repository ".concat(repository.getName()).concat(" not found"));
|
||||
throw new RepositoryNotFoundException(repository);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,5 +429,4 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,11 +41,11 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.ManagerDaoAdapter;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.TransformFilter;
|
||||
import sonia.scm.search.SearchRequest;
|
||||
import sonia.scm.search.SearchUtil;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.CollectionAppender;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
@@ -96,6 +96,10 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
public DefaultUserManager(UserDAO userDAO)
|
||||
{
|
||||
this.userDAO = userDAO;
|
||||
this.managerDaoAdapter = new ManagerDaoAdapter<>(
|
||||
userDAO,
|
||||
UserNotFoundException::new,
|
||||
UserAlreadyExistsException::new);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -137,65 +141,31 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
* @throws UserException
|
||||
*/
|
||||
@Override
|
||||
public User create(User user) throws UserException
|
||||
{
|
||||
public User create(User user) throws UserException {
|
||||
String type = user.getType();
|
||||
|
||||
if (Util.isEmpty(type))
|
||||
{
|
||||
if (Util.isEmpty(type)) {
|
||||
user.setType(userDAO.getType());
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("create user {} of type {}", user.getName(), user.getType());
|
||||
}
|
||||
logger.info("create user {} of type {}", user.getName(), user.getType());
|
||||
|
||||
UserPermissions.create().check();
|
||||
|
||||
if (userDAO.contains(user.getName()))
|
||||
{
|
||||
throw new UserAlreadyExistsException(user.getName());
|
||||
}
|
||||
|
||||
AssertUtil.assertIsValid(user);
|
||||
user.setCreationDate(System.currentTimeMillis());
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, user);
|
||||
userDAO.add(user);
|
||||
fireEvent(HandlerEventType.CREATE, user);
|
||||
return user;
|
||||
return managerDaoAdapter.create(
|
||||
user,
|
||||
UserPermissions::create,
|
||||
newUser -> fireEvent(HandlerEventType.BEFORE_CREATE, newUser),
|
||||
newUser -> fireEvent(HandlerEventType.CREATE, newUser)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param user
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws UserException
|
||||
*/
|
||||
@Override
|
||||
public void delete(User user) throws UserException
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("delete user {} of type {}", user.getName(), user.getType());
|
||||
}
|
||||
|
||||
String name = user.getName();
|
||||
UserPermissions.delete(name).check();
|
||||
|
||||
if (userDAO.contains(name))
|
||||
{
|
||||
fireEvent(HandlerEventType.BEFORE_DELETE, user);
|
||||
userDAO.delete(user);
|
||||
fireEvent(HandlerEventType.DELETE, user);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
public void delete(User user) throws UserException {
|
||||
logger.info("delete user {} of type {}", user.getName(), user.getType());
|
||||
managerDaoAdapter.delete(
|
||||
user,
|
||||
() -> UserPermissions.delete(user.getName()),
|
||||
toDelete -> fireEvent(HandlerEventType.BEFORE_DELETE, toDelete),
|
||||
toDelete -> fireEvent(HandlerEventType.DELETE, toDelete)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,27 +197,13 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
@Override
|
||||
public void modify(User user) throws UserException
|
||||
{
|
||||
String name = user.getName();
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("modify user {} of type {}", user.getName(), user.getType());
|
||||
}
|
||||
logger.info("modify user {} of type {}", user.getName(), user.getType());
|
||||
|
||||
UserPermissions.modify(user).check();
|
||||
User notModified = userDAO.get(name);
|
||||
if (notModified != null)
|
||||
{
|
||||
AssertUtil.assertIsValid(user);
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, user, notModified);
|
||||
user.setLastModified(System.currentTimeMillis());
|
||||
user.setCreationDate(notModified.getCreationDate());
|
||||
userDAO.modify(user);
|
||||
fireEvent(HandlerEventType.MODIFY, user, notModified);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
managerDaoAdapter.modify(
|
||||
user,
|
||||
UserPermissions::modify,
|
||||
notModified -> fireEvent(HandlerEventType.BEFORE_MODIFY, user, notModified),
|
||||
notModified -> fireEvent(HandlerEventType.MODIFY, user, notModified));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,7 +228,7 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
|
||||
if (fresh == null)
|
||||
{
|
||||
throw new UserNotFoundException();
|
||||
throw new UserNotFoundException(user);
|
||||
}
|
||||
|
||||
fresh.copyProperties(user);
|
||||
@@ -497,6 +453,6 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final UserDAO userDAO;
|
||||
private final ManagerDaoAdapter<User, UserException> managerDaoAdapter;
|
||||
}
|
||||
|
||||
@@ -105,6 +105,21 @@ public class AbstractManagerResourceTest {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastModified(Long timestamp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCreationDate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreationDate(Long timestamp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getLastModified() {
|
||||
return null;
|
||||
|
||||
@@ -37,7 +37,6 @@ import com.github.sdorra.shiro.ShiroRule;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.apache.shiro.util.ThreadContext;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
@@ -45,7 +44,9 @@ import org.mockito.invocation.InvocationOnMock;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.ManagerTestBase;
|
||||
import sonia.scm.ModelObject;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.TypedObject;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.api.HookContext;
|
||||
@@ -99,6 +100,8 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository, Re
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private ScmConfiguration configuration;
|
||||
|
||||
private String mockedNamespace = "default_namespace";
|
||||
|
||||
@Test
|
||||
@@ -139,7 +142,8 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository, Re
|
||||
|
||||
@Test(expected = RepositoryIsNotArchivedException.class)
|
||||
public void testDeleteNonArchived() throws RepositoryException {
|
||||
delete(createRepositoryManager(true), createTestRepository());
|
||||
configuration.setEnableRepositoryArchive(true);
|
||||
delete(manager, createTestRepository());
|
||||
}
|
||||
|
||||
@Test(expected = RepositoryNotFoundException.class)
|
||||
@@ -492,7 +496,7 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository, Re
|
||||
|
||||
XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(factory);
|
||||
|
||||
ScmConfiguration configuration = new ScmConfiguration();
|
||||
this.configuration = new ScmConfiguration();
|
||||
|
||||
configuration.setEnableRepositoryArchive(archiveEnabled);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user