mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
improve RepositoryManager api
This commit is contained in:
@@ -36,7 +36,7 @@ import javax.xml.bind.JAXB;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class HgRepositoryManager extends AbstractRepositoryManager
|
public class HgRepositoryHandler implements RepositoryHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@@ -59,7 +59,7 @@ public class HgRepositoryManager extends AbstractRepositoryManager
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
Logger.getLogger(HgRepositoryManager.class.getName());
|
Logger.getLogger(HgRepositoryHandler.class.getName());
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
@@ -111,7 +111,6 @@ public class HgRepositoryManager extends AbstractRepositoryManager
|
|||||||
File hgDirectory = new File(directory, ".hg");
|
File hgDirectory = new File(directory, ".hg");
|
||||||
|
|
||||||
writeHgrc(repository, hgDirectory);
|
writeHgrc(repository, hgDirectory);
|
||||||
fireEvent(repository, RepositoryEvent.CREATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,7 +131,6 @@ public class HgRepositoryManager extends AbstractRepositoryManager
|
|||||||
if (new File(directory, ".hg").exists())
|
if (new File(directory, ".hg").exists())
|
||||||
{
|
{
|
||||||
Util.delete(directory);
|
Util.delete(directory);
|
||||||
fireEvent(repository, RepositoryEvent.DELETE);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -187,7 +185,6 @@ public class HgRepositoryManager extends AbstractRepositoryManager
|
|||||||
if (hgDirectory.exists())
|
if (hgDirectory.exists())
|
||||||
{
|
{
|
||||||
writeHgrc(repository, hgDirectory);
|
writeHgrc(repository, hgDirectory);
|
||||||
fireEvent(repository, RepositoryEvent.MODIFY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +232,9 @@ public class HgRepositoryManager extends AbstractRepositoryManager
|
|||||||
|
|
||||||
if (hgDirectory.exists() && hgDirectory.isDirectory())
|
if (hgDirectory.exists() && hgDirectory.isDirectory())
|
||||||
{
|
{
|
||||||
repository = new Repository(TYPE_NAME, name);
|
repository = new Repository();
|
||||||
|
repository.setType(TYPE_NAME);
|
||||||
|
repository.setName(name);
|
||||||
readHgrc(repository, hgDirectory);
|
readHgrc(repository, hgDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -357,6 +356,15 @@ public class HgRepositoryManager extends AbstractRepositoryManager
|
|||||||
repository.setPermissions(permissions);
|
repository.setPermissions(permissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INISection scmSection = iniConfig.getSection("scm");
|
||||||
|
|
||||||
|
if (scmSection != null)
|
||||||
|
{
|
||||||
|
String id = scmSection.getParameter("id");
|
||||||
|
|
||||||
|
repository.setId(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
@@ -402,9 +410,14 @@ public class HgRepositoryManager extends AbstractRepositoryManager
|
|||||||
appendPermission(section, permissions);
|
appendPermission(section, permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INISection scmSection = new INISection("scm");
|
||||||
|
|
||||||
|
section.setParameter("id", repository.getId());
|
||||||
|
|
||||||
INIConfiguration iniConfig = new INIConfiguration();
|
INIConfiguration iniConfig = new INIConfiguration();
|
||||||
|
|
||||||
iniConfig.addSection(section);
|
iniConfig.addSection(section);
|
||||||
|
iniConfig.addSection(scmSection);
|
||||||
|
|
||||||
File hgrc = new File(hgDirectory, "hgrc");
|
File hgrc = new File(hgDirectory, "hgrc");
|
||||||
INIConfigurationWriter writer = new INIConfigurationWriter();
|
INIConfigurationWriter writer = new INIConfigurationWriter();
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
sonia.scm.repository.HgRepositoryHandler
|
||||||
@@ -1 +0,0 @@
|
|||||||
sonia.scm.repository.HgRepositoryManager
|
|
||||||
@@ -10,8 +10,8 @@ package sonia.scm;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.group.GroupManager;
|
import sonia.scm.group.GroupManager;
|
||||||
|
import sonia.scm.repository.BasicRepositoryManager;
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.repository.RepositoryType;
|
|
||||||
import sonia.scm.util.ServiceUtil;
|
import sonia.scm.util.ServiceUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
@@ -20,7 +20,6 @@ import sonia.scm.util.Util;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -68,10 +67,7 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
manager.close();
|
manager.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (RepositoryManager manager : repositoryManagerMap.values())
|
repositoryManager.close();
|
||||||
{
|
|
||||||
manager.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +78,7 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
loadGroupManagers();
|
loadGroupManagers();
|
||||||
loadRepositoryManagers();
|
loadRepositoryManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -117,26 +113,13 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param type
|
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public RepositoryManager getRepositoryManager(String type)
|
public RepositoryManager getRepositoryManager()
|
||||||
{
|
{
|
||||||
return repositoryManagerMap.get(type);
|
return repositoryManager;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<RepositoryType> getRepositoryTypes()
|
|
||||||
{
|
|
||||||
return repositoryTypes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -194,20 +177,16 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void loadRepositoryManagers()
|
private void loadRepositoryManager()
|
||||||
{
|
{
|
||||||
repositoryManagerMap = new HashMap<String, RepositoryManager>();
|
repositoryManager = ServiceUtil.getService(RepositoryManager.class);
|
||||||
repositoryTypes = new ArrayList<RepositoryType>();
|
|
||||||
|
|
||||||
List<RepositoryManager> repositoryManagers =
|
if (repositoryManager == null)
|
||||||
ServiceUtil.getServices(RepositoryManager.class);
|
|
||||||
|
|
||||||
for (RepositoryManager manager : repositoryManagers)
|
|
||||||
{
|
{
|
||||||
manager.init(this);
|
repositoryManager = new BasicRepositoryManager();
|
||||||
repositoryManagerMap.put(manager.getType().getName(), manager);
|
|
||||||
repositoryTypes.add(manager.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repositoryManager.init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
@@ -219,8 +198,5 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
private Map<String, GroupManager> groupManagerMap;
|
private Map<String, GroupManager> groupManagerMap;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Map<String, RepositoryManager> repositoryManagerMap;
|
private RepositoryManager repositoryManager;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private List<RepositoryType> repositoryTypes;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.util.Collection;
|
|||||||
* @param <T>
|
* @param <T>
|
||||||
* @param <E>
|
* @param <E>
|
||||||
*/
|
*/
|
||||||
public interface Manager<T, E extends Exception> extends Initable, Closeable
|
public interface Handler<T, E extends Exception> extends Initable, Closeable
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,7 +78,7 @@ public interface Manager<T, E extends Exception> extends Initable, Closeable
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public T get(String name);
|
public T get(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
@@ -87,12 +87,4 @@ public interface Manager<T, E extends Exception> extends Initable, Closeable
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Collection<T> getAll();
|
public Collection<T> getAll();
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isConfigured();
|
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@ import sonia.scm.repository.RepositoryType;
|
|||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,16 +58,7 @@ public interface SCMContextProvider extends Closeable
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param type
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RepositoryManager getRepositoryManager(String type);
|
public RepositoryManager getRepositoryManager();
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Collection<RepositoryType> getRepositoryTypes();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ package sonia.scm.group;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.Manager;
|
import sonia.scm.Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public interface GroupManager extends Manager<Group, GroupException>
|
public interface GroupManager extends Handler<Group, GroupException>
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,251 @@
|
|||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.repository;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.SCMContextProvider;
|
||||||
|
import sonia.scm.util.ServiceUtil;
|
||||||
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public BasicRepositoryManager()
|
||||||
|
{
|
||||||
|
handlerMap = new HashMap<String, RepositoryHandler>();
|
||||||
|
types = new ArrayList<RepositoryType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
for (RepositoryHandler manager : handlerMap.values())
|
||||||
|
{
|
||||||
|
manager.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param repository
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void create(Repository repository)
|
||||||
|
throws RepositoryException, IOException
|
||||||
|
{
|
||||||
|
getHandler(repository).create(repository);
|
||||||
|
fireEvent(repository, RepositoryEvent.CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param repository
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delete(Repository repository)
|
||||||
|
throws RepositoryException, IOException
|
||||||
|
{
|
||||||
|
getHandler(repository).delete(repository);
|
||||||
|
fireEvent(repository, RepositoryEvent.DELETE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void init(SCMContextProvider context)
|
||||||
|
{
|
||||||
|
List<RepositoryHandler> handlerList =
|
||||||
|
ServiceUtil.getServices(RepositoryHandler.class);
|
||||||
|
|
||||||
|
if (Util.isNotEmpty(handlerList))
|
||||||
|
{
|
||||||
|
for (RepositoryHandler handler : handlerList)
|
||||||
|
{
|
||||||
|
RepositoryType type = handler.getType();
|
||||||
|
|
||||||
|
types.add(type);
|
||||||
|
handlerMap.put(type.getName(), handler);
|
||||||
|
handler.init(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param repository
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void modify(Repository repository)
|
||||||
|
throws RepositoryException, IOException
|
||||||
|
{
|
||||||
|
getHandler(repository).modify(repository);
|
||||||
|
fireEvent(repository, RepositoryEvent.MODIFY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param repository
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void refresh(Repository repository)
|
||||||
|
throws RepositoryException, IOException
|
||||||
|
{
|
||||||
|
getHandler(repository).refresh(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Repository get(String id)
|
||||||
|
{
|
||||||
|
Repository repository = null;
|
||||||
|
|
||||||
|
for (RepositoryHandler handler : handlerMap.values())
|
||||||
|
{
|
||||||
|
repository = handler.get(id);
|
||||||
|
|
||||||
|
if (repository != null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Collection<Repository> getAll()
|
||||||
|
{
|
||||||
|
Set<Repository> repositories = new HashSet<Repository>();
|
||||||
|
|
||||||
|
for (RepositoryHandler handler : handlerMap.values())
|
||||||
|
{
|
||||||
|
Collection<Repository> handlerRepositories = handler.getAll();
|
||||||
|
|
||||||
|
if (handlerRepositories != null)
|
||||||
|
{
|
||||||
|
repositories.addAll(handlerRepositories);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return repositories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Collection<RepositoryType> getTypes()
|
||||||
|
{
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param repository
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws RepositoryHandlerNotFoundException
|
||||||
|
*/
|
||||||
|
private RepositoryHandler getHandler(Repository repository)
|
||||||
|
throws RepositoryHandlerNotFoundException
|
||||||
|
{
|
||||||
|
String type = repository.getType();
|
||||||
|
RepositoryHandler handler = handlerMap.get(type);
|
||||||
|
|
||||||
|
if (handler == null)
|
||||||
|
{
|
||||||
|
throw new RepositoryHandlerNotFoundException(
|
||||||
|
"could not find handler for ".concat(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Map<String, RepositoryHandler> handlerMap;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private List<RepositoryType> types;
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@ import javax.xml.bind.annotation.XmlType;
|
|||||||
@XmlRootElement(name = "repositories")
|
@XmlRootElement(name = "repositories")
|
||||||
@XmlType(propOrder =
|
@XmlType(propOrder =
|
||||||
{
|
{
|
||||||
"type", "name", "contact", "description", "permissions"
|
"id", "type", "name", "contact", "description", "permissions"
|
||||||
})
|
})
|
||||||
public class Repository implements Serializable
|
public class Repository implements Serializable
|
||||||
{
|
{
|
||||||
@@ -49,11 +49,14 @@ public class Repository implements Serializable
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
* @param type
|
* @param type
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public Repository(String type, String name)
|
public Repository(String id, String type, String name)
|
||||||
{
|
{
|
||||||
|
this.id = id;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@@ -62,15 +65,18 @@ public class Repository implements Serializable
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
* @param type
|
* @param type
|
||||||
* @param name
|
* @param name
|
||||||
* @param contact
|
* @param contact
|
||||||
* @param description
|
* @param description
|
||||||
* @param permissions
|
* @param permissions
|
||||||
*/
|
*/
|
||||||
public Repository(String type, String name, String contact,
|
public Repository(String id, String type, String name, String contact,
|
||||||
String description, Permission... permissions)
|
String description, Permission... permissions)
|
||||||
{
|
{
|
||||||
|
this.id = id;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.contact = contact;
|
this.contact = contact;
|
||||||
@@ -107,6 +113,17 @@ public class Repository implements Serializable
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -164,6 +181,17 @@ public class Repository implements Serializable
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
public void setId(String id)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -205,6 +233,9 @@ public class Repository implements Serializable
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String id;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.repository;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.Handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public interface RepositoryHandler
|
||||||
|
extends Handler<Repository, RepositoryException>
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isConfigured();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public RepositoryType getType();
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class RepositoryHandlerNotFoundException extends RepositoryException
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final long serialVersionUID = 5270463060802850944L;
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public RepositoryHandlerNotFoundException() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public RepositoryHandlerNotFoundException(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,15 +9,20 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.Handler;
|
||||||
import sonia.scm.ListenerSupport;
|
import sonia.scm.ListenerSupport;
|
||||||
import sonia.scm.Manager;
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public interface RepositoryManager
|
public interface RepositoryManager
|
||||||
extends Manager<Repository, RepositoryException>, ListenerSupport<RepositoryListener>
|
extends Handler<Repository, RepositoryException>,
|
||||||
|
ListenerSupport<RepositoryListener>
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,5 +31,5 @@ public interface RepositoryManager
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RepositoryType getType();
|
public Collection<RepositoryType> getTypes();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ import com.google.inject.servlet.ServletModule;
|
|||||||
|
|
||||||
import sonia.scm.api.rest.UriExtensionsConfig;
|
import sonia.scm.api.rest.UriExtensionsConfig;
|
||||||
import sonia.scm.filter.GZipFilter;
|
import sonia.scm.filter.GZipFilter;
|
||||||
|
import sonia.scm.filter.SecurityFilter;
|
||||||
import sonia.scm.filter.StaticResourceFilter;
|
import sonia.scm.filter.StaticResourceFilter;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.security.Authenticator;
|
import sonia.scm.security.Authenticator;
|
||||||
import sonia.scm.security.DemoAuthenticator;
|
import sonia.scm.security.DemoAuthenticator;
|
||||||
import sonia.scm.security.SecurityFilter;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -79,8 +81,12 @@ public class ContextListener extends GuiceServletContextListener
|
|||||||
@Override
|
@Override
|
||||||
protected void configureServlets()
|
protected void configureServlets()
|
||||||
{
|
{
|
||||||
|
SCMContextProvider context = SCMContext.getContext();
|
||||||
|
|
||||||
bind(Authenticator.class).to(DemoAuthenticator.class);
|
bind(Authenticator.class).to(DemoAuthenticator.class);
|
||||||
bind(SCMContextProvider.class).toInstance(SCMContext.getContext());
|
bind(SCMContextProvider.class).toInstance(context);
|
||||||
|
bind(RepositoryManager.class).toInstance(
|
||||||
|
context.getRepositoryManager());
|
||||||
|
|
||||||
// filters
|
// filters
|
||||||
filter(PATTERN_PAGE,
|
filter(PATTERN_PAGE,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import com.google.inject.Inject;
|
|||||||
import sonia.scm.SCMContext;
|
import sonia.scm.SCMContext;
|
||||||
import sonia.scm.ScmState;
|
import sonia.scm.ScmState;
|
||||||
import sonia.scm.User;
|
import sonia.scm.User;
|
||||||
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.repository.RepositoryType;
|
import sonia.scm.repository.RepositoryType;
|
||||||
import sonia.scm.security.Authenticator;
|
import sonia.scm.security.Authenticator;
|
||||||
|
|
||||||
@@ -111,8 +112,7 @@ public class AuthenticationResource
|
|||||||
|
|
||||||
state.setUser(user);
|
state.setUser(user);
|
||||||
state.setRepositoryTypes(
|
state.setRepositoryTypes(
|
||||||
SCMContext.getContext().getRepositoryTypes().toArray(
|
repositoryManger.getTypes().toArray(new RepositoryType[0]));
|
||||||
new RepositoryType[0]));
|
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -122,4 +122,8 @@ public class AuthenticationResource
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
@Inject
|
@Inject
|
||||||
private Authenticator authenticator;
|
private Authenticator authenticator;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@Inject
|
||||||
|
private RepositoryManager repositoryManger;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import sonia.scm.repository.Repository;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
@@ -45,29 +45,31 @@ public class RepositoryResource extends AbstractResource<Repository>
|
|||||||
{
|
{
|
||||||
repositoryStore = new LinkedHashMap<String, Repository>();
|
repositoryStore = new LinkedHashMap<String, Repository>();
|
||||||
repositoryStore.put("sonia.lib",
|
repositoryStore.put("sonia.lib",
|
||||||
new Repository("hg", "sonia.lib", "csit@ostfalia.de",
|
new Repository(createId(), "hg", "sonia.lib",
|
||||||
"SONIA Library",
|
"csit@ostfalia.de", "SONIA Library",
|
||||||
new Permission("csit", true, true,
|
new Permission("csit", true, true,
|
||||||
true)));
|
true)));
|
||||||
repositoryStore.put("sonia.misc",
|
repositoryStore.put("sonia.misc",
|
||||||
new Repository("hg", "sonia.misc", "csit@ostfalia.de",
|
new Repository(createId(), "hg", "sonia.misc",
|
||||||
|
"csit@ostfalia.de",
|
||||||
"SONIA Miscelanious",
|
"SONIA Miscelanious",
|
||||||
new Permission("csit", true, true,
|
new Permission("csit", true, true,
|
||||||
true)));
|
true)));
|
||||||
repositoryStore.put("PWA",
|
repositoryStore.put("PWA",
|
||||||
new Repository("svn", "PWA",
|
new Repository(createId(), "svn", "PWA",
|
||||||
"csit@fh-wolfenbuettel.de", "PWA",
|
"csit@fh-wolfenbuettel.de", "PWA",
|
||||||
new Permission("th", true, true),
|
new Permission("th", true, true),
|
||||||
new Permission("sdorra", true, true),
|
new Permission("sdorra", true, true),
|
||||||
new Permission("oelkersd", true,
|
new Permission("oelkersd", true,
|
||||||
false)));
|
false)));
|
||||||
repositoryStore.put("sonia.app",
|
repositoryStore.put("sonia.app",
|
||||||
new Repository("hg", "sonia.app", "csit@ostfalia.de",
|
new Repository(createId(), "hg", "sonia.app",
|
||||||
|
"csit@ostfalia.de",
|
||||||
"SONIA Applications",
|
"SONIA Applications",
|
||||||
new Permission("csit", true, true,
|
new Permission("csit", true, true,
|
||||||
true)));
|
true)));
|
||||||
repositoryStore.put("sonia.webapps",
|
repositoryStore.put("sonia.webapps",
|
||||||
new Repository("hg", "sonia.webapps",
|
new Repository(createId(), "hg", "sonia.webapps",
|
||||||
"csit@ostfalia.de",
|
"csit@ostfalia.de",
|
||||||
"SONIA WebApplications",
|
"SONIA WebApplications",
|
||||||
new Permission("csit", true, true,
|
new Permission("csit", true, true,
|
||||||
@@ -173,6 +175,19 @@ public class RepositoryResource extends AbstractResource<Repository>
|
|||||||
return PATH_PART;
|
return PATH_PART;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String createId()
|
||||||
|
{
|
||||||
|
return UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.security;
|
package sonia.scm.filter;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
@@ -13,7 +13,6 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import sonia.scm.User;
|
import sonia.scm.User;
|
||||||
import sonia.scm.filter.HttpFilter;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -26,6 +25,7 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequestWrapper;
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import sonia.scm.security.Authenticator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -75,7 +75,7 @@ public class DemoAuthenticator implements Authenticator
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public User getUser(HttpServletRequest request)
|
public User getUser(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
User user = null;
|
User user = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user