Merged 2.0.0-m3 into feature/global_config_v2_endpoint

This commit is contained in:
Johannes Schnatterer
2018-08-01 10:30:38 +02:00
358 changed files with 24149 additions and 21316 deletions

View File

@@ -0,0 +1,28 @@
package sonia.scm.config;
import com.github.sdorra.ssp.PermissionObject;
import com.github.sdorra.ssp.StaticPermissions;
/**
* Base for all kinds of configurations.
*
* Allows for permission like
*
* <ul>
* <li>"configuration:read:global",</li>
* <li>"configuration:write:svn",</li>
* <li>"configuration:*:git",</li>
* <li>"configuration:*"</li>
* </ul>
*
* <br/>
*
* And for permission checks like {@code ConfigurationPermissions.read(configurationObject).check();}
*/
@StaticPermissions(
value = "configuration",
permissions = {"read", "write"},
globalPermissions = {}
)
public interface Configuration extends PermissionObject {
}

View File

@@ -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,33 @@
* 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.XmlTransient;
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.
@@ -64,41 +58,141 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
*
* @author Sebastian Sdorra
*/
@Singleton
@XmlRootElement(name = "scm-config")
@XmlAccessorType(XmlAccessType.FIELD)
public class ScmConfiguration
{
public class ScmConfiguration implements Configuration {
/** 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 +203,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 +226,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 +241,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 +252,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 +268,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 +286,7 @@ public class ScmConfiguration
*
* @return the complete plugin url.
*/
public String getPluginUrl()
{
public String getPluginUrl() {
return pluginUrl;
}
@@ -231,289 +294,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 +437,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 +451,64 @@ 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 ---------------------------------------------------------------
public void setDefaultNamespaceStrategy(String defaultNamespaceStrategy) {
this.defaultNamespaceStrategy = defaultNamespaceStrategy;
}
/** 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;
@Override
// Only for permission checks, don't serialize to XML
@XmlTransient
public String getId() {
// Don't change this without migrating SCM permission configuration!
return "global";
}
}

View File

@@ -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);
// }
}
/**

View File

@@ -56,7 +56,7 @@ import sonia.scm.store.ConfigurationStoreFactory;
*
* @param <C>
*/
public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig>
public abstract class AbstractRepositoryHandler<C extends RepositoryConfig>
implements RepositoryHandler
{

View File

@@ -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
{
public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig>
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;
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
/**

View File

@@ -33,15 +33,12 @@
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Validateable;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import sonia.scm.config.Configuration;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.io.File;
/**
* Basic {@link Repository} configuration class.
@@ -49,7 +46,7 @@ import javax.xml.bind.annotation.XmlRootElement;
* @author Sebastian Sdorra
*/
@XmlRootElement
public class SimpleRepositoryConfig implements Validateable
public abstract class RepositoryConfig implements Validateable, Configuration
{
/**
@@ -119,4 +116,19 @@ public class SimpleRepositoryConfig implements Validateable
/** directory for repositories */
private File repositoryDirectory;
/**
* Specifies the identifier of the concrete {@link RepositoryConfig} when checking permissions of an object.
* The permission Strings will have the following format: "configuration:*:ID", where the ID part is defined by this
* method.
*
* For example: "configuration:read:git".
*
* No need to serialize this.
*
* @return identifier of this RepositoryConfig in permission strings
*/
@Override
@XmlTransient // Only for permission checks, don't serialize to XML
public abstract String getId();
}

View File

@@ -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);
}

View File

@@ -43,13 +43,5 @@ import java.io.File;
public interface RepositoryDirectoryHandler extends RepositoryHandler
{
/**
* Method description
*
*
* @param repository
*
* @return
*/
public File getDirectory(Repository repository);
}

View File

@@ -37,7 +37,7 @@ import sonia.scm.event.Event;
* @since 2.0.0
*/
@Event
public class RepositoryHandlerConfigChangedEvent<C extends SimpleRepositoryConfig>
public class RepositoryHandlerConfigChangedEvent<C extends RepositoryConfig>
{
private final C configuration;

View File

@@ -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.
*

View File

@@ -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}
*

View File

@@ -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(RepositoryConfig 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);
}
}

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -1,58 +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.url;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public interface ModelUrlProvider
{
/**
* Method description
*
*
* @param name
*
* @return
*/
public String getDetailUrl(String name);
/**
* Method description
*
*
* @return
*/
public String getAllUrl();
}

View File

@@ -1,153 +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.url;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public interface RepositoryUrlProvider extends ModelUrlProvider
{
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
public String getBlameUrl(String repositoryId, String path, String revision);
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
public String getBrowseUrl(String repositoryId, String path, String revision);
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
* @param start
* @param limit
*
* @return
*/
public String getChangesetUrl(String repositoryId, String path,
String revision, int start, int limit);
/**
* Method description
*
*
* @param repositoryId
* @param revision
*
* @return
*
* @since 1.12
*/
public String getChangesetUrl(String repositoryId, String revision);
/**
* Method description
*
*
* @param repositoryId
* @param start
* @param limit
*
* @return
*/
public String getChangesetUrl(String repositoryId, int start, int limit);
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
public String getContentUrl(String repositoryId, String path,
String revision);
/**
* Method description
*
*
* @param type
* @param name
*
* @return
* @since 1.11
*/
public String getDetailUrl(String type, String name);
/**
* Method description
*
*
* @param repositoryId
* @param revision
*
* @return
*/
public String getDiffUrl(String repositoryId, String revision);
/**
* Method description
*
*
* @param repositoryId
*
* @return
* @since 1.18
*/
public String getTagsUrl(String repositoryId);
}

View File

@@ -1,97 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public class RestModelUrlProvider implements ModelUrlProvider
{
/**
* Constructs ...
*
*
* @param baseUrl
* @param modelSuffix
* @param extension
*/
public RestModelUrlProvider(String baseUrl, String modelSuffix,
String extension)
{
this.base = HttpUtil.append(baseUrl, modelSuffix);
this.extension = extension;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getAllUrl()
{
return base.concat(extension);
}
/**
* Method description
*
*
* @param name
*
* @return
*/
@Override
public String getDetailUrl(String name)
{
return HttpUtil.append(base, name).concat(extension);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected String base;
/** Field description */
protected String extension;
}

View File

@@ -1,278 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.UrlBuilder;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public class RestRepositoryUrlProvider extends RestModelUrlProvider
implements RepositoryUrlProvider
{
/** Field description */
public static final String PARAMETER_LIMIT = "limit";
/** Field description */
public static final String PARAMETER_PATH = "path";
/** Field description */
public static final String PARAMETER_REVISION = "revision";
/** Field description */
public static final String PARAMETER_START = "start";
/** Field description */
public static final String PART_BLAME = "blame";
/** Field description */
public static final String PART_BROWSE = "browse";
/**
* @since 1.12
*/
public static final String PART_CHANGESET = "changeset";
/** Field description */
public static final String PART_CHANGESETS = "changesets";
/** Field description */
public static final String PART_CONTENT = "content";
/** Field description */
public static final String PART_DIFF = "diff";
/** Field description */
public static final String PART_TAGS = "tags";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param baseUrl
* @param modelSuffix
* @param extension
*/
public RestRepositoryUrlProvider(String baseUrl, String modelSuffix,
String extension)
{
super(baseUrl, modelSuffix, extension);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
public String getBlameUrl(String repositoryId, String path, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
PART_BLAME).append(extension).appendParameter(
PARAMETER_PATH, path).appendParameter(
PARAMETER_REVISION, revision).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
public String getBrowseUrl(String repositoryId, String path, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
PART_BROWSE).append(extension).appendParameter(
PARAMETER_PATH, path).appendParameter(
PARAMETER_REVISION, revision).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
* @param start
* @param limit
*
* @return
*/
@Override
public String getChangesetUrl(String repositoryId, String path,
String revision, int start, int limit)
{
revision = UrlUtil.fixRevision(revision);
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
PART_CHANGESETS).append(extension).appendParameter(
PARAMETER_PATH, path).appendParameter(
PARAMETER_REVISION, revision).appendParameter(
PARAMETER_START, start).appendParameter(
PARAMETER_LIMIT, limit).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param start
* @param limit
*
* @return
*/
@Override
public String getChangesetUrl(String repositoryId, int start, int limit)
{
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
PART_CHANGESETS).append(extension).appendParameter(
PARAMETER_START, start).appendParameter(
PARAMETER_LIMIT, limit).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param revision
*
* @return
*
* @since 1.12
*/
@Override
public String getChangesetUrl(String repositoryId, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
PART_CHANGESET).appendUrlPart(revision).append(extension).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
public String getContentUrl(String repositoryId, String path, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
PART_CONTENT).appendParameter(PARAMETER_PATH, path).appendParameter(
PARAMETER_REVISION, revision).toString();
}
/**
* Method description
*
*
* @param type
* @param name
*
* @return
* @since 1.11
*/
@Override
public String getDetailUrl(String type, String name)
{
return new UrlBuilder(base).appendUrlPart(type).appendUrlPart(name).append(
extension).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param revision
*
* @return
*/
@Override
public String getDiffUrl(String repositoryId, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
PART_DIFF).appendParameter(PARAMETER_REVISION, revision).toString();
}
/**
* Method description
*
*
* @param repositoryId
*
* @return
* @since 1.18
*/
@Override
public String getTagsUrl(String repositoryId)
{
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
PART_TAGS).append(extension).toString();
}
}

View File

@@ -1,95 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
*
* @author Sebastian Sdorra
* @since 1.41
*/
public class RestSecurityUrlProvider implements SecurityUrlProvider
{
/** Field description */
private static final String PATH_ENCRYPT = "security/cipher/encrypt";
/** Field description */
private static final String PATH_KEY = "security/key";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param baseUrl
*/
public RestSecurityUrlProvider(String baseUrl)
{
this.baseUrl = baseUrl;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getEncryptUrl()
{
return HttpUtil.append(baseUrl, PATH_ENCRYPT);
}
/**
* Method description
*
*
* @return
*/
@Override
public String getGenerateKeyUrl()
{
return HttpUtil.append(baseUrl, PATH_KEY);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private final String baseUrl;
}

View File

@@ -1,190 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public class RestUrlProvider implements UrlProvider
{
/** Field description */
public static final String PART_API = "api/rest/";
/** Field description */
public static final String PART_AUTHENTICATION = "auth/access_token";
/** Field description */
public static final String PART_CONFIG = "config";
/** Field description */
public static final String PART_GROUP = "groups";
/** Field description */
public static final String PART_REPOSITORIES = "repositories";
/** Field description */
public static final String PART_STATE = "auth";
/** Field description */
public static final String PART_USER = "users";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param baseUrl
* @param extension
*/
public RestUrlProvider(String baseUrl, String extension)
{
this.baseUrl = HttpUtil.append(baseUrl, PART_API);
this.extension = extension;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getAuthenticationUrl()
{
return HttpUtil.append(baseUrl, PART_AUTHENTICATION).concat(extension);
}
/**
* Method description
*
*
* @return
*
* @since 1.43
*/
@Override
public String getBaseUrl()
{
return baseUrl;
}
/**
* Method description
*
*
* @return
*/
@Override
public String getConfigUrl()
{
return HttpUtil.append(baseUrl, PART_CONFIG).concat(extension);
}
/**
* Method description
*
*
* @return
*/
@Override
public ModelUrlProvider getGroupUrlProvider()
{
return new RestModelUrlProvider(baseUrl, PART_GROUP, extension);
}
/**
* Method description
*
*
* @return
*/
@Override
public RepositoryUrlProvider getRepositoryUrlProvider()
{
return new RestRepositoryUrlProvider(baseUrl, PART_REPOSITORIES, extension);
}
/**
* Method description
*
*
* @return
*/
@Override
public SecurityUrlProvider getSecurityUrlProvider()
{
return new RestSecurityUrlProvider(baseUrl);
}
/**
* Method description
*
*
* @return
*/
@Override
public String getStateUrl()
{
return HttpUtil.append(baseUrl, PART_STATE).concat(extension);
}
/**
* Method description
*
*
* @return
*/
@Override
public ModelUrlProvider getUserUrlProvider()
{
return new RestModelUrlProvider(baseUrl, PART_USER, extension);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected String baseUrl;
/** Field description */
protected String extension;
}

View File

@@ -1,59 +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.url;
/**
*
* @author Sebastian Sdorra
* @since 1.41
*/
public interface SecurityUrlProvider
{
/**
* Method description
*
*
* @return
*/
public String getGenerateKeyUrl();
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getEncryptUrl();
}

View File

@@ -1,110 +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.url;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public interface UrlProvider
{
/**
* Method description
*
*
* @return
*/
public String getAuthenticationUrl();
/**
* Method description
*
*
* @return
*
* @since 1.43
*/
public String getBaseUrl();
/**
* Method description
*
*
* @return
*/
public String getConfigUrl();
/**
* Method description
*
*
* @return
*/
public ModelUrlProvider getGroupUrlProvider();
/**
* Method description
*
*
* @return
*/
public RepositoryUrlProvider getRepositoryUrlProvider();
/**
* Method description
*
*
* @return
*
* @since 1.41
*/
public SecurityUrlProvider getSecurityUrlProvider();
/**
* Method description
*
*
* @return
*/
public String getStateUrl();
/**
* Method description
*
*
* @return
*/
public ModelUrlProvider getUserUrlProvider();
}

View File

@@ -1,97 +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.url;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public final class UrlProviderFactory
{
/** Field description */
public static final String TYPE_RESTAPI_JSON = "json-rest-api";
/** Field description */
public static final String TYPE_RESTAPI_XML = "xml-rest-api";
/** Field description */
public static final String TYPE_WUI = "wui";
/** Field description */
private static final String EXTENSION_JSON = ".json";
/** Field description */
private static final String EXTENSION_XML = ".xml";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private UrlProviderFactory() {}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
*
* @param baseUrl
* @param type
*
* @return
*/
public static UrlProvider createUrlProvider(String baseUrl, String type)
{
UrlProvider provider = null;
if (TYPE_RESTAPI_JSON.equals(type))
{
provider = new RestUrlProvider(baseUrl, EXTENSION_JSON);
}
else if (TYPE_RESTAPI_XML.equals(type))
{
provider = new RestUrlProvider(baseUrl, EXTENSION_XML);
}
else if (TYPE_WUI.equals(type))
{
provider = new WUIUrlProvider(baseUrl);
}
return provider;
}
}

View File

@@ -1,80 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.Util;
/**
*
* @author Sebastian Sdorra
* @since 1.11
*/
public final class UrlUtil
{
/**
* Constructs ...
*
*/
private UrlUtil() {}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param revision
*
* @return
*/
public static String fixRevision(String revision)
{
String fixedRevision = revision;
if (Util.isNotEmpty(revision))
{
int index = revision.indexOf(':');
if (index > 0)
{
fixedRevision = revision.substring(index + 1);
}
}
return fixedRevision;
}
}

View File

@@ -1,91 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public class WUIModelUrlProvider implements ModelUrlProvider
{
/**
* Constructs ...
*
*
* @param baseUrl
* @param component
*/
public WUIModelUrlProvider(String baseUrl, String component)
{
this.url = HttpUtil.appendHash(baseUrl, component);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getAllUrl()
{
return url;
}
/**
* Method description
*
*
* @param name
*
* @return
*/
@Override
public String getDetailUrl(String name)
{
return url.concat(WUIUrlBuilder.SEPARATOR).concat(name);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String url;
}

View File

@@ -1,274 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
*
* @author Sebastian Sdorra
*/
public class WUIRepositoryUrlProvider extends WUIModelUrlProvider
implements RepositoryUrlProvider
{
/** Field description */
public static final String COMPONENT_BROWSER = "repositoryBrowser";
/**
* @since 1.15
*/
public static final String COMPONENT_CHANGESET = "changesetPanel";
/** Field description */
public static final String COMPONENT_CHANGESETS =
"repositoryChangesetViewerPanel";
/** Field description */
public static final String COMPONENT_CONTENT = "contentPanel";
/** Field description */
public static final String COMPONENT_DETAIL = "repositoryPanel";
/** Field description */
public static final String COMPONENT_DIFF = "diffPanel";
/** Field description */
public static final String VIEW_BLAME = "blame";
/**
* @since 1.12
*/
public static final String VIEW_CHANGESET = "changeset";
/** Field description */
public static final String VIEW_CONTENT = "content";
/** Field description */
public static final String VIEW_HISTORY = "history";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param baseUrl
* @param component
*/
public WUIRepositoryUrlProvider(String baseUrl, String component)
{
super(baseUrl, component);
this.baseUrl = baseUrl;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
public String getBlameUrl(String repositoryId, String path, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new WUIUrlBuilder(baseUrl, COMPONENT_CONTENT).append(
repositoryId).append(revision).append(path).append(VIEW_BLAME).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
public String getBrowseUrl(String repositoryId, String path, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new WUIUrlBuilder(baseUrl, COMPONENT_BROWSER).append(
repositoryId).append(revision).append(path).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
* @param start
* @param limit
*
* @return
*/
@Override
public String getChangesetUrl(String repositoryId, String path,
String revision, int start, int limit)
{
revision = UrlUtil.fixRevision(revision);
// TODO handle start and limit
return new WUIUrlBuilder(baseUrl, COMPONENT_CONTENT).append(
repositoryId).append(revision).append(path).append(
VIEW_HISTORY).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param start
* @param limit
*
* @return
*/
@Override
public String getChangesetUrl(String repositoryId, int start, int limit)
{
return new WUIUrlBuilder(baseUrl, COMPONENT_CHANGESETS).append(
repositoryId).append(start).append(limit).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param revision
*
* @return
*
* @since 1.12
*/
@Override
public String getChangesetUrl(String repositoryId, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new WUIUrlBuilder(baseUrl,
COMPONENT_CHANGESET).append(repositoryId).append(revision).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
public String getContentUrl(String repositoryId, String path, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new WUIUrlBuilder(baseUrl, COMPONENT_CONTENT).append(
repositoryId).append(revision).append(path).append(
VIEW_HISTORY).toString();
}
/**
* Method description
*
*
* @param type
* @param name
*
* @return
* @since 1.11
*/
@Override
public String getDetailUrl(String type, String name)
{
name = type.concat(HttpUtil.SEPARATOR_PATH).concat(name);
return new WUIUrlBuilder(baseUrl, COMPONENT_DETAIL).append(name).toString();
}
/**
* Method description
*
*
* @param repositoryId
* @param revision
*
* @return
*/
@Override
public String getDiffUrl(String repositoryId, String revision)
{
revision = UrlUtil.fixRevision(revision);
return new WUIUrlBuilder(baseUrl,
COMPONENT_DIFF).append(repositoryId).append(revision).toString();
}
/**
* Method description
*
*
* @param repositoryId
*
* @return
* @since 1.18
*/
@Override
public String getTagsUrl(String repositoryId)
{
return getBrowseUrl(repositoryId, null, null);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String baseUrl;
}

View File

@@ -1,123 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public class WUIUrlBuilder
{
/** Field description */
public static final String NULL = "null";
/** Field description */
public static final String SEPARATOR = ";";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param baseUrl
* @param component
*/
public WUIUrlBuilder(String baseUrl, String component)
{
this.url = HttpUtil.appendHash(baseUrl, component);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param value
*
* @return
*/
public WUIUrlBuilder append(String value)
{
if (value == null)
{
value = NULL;
}
if (!this.url.endsWith(SEPARATOR))
{
this.url = this.url.concat(SEPARATOR);
}
this.url = this.url.concat(value);
return this;
}
/**
* Method description
*
*
* @param value
*
* @return
*/
public WUIUrlBuilder append(int value)
{
return append(String.valueOf(value));
}
/**
* Method description
*
*
* @return
*/
@Override
public String toString()
{
return url;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String url;
}

View File

@@ -1,182 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
* @since 1.9
* @author Sebastian Sdorra
*/
public class WUIUrlProvider implements UrlProvider
{
/** Field description */
public static final String COMPONENT_CONFIG = "scmConfig";
/** Field description */
public static final String COMPONENT_GROUP = "groupPanel";
/** Field description */
public static final String COMPONENT_REPOSITORY = "repositoryPanel";
/** Field description */
public static final String COMPONENT_USER = "userPanel";
/** Field description */
public static final String PART_INDEX = "index.html";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param baseUrl
*/
public WUIUrlProvider(String baseUrl)
{
this.baseUrl = HttpUtil.append(baseUrl, PART_INDEX);
}
//~--- get methods ----------------------------------------------------------
/**
* Returns the baseUrl, because there is no authentication url.
*
*
* @returns the baseUrl, because there is no authentication url
*
* @return
*/
@Override
public String getAuthenticationUrl()
{
return baseUrl;
}
/**
* Method description
*
*
* @return
*
* @since 1.43
*/
@Override
public String getBaseUrl()
{
return baseUrl;
}
/**
* Method description
*
*
* @return
*/
@Override
public String getConfigUrl()
{
return HttpUtil.appendHash(baseUrl, COMPONENT_CONFIG);
}
/**
* Method description
*
*
* @return
*/
@Override
public ModelUrlProvider getGroupUrlProvider()
{
return new WUIModelUrlProvider(baseUrl, COMPONENT_GROUP);
}
/**
* Method description
*
*
* @return
*/
@Override
public RepositoryUrlProvider getRepositoryUrlProvider()
{
return new WUIRepositoryUrlProvider(baseUrl, COMPONENT_REPOSITORY);
}
/**
* Method description
*
*
* @return
*/
@Override
public SecurityUrlProvider getSecurityUrlProvider()
{
throw new UnsupportedOperationException(
"this provider does not support security url provider.");
}
/**
* Returns the baseUrl, because there is no state url.
*
*
* @return the baseUrl, because there is no state url
*/
@Override
public String getStateUrl()
{
return baseUrl;
}
/**
* Method description
*
*
* @return
*/
@Override
public ModelUrlProvider getUserUrlProvider()
{
return new WUIModelUrlProvider(baseUrl, COMPONENT_USER);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String baseUrl;
}

View File

@@ -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
*/

View File

@@ -18,6 +18,9 @@ public class VndMediaType {
public static final String USER_COLLECTION = PREFIX + "userCollection" + SUFFIX;
public static final String GROUP_COLLECTION = PREFIX + "groupCollection" + SUFFIX;
public static final String REPOSITORY_COLLECTION = PREFIX + "repositoryCollection" + SUFFIX;
public static final String ME = PREFIX + "me" + SUFFIX;
public static final String CONFIG = PREFIX + "config" + SUFFIX;
private VndMediaType() {
}

View File

@@ -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;
}

View File

@@ -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"));

View File

@@ -0,0 +1,78 @@
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<RepositoryConfig> repositoryHandler;
private RepositoryConfig repositoryConfig = new RepositoryConfig() {
@Override
public String getId() {
return "repository";
}
};
@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());
}
}

View File

@@ -1,70 +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.url;
/**
*
* @author Sebastian Sdorra
*/
public class JSONRestModelUrlProviderTest extends RestModelUrlProviderTestBase
{
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected UrlProvider createUrlProvider(String baseUrl)
{
return UrlProviderFactory.createUrlProvider(baseUrl,
UrlProviderFactory.TYPE_RESTAPI_JSON);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
protected String getExtension()
{
return EXTENSION_JSON;
}
}

View File

@@ -1,71 +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.url;
/**
*
* @author Sebastian Sdorra
*/
public class JSONRestRepositoryUrlProviderTest
extends RestRepositoryUrlProviderTestBase
{
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected RepositoryUrlProvider createRepositoryUrlProvider(String baseUrl)
{
return UrlProviderFactory.createUrlProvider(baseUrl,
UrlProviderFactory.TYPE_RESTAPI_JSON).getRepositoryUrlProvider();
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
protected String getExtension()
{
return EXTENSION_JSON;
}
}

View File

@@ -1,70 +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.url;
/**
*
* @author Sebastian Sdorra
*/
public class JSONRestUrlProviderTest extends RestUrlProviderTestBase
{
/**
* Method description
*
*
*
* @param baseUrl
* @return
*/
@Override
protected UrlProvider createUrlProvider(String baseUrl)
{
return UrlProviderFactory.createUrlProvider(baseUrl,
UrlProviderFactory.TYPE_RESTAPI_JSON);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
protected String getExtension()
{
return EXTENSION_JSON;
}
}

View File

@@ -1,184 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author Sebastian Sdorra
*/
public abstract class ModelUrlProviderTestBase extends UrlTestBase
{
/** Field description */
public static final String ITEM = "hitchhiker";
/** Field description */
public static final String MODEL_GROUPS = "groups";
/** Field description */
public static final String MODEL_REPOSITORY = "repositories";
/** Field description */
public static final String MODEL_USERS = "users";
/** Field description */
private static final String[] MODELS = new String[] { MODEL_REPOSITORY,
MODEL_USERS, MODEL_GROUPS };
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
*
* @param baseUrl
* @return
*/
protected abstract ModelUrlProvider createGroupModelUrlProvider(
String baseUrl);
/**
* Method description
*
*
*
* @param baseUrl
* @return
*/
protected abstract ModelUrlProvider createRepositoryModelUrlProvider(
String baseUrl);
/**
* Method description
*
*
*
* @param baseUrl
* @return
*/
protected abstract ModelUrlProvider createUserModelUrlProvider(
String baseUrl);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
* @param model
*
* @return
*/
protected abstract String getExpectedAllUrl(String baseUrl, String model);
/**
* Method description
*
*
* @param baseUrl
* @param model
* @param item
*
* @return
*/
protected abstract String getExpectedDetailUrl(String baseUrl, String model,
String item);
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
@Test
public void testGetAllUrl()
{
for (String model : MODELS)
{
assertEquals(getExpectedAllUrl(BASEURL, model),
createModelUrlProvider(BASEURL, model).getAllUrl());
}
}
/**
* Method description
*
*/
@Test
public void testGetDetailUrl()
{
for (String model : MODELS)
{
assertEquals(getExpectedDetailUrl(BASEURL, model, ITEM),
createModelUrlProvider(BASEURL, model).getDetailUrl(ITEM));
}
}
/**
* Method description
*
*
*
* @param baseUrl
* @param model
*
* @return
*/
private ModelUrlProvider createModelUrlProvider(String baseUrl, String model)
{
ModelUrlProvider urlProvider = null;
if (MODEL_REPOSITORY.equals(model))
{
urlProvider = createRepositoryModelUrlProvider(baseUrl);
}
else if (MODEL_USERS.equals(model))
{
urlProvider = createUserModelUrlProvider(baseUrl);
}
else if (MODEL_GROUPS.equals(model))
{
urlProvider = createGroupModelUrlProvider(baseUrl);
}
return urlProvider;
}
}

View File

@@ -1,265 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author Sebastian Sdorra
*/
public abstract class RepositoryUrlProviderTestBase extends UrlTestBase
{
/** Field description */
private static final String NAME = "scm/main";
/** Field description */
private static final String PATH = "scm-webapp/pom.xml";
/** Field description */
private static final String REPOSITORY_ID =
"E3882BE7-7D0D-421B-B178-B2AA9E897135";
/** Field description */
private static final String REVISION = "b282fb2dd12a";
/** Field description */
private static final String TYPE = "hg";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
protected abstract RepositoryUrlProvider createRepositoryUrlProvider(
String baseUrl);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
protected abstract String getExpectedBlameUrl(String baseUrl,
String repositoryId, String path, String revision);
/**
* Method description
*
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
protected abstract String getExpectedBrowseUrl(String baseUrl,
String repositoryId, String path, String revision);
/**
* Method description
*
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
* @param start
* @param limit
*
* @return
*/
protected abstract String getExpectedChangesetUrl(String baseUrl,
String repositoryId, String path, String revision, int start,
int limit);
/**
* Method description
*
*
*
* @param baseUrl
* @param repositoryId
* @param start
* @param limit
*
* @return
*/
protected abstract String getExpectedChangesetUrl(String baseUrl,
String repositoryId, int start, int limit);
/**
* Method description
*
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
protected abstract String getExpectedContentUrl(String baseUrl,
String repositoryId, String path, String revision);
/**
* Method description
*
*
*
* @param baseUrl
* @param type
* @param name
*
* @return
* @since 1.11
*/
protected abstract String getExpectedDetailUrl(String baseUrl, String type,
String name);
/**
* Method description
*
*
*
* @param baseUrl
* @param repositoryId
* @param revision
*
* @return
*/
protected abstract String getExpectedDiffUrl(String baseUrl,
String repositoryId, String revision);
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
@Test
public void testGetBlameUrl()
{
assertEquals(
getExpectedBlameUrl(BASEURL, REPOSITORY_ID, PATH, REVISION),
createRepositoryUrlProvider(BASEURL).getBlameUrl(
REPOSITORY_ID, PATH, REVISION));
}
/**
* Method description
*
*/
@Test
public void testGetBrowserUrl()
{
assertEquals(
getExpectedBrowseUrl(BASEURL, REPOSITORY_ID, PATH, REVISION),
createRepositoryUrlProvider(BASEURL).getBrowseUrl(
REPOSITORY_ID, PATH, REVISION));
}
/**
* Method description
*
*/
@Test
public void testGetChangesetUrl()
{
assertEquals(
getExpectedChangesetUrl(BASEURL, REPOSITORY_ID, PATH, REVISION, 0, 20),
createRepositoryUrlProvider(BASEURL).getChangesetUrl(
REPOSITORY_ID, PATH, REVISION, 0, 20));
assertEquals(
getExpectedChangesetUrl(BASEURL, REPOSITORY_ID, 0, 20),
createRepositoryUrlProvider(BASEURL).getChangesetUrl(
REPOSITORY_ID, 0, 20));
}
/**
* Method description
*
*/
@Test
public void testGetContentUrl()
{
assertEquals(
getExpectedContentUrl(BASEURL, REPOSITORY_ID, PATH, REVISION),
createRepositoryUrlProvider(BASEURL).getContentUrl(
REPOSITORY_ID, PATH, REVISION));
}
/**
* Method description
*
*/
@Test
public void testGetDetailUrl()
{
assertEquals(getExpectedDetailUrl(BASEURL, TYPE, NAME),
createRepositoryUrlProvider(BASEURL).getDetailUrl(TYPE, NAME));
}
/**
* Method description
*
*/
@Test
public void testGetDiffUrl()
{
assertEquals(getExpectedDiffUrl(BASEURL, REPOSITORY_ID, REVISION),
createRepositoryUrlProvider(BASEURL).getDiffUrl(REPOSITORY_ID,
REVISION));
}
}

View File

@@ -1,159 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
*
* @author Sebastian Sdorra
*/
public abstract class RestModelUrlProviderTestBase
extends ModelUrlProviderTestBase
{
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
protected abstract UrlProvider createUrlProvider(String baseUrl);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
protected abstract String getExtension();
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected ModelUrlProvider createGroupModelUrlProvider(String baseUrl)
{
return createUrlProvider(baseUrl).getGroupUrlProvider();
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected ModelUrlProvider createRepositoryModelUrlProvider(String baseUrl)
{
return createUrlProvider(baseUrl).getRepositoryUrlProvider();
}
/**
* Method description
*
*
* @param baseUrl
* @param urlPart
*
* @return
*/
protected String createRestUrl(String baseUrl, String urlPart)
{
return createRestUrl(baseUrl, urlPart, getExtension());
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected ModelUrlProvider createUserModelUrlProvider(String baseUrl)
{
return createUrlProvider(baseUrl).getUserUrlProvider();
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
* @param model
*
* @return
*/
@Override
protected String getExpectedAllUrl(String baseUrl, String model)
{
return createRestUrl(baseUrl, model);
}
/**
* Method description
*
*
* @param baseUrl
* @param model
* @param item
*
* @return
*/
@Override
protected String getExpectedDetailUrl(String baseUrl, String model,
String item)
{
return createRestUrl(baseUrl,
model.concat(HttpUtil.SEPARATOR_PATH).concat(item));
}
}

View File

@@ -1,230 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
*
* @author Sebastian Sdorra
*/
public abstract class RestRepositoryUrlProviderTestBase
extends RepositoryUrlProviderTestBase
{
/** Field description */
public static final String URLPART_PREFIX = "repositories";
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
protected abstract String getExtension();
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
protected String getExpectedBlameUrl(String baseUrl, String repositoryId,
String path, String revision)
{
return createRestUrl(
baseUrl,
repositoryId.concat(HttpUtil.SEPARATOR_PATH).concat("blame")).concat(
"?path=").concat(path).concat("&revision=").concat(revision);
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
protected String getExpectedBrowseUrl(String baseUrl, String repositoryId,
String path, String revision)
{
return createRestUrl(
baseUrl,
repositoryId.concat(HttpUtil.SEPARATOR_PATH).concat("browse")).concat(
"?path=").concat(path).concat("&revision=").concat(revision);
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
* @param start
* @param limit
*
* @return
*/
@Override
protected String getExpectedChangesetUrl(String baseUrl, String repositoryId,
String path, String revision, int start, int limit)
{
return createRestUrl(
baseUrl,
repositoryId.concat(HttpUtil.SEPARATOR_PATH).concat(
"changesets")).concat("?path=").concat(path).concat(
"&revision=").concat(revision).concat("&start=").concat(
String.valueOf(start)).concat("&limit=").concat(
String.valueOf(limit));
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param start
* @param limit
*
* @return
*/
@Override
protected String getExpectedChangesetUrl(String baseUrl, String repositoryId,
int start, int limit)
{
return createRestUrl(
baseUrl,
repositoryId.concat(HttpUtil.SEPARATOR_PATH).concat(
"changesets")).concat("?start=").concat(String.valueOf(start)).concat(
"&limit=").concat(String.valueOf(limit));
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
protected String getExpectedContentUrl(String baseUrl, String repositoryId,
String path, String revision)
{
return createRestUrl(
baseUrl,
"repositories".concat(HttpUtil.SEPARATOR_PATH).concat(
repositoryId).concat(HttpUtil.SEPARATOR_PATH).concat(
"content"), "").concat("?path=").concat(path).concat(
"&revision=").concat(revision);
}
/**
* Method description
*
*
* @param baseUrl
* @param type
* @param name
*
* @return
*/
@Override
protected String getExpectedDetailUrl(String baseUrl, String type,
String name)
{
return createRestUrl(baseUrl,
type.concat(HttpUtil.SEPARATOR_PATH).concat(name));
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param revision
*
* @return
*/
@Override
protected String getExpectedDiffUrl(String baseUrl, String repositoryId,
String revision)
{
return createRestUrl(
baseUrl,
"repositories".concat(HttpUtil.SEPARATOR_PATH).concat(
repositoryId).concat(HttpUtil.SEPARATOR_PATH).concat(
"diff"), "").concat("?revision=").concat(revision);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
* @param urlPart
*
* @return
*/
private String createRestUrl(String baseUrl, String urlPart)
{
return createRestUrl(
baseUrl,
URLPART_PREFIX.concat(HttpUtil.SEPARATOR_PATH).concat(urlPart),
getExtension());
}
}

View File

@@ -1,109 +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.url;
/**
*
* @author Sebastian Sdorra
*/
public abstract class RestUrlProviderTestBase extends UrlProviderTestBase
{
/**
* Method description
*
*
* @return
*/
protected abstract String getExtension();
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
* @param urlPart
*
* @return
*/
protected String createRestUrl(String baseUrl, String urlPart)
{
return createRestUrl(baseUrl, urlPart, getExtension());
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected String getExpectedAuthenticationUrl(String baseUrl)
{
return createRestUrl(baseUrl, "auth/access_token");
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected String getExpectedConfigUrl(String baseUrl)
{
return createRestUrl(baseUrl, "config");
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected String getExpectedStateUrl(String baseUrl)
{
return createRestUrl(baseUrl, "auth");
}
}

View File

@@ -1,156 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author Sebastian Sdorra
*/
public abstract class UrlProviderTestBase extends UrlTestBase
{
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
*
* @param baseUrl
* @return
*/
protected abstract UrlProvider createUrlProvider(String baseUrl);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
protected abstract String getExpectedAuthenticationUrl(String baseUrl);
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
protected abstract String getExpectedConfigUrl(String baseUrl);
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
protected abstract String getExpectedStateUrl(String baseUrl);
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
@Test
public void testGetAuthenticationUrl()
{
assertEquals(getExpectedAuthenticationUrl(BASEURL),
createUrlProvider(BASEURL).getAuthenticationUrl());
}
/**
* Method description
*
*/
@Test
public void testGetConfigUrl()
{
assertEquals(getExpectedConfigUrl(BASEURL),
createUrlProvider(BASEURL).getConfigUrl());
}
/**
* Method description
*
*/
@Test
public void testGetGroupUrlProvider()
{
assertNotNull(createUrlProvider(BASEURL).getGroupUrlProvider());
}
/**
* Method description
*
*/
@Test
public void testGetStateUrl()
{
assertEquals(getExpectedStateUrl(BASEURL),
createUrlProvider(BASEURL).getStateUrl());
}
/**
* Method description
*
*/
@Test
public void testGetUserRepositoryUrlProvider()
{
assertNotNull(createUrlProvider(BASEURL).getRepositoryUrlProvider());
}
/**
* Method description
*
*/
@Test
public void testGetUserUrlProvider()
{
assertNotNull(createUrlProvider(BASEURL).getUserUrlProvider());
}
}

View File

@@ -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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
*
* @author Sebastian Sdorra
*/
public abstract class UrlTestBase
{
/** Field description */
public static final String EXTENSION_JSON = ".json";
/** Field description */
public static final String EXTENSION_XML = ".xml";
/** Field description */
public static final String URLSUFFIX_INDEX = "/index.html";
/** Field description */
public static final String URLSUFFIX_RESTAPI = "/api/rest/";
/** Field description */
protected static final String BASEURL = "http://scm.scm-manager.org/scm";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
protected String createBaseRestUrl(String baseUrl)
{
return baseUrl.concat(URLSUFFIX_RESTAPI);
}
/**
* Method description
*
*
* @param baseUrl
* @param urlPart
* @param extension
*
* @return
*/
protected String createRestUrl(String baseUrl, String urlPart,
String extension)
{
return createBaseRestUrl(baseUrl).concat(urlPart).concat(extension);
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
protected String createWuiUrl(String baseUrl)
{
return baseUrl.concat(URLSUFFIX_INDEX);
}
/**
* Method description
*
*
* @param baseUrl
* @param param
*
* @return
*/
protected String createWuiUrl(String baseUrl, String param)
{
return baseUrl.concat(URLSUFFIX_INDEX).concat(
HttpUtil.SEPARATOR_HASH).concat(param);
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
protected UrlProvider createWuiUrlProvider(String baseUrl)
{
return UrlProviderFactory.createUrlProvider(baseUrl,
UrlProviderFactory.TYPE_WUI);
}
}

View File

@@ -1,60 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author Sebastian Sdorra
*/
public class UrlUtilTest
{
/**
* Method description
*
*/
@Test
public void testFixRevision()
{
assertEquals("42694c4a4a7a", UrlUtil.fixRevision("42694c4a4a7a"));
assertEquals("42694c4a4a7a", UrlUtil.fixRevision("298:42694c4a4a7a"));
assertNull(UrlUtil.fixRevision(null));
}
}

View File

@@ -1,158 +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.url;
//~--- JDK imports ------------------------------------------------------------
import java.util.HashMap;
import java.util.Map;
/**
*
* @author Sebastian Sdorra
*/
public class WUIModelUrlProviderTest extends ModelUrlProviderTestBase
{
/**
* Constructs ...
*
*/
public WUIModelUrlProviderTest()
{
modelMap = new HashMap<String, String>();
modelMap.put(MODEL_REPOSITORY, "repositoryPanel");
modelMap.put(MODEL_USERS, "userPanel");
modelMap.put(MODEL_GROUPS, "groupPanel");
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected ModelUrlProvider createGroupModelUrlProvider(String baseUrl)
{
return createWuiUrlProvider(baseUrl).getGroupUrlProvider();
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected ModelUrlProvider createRepositoryModelUrlProvider(String baseUrl)
{
return createWuiUrlProvider(baseUrl).getRepositoryUrlProvider();
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected ModelUrlProvider createUserModelUrlProvider(String baseUrl)
{
return createWuiUrlProvider(baseUrl).getUserUrlProvider();
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
* @param model
*
* @return
*/
@Override
protected String getExpectedAllUrl(String baseUrl, String model)
{
return createModelBaseUrl(baseUrl, model);
}
/**
* Method description
*
*
* @param baseUrl
* @param model
* @param item
*
* @return
*/
@Override
protected String getExpectedDetailUrl(String baseUrl, String model,
String item)
{
return createModelBaseUrl(baseUrl, model).concat(
WUIUrlBuilder.SEPARATOR).concat(item);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
* @param model
*
* @return
*/
private String createModelBaseUrl(String baseUrl, String model)
{
return createWuiUrl(baseUrl, modelMap.get(model));
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Map<String, String> modelMap;
}

View File

@@ -1,218 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.HttpUtil;
/**
*
* @author Sebastian Sdorra
*/
public class WUIRepositoryUrlProviderTest extends RepositoryUrlProviderTestBase
{
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected RepositoryUrlProvider createRepositoryUrlProvider(String baseUrl)
{
return UrlProviderFactory.createUrlProvider(baseUrl,
UrlProviderFactory.TYPE_WUI).getRepositoryUrlProvider();
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
protected String getExpectedBlameUrl(String baseUrl, String repositoryId,
String path, String revision)
{
return createRepositoryWuiUrl(baseUrl, "contentPanel", repositoryId).concat(
";").concat(revision).concat(";").concat(path).concat(";blame");
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
protected String getExpectedBrowseUrl(String baseUrl, String repositoryId,
String path, String revision)
{
return createRepositoryWuiUrl(
baseUrl, "repositoryBrowser", repositoryId).concat(";").concat(
revision).concat(";").concat(path);
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
* @param start
* @param limit
*
* @return
*/
@Override
protected String getExpectedChangesetUrl(String baseUrl, String repositoryId,
String path, String revision, int start, int limit)
{
return createRepositoryWuiUrl(baseUrl, "contentPanel", repositoryId).concat(
";").concat(revision).concat(";").concat(path).concat(";history");
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param start
* @param limit
*
* @return
*/
@Override
protected String getExpectedChangesetUrl(String baseUrl, String repositoryId,
int start, int limit)
{
return createRepositoryWuiUrl(
baseUrl, "repositoryChangesetViewerPanel", repositoryId).concat(
";").concat(String.valueOf(start)).concat(";").concat(
String.valueOf(limit));
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param path
* @param revision
*
* @return
*/
@Override
protected String getExpectedContentUrl(String baseUrl, String repositoryId,
String path, String revision)
{
return createRepositoryWuiUrl(baseUrl, "contentPanel", repositoryId).concat(
";").concat(revision).concat(";").concat(path).concat(";history");
}
/**
* Method description
*
*
* @param baseUrl
* @param type
* @param name
*
* @return
*/
@Override
protected String getExpectedDetailUrl(String baseUrl, String type,
String name)
{
return createRepositoryWuiUrl(
baseUrl, "repositoryPanel",
type.concat(HttpUtil.SEPARATOR_PATH).concat(name));
}
/**
* Method description
*
*
* @param baseUrl
* @param repositoryId
* @param revision
*
* @return
*/
@Override
protected String getExpectedDiffUrl(String baseUrl, String repositoryId,
String revision)
{
return createRepositoryWuiUrl(baseUrl, "diffPanel",
repositoryId).concat(";").concat(revision);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
* @param component
* @param repository
*
* @return
*/
private String createRepositoryWuiUrl(String baseUrl, String component,
String repository)
{
return createWuiUrl(baseUrl, component).concat(
WUIUrlBuilder.SEPARATOR).concat(repository);
}
}

View File

@@ -1,114 +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.url;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import sonia.scm.util.HttpUtil;
import static org.junit.Assert.*;
/**
*
* @author Sebastian Sdorra
*/
public class WUIUrlBuilderTest
{
/** Field description */
private static final String BASEURL =
"http://scm.scm-manager.org/scm/index.html";
/** Field description */
private static final String COMPONENT = "testCmp";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
@Test
public void testStringAppend()
{
WUIUrlBuilder builder = createBuilder();
builder.append("testParam");
assertEquals(createBaseWuiUrl().concat(";testParam"), builder.toString());
builder = createBuilder();
builder.append("param1").append("param2").append("param3");
assertEquals(createBaseWuiUrl().concat(";param1;param2;param3"),
builder.toString());
}
/**
* Method description
*
*/
@Test
public void testIntAppend()
{
WUIUrlBuilder builder = createBuilder();
builder.append(3);
assertEquals(createBaseWuiUrl().concat(";3"), builder.toString());
builder = createBuilder();
builder.append(1).append(2).append(3);
assertEquals(createBaseWuiUrl().concat(";1;2;3"),
builder.toString());
}
/**
* Method description
*
*
* @return
*/
private String createBaseWuiUrl()
{
return BASEURL.concat(HttpUtil.SEPARATOR_HASH).concat(COMPONENT);
}
/**
* Method description
*
*
* @return
*/
private WUIUrlBuilder createBuilder()
{
return new WUIUrlBuilder(BASEURL, COMPONENT);
}
}

View File

@@ -1,102 +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.url;
//~--- non-JDK imports --------------------------------------------------------
/**
*
* @author Sebastian Sdorra
*/
public class WUIUrlProviderTest extends UrlProviderTestBase
{
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected UrlProvider createUrlProvider(String baseUrl)
{
return UrlProviderFactory.createUrlProvider(baseUrl,
UrlProviderFactory.TYPE_WUI);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected String getExpectedAuthenticationUrl(String baseUrl)
{
return createWuiUrl(baseUrl);
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected String getExpectedConfigUrl(String baseUrl)
{
return createWuiUrl(baseUrl, "scmConfig");
}
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected String getExpectedStateUrl(String baseUrl)
{
return createWuiUrl(baseUrl);
}
}

View File

@@ -1,70 +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.url;
/**
*
* @author Sebastian Sdorra
*/
public class XMLRestModelUrlProviderTest extends RestModelUrlProviderTestBase
{
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected UrlProvider createUrlProvider(String baseUrl)
{
return UrlProviderFactory.createUrlProvider(baseUrl,
UrlProviderFactory.TYPE_RESTAPI_XML);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
protected String getExtension()
{
return EXTENSION_XML;
}
}

View File

@@ -1,70 +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.url;
/**
*
* @author Sebastian Sdorra
*/
public class XMLRestUrlProviderTest extends RestUrlProviderTestBase
{
/**
* Method description
*
*
* @param baseUrl
*
* @return
*/
@Override
protected UrlProvider createUrlProvider(String baseUrl)
{
return UrlProviderFactory.createUrlProvider(baseUrl,
UrlProviderFactory.TYPE_RESTAPI_XML);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
protected String getExtension()
{
return EXTENSION_XML;
}
}

View File

@@ -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+