mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
implementing SCMContextProvider
This commit is contained in:
@@ -3,27 +3,183 @@
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.group.GroupManager;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.util.ServiceUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class BasicContextProvider implements SCMContextProvider {
|
||||
public class BasicContextProvider implements SCMContextProvider
|
||||
{
|
||||
|
||||
@Override
|
||||
public GroupManager getGroupManager()
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_DEFAULT = ".scm";
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_ENVIRONMENT = "SCM_HOME";
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_PROPERTY = "scm.home";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public BasicContextProvider()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
baseDirectory = findBaseDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositoryManager getRepositoryManager()
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
loadGroupManagers();
|
||||
loadRepositoryManagers();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public File getBaseDirectory()
|
||||
{
|
||||
return baseDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GroupManager getGroupManager(String type)
|
||||
{
|
||||
return groupManagerMap.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public RepositoryManager getRepositoryManager(String type)
|
||||
{
|
||||
return repositoryManagerMap.get(type);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private File findBaseDirectory()
|
||||
{
|
||||
String path = System.getProperty(DIRECTORY_PROPERTY);
|
||||
|
||||
if (Util.isEmpty(path))
|
||||
{
|
||||
path = System.getenv(DIRECTORY_ENVIRONMENT);
|
||||
|
||||
if (Util.isEmpty(path))
|
||||
{
|
||||
path = System.getProperty("user.home").concat(File.separator).concat(
|
||||
DIRECTORY_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
File directory = new File(path);
|
||||
|
||||
if (!directory.exists() &&!directory.mkdirs())
|
||||
{
|
||||
throw new IllegalStateException("could not create directory");
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
private void loadGroupManagers()
|
||||
{
|
||||
groupManagerMap = new HashMap<String, GroupManager>();
|
||||
|
||||
List<GroupManager> groupManagers =
|
||||
ServiceUtil.getServices(GroupManager.class);
|
||||
|
||||
for (GroupManager manager : groupManagers)
|
||||
{
|
||||
manager.init(this);
|
||||
groupManagerMap.put(manager.getType(), manager);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
private void loadRepositoryManagers()
|
||||
{
|
||||
repositoryManagerMap = new HashMap<String, RepositoryManager>();
|
||||
|
||||
List<RepositoryManager> repositoryManagers =
|
||||
ServiceUtil.getServices(RepositoryManager.class);
|
||||
|
||||
for (RepositoryManager manager : repositoryManagers)
|
||||
{
|
||||
manager.init(this);
|
||||
repositoryManagerMap.put(manager.getType().getName(), manager);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private File baseDirectory;
|
||||
|
||||
/** Field description */
|
||||
private Map<String, GroupManager> groupManagerMap;
|
||||
|
||||
/** Field description */
|
||||
private Map<String, RepositoryManager> repositoryManagerMap;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ package sonia.scm;
|
||||
import sonia.scm.group.GroupManager;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -25,13 +29,25 @@ public interface SCMContextProvider
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public GroupManager getGroupManager();
|
||||
public File getBaseDirectory();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public RepositoryManager getRepositoryManager();
|
||||
public GroupManager getGroupManager(String type);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public RepositoryManager getRepositoryManager(String type);
|
||||
}
|
||||
|
||||
@@ -15,4 +15,14 @@ import sonia.scm.Manager;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface GroupManager extends Manager<Group, GroupException> {}
|
||||
public interface GroupManager extends Manager<Group, GroupException>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getType();
|
||||
}
|
||||
|
||||
@@ -16,4 +16,14 @@ import sonia.scm.Manager;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface RepositoryManager
|
||||
extends Manager<Repository, RepositoryException> {}
|
||||
extends Manager<Repository, RepositoryException>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public RepositoryType getType();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user