mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 22:45:45 +01:00
generate repository urls
This commit is contained in:
@@ -37,11 +37,6 @@ registerConfigPanel({
|
||||
name: 'repositoryDirectory',
|
||||
fieldLabel: 'Repository directory',
|
||||
allowBlank : false
|
||||
},{
|
||||
xtype: 'textfield',
|
||||
name: 'baseUrl',
|
||||
fieldLabel: 'Base URL',
|
||||
allowBlank : false
|
||||
}],
|
||||
|
||||
onSubmit: function(values){
|
||||
|
||||
@@ -63,7 +63,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -131,6 +130,20 @@ public class HgRepositoryHandler extends AbstractRepositoryHandler<HgConfig>
|
||||
storeRepository(repository, hgDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String createResourcePath(Repository repository)
|
||||
{
|
||||
return "/hg/".concat(repository.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -361,7 +374,6 @@ public class HgRepositoryHandler extends AbstractRepositoryHandler<HgConfig>
|
||||
repository = new Repository();
|
||||
repository.setType(TYPE_NAME);
|
||||
repository.setName(name);
|
||||
repository.setUrl(buildUrl(repository));
|
||||
loadRepository(repository, hgDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,11 +47,6 @@ registerConfigPanel({
|
||||
name: 'repositoryDirectory',
|
||||
fieldLabel: 'Repository directory',
|
||||
allowBlank : false
|
||||
},{
|
||||
xtype: 'textfield',
|
||||
name: 'baseUrl',
|
||||
fieldLabel: 'Base URL',
|
||||
allowBlank : false
|
||||
}],
|
||||
|
||||
onSubmit: function(values){
|
||||
|
||||
@@ -37,16 +37,6 @@ registerConfigPanel({
|
||||
name: 'repositoryDirectory',
|
||||
fieldLabel: 'Repository directory',
|
||||
allowBlank : false
|
||||
},{
|
||||
xtype: 'textfield',
|
||||
name: 'baseUrl',
|
||||
fieldLabel: 'Base URL',
|
||||
allowBlank : false
|
||||
},{
|
||||
xtype: 'textfield',
|
||||
name: 'svnAccessFile',
|
||||
fieldLabel: 'Svn Accessfile',
|
||||
allowBlank : true
|
||||
}],
|
||||
|
||||
onSubmit: function(values){
|
||||
|
||||
@@ -41,7 +41,6 @@ import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -60,7 +59,7 @@ import javax.xml.bind.JAXB;
|
||||
*
|
||||
* @param <C>
|
||||
*/
|
||||
public abstract class AbstractRepositoryHandler<C extends BasicRepositoryConfig>
|
||||
public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig>
|
||||
implements RepositoryHandler
|
||||
{
|
||||
|
||||
@@ -213,31 +212,6 @@ public abstract class AbstractRepositoryHandler<C extends BasicRepositoryConfig>
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String buildUrl(Repository repository)
|
||||
{
|
||||
String url = config.getBaseUrl();
|
||||
|
||||
if (Util.isNotEmpty(url))
|
||||
{
|
||||
if (!url.endsWith("/"))
|
||||
{
|
||||
url = url.concat("/");
|
||||
}
|
||||
|
||||
url = url.concat(repository.getName());
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -247,7 +221,6 @@ public abstract class AbstractRepositoryHandler<C extends BasicRepositoryConfig>
|
||||
protected void initNewRepository(Repository repository)
|
||||
{
|
||||
repository.setId(UUID.randomUUID().toString());
|
||||
repository.setUrl(buildUrl(repository));
|
||||
repository.setCreationDate(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.io.CommandResult;
|
||||
import sonia.scm.io.ExtendedCommand;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -105,6 +104,24 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
storeRepositoryConfig(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String createResourcePath(Repository repository)
|
||||
{
|
||||
StringBuilder path = new StringBuilder("/");
|
||||
|
||||
path.append(getType().getName()).append("/").append(repository.getName());
|
||||
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -430,15 +447,6 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
|
||||
repository = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
String url = buildUrl(repository);
|
||||
|
||||
if (Util.isNotEmpty(url))
|
||||
{
|
||||
repository.setUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
@@ -1,69 +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.repository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class BasicRepositoryConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getBaseUrl()
|
||||
{
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
*/
|
||||
public void setBaseUrl(String baseUrl)
|
||||
{
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String baseUrl;
|
||||
}
|
||||
@@ -46,4 +46,14 @@ import sonia.scm.ListenerSupport;
|
||||
*/
|
||||
public interface RepositoryHandler
|
||||
extends Handler<Repository, RepositoryException>,
|
||||
ListenerSupport<ConfigChangedListener> {}
|
||||
ListenerSupport<ConfigChangedListener>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String createResourcePath( Repository repository );
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import java.io.File;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class SimpleRepositoryConfig extends BasicRepositoryConfig
|
||||
public class SimpleRepositoryConfig
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -349,7 +349,7 @@ public class ScmServletModule extends ServletModule
|
||||
{
|
||||
try
|
||||
{
|
||||
JAXB.unmarshal(file, ScmConfiguration.class);
|
||||
config = JAXB.unmarshal(file, ScmConfiguration.class);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -36,8 +38,10 @@ package sonia.scm.api.rest.resources;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RepositoryHandler;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -46,8 +50,11 @@ import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
@@ -63,6 +70,23 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
/** Field description */
|
||||
public static final String PATH_PART = "repositories";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
* @param repositoryManager
|
||||
*/
|
||||
@Inject
|
||||
public RepositoryResource(ScmConfiguration configuration,
|
||||
RepositoryManager repositoryManager)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.repositoryManager = repositoryManager;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -126,9 +150,15 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
protected Repository[] getAllItems()
|
||||
{
|
||||
Collection<Repository> repositoryCollection = repositoryManager.getAll();
|
||||
Repository[] repositories =
|
||||
repositoryCollection.toArray(new Repository[repositoryCollection.size()]);
|
||||
|
||||
return repositoryCollection.toArray(
|
||||
new Repository[repositoryCollection.size()]);
|
||||
for (Repository repository : repositories)
|
||||
{
|
||||
appendUrl(repository);
|
||||
}
|
||||
|
||||
return repositories;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +187,11 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
@Override
|
||||
protected Repository getItem(String id)
|
||||
{
|
||||
return repositoryManager.get(id);
|
||||
Repository repository = repositoryManager.get(id);
|
||||
|
||||
appendUrl(repository);
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,9 +206,46 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
return PATH_PART;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*/
|
||||
private void appendUrl(Repository repository)
|
||||
{
|
||||
StringBuilder url = new StringBuilder(request.getScheme());
|
||||
|
||||
url.append("://").append(configuration.getServername());
|
||||
url.append(":").append(request.getLocalPort());
|
||||
|
||||
String ctxPath = request.getContextPath();
|
||||
|
||||
url.append(ctxPath);
|
||||
|
||||
if (ctxPath.endsWith("/"))
|
||||
{
|
||||
ctxPath.substring(0, ctxPath.length() - 1);
|
||||
}
|
||||
|
||||
RepositoryHandler handler =
|
||||
repositoryManager.getHandler(repository.getType());
|
||||
|
||||
url.append(handler.createResourcePath(repository));
|
||||
repository.setUrl(url.toString());
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@Inject
|
||||
private ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private RepositoryManager repositoryManager;
|
||||
|
||||
/** TODO path request direct to method */
|
||||
@Context
|
||||
private HttpServletRequest request;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user