Merge parallel development

This commit is contained in:
René Pfeuffer
2018-07-02 14:36:04 +02:00
17 changed files with 478 additions and 978 deletions

View File

@@ -0,0 +1,8 @@
package sonia.scm.repository;
import sonia.scm.plugin.ExtensionPoint;
@ExtensionPoint
public interface NamespaceStrategy {
String getNamespace();
}

View File

@@ -33,28 +33,26 @@
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
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 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;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
//~--- JDK imports ------------------------------------------------------------
/**
* Source code repository.
@@ -67,32 +65,43 @@ import java.util.List;
)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "repositories")
public class Repository extends BasicPropertiesAware implements ModelObject, PermissionObject
{
public class Repository extends BasicPropertiesAware implements ModelObject, PermissionObject {
/** Field description */
private static final long serialVersionUID = 3486560714961909711L;
//~--- constructors ---------------------------------------------------------
private String contact;
private Long creationDate;
private String description;
@XmlElement(name = "healthCheckFailure")
@XmlElementWrapper(name = "healthCheckFailures")
private List<HealthCheckFailure> healthCheckFailures;
private String id;
private Long lastModified;
private String namespace;
private String name;
private List<Permission> permissions;
@XmlElement(name = "public")
private boolean publicReadable = false;
private boolean archived = false;
private String type;
/**
* Constructs a new {@link Repository}.
* This constructor is used by JAXB.
*
*/
public Repository() {}
public Repository() {
}
/**
* Constructs a new {@link Repository}.
*
*
*
* @param id id of the {@link Repository}
* @param id id of the {@link Repository}
* @param type type of the {@link Repository}
* @param name name of the {@link Repository}
*/
public Repository(String id, String type, String name)
{
public Repository(String id, String type, String name) {
this.id = id;
this.type = type;
this.name = name;
@@ -101,51 +110,231 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
/**
* Constructs a new {@link Repository}.
*
*
*
* @param id id of the {@link Repository}
* @param type type of the {@link Repository}
* @param name name of the {@link Repository}
* @param contact email address of a person who is responsible for
* this repository.
* @param id id of the {@link Repository}
* @param type type of the {@link Repository}
* @param name name of the {@link Repository}
* @param namespace namespace of the {@link Repository}
* @param contact email address of a person who is responsible for
* this repository.
* @param description a short description of the repository
* @param permissions permissions for specific users and groups.
*/
public Repository(String id, String type, String name, String contact,
String description, Permission... permissions)
{
public Repository(String id, String type, String namespace, String name, String contact,
String description, Permission... permissions) {
this.id = id;
this.type = type;
this.namespace = namespace;
this.name = name;
this.contact = contact;
this.description = description;
this.permissions = Lists.newArrayList();
if (Util.isNotEmpty(permissions))
{
if (Util.isNotEmpty(permissions)) {
this.permissions.addAll(Arrays.asList(permissions));
}
}
//~--- methods --------------------------------------------------------------
/**
* Returns a contact email address of a person who is responsible for
* the {@link Repository}.
*
* @return contact email address
*/
public String getContact() {
return contact;
}
/**
* Create a clone of this {@link Repository} object.
* Returns a timestamp of the creation date of the {@link Repository}.
*
* @return a timestamp of the creation date of the {@link Repository}
*/
public Long getCreationDate() {
return creationDate;
}
/**
* Returns a short description of the {@link Repository}.
*
* @return clone of this {@link Repository}
* @return short description
*/
public String getDescription() {
return description;
}
/**
* Returns a {@link List} of {@link HealthCheckFailure}s. The {@link List}
* is empty if the repository is healthy.
*
* @return {@link List} of {@link HealthCheckFailure}s
* @since 1.36
*/
@SuppressWarnings("unchecked")
public List<HealthCheckFailure> getHealthCheckFailures() {
if (healthCheckFailures == null) {
healthCheckFailures = Collections.EMPTY_LIST;
}
return healthCheckFailures;
}
/**
* Returns the unique id of the {@link Repository}.
*
* @return unique id
*/
@Override
public Repository clone()
{
public String getId() {
return id;
}
/**
* Returns the timestamp of the last modified date of the {@link Repository}.
*
* @return timestamp of the last modified date
*/
@Override
public Long getLastModified() {
return lastModified;
}
/**
* Returns the name of the {@link Repository}.
*
* @return name of the {@link Repository}
*/
public String getName() {
return name;
}
/**
* Returns the access permissions of the {@link Repository}.
*
* @return access permissions
*/
public List<Permission> getPermissions() {
if (permissions == null) {
permissions = Lists.newArrayList();
}
return permissions;
}
/**
* Returns the type (hg, git, svn ...) of the {@link Repository}.
*
* @return type of the repository
*/
@Override
public String getType() {
return type;
}
/**
* Returns true if the repository is archived.
*
* @return true if the repository is archived
* @since 1.14
*/
public boolean isArchived() {
return archived;
}
/**
* Returns {@code true} if the repository is healthy.
*
* @return {@code true} if the repository is healthy
* @since 1.36
*/
public boolean isHealthy() {
return Util.isEmpty(healthCheckFailures);
}
/**
* Returns true if the {@link Repository} is public readable.
*
* @return true if the {@link Repository} is public readable
*/
public boolean isPublicReadable() {
return publicReadable;
}
/**
* Returns true if the {@link Repository} is valid.
* <ul>
* <li>The name is not empty and contains only A-z, 0-9, _, -, /</li>
* <li>The type is not empty</li>
* <li>The contact is empty or contains a valid email address</li>
* </ul>
*
* @return true if the {@link Repository} is valid
*/
@Override
public boolean isValid() {
return ValidationUtil.isRepositoryNameValid(name) && Util.isNotEmpty(type)
&& ((Util.isEmpty(contact))
|| ValidationUtil.isMailAddressValid(contact));
}
/**
* Archive or un archive this repository.
*
* @param archived true to enable archive
* @since 1.14
*/
public void setArchived(boolean archived) {
this.archived = archived;
}
public void setContact(String contact) {
this.contact = contact;
}
public void setCreationDate(Long creationDate) {
this.creationDate = creationDate;
}
public void setDescription(String description) {
this.description = description;
}
public void setId(String id) {
this.id = id;
}
public void setLastModified(Long lastModified) {
this.lastModified = lastModified;
}
public void setNamespace(String namespace) { this.namespace = namespace; }
public void setName(String name) {
this.name = name;
}
public void setPermissions(List<Permission> permissions) {
this.permissions = permissions;
}
public void setPublicReadable(boolean publicReadable) {
this.publicReadable = publicReadable;
}
public void setType(String type) {
this.type = type;
}
public void setHealthCheckFailures(List<HealthCheckFailure> healthCheckFailures) {
this.healthCheckFailures = healthCheckFailures;
}
@Override
public Repository clone() {
Repository repository = null;
try
{
try {
repository = (Repository) super.clone();
}
catch (CloneNotSupportedException ex)
{
} catch (CloneNotSupportedException ex) {
throw new RuntimeException(ex);
}
@@ -155,11 +344,10 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
/**
* Copies all properties of the {@link Repository} to the given one.
*
*
* @param repository to copies all properties of this one
* @param repository the target {@link Repository}
*/
public void copyProperties(Repository repository)
{
public void copyProperties(Repository repository) {
repository.setNamespace(namespace);
repository.setName(name);
repository.setContact(contact);
repository.setCreationDate(creationDate);
@@ -175,14 +363,11 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
/**
* Creates the url of the repository.
*
*
* @param baseUrl base url of the server including the context path
*
* @return url of the repository
* @since 1.17
*/
public String createUrl(String baseUrl)
{
public String createUrl(String baseUrl) {
String url = HttpUtil.append(baseUrl, type);
return HttpUtil.append(url, name);
@@ -191,429 +376,59 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
/**
* Returns true if the {@link Repository} is the same as the obj argument.
*
*
* @param obj the reference object with which to compare
*
* @return true if the {@link Repository} is the same as the obj argument
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass())
{
if (getClass() != obj.getClass()) {
return false;
}
final Repository other = (Repository) obj;
//J-
return Objects.equal(id, other.id)
&& Objects.equal(name, other.name)
&& Objects.equal(contact, other.contact)
&& Objects.equal(description, other.description)
&& Objects.equal(publicReadable, other.publicReadable)
&& Objects.equal(archived, other.archived)
&& Objects.equal(permissions, other.permissions)
&& Objects.equal(type, other.type)
&& Objects.equal(creationDate, other.creationDate)
&& Objects.equal(lastModified, other.lastModified)
&& Objects.equal(properties, other.properties)
&& Objects.equal(healthCheckFailures, other.healthCheckFailures);
//J+
return Objects.equal(id, other.id)
&& Objects.equal(namespace, other.namespace)
&& Objects.equal(name, other.name)
&& Objects.equal(contact, other.contact)
&& Objects.equal(description, other.description)
&& Objects.equal(publicReadable, other.publicReadable)
&& Objects.equal(archived, other.archived)
&& Objects.equal(permissions, other.permissions)
&& Objects.equal(type, other.type)
&& Objects.equal(creationDate, other.creationDate)
&& Objects.equal(lastModified, other.lastModified)
&& Objects.equal(properties, other.properties)
&& Objects.equal(healthCheckFailures, other.healthCheckFailures);
}
/**
* Returns the hash code value for the {@link Repository}.
*
*
* @return the hash code value for the {@link Repository}
*/
@Override
public int hashCode()
{
return Objects.hashCode(id, name, contact, description, publicReadable,
public int hashCode() {
return Objects.hashCode(id, namespace, name, contact, description, publicReadable,
archived, permissions, type, creationDate, lastModified, properties,
healthCheckFailures);
}
/**
* Returns a {@link String} that represents the {@link Repository}.
*
*
* @return {@link String} that represents the {@link Repository}
*/
@Override
public String toString()
{
//J-
public String toString() {
return Objects.toStringHelper(this)
.add("id", id)
.add("name", name)
.add("contact", contact)
.add("description", description)
.add("publicReadable", publicReadable)
.add("archived", archived)
.add("permissions", permissions)
.add("type", type)
.add("lastModified", lastModified)
.add("creationDate", creationDate)
.add("properties", properties)
.add("healthCheckFailures", healthCheckFailures)
.toString();
//J+
.add("id", id)
.add("namespace", namespace)
.add("name", name)
.add("contact", contact)
.add("description", description)
.add("publicReadable", publicReadable)
.add("archived", archived)
.add("permissions", permissions)
.add("type", type)
.add("lastModified", lastModified)
.add("creationDate", creationDate)
.add("properties", properties)
.add("healthCheckFailures", healthCheckFailures)
.toString();
}
//~--- get methods ----------------------------------------------------------
/**
* Returns a contact email address of a person who is responsible for
* the {@link Repository}.
*
*
* @return contact email address
*/
public String getContact()
{
return contact;
}
/**
* Returns a timestamp of the creation date of the {@link Repository}.
*
*
* @return a timestamp of the creation date of the {@link Repository}
*/
public Long getCreationDate()
{
return creationDate;
}
/**
* Returns a short description of the {@link Repository}.
*
*
* @return short description
*/
public String getDescription()
{
return description;
}
/**
* Returns a {@link List} of {@link HealthCheckFailure}s. The {@link List}
* is empty if the repository is healthy.
*
*
* @return {@link List} of {@link HealthCheckFailure}s
* @since 1.36
*/
@SuppressWarnings("unchecked")
public List<HealthCheckFailure> getHealthCheckFailures()
{
if (healthCheckFailures == null)
{
healthCheckFailures = Collections.EMPTY_LIST;
}
return healthCheckFailures;
}
/**
* Returns the unique id of the {@link Repository}.
*
*
* @return unique id
*/
@Override
public String getId()
{
return id;
}
/**
* Returns the timestamp of the last modified date of the {@link Repository}.
*
*
* @return timestamp of the last modified date
*/
@Override
public Long getLastModified()
{
return lastModified;
}
/**
* Returns the name of the {@link Repository}.
*
*
* @return name of the {@link Repository}
*/
public String getName()
{
return name;
}
/**
* Returns the access permissions of the {@link Repository}.
*
*
* @return access permissions
*/
public List<Permission> getPermissions()
{
if (permissions == null)
{
permissions = Lists.newArrayList();
}
return permissions;
}
/**
* Returns the type (hg, git, svn ...) of the {@link Repository}.
*
*
* @return type of the repository
*/
@Override
public String getType()
{
return type;
}
/**
* Returns true if the repository is archived.
*
*
* @return true if the repository is archived
* @since 1.14
*/
public boolean isArchived()
{
return archived;
}
/**
* Returns {@code true} if the repository is healthy.
*
*
* @return {@code true} if the repository is healthy
*
* @since 1.36
*/
public boolean isHealthy()
{
return Util.isEmpty(healthCheckFailures);
}
/**
* Returns true if the {@link Repository} is public readable.
*
*
* @return true if the {@link Repository} is public readable
*/
public boolean isPublicReadable()
{
return publicReadable;
}
/**
* Returns true if the {@link Repository} is valid.
* <ul>
* <li>The name is not empty and contains only A-z, 0-9, _, -, /</li>
* <li>The type is not empty</li>
* <li>The contact is empty or contains a valid email address</li>
* </ul>
*
*
* @return true if the {@link Repository} is valid
*/
@Override
public boolean isValid()
{
return ValidationUtil.isRepositoryNameValid(name) && Util.isNotEmpty(type)
&& ((Util.isEmpty(contact))
|| ValidationUtil.isMailAddressValid(contact));
}
public String getSpace() {
return space;
}
//~--- set methods ----------------------------------------------------------
/**
* Archive or un archive this repository.
*
*
* @param archived true to enable archive
* @since 1.14
*/
public void setArchived(boolean archived)
{
this.archived = archived;
}
/**
* Sets the contact of the {@link Repository}. The contact address should be
* a email address of a person who is responsible for the {@link Repository}.
*
*
* @param contact email address of a person who is responsible for
* the {@link Repository}
*/
public void setContact(String contact)
{
this.contact = contact;
}
/**
* Set the creation date of the {@link Repository}.
*
*
* @param creationDate creation date of the {@link Repository}
*/
public void setCreationDate(Long creationDate)
{
this.creationDate = creationDate;
}
/**
* Sets a short description of the {@link Repository}.
*
*
* @param description short description
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* The unique id of the {@link Repository}.
*
*
* @param id unique id
*/
public void setId(String id)
{
this.id = id;
}
/**
* Set the last modified timestamp of the {@link Repository}.
*
*
* @param lastModified last modified timestamp
*/
public void setLastModified(Long lastModified)
{
this.lastModified = lastModified;
}
/**
* Set the name of the {@link Repository}.
*
*
* @param name name of the {@link Repository}
*/
public void setName(String name)
{
this.name = name;
}
/**
* Set the access permissions for the {@link Repository}.
*
*
* @param permissions list of access permissions
*/
public void setPermissions(List<Permission> permissions)
{
this.permissions = permissions;
}
/**
* Sets true if the {@link Repository} is public readable.
*
*
* @param publicReadable public readable
*/
public void setPublicReadable(boolean publicReadable)
{
this.publicReadable = publicReadable;
}
/**
* Sets the type (hg, svn, git ...) of the {@link Repository}.
*
*
* @param type type of the {@link Repository}
*/
public void setType(String type)
{
this.type = type;
}
/**
* Sets {@link HealthCheckFailure} for a unhealthy repository.
*
* @param healthCheckFailures list of {@link HealthCheckFailure}s
*
* @since 1.36
*/
public void setHealthCheckFailures(List<HealthCheckFailure> healthCheckFailures)
{
this.healthCheckFailures = healthCheckFailures;
}
public void setSpace(String space) {
this.space = space;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String contact;
/** Field description */
private Long creationDate;
/** Field description */
private String description;
/**
* @since 1.36
*/
@XmlElement(name = "healthCheckFailure")
@XmlElementWrapper(name = "healthCheckFailures")
private List<HealthCheckFailure> healthCheckFailures;
/** Field description */
private String id;
/** Field description */
private Long lastModified;
/** Field description */
private String name;
/** Field description */
private List<Permission> permissions;
/** Field description */
@XmlElement(name = "public")
private boolean publicReadable = false;
/** Field description */
private boolean archived = false;
/** Field description */
private String type;
private String space;
}

View File

@@ -1,8 +0,0 @@
package sonia.scm.repository;
import sonia.scm.plugin.ExtensionPoint;
@ExtensionPoint(multi = true)
public interface SpacesStrategy {
String getCurrentSpace();
}

View File

@@ -1,11 +0,0 @@
package sonia.scm.repository;
import sonia.scm.plugin.Extension;
@Extension
public class StaticSpacesStrategy implements SpacesStrategy {
@Override
public String getCurrentSpace() {
return "test";
}
}

View File

@@ -253,7 +253,7 @@ public final class RepositoryServiceFactory
for (RepositoryServiceResolver resolver : resolvers)
{
RepositoryServiceProvider provider = resolver.reslove(repository);
RepositoryServiceProvider provider = resolver.resolve(repository);
if (provider != null)
{

View File

@@ -33,8 +33,6 @@
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.plugin.ExtensionPoint;
import sonia.scm.repository.Repository;
@@ -55,5 +53,5 @@ public interface RepositoryServiceResolver
*
* @return
*/
public RepositoryServiceProvider reslove(Repository repository);
public RepositoryServiceProvider resolve(Repository repository);
}