mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 18:26:16 +01:00
merge branch heads of 2.0.0-m3
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
@@ -24,39 +24,32 @@
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.config;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.xml.XmlSetStringAdapter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The main configuration object for SCM-Manager.
|
||||
@@ -67,38 +60,137 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
@Singleton
|
||||
@XmlRootElement(name = "scm-config")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ScmConfiguration
|
||||
{
|
||||
public class ScmConfiguration {
|
||||
|
||||
/** Default JavaScript date format */
|
||||
/**
|
||||
* Default JavaScript date format
|
||||
*/
|
||||
public static final String DEFAULT_DATEFORMAT = "YYYY-MM-DD HH:mm:ss";
|
||||
|
||||
/** Default plugin url */
|
||||
/**
|
||||
* Default plugin url
|
||||
*/
|
||||
public static final String DEFAULT_PLUGINURL =
|
||||
"http://plugins.scm-manager.org/scm-plugin-backend/api/{version}/plugins?os={os}&arch={arch}&snapshot=false";
|
||||
|
||||
/** Default plugin url from version 1.0 */
|
||||
/**
|
||||
* Default plugin url from version 1.0
|
||||
*/
|
||||
public static final String OLD_PLUGINURL =
|
||||
"http://plugins.scm-manager.org/plugins.xml.gz";
|
||||
|
||||
/** Path to the configuration file */
|
||||
/**
|
||||
* Path to the configuration file
|
||||
*/
|
||||
public static final String PATH =
|
||||
"config".concat(File.separator).concat("config.xml");
|
||||
|
||||
/** the logger for ScmConfiguration */
|
||||
/**
|
||||
* the logger for ScmConfiguration
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(ScmConfiguration.class);
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@XmlElement(name = "admin-groups")
|
||||
@XmlJavaTypeAdapter(XmlSetStringAdapter.class)
|
||||
private Set<String> adminGroups;
|
||||
|
||||
|
||||
@XmlElement(name = "admin-users")
|
||||
@XmlJavaTypeAdapter(XmlSetStringAdapter.class)
|
||||
private Set<String> adminUsers;
|
||||
|
||||
|
||||
@XmlElement(name = "base-url")
|
||||
private String baseUrl;
|
||||
|
||||
|
||||
@XmlElement(name = "force-base-url")
|
||||
private boolean forceBaseUrl;
|
||||
|
||||
/**
|
||||
* Maximum allowed login attempts.
|
||||
*
|
||||
* @since 1.34
|
||||
*/
|
||||
@XmlElement(name = "login-attempt-limit")
|
||||
private int loginAttemptLimit = -1;
|
||||
|
||||
/**
|
||||
* glob patterns for urls which are excluded from proxy
|
||||
*/
|
||||
@XmlElement(name = "proxy-excludes")
|
||||
@XmlJavaTypeAdapter(XmlSetStringAdapter.class)
|
||||
private Set<String> proxyExcludes;
|
||||
|
||||
|
||||
private String proxyPassword;
|
||||
|
||||
|
||||
private int proxyPort = 8080;
|
||||
|
||||
|
||||
private String proxyServer = "proxy.mydomain.com";
|
||||
|
||||
|
||||
private String proxyUser;
|
||||
|
||||
/**
|
||||
* Skip failed authenticators.
|
||||
*
|
||||
* @since 1.36
|
||||
*/
|
||||
@XmlElement(name = "skip-failed-authenticators")
|
||||
private boolean skipFailedAuthenticators = false;
|
||||
|
||||
|
||||
@XmlElement(name = "plugin-url")
|
||||
private String pluginUrl = DEFAULT_PLUGINURL;
|
||||
|
||||
/**
|
||||
* Login attempt timeout.
|
||||
*
|
||||
* @since 1.34
|
||||
*/
|
||||
@XmlElement(name = "login-attempt-limit-timeout")
|
||||
private long loginAttemptLimitTimeout = TimeUnit.MINUTES.toSeconds(5l);
|
||||
|
||||
|
||||
private boolean enableProxy = false;
|
||||
|
||||
/**
|
||||
* Authentication realm for basic authentication.
|
||||
*/
|
||||
private String realmDescription = HttpUtil.AUTHENTICATION_REALM;
|
||||
private boolean enableRepositoryArchive = false;
|
||||
private boolean disableGroupingGrid = false;
|
||||
/**
|
||||
* JavaScript date format from moment.js
|
||||
*
|
||||
* @see <a href="http://momentjs.com/docs/#/parsing/" target="_blank">http://momentjs.com/docs/#/parsing/</a>
|
||||
*/
|
||||
private String dateFormat = DEFAULT_DATEFORMAT;
|
||||
private boolean anonymousAccessEnabled = false;
|
||||
|
||||
/**
|
||||
* Enables xsrf cookie protection.
|
||||
*
|
||||
* @since 1.47
|
||||
*/
|
||||
@XmlElement(name = "xsrf-protection")
|
||||
private boolean enabledXsrfProtection = true;
|
||||
|
||||
@XmlElement(name = "default-namespace-strategy")
|
||||
private String defaultNamespaceStrategy = "sonia.scm.repository.DefaultNamespaceStrategy";
|
||||
|
||||
|
||||
/**
|
||||
* Calls the {@link sonia.scm.ConfigChangedListener#configChanged(Object)}
|
||||
* method of all registered listeners.
|
||||
*/
|
||||
public void fireChangeEvent()
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
public void fireChangeEvent() {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("fire config changed event");
|
||||
}
|
||||
|
||||
@@ -109,12 +201,9 @@ public class ScmConfiguration
|
||||
/**
|
||||
* Load all properties from another {@link ScmConfiguration} object.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param other
|
||||
*/
|
||||
public void load(ScmConfiguration other)
|
||||
{
|
||||
public void load(ScmConfiguration other) {
|
||||
this.realmDescription = other.realmDescription;
|
||||
this.dateFormat = other.dateFormat;
|
||||
this.pluginUrl = other.pluginUrl;
|
||||
@@ -135,29 +224,14 @@ public class ScmConfiguration
|
||||
this.loginAttemptLimit = other.loginAttemptLimit;
|
||||
this.loginAttemptLimitTimeout = other.loginAttemptLimitTimeout;
|
||||
this.enabledXsrfProtection = other.enabledXsrfProtection;
|
||||
this.defaultNamespaceStrategy = other.defaultNamespaceStrategy;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a set of admin group names.
|
||||
*
|
||||
*
|
||||
* @return set of admin group names
|
||||
*/
|
||||
public Set<String> getAdminGroups()
|
||||
{
|
||||
public Set<String> getAdminGroups() {
|
||||
return adminGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of admin user names.
|
||||
*
|
||||
*
|
||||
* @return set of admin user names
|
||||
*/
|
||||
public Set<String> getAdminUsers()
|
||||
{
|
||||
public Set<String> getAdminUsers() {
|
||||
return adminUsers;
|
||||
}
|
||||
|
||||
@@ -165,11 +239,10 @@ public class ScmConfiguration
|
||||
* Returns the complete base url of the scm-manager including the context path.
|
||||
* For example http://localhost:8080/scm
|
||||
*
|
||||
* @since 1.5
|
||||
* @return complete base url of the scm-manager
|
||||
* @since 1.5
|
||||
*/
|
||||
public String getBaseUrl()
|
||||
{
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
@@ -177,23 +250,14 @@ public class ScmConfiguration
|
||||
* Returns the date format for the user interface. This format is a
|
||||
* JavaScript date format, from the library moment.js.
|
||||
*
|
||||
* @see <a href="http://momentjs.com/docs/#/parsing/" target="_blank">http://momentjs.com/docs/#/parsing/</a>
|
||||
* @return moment.js date format
|
||||
* @see <a href="http://momentjs.com/docs/#/parsing/" target="_blank">http://momentjs.com/docs/#/parsing/</a>
|
||||
*/
|
||||
public String getDateFormat()
|
||||
{
|
||||
public String getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns maximum allowed login attempts.
|
||||
*
|
||||
* @return maximum allowed login attempts
|
||||
*
|
||||
* @since 1.34
|
||||
*/
|
||||
public int getLoginAttemptLimit()
|
||||
{
|
||||
public int getLoginAttemptLimit() {
|
||||
return loginAttemptLimit;
|
||||
}
|
||||
|
||||
@@ -202,11 +266,9 @@ public class ScmConfiguration
|
||||
* because of too many failed login attempts.
|
||||
*
|
||||
* @return login attempt timeout in seconds
|
||||
*
|
||||
* @since 1.34
|
||||
*/
|
||||
public long getLoginAttemptLimitTimeout()
|
||||
{
|
||||
public long getLoginAttemptLimitTimeout() {
|
||||
return loginAttemptLimitTimeout;
|
||||
}
|
||||
|
||||
@@ -222,8 +284,7 @@ public class ScmConfiguration
|
||||
*
|
||||
* @return the complete plugin url.
|
||||
*/
|
||||
public String getPluginUrl()
|
||||
{
|
||||
public String getPluginUrl() {
|
||||
return pluginUrl;
|
||||
}
|
||||
|
||||
@@ -231,289 +292,141 @@ public class ScmConfiguration
|
||||
* Returns a set of glob patterns for urls which should excluded from
|
||||
* proxy settings.
|
||||
*
|
||||
*
|
||||
* @return set of glob patterns
|
||||
* @since 1.23
|
||||
*/
|
||||
public Set<String> getProxyExcludes()
|
||||
{
|
||||
if (proxyExcludes == null)
|
||||
{
|
||||
public Set<String> getProxyExcludes() {
|
||||
if (proxyExcludes == null) {
|
||||
proxyExcludes = Sets.newHashSet();
|
||||
}
|
||||
|
||||
return proxyExcludes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @since 1.7
|
||||
*/
|
||||
public String getProxyPassword()
|
||||
{
|
||||
public String getProxyPassword() {
|
||||
return proxyPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the proxy port.
|
||||
*
|
||||
*
|
||||
* @return proxy port
|
||||
*/
|
||||
public int getProxyPort()
|
||||
{
|
||||
public int getProxyPort() {
|
||||
return proxyPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the servername or ip of the proxyserver.
|
||||
*
|
||||
*
|
||||
* @return servername or ip of the proxyserver
|
||||
*/
|
||||
public String getProxyServer()
|
||||
{
|
||||
public String getProxyServer() {
|
||||
return proxyServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @since 1.7
|
||||
*/
|
||||
public String getProxyUser()
|
||||
{
|
||||
public String getProxyUser() {
|
||||
return proxyUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the realm description.
|
||||
*
|
||||
*
|
||||
* @return realm description
|
||||
* @since 1.36
|
||||
*/
|
||||
public String getRealmDescription()
|
||||
{
|
||||
public String getRealmDescription() {
|
||||
return realmDescription;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the anonymous access to the SCM-Manager is enabled.
|
||||
*
|
||||
*
|
||||
* @return true if the anonymous access to the SCM-Manager is enabled
|
||||
*/
|
||||
public boolean isAnonymousAccessEnabled()
|
||||
{
|
||||
public boolean isAnonymousAccessEnabled() {
|
||||
return anonymousAccessEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
* @since 1.9
|
||||
* @return
|
||||
*/
|
||||
public boolean isDisableGroupingGrid()
|
||||
{
|
||||
public boolean isDisableGroupingGrid() {
|
||||
return disableGroupingGrid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the cookie xsrf protection is enabled.
|
||||
*
|
||||
* @see <a href="https://goo.gl/s67xO3">Issue 793</a>
|
||||
*
|
||||
* @return {@code true} if the cookie xsrf protection is enabled
|
||||
*
|
||||
* @see <a href="https://goo.gl/s67xO3">Issue 793</a>
|
||||
* @since 1.47
|
||||
*/
|
||||
public boolean isEnabledXsrfProtection()
|
||||
{
|
||||
public boolean isEnabledXsrfProtection() {
|
||||
return enabledXsrfProtection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if proxy is enabled.
|
||||
*
|
||||
*
|
||||
* @return true if proxy is enabled
|
||||
*/
|
||||
public boolean isEnableProxy()
|
||||
{
|
||||
public boolean isEnableProxy() {
|
||||
return enableProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the repository archive is enabled.
|
||||
*
|
||||
*
|
||||
* @return true if the repository archive is enabled
|
||||
* @since 1.14
|
||||
*/
|
||||
public boolean isEnableRepositoryArchive()
|
||||
{
|
||||
public boolean isEnableRepositoryArchive() {
|
||||
return enableRepositoryArchive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if force base url is enabled.
|
||||
*
|
||||
* @since 1.5
|
||||
* @return true if force base url is enabled
|
||||
*/
|
||||
public boolean isForceBaseUrl()
|
||||
{
|
||||
public boolean isForceBaseUrl() {
|
||||
return forceBaseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the login attempt limit is enabled.
|
||||
*
|
||||
*
|
||||
* @return true if login attempt limit is enabled
|
||||
*
|
||||
* @since 1.37
|
||||
*/
|
||||
public boolean isLoginAttemptLimitEnabled()
|
||||
{
|
||||
public boolean isLoginAttemptLimitEnabled() {
|
||||
return loginAttemptLimit > 0;
|
||||
}
|
||||
|
||||
public String getDefaultNamespaceStrategy() {
|
||||
return defaultNamespaceStrategy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if failed authenticators are skipped.
|
||||
*
|
||||
*
|
||||
* @return true if failed authenticators are skipped
|
||||
*
|
||||
* @since 1.36
|
||||
*/
|
||||
public boolean isSkipFailedAuthenticators()
|
||||
{
|
||||
public boolean isSkipFailedAuthenticators() {
|
||||
return skipFailedAuthenticators;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param adminGroups
|
||||
*/
|
||||
public void setAdminGroups(Set<String> adminGroups)
|
||||
{
|
||||
public void setAdminGroups(Set<String> adminGroups) {
|
||||
this.adminGroups = adminGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param adminUsers
|
||||
*/
|
||||
public void setAdminUsers(Set<String> adminUsers)
|
||||
{
|
||||
public void setAdminUsers(Set<String> adminUsers) {
|
||||
this.adminUsers = adminUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param anonymousAccessEnabled
|
||||
*/
|
||||
public void setAnonymousAccessEnabled(boolean anonymousAccessEnabled)
|
||||
{
|
||||
public void setAnonymousAccessEnabled(boolean anonymousAccessEnabled) {
|
||||
this.anonymousAccessEnabled = anonymousAccessEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
* @since 1.5
|
||||
*/
|
||||
public void setBaseUrl(String baseUrl)
|
||||
{
|
||||
public void setBaseUrl(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the date format for the ui.
|
||||
*
|
||||
*
|
||||
* @param dateFormat date format for ui
|
||||
*/
|
||||
public void setDateFormat(String dateFormat)
|
||||
{
|
||||
public void setDateFormat(String dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
* @since 1.9
|
||||
*
|
||||
* @param disableGroupingGrid
|
||||
*/
|
||||
public void setDisableGroupingGrid(boolean disableGroupingGrid)
|
||||
{
|
||||
public void setDisableGroupingGrid(boolean disableGroupingGrid) {
|
||||
this.disableGroupingGrid = disableGroupingGrid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param enableProxy
|
||||
*/
|
||||
public void setEnableProxy(boolean enableProxy)
|
||||
{
|
||||
public void setEnableProxy(boolean enableProxy) {
|
||||
this.enableProxy = enableProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable the repository archive. Default is disabled.
|
||||
*
|
||||
*
|
||||
* @param enableRepositoryArchive true to disable the repository archive
|
||||
* @since 1.14
|
||||
*/
|
||||
public void setEnableRepositoryArchive(boolean enableRepositoryArchive)
|
||||
{
|
||||
public void setEnableRepositoryArchive(boolean enableRepositoryArchive) {
|
||||
this.enableRepositoryArchive = enableRepositoryArchive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param forceBaseUrl
|
||||
* @since 1.5
|
||||
*/
|
||||
public void setForceBaseUrl(boolean forceBaseUrl)
|
||||
{
|
||||
public void setForceBaseUrl(boolean forceBaseUrl) {
|
||||
this.forceBaseUrl = forceBaseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set maximum allowed login attempts.
|
||||
*
|
||||
*
|
||||
* @param loginAttemptLimit login attempt limit
|
||||
*
|
||||
* @since 1.34
|
||||
*/
|
||||
public void setLoginAttemptLimit(int loginAttemptLimit)
|
||||
{
|
||||
public void setLoginAttemptLimit(int loginAttemptLimit) {
|
||||
this.loginAttemptLimit = loginAttemptLimit;
|
||||
}
|
||||
|
||||
@@ -522,22 +435,13 @@ public class ScmConfiguration
|
||||
* because of too many failed login attempts.
|
||||
*
|
||||
* @param loginAttemptLimitTimeout login attempt timeout in seconds
|
||||
*
|
||||
* @since 1.34
|
||||
*/
|
||||
public void setLoginAttemptLimitTimeout(long loginAttemptLimitTimeout)
|
||||
{
|
||||
public void setLoginAttemptLimitTimeout(long loginAttemptLimitTimeout) {
|
||||
this.loginAttemptLimitTimeout = loginAttemptLimitTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param pluginUrl
|
||||
*/
|
||||
public void setPluginUrl(String pluginUrl)
|
||||
{
|
||||
public void setPluginUrl(String pluginUrl) {
|
||||
this.pluginUrl = pluginUrl;
|
||||
}
|
||||
|
||||
@@ -545,194 +449,56 @@ public class ScmConfiguration
|
||||
* Set glob patterns for urls which are should be excluded from proxy
|
||||
* settings.
|
||||
*
|
||||
*
|
||||
* @param proxyExcludes glob patterns
|
||||
* @since 1.23
|
||||
*/
|
||||
public void setProxyExcludes(Set<String> proxyExcludes)
|
||||
{
|
||||
public void setProxyExcludes(Set<String> proxyExcludes) {
|
||||
this.proxyExcludes = proxyExcludes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param proxyPassword
|
||||
* @since 1.7
|
||||
*/
|
||||
public void setProxyPassword(String proxyPassword)
|
||||
{
|
||||
public void setProxyPassword(String proxyPassword) {
|
||||
this.proxyPassword = proxyPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param proxyPort
|
||||
*/
|
||||
public void setProxyPort(int proxyPort)
|
||||
{
|
||||
public void setProxyPort(int proxyPort) {
|
||||
this.proxyPort = proxyPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param proxyServer
|
||||
*/
|
||||
public void setProxyServer(String proxyServer)
|
||||
{
|
||||
public void setProxyServer(String proxyServer) {
|
||||
this.proxyServer = proxyServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param proxyUser
|
||||
* @since 1.7
|
||||
*/
|
||||
public void setProxyUser(String proxyUser)
|
||||
{
|
||||
public void setProxyUser(String proxyUser) {
|
||||
this.proxyUser = proxyUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the realm description.
|
||||
*
|
||||
*
|
||||
* @param realmDescription
|
||||
* @since 1.36
|
||||
*/
|
||||
public void setRealmDescription(String realmDescription)
|
||||
{
|
||||
public void setRealmDescription(String realmDescription) {
|
||||
this.realmDescription = realmDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to true the authentication chain is not stopped, if an
|
||||
* If set to true the authentication chain is not stopped, if an
|
||||
* authenticator finds the user but fails to authenticate the user.
|
||||
*
|
||||
* @param skipFailedAuthenticators true to skip failed authenticators
|
||||
*
|
||||
* @since 1.36
|
||||
*/
|
||||
public void setSkipFailedAuthenticators(boolean skipFailedAuthenticators)
|
||||
{
|
||||
public void setSkipFailedAuthenticators(boolean skipFailedAuthenticators) {
|
||||
this.skipFailedAuthenticators = skipFailedAuthenticators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set {@code true} to enable xsrf cookie protection.
|
||||
*
|
||||
*
|
||||
* @param enabledXsrfProtection {@code true} to enable xsrf protection
|
||||
* @see <a href="https://goo.gl/s67xO3">Issue 793</a>
|
||||
*
|
||||
* @since 1.47
|
||||
*/
|
||||
public void setEnabledXsrfProtection(boolean enabledXsrfProtection)
|
||||
{
|
||||
public void setEnabledXsrfProtection(boolean enabledXsrfProtection) {
|
||||
this.enabledXsrfProtection = enabledXsrfProtection;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "admin-groups")
|
||||
@XmlJavaTypeAdapter(XmlSetStringAdapter.class)
|
||||
private Set<String> adminGroups;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "admin-users")
|
||||
@XmlJavaTypeAdapter(XmlSetStringAdapter.class)
|
||||
private Set<String> adminUsers;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "base-url")
|
||||
private String baseUrl;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "force-base-url")
|
||||
private boolean forceBaseUrl;
|
||||
|
||||
/**
|
||||
* Maximum allowed login attempts.
|
||||
*
|
||||
* @since 1.34
|
||||
*/
|
||||
@XmlElement(name = "login-attempt-limit")
|
||||
private int loginAttemptLimit = -1;
|
||||
|
||||
/** glob patterns for urls which are excluded from proxy */
|
||||
@XmlElement(name = "proxy-excludes")
|
||||
@XmlJavaTypeAdapter(XmlSetStringAdapter.class)
|
||||
private Set<String> proxyExcludes;
|
||||
|
||||
/** Field description */
|
||||
private String proxyPassword;
|
||||
|
||||
/** Field description */
|
||||
private int proxyPort = 8080;
|
||||
|
||||
/** Field description */
|
||||
private String proxyServer = "proxy.mydomain.com";
|
||||
|
||||
/** Field description */
|
||||
private String proxyUser;
|
||||
|
||||
/**
|
||||
* Skip failed authenticators.
|
||||
*
|
||||
* @since 1.36
|
||||
*/
|
||||
@XmlElement(name = "skip-failed-authenticators")
|
||||
private boolean skipFailedAuthenticators = false;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "plugin-url")
|
||||
private String pluginUrl = DEFAULT_PLUGINURL;
|
||||
|
||||
/**
|
||||
* Login attempt timeout.
|
||||
*
|
||||
* @since 1.34
|
||||
*/
|
||||
@XmlElement(name = "login-attempt-limit-timeout")
|
||||
private long loginAttemptLimitTimeout = TimeUnit.MINUTES.toSeconds(5l);
|
||||
|
||||
/** Field description */
|
||||
private boolean enableProxy = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* Authentication realm for basic authentication.
|
||||
*
|
||||
*/
|
||||
private String realmDescription = HttpUtil.AUTHENTICATION_REALM;
|
||||
|
||||
/** Field description */
|
||||
private boolean enableRepositoryArchive = false;
|
||||
|
||||
/** Field description */
|
||||
private boolean disableGroupingGrid = false;
|
||||
|
||||
/**
|
||||
* JavaScript date format from moment.js
|
||||
* @see <a href="http://momentjs.com/docs/#/parsing/" target="_blank">http://momentjs.com/docs/#/parsing/</a>
|
||||
*/
|
||||
private String dateFormat = DEFAULT_DATEFORMAT;
|
||||
|
||||
/** Field description */
|
||||
private boolean anonymousAccessEnabled = false;
|
||||
|
||||
/**
|
||||
* Enables xsrf cookie protection.
|
||||
*
|
||||
* @since 1.47
|
||||
*/
|
||||
@XmlElement(name = "xsrf-protection")
|
||||
private boolean enabledXsrfProtection = true;
|
||||
public void setDefaultNamespaceStrategy(String defaultNamespaceStrategy) {
|
||||
this.defaultNamespaceStrategy = defaultNamespaceStrategy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,19 +36,16 @@ package sonia.scm.repository;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.ImportResult.Builder;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Abstract base class for directory based {@link ImportHandler} and
|
||||
* {@link AdvancedImportHandler}.
|
||||
@@ -164,23 +161,24 @@ public abstract class AbstactImportHandler implements AdvancedImportHandler
|
||||
|
||||
logger.trace("search for repositories to import");
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
List<String> repositoryNames =
|
||||
RepositoryUtil.getRepositoryNames(getRepositoryHandler(),
|
||||
getDirectoryNames());
|
||||
|
||||
for (String repositoryName : repositoryNames)
|
||||
{
|
||||
importRepository(manager, builder, throwExceptions, repositoryName);
|
||||
}
|
||||
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
handleException(ex, throwExceptions);
|
||||
}
|
||||
// TODO #8783
|
||||
// try
|
||||
// {
|
||||
//
|
||||
// List<String> repositoryNames =
|
||||
// RepositoryUtil.getRepositoryNames(getRepositoryHandler(),
|
||||
// getDirectoryNames());
|
||||
//
|
||||
// for (String repositoryName : repositoryNames)
|
||||
// {
|
||||
// importRepository(manager, builder, throwExceptions, repositoryName);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// catch (IOException ex)
|
||||
// {
|
||||
// handleException(ex, throwExceptions);
|
||||
// }
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
@@ -214,46 +212,48 @@ public abstract class AbstactImportHandler implements AdvancedImportHandler
|
||||
* @param manager
|
||||
* @param builder
|
||||
* @param throwExceptions
|
||||
* @param repositoryName
|
||||
* @param directoryName
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private void importRepository(RepositoryManager manager, Builder builder,
|
||||
boolean throwExceptions, String repositoryName)
|
||||
boolean throwExceptions, String directoryName)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
logger.trace("check repository {} for import", repositoryName);
|
||||
logger.trace("check repository {} for import", directoryName);
|
||||
|
||||
Repository repository = manager.get(getTypeName(), repositoryName);
|
||||
|
||||
if (repository == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
importRepository(manager, repositoryName);
|
||||
builder.addImportedDirectory(repositoryName);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
builder.addFailedDirectory(repositoryName);
|
||||
handleException(ex, throwExceptions);
|
||||
}
|
||||
catch (IllegalStateException ex)
|
||||
{
|
||||
builder.addFailedDirectory(repositoryName);
|
||||
handleException(ex, throwExceptions);
|
||||
}
|
||||
catch (RepositoryException ex)
|
||||
{
|
||||
builder.addFailedDirectory(repositoryName);
|
||||
handleException(ex, throwExceptions);
|
||||
}
|
||||
}
|
||||
else if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("repository {} is allready managed", repositoryName);
|
||||
}
|
||||
// TODO #8783
|
||||
//
|
||||
// Repository repository = manager.get(namespaceAndName);
|
||||
//
|
||||
// if (repository == null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// importRepository(manager, repositoryName);
|
||||
// builder.addImportedDirectory(repositoryName);
|
||||
// }
|
||||
// catch (IOException ex)
|
||||
// {
|
||||
// builder.addFailedDirectory(repositoryName);
|
||||
// handleException(ex, throwExceptions);
|
||||
// }
|
||||
// catch (IllegalStateException ex)
|
||||
// {
|
||||
// builder.addFailedDirectory(repositoryName);
|
||||
// handleException(ex, throwExceptions);
|
||||
// }
|
||||
// catch (RepositoryException ex)
|
||||
// {
|
||||
// builder.addFailedDirectory(repositoryName);
|
||||
// handleException(ex, throwExceptions);
|
||||
// }
|
||||
// }
|
||||
// else if (logger.isDebugEnabled())
|
||||
// {
|
||||
// logger.debug("repository {} is already managed", repositoryName);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
@@ -24,13 +24,11 @@
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -54,91 +52,56 @@ import java.net.URL;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
*
|
||||
* @param <C>
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepositoryConfig>
|
||||
extends AbstractRepositoryHandler<C> implements RepositoryDirectoryHandler
|
||||
{
|
||||
extends AbstractRepositoryHandler<C> implements RepositoryDirectoryHandler {
|
||||
|
||||
/** Field description */
|
||||
public static final String DEFAULT_VERSION_INFORMATION = "unknown";
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_REPOSITORY = "repositories";
|
||||
|
||||
/** Field description */
|
||||
public static final String DOT = ".";
|
||||
|
||||
/** the logger for AbstractSimpleRepositoryHandler */
|
||||
/**
|
||||
* the logger for AbstractSimpleRepositoryHandler
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(AbstractSimpleRepositoryHandler.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
private FileSystem fileSystem;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param storeFactory
|
||||
* @param fileSystem
|
||||
*/
|
||||
public AbstractSimpleRepositoryHandler(ConfigurationStoreFactory storeFactory,
|
||||
FileSystem fileSystem)
|
||||
{
|
||||
FileSystem fileSystem) {
|
||||
super(storeFactory);
|
||||
this.fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public Repository create(Repository repository)
|
||||
throws RepositoryException
|
||||
{
|
||||
throws RepositoryException {
|
||||
File directory = getDirectory(repository);
|
||||
|
||||
if (directory.exists())
|
||||
{
|
||||
if (directory.exists()) {
|
||||
throw RepositoryAlreadyExistsException.create(repository);
|
||||
}
|
||||
|
||||
checkPath(directory);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
fileSystem.create(directory);
|
||||
create(repository, directory);
|
||||
postCreate(repository, directory);
|
||||
return repository;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (directory.exists())
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(
|
||||
"delete repository directory {}, because of failed repository creation",
|
||||
directory);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
if (directory.exists()) {
|
||||
logger.warn("delete repository directory {}, because of failed repository creation", directory);
|
||||
try {
|
||||
fileSystem.destroy(directory);
|
||||
} catch (IOException e) {
|
||||
logger.error("could not delete directory after failed repository creation: {}", directory, e);
|
||||
logger.error("Could not destroy directory", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,77 +111,48 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String createResourcePath(Repository repository)
|
||||
{
|
||||
public String createResourcePath(Repository repository) {
|
||||
StringBuilder path = new StringBuilder("/");
|
||||
|
||||
path.append(getType().getName()).append("/").append(repository.getName());
|
||||
path.append(getType().getName()).append("/").append(repository.getId());
|
||||
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void delete(Repository repository) throws RepositoryException
|
||||
{
|
||||
public void delete(Repository repository)
|
||||
throws RepositoryException {
|
||||
File directory = getDirectory(repository);
|
||||
|
||||
if (directory.exists())
|
||||
{
|
||||
if (directory.exists()) {
|
||||
try {
|
||||
fileSystem.destroy(directory);
|
||||
} catch (IOException e) {
|
||||
throw new RepositoryException("could not delete repository", e);
|
||||
}
|
||||
cleanupEmptyDirectories(config.getRepositoryDirectory(),
|
||||
directory.getParentFile());
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("repository {} not found", repository);
|
||||
directory.getParentFile());
|
||||
} else {
|
||||
logger.warn("repository {} not found", repository.getNamespaceAndName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void loadConfig()
|
||||
{
|
||||
public void loadConfig() {
|
||||
super.loadConfig();
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
if (config == null) {
|
||||
config = createInitialConfig();
|
||||
|
||||
if (config != null)
|
||||
{
|
||||
if (config != null) {
|
||||
File repositoryDirectory = config.getRepositoryDirectory();
|
||||
|
||||
if (repositoryDirectory == null)
|
||||
{
|
||||
if (repositoryDirectory == null) {
|
||||
repositoryDirectory = new File(
|
||||
baseDirectory,
|
||||
DIRECTORY_REPOSITORY.concat(File.separator).concat(
|
||||
getType().getName()));
|
||||
baseDirectory,
|
||||
DIRECTORY_REPOSITORY.concat(File.separator).concat(
|
||||
getType().getName()));
|
||||
config.setRepositoryDirectory(repositoryDirectory);
|
||||
}
|
||||
|
||||
@@ -228,107 +162,51 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void modify(Repository repository) throws RepositoryException
|
||||
{
|
||||
public void modify(Repository repository) {
|
||||
|
||||
// nothing todo
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public File getDirectory(Repository repository)
|
||||
{
|
||||
public File getDirectory(Repository repository) {
|
||||
File directory = null;
|
||||
|
||||
if (isConfigured())
|
||||
{
|
||||
if (isConfigured()) {
|
||||
File repositoryDirectory = config.getRepositoryDirectory();
|
||||
|
||||
directory = new File(repositoryDirectory, repository.getName());
|
||||
directory = new File(repositoryDirectory, repository.getId());
|
||||
|
||||
if (!IOUtil.isChild(repositoryDirectory, directory))
|
||||
{
|
||||
if (!IOUtil.isChild(repositoryDirectory, directory)) {
|
||||
StringBuilder msg = new StringBuilder(directory.getPath());
|
||||
|
||||
msg.append("is not a child of ").append(repositoryDirectory.getPath());
|
||||
|
||||
throw new ConfigurationException(msg.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new ConfigurationException("RepositoryHandler is not configured");
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getVersionInformation()
|
||||
{
|
||||
public String getVersionInformation() {
|
||||
return DEFAULT_VERSION_INFORMATION;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected ExtendedCommand buildCreateCommand(Repository repository,
|
||||
File directory)
|
||||
{
|
||||
File directory) {
|
||||
throw new UnsupportedOperationException("method is not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param directory
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected void create(Repository repository, File directory)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
throws RepositoryException, IOException {
|
||||
ExtendedCommand cmd = buildCreateCommand(repository, directory);
|
||||
CommandResult result = cmd.execute();
|
||||
|
||||
if (!result.isSuccessfull())
|
||||
{
|
||||
if (!result.isSuccessfull()) {
|
||||
StringBuilder msg = new StringBuilder("command exit with error ");
|
||||
|
||||
msg.append(result.getReturnCode()).append(" and message: '");
|
||||
@@ -338,56 +216,31 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected C createInitialConfig()
|
||||
{
|
||||
protected C createInitialConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param directory
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected void postCreate(Repository repository, File directory)
|
||||
throws IOException, RepositoryException {}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
throws IOException, RepositoryException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of a classpath resource or the given default content.
|
||||
*
|
||||
*
|
||||
* @param resource path of a classpath resource
|
||||
* @param resource path of a classpath resource
|
||||
* @param defaultContent default content to return
|
||||
*
|
||||
* @return content of a classpath resource or defaultContent
|
||||
*/
|
||||
protected String getStringFromResource(String resource, String defaultContent)
|
||||
{
|
||||
protected String getStringFromResource(String resource, String defaultContent) {
|
||||
String content = defaultContent;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
URL url = Resources.getResource(resource);
|
||||
|
||||
if (url != null)
|
||||
{
|
||||
if (url != null) {
|
||||
content = Resources.toString(url, Charsets.UTF_8);
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
logger.error("could not read resource", ex);
|
||||
}
|
||||
|
||||
@@ -397,45 +250,29 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
/**
|
||||
* Returns true if the directory is a repository.
|
||||
*
|
||||
*
|
||||
* @param directory directory to check
|
||||
*
|
||||
* @return true if the directory is a repository
|
||||
* @since 1.9
|
||||
*/
|
||||
protected boolean isRepository(File directory)
|
||||
{
|
||||
protected boolean isRepository(File directory) {
|
||||
return new File(directory, DOT.concat(getType().getName())).exists();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Check path for existing repositories
|
||||
*
|
||||
*
|
||||
* @param directory repository target directory
|
||||
*
|
||||
* @throws RepositoryAlreadyExistsException
|
||||
*/
|
||||
private void checkPath(File directory) throws RepositoryAlreadyExistsException
|
||||
{
|
||||
private void checkPath(File directory) throws RepositoryAlreadyExistsException {
|
||||
File repositoryDirectory = config.getRepositoryDirectory();
|
||||
File parent = directory.getParentFile();
|
||||
|
||||
while ((parent != null) &&!repositoryDirectory.equals(parent))
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("check {} for existing repository", parent);
|
||||
}
|
||||
while ((parent != null) && !repositoryDirectory.equals(parent)) {
|
||||
logger.trace("check {} for existing repository", parent);
|
||||
|
||||
if (isRepository(parent))
|
||||
{
|
||||
if (logger.isErrorEnabled())
|
||||
{
|
||||
logger.error("parent path {} is a repository", parent);
|
||||
}
|
||||
if (isRepository(parent)) {
|
||||
logger.error("parent path {} is a repository", parent);
|
||||
|
||||
StringBuilder buffer = new StringBuilder("repository with name ");
|
||||
buffer.append(directory.getName()).append(" already exists");
|
||||
@@ -446,49 +283,25 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param directory
|
||||
*/
|
||||
private void cleanupEmptyDirectories(File baseDirectory, File directory)
|
||||
{
|
||||
if (IOUtil.isChild(baseDirectory, directory))
|
||||
{
|
||||
if (IOUtil.isEmpty(directory))
|
||||
{
|
||||
private void cleanupEmptyDirectories(File baseDirectory, File directory) {
|
||||
if (IOUtil.isChild(baseDirectory, directory)) {
|
||||
if (IOUtil.isEmpty(directory)) {
|
||||
|
||||
// TODO use filesystem
|
||||
if (directory.delete())
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("successfully deleted directory {}", directory);
|
||||
}
|
||||
|
||||
if (directory.delete()) {
|
||||
logger.info("successfully deleted directory {}", directory);
|
||||
cleanupEmptyDirectories(baseDirectory, directory.getParentFile());
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
} else {
|
||||
logger.warn("could not delete directory {}", directory);
|
||||
}
|
||||
}
|
||||
else if (logger.isDebugEnabled())
|
||||
{
|
||||
|
||||
} else {
|
||||
logger.debug("could not remove non empty directory {}", directory);
|
||||
}
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("directory {} is not a child of {}", directory,
|
||||
baseDirectory);
|
||||
} else {
|
||||
logger.warn("directory {} is not a child of {}", directory, baseDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private FileSystem fileSystem;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package sonia.scm.repository;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class NamespaceAndName {
|
||||
|
||||
private final String namespace;
|
||||
private final String name;
|
||||
|
||||
public NamespaceAndName(String namespace, String name) {
|
||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(namespace), "a non empty namespace is required");
|
||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "a non empty name is required");
|
||||
this.namespace = namespace;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getNamespace() + "/" + getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
NamespaceAndName that = (NamespaceAndName) o;
|
||||
return Objects.equals(namespace, that.namespace) &&
|
||||
Objects.equals(name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(namespace, name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package sonia.scm.repository;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import java.util.Set;
|
||||
|
||||
public class NamespaceStrategyProvider implements Provider<NamespaceStrategy> {
|
||||
|
||||
private final Set<NamespaceStrategy> strategies;
|
||||
private final ScmConfiguration scmConfiguration;
|
||||
|
||||
@Inject
|
||||
public NamespaceStrategyProvider(Set<NamespaceStrategy> strategies, ScmConfiguration scmConfiguration) {
|
||||
this.strategies = strategies;
|
||||
this.scmConfiguration = scmConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceStrategy get() {
|
||||
String namespaceStrategy = scmConfiguration.getDefaultNamespaceStrategy();
|
||||
|
||||
for (NamespaceStrategy s : this.strategies) {
|
||||
if (s.getClass().getCanonicalName().equals(namespaceStrategy)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,6 +48,7 @@ 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 javax.xml.bind.annotation.XmlTransient;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -58,7 +59,7 @@ import java.util.List;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@StaticPermissions(
|
||||
value = "repository",
|
||||
value = "repository",
|
||||
permissions = {"read", "write", "modify", "delete", "healthCheck"}
|
||||
)
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@@ -99,9 +100,10 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
|
||||
* @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 namespace, String name) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.namespace = namespace;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -176,44 +178,28 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
|
||||
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;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
public String getNamespace() { return namespace; }
|
||||
|
||||
@XmlTransient
|
||||
public NamespaceAndName getNamespaceAndName() {
|
||||
return new NamespaceAndName(getNamespace(), getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the access permissions of the {@link Repository}.
|
||||
*
|
||||
* @return access permissions
|
||||
*/
|
||||
public List<Permission> getPermissions() {
|
||||
if (permissions == null) {
|
||||
permissions = Lists.newArrayList();
|
||||
@@ -370,9 +356,7 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
|
||||
* @since 1.17
|
||||
*/
|
||||
public String createUrl(String baseUrl) {
|
||||
String url = HttpUtil.append(baseUrl, type);
|
||||
|
||||
return HttpUtil.append(url, name);
|
||||
return HttpUtil.concatenate(baseUrl, type, namespace, name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,27 +49,22 @@ public interface RepositoryDAO extends GenericDAO<Repository>
|
||||
|
||||
/**
|
||||
* Returns true if a repository with specified
|
||||
* type and name exists in the backend.
|
||||
* namespace and name exists in the backend.
|
||||
*
|
||||
*
|
||||
* @param type type of the repository
|
||||
* @param name name of the repository
|
||||
* @param namespaceAndName namespace and name of the repository
|
||||
*
|
||||
* @return true if the repository exists
|
||||
*/
|
||||
public boolean contains(String type, String name);
|
||||
boolean contains(NamespaceAndName namespaceAndName);
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the repository with the specified type and name or null
|
||||
* Returns the repository with the specified namespace and name or null
|
||||
* if no such repository exists in the backend.
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
*
|
||||
* @return repository with the specified type and name or null
|
||||
* @return repository with the specified namespace and name or null
|
||||
*/
|
||||
public Repository get(String type, String name);
|
||||
Repository get(NamespaceAndName namespaceAndName);
|
||||
}
|
||||
|
||||
@@ -43,13 +43,5 @@ import java.io.File;
|
||||
public interface RepositoryDirectoryHandler extends RepositoryHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getDirectory(Repository repository);
|
||||
}
|
||||
|
||||
@@ -82,18 +82,17 @@ public interface RepositoryManager
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a {@link Repository} by its type and name or
|
||||
* Returns a {@link Repository} by its namespace and name or
|
||||
* null if the {@link Repository} could not be found.
|
||||
*
|
||||
*
|
||||
* @param type type of the {@link Repository}
|
||||
* @param name name of the {@link Repository}
|
||||
* @param namespaceAndName namespace and name of the {@link Repository}
|
||||
*
|
||||
*
|
||||
* @return {@link Repository} by its type and name or null
|
||||
* @return {@link Repository} by its namespace and name or null
|
||||
* if the {@link Repository} could not be found
|
||||
*/
|
||||
public Repository get(String type, String name);
|
||||
public Repository get(NamespaceAndName namespaceAndName);
|
||||
|
||||
/**
|
||||
* Returns all configured repository types.
|
||||
@@ -114,18 +113,6 @@ public interface RepositoryManager
|
||||
*/
|
||||
public Repository getFromRequest(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} associated to the given type and path.
|
||||
*
|
||||
*
|
||||
* @param type type of the repository (hg, git ...)
|
||||
* @param uri
|
||||
*
|
||||
* @return the {@link Repository} associated to the given type and path
|
||||
* @since 1.9
|
||||
*/
|
||||
public Repository getFromTypeAndUri(String type, String uri);
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} associated to the request uri.
|
||||
*
|
||||
|
||||
@@ -91,9 +91,9 @@ public class RepositoryManagerDecorator
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Repository get(String namespace, String name)
|
||||
public Repository get(NamespaceAndName namespaceAndName)
|
||||
{
|
||||
return decorated.get(namespace, name);
|
||||
return decorated.get(namespaceAndName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,21 +135,6 @@ public class RepositoryManagerDecorator
|
||||
return decorated.getFromRequest(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param uri
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Repository getFromTypeAndUri(String type, String uri)
|
||||
{
|
||||
return decorated.getFromTypeAndUri(type, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
||||
@@ -35,278 +35,86 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import sonia.scm.io.DirectoryFileFilter;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.11
|
||||
*/
|
||||
public final class RepositoryUtil
|
||||
{
|
||||
public final class RepositoryUtil {
|
||||
|
||||
/** the logger for RepositoryUtil */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(RepositoryUtil.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
private RepositoryUtil() {}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
* @param names
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<File> searchRepositoryDirectories(File directory,
|
||||
String... names)
|
||||
{
|
||||
List<File> repositories = new ArrayList<File>();
|
||||
public static List<File> searchRepositoryDirectories(File directory, String... names) {
|
||||
List<File> repositories = new ArrayList<>();
|
||||
|
||||
searchRepositoryDirectories(repositories, directory, Arrays.asList(names));
|
||||
|
||||
return repositories;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param directoryPath
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String getRepositoryName(AbstractRepositoryHandler handler,
|
||||
String directoryPath)
|
||||
throws IOException
|
||||
{
|
||||
return getRepositoryName(handler.getConfig().getRepositoryDirectory(),
|
||||
new File(directoryPath));
|
||||
@SuppressWarnings("squid:S2083") // ignore, because the path is validated at {@link #getRepositoryId(File, File)}
|
||||
public static String getRepositoryId(AbstractRepositoryHandler handler, String directoryPath) throws IOException {
|
||||
return getRepositoryId(handler.getConfig().getRepositoryDirectory(), new File(directoryPath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param config
|
||||
* @param directoryPath
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String getRepositoryName(SimpleRepositoryConfig config,
|
||||
String directoryPath)
|
||||
throws IOException
|
||||
{
|
||||
return getRepositoryName(config.getRepositoryDirectory(),
|
||||
new File(directoryPath));
|
||||
public static String getRepositoryId(AbstractRepositoryHandler handler, File directory) throws IOException {
|
||||
return getRepositoryId(handler.getConfig(), directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param directory
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String getRepositoryName(AbstractRepositoryHandler handler,
|
||||
File directory)
|
||||
throws IOException
|
||||
{
|
||||
return getRepositoryName(handler.getConfig().getRepositoryDirectory(),
|
||||
directory);
|
||||
public static String getRepositoryId(SimpleRepositoryConfig config, File directory) throws IOException {
|
||||
return getRepositoryId(config.getRepositoryDirectory(), directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param config
|
||||
* @param directory
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String getRepositoryName(SimpleRepositoryConfig config,
|
||||
File directory)
|
||||
throws IOException
|
||||
{
|
||||
return getRepositoryName(config.getRepositoryDirectory(), directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param directory
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String getRepositoryName(File baseDirectory, File directory)
|
||||
throws IOException
|
||||
{
|
||||
String name = null;
|
||||
public static String getRepositoryId(File baseDirectory, File directory) throws IOException {
|
||||
String path = directory.getCanonicalPath();
|
||||
int directoryLength = baseDirectory.getCanonicalPath().length();
|
||||
String basePath = baseDirectory.getCanonicalPath();
|
||||
|
||||
if (directoryLength < path.length())
|
||||
{
|
||||
name = IOUtil.trimSeperatorChars(path.substring(directoryLength));
|
||||
Preconditions.checkArgument(
|
||||
path.startsWith(basePath),
|
||||
"repository path %s is not in the main repository path %s", path, basePath
|
||||
);
|
||||
|
||||
// replace windows path seperator
|
||||
name = name.replaceAll("\\\\", "/");
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("path is shorter as the main repository path");
|
||||
}
|
||||
String id = IOUtil.trimSeperatorChars(path.substring(basePath.length()));
|
||||
|
||||
return name;
|
||||
Preconditions.checkArgument(
|
||||
!id.contains("\\") && !id.contains("/"),
|
||||
"got illegal repository directory with separators in id: %s", path
|
||||
);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param directoryNames
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<String> getRepositoryNames(
|
||||
AbstractRepositoryHandler handler, String... directoryNames)
|
||||
throws IOException
|
||||
{
|
||||
return getRepositoryNames(handler.getConfig(), directoryNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param config
|
||||
* @param directoryNames
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<String> getRepositoryNames(SimpleRepositoryConfig config,
|
||||
String... directoryNames)
|
||||
throws IOException
|
||||
{
|
||||
return getRepositoryNames(config.getRepositoryDirectory(), directoryNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param directoryNames
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<String> getRepositoryNames(File baseDirectory,
|
||||
String... directoryNames)
|
||||
throws IOException
|
||||
{
|
||||
List<String> repositories = new ArrayList<String>();
|
||||
List<File> repositoryFiles = searchRepositoryDirectories(baseDirectory,
|
||||
directoryNames);
|
||||
|
||||
for (File file : repositoryFiles)
|
||||
{
|
||||
String name = getRepositoryName(baseDirectory, file);
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
repositories.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
return repositories;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositories
|
||||
* @param directory
|
||||
* @param names
|
||||
*/
|
||||
private static void searchRepositoryDirectories(List<File> repositories,
|
||||
File directory, List<String> names)
|
||||
{
|
||||
private static void searchRepositoryDirectories(List<File> repositories, File directory, List<String> names) {
|
||||
boolean found = false;
|
||||
|
||||
for (String name : names)
|
||||
{
|
||||
if (new File(directory, name).exists())
|
||||
{
|
||||
for (String name : names) {
|
||||
if (new File(directory, name).exists()) {
|
||||
found = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
if (found) {
|
||||
repositories.add(directory);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
File[] directories = directory.listFiles(DirectoryFileFilter.instance);
|
||||
|
||||
if (directories != null)
|
||||
{
|
||||
for (File d : directories)
|
||||
{
|
||||
if (directories != null) {
|
||||
for (File d : directories) {
|
||||
searchRepositoryDirectories(repositories, d, names);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.ClearRepositoryCacheEvent;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.PostReceiveRepositoryHookEvent;
|
||||
import sonia.scm.repository.PreProcessorUtil;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -186,8 +187,7 @@ public final class RepositoryServiceFactory
|
||||
* Creates a new RepositoryService for the given repository.
|
||||
*
|
||||
*
|
||||
* @param type type of the repository
|
||||
* @param name name of the repository
|
||||
* @param namespaceAndName namespace and name of the repository
|
||||
*
|
||||
* @return a implementation of RepositoryService
|
||||
* for the given type of repository
|
||||
@@ -200,24 +200,19 @@ public final class RepositoryServiceFactory
|
||||
* @throws ScmSecurityException if current user has not read permissions
|
||||
* for that repository
|
||||
*/
|
||||
public RepositoryService create(String type, String name)
|
||||
public RepositoryService create(NamespaceAndName namespaceAndName)
|
||||
throws RepositoryNotFoundException
|
||||
{
|
||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(type),
|
||||
"a non empty type is required");
|
||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(name),
|
||||
"a non empty name is required");
|
||||
Preconditions.checkArgument(namespaceAndName != null,
|
||||
"a non empty namespace and name is required");
|
||||
|
||||
Repository repository = repositoryManager.get(type, name);
|
||||
Repository repository = repositoryManager.get(namespaceAndName);
|
||||
|
||||
if (repository == null)
|
||||
{
|
||||
StringBuilder msg =
|
||||
new StringBuilder("could not find a repository with type ");
|
||||
String msg = "could not find a repository with namespace/name " + namespaceAndName;
|
||||
|
||||
msg.append(type).append(" and name ").append(name);
|
||||
|
||||
throw new RepositoryNotFoundException(msg.toString());
|
||||
throw new RepositoryNotFoundException(msg);
|
||||
}
|
||||
|
||||
return create(repository);
|
||||
|
||||
@@ -35,7 +35,7 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RepositoryHookEvent;
|
||||
@@ -72,50 +72,15 @@ public final class HookEventFacade
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public HookEventHandler handle(String id) throws RepositoryException
|
||||
{
|
||||
public HookEventHandler handle(String id) throws RepositoryException {
|
||||
return handle(repositoryManagerProvider.get().get(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param repositoryName
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public HookEventHandler handle(String type, String repositoryName)
|
||||
throws RepositoryException
|
||||
{
|
||||
return handle(repositoryManagerProvider.get().get(type, repositoryName));
|
||||
public HookEventHandler handle(NamespaceAndName namespaceAndName) throws RepositoryException {
|
||||
return handle(repositoryManagerProvider.get().get(namespaceAndName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public HookEventHandler handle(Repository repository)
|
||||
throws RepositoryException
|
||||
public HookEventHandler handle(Repository repository) throws RepositoryException
|
||||
{
|
||||
if (repository == null)
|
||||
{
|
||||
|
||||
@@ -39,27 +39,23 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Util method for the http protocol.
|
||||
@@ -86,9 +82,9 @@ public final class HttpUtil
|
||||
|
||||
/**
|
||||
* Name of bearer authentication cookie.
|
||||
*
|
||||
*
|
||||
* TODO find a better place
|
||||
*
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public static final String COOKIE_BEARER_AUTHENTICATION = "X-Bearer-Token";
|
||||
@@ -101,7 +97,7 @@ public final class HttpUtil
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public static final String HEADER_AUTHORIZATION = "Authorization";
|
||||
|
||||
|
||||
/**
|
||||
* content-length header
|
||||
* @since 1.46
|
||||
@@ -252,13 +248,23 @@ public final class HttpUtil
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Joins all path elements together separated by {@code {@link #SEPARATOR_PATH}}.
|
||||
*
|
||||
* @param pathElements path elements
|
||||
*
|
||||
* @return concatenated path
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public static String concatenate(String... pathElements) {
|
||||
return Arrays.stream(pathElements).reduce(HttpUtil::append).orElse("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the suffix to given uri.
|
||||
*
|
||||
*
|
||||
* @param uri uri
|
||||
* @param uri uri
|
||||
* @param suffix suffix
|
||||
*
|
||||
* @return
|
||||
* @since 1.9
|
||||
*/
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web.filter;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class RegexPermissionFilter extends PermissionFilter
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final Pattern PATTERN_REPOSITORYNAME =
|
||||
Pattern.compile("/[^/]+/([^/]+)(?:/.*)?");
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
* @param repositoryManager
|
||||
*/
|
||||
public RegexPermissionFilter(ScmConfiguration configuration,
|
||||
RepositoryManager repositoryManager)
|
||||
{
|
||||
super(configuration);
|
||||
this.repositoryManager = repositoryManager;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getType();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Repository getRepository(HttpServletRequest request)
|
||||
{
|
||||
Repository repository = null;
|
||||
String uri = request.getRequestURI();
|
||||
|
||||
uri = uri.substring(request.getContextPath().length());
|
||||
|
||||
Matcher m = PATTERN_REPOSITORYNAME.matcher(uri);
|
||||
|
||||
if (m.matches())
|
||||
{
|
||||
String repositoryname = m.group(1);
|
||||
|
||||
repository = getRepository(repositoryname);
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected Repository getRepository(String name)
|
||||
{
|
||||
return repositoryManager.get(getType(), name);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private RepositoryManager repositoryManager;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ package sonia.scm.repository;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -50,7 +50,7 @@ public class RepositoryTest
|
||||
@Test
|
||||
public void testCreateUrl()
|
||||
{
|
||||
Repository repository = new Repository("123", "hg", "test/repo");
|
||||
Repository repository = new Repository("123", "hg", "test", "repo");
|
||||
|
||||
assertEquals("http://localhost:8080/scm/hg/test/repo",
|
||||
repository.createUrl("http://localhost:8080/scm"));
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package sonia.scm.repository;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RepositoryUtilTest {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Mock
|
||||
private AbstractRepositoryHandler<SimpleRepositoryConfig> repositoryHandler;
|
||||
|
||||
private SimpleRepositoryConfig repositoryConfig = new SimpleRepositoryConfig();
|
||||
|
||||
@Before
|
||||
public void setUpMocks() {
|
||||
when(repositoryHandler.getConfig()).thenReturn(repositoryConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRepositoryId() throws IOException {
|
||||
File repositoryTypeRoot = temporaryFolder.newFolder();
|
||||
repositoryConfig.setRepositoryDirectory(repositoryTypeRoot);
|
||||
|
||||
File repository = new File(repositoryTypeRoot, "abc");
|
||||
String id = RepositoryUtil.getRepositoryId(repositoryHandler, repository.getPath());
|
||||
assertEquals("abc", id);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetRepositoryIdWithInvalidPath() throws IOException {
|
||||
File repositoryTypeRoot = temporaryFolder.newFolder();
|
||||
repositoryConfig.setRepositoryDirectory(repositoryTypeRoot);
|
||||
|
||||
File repository = new File("/etc/abc");
|
||||
String id = RepositoryUtil.getRepositoryId(repositoryHandler, repository.getPath());
|
||||
assertEquals("abc", id);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetRepositoryIdWithInvalidPathButSameLength() throws IOException {
|
||||
File repositoryTypeRoot = temporaryFolder.newFolder();
|
||||
repositoryConfig.setRepositoryDirectory(repositoryTypeRoot);
|
||||
|
||||
File repository = new File(temporaryFolder.newFolder(), "abc");
|
||||
|
||||
String id = RepositoryUtil.getRepositoryId(repositoryHandler, repository.getPath());
|
||||
assertEquals("abc", id);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetRepositoryIdWithInvalidId() throws IOException {
|
||||
File repositoryTypeRoot = temporaryFolder.newFolder();
|
||||
repositoryConfig.setRepositoryDirectory(repositoryTypeRoot);
|
||||
|
||||
File repository = new File(repositoryTypeRoot, "abc/123");
|
||||
RepositoryUtil.getRepositoryId(repositoryHandler, repository.getPath());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,6 +54,18 @@ import javax.servlet.http.HttpServletRequest;
|
||||
public class HttpUtilTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void concatenateTest() {
|
||||
assertEquals(
|
||||
"/scm/git/hitchhiker/tricia",
|
||||
HttpUtil.concatenate("/scm", "git", "hitchhiker", "tricia")
|
||||
);
|
||||
assertEquals(
|
||||
"scm/git/hitchhiker/tricia",
|
||||
HttpUtil.concatenate("scm", "git", "hitchhiker", "tricia")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -63,19 +75,19 @@ public class HttpUtilTest
|
||||
{
|
||||
//J-
|
||||
assertEquals(
|
||||
"http://www.scm-manager/scm/test",
|
||||
"http://www.scm-manager/scm/test",
|
||||
HttpUtil.append("http://www.scm-manager/scm/", "test")
|
||||
);
|
||||
assertEquals(
|
||||
"http://www.scm-manager/scm/test",
|
||||
"http://www.scm-manager/scm/test",
|
||||
HttpUtil.append("http://www.scm-manager/scm", "test")
|
||||
);
|
||||
assertEquals(
|
||||
"http://www.scm-manager/scm/test",
|
||||
"http://www.scm-manager/scm/test",
|
||||
HttpUtil.append("http://www.scm-manager/scm", "/test")
|
||||
);
|
||||
assertEquals(
|
||||
"http://www.scm-manager/scm/test",
|
||||
"http://www.scm-manager/scm/test",
|
||||
HttpUtil.append("http://www.scm-manager/scm/", "/test")
|
||||
);
|
||||
//J+
|
||||
|
||||
Reference in New Issue
Block a user