implementing SCMContextProvider

This commit is contained in:
Sebastian Sdorra
2010-09-08 15:58:12 +02:00
parent 6250565bf3
commit 4b74fc9cf1
4 changed files with 203 additions and 11 deletions

View File

@@ -3,27 +3,183 @@
* and open the template in the editor. * and open the template in the editor.
*/ */
package sonia.scm; package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.group.GroupManager; import sonia.scm.group.GroupManager;
import sonia.scm.repository.RepositoryManager; 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 * @author Sebastian Sdorra
*/ */
public class BasicContextProvider implements SCMContextProvider { public class BasicContextProvider implements SCMContextProvider
{
@Override /** Field description */
public GroupManager getGroupManager() 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 //~--- methods --------------------------------------------------------------
public RepositoryManager getRepositoryManager()
/**
* 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;
} }

View File

@@ -12,6 +12,10 @@ package sonia.scm;
import sonia.scm.group.GroupManager; import sonia.scm.group.GroupManager;
import sonia.scm.repository.RepositoryManager; import sonia.scm.repository.RepositoryManager;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
/** /**
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
@@ -25,13 +29,25 @@ public interface SCMContextProvider
* *
* @return * @return
*/ */
public GroupManager getGroupManager(); public File getBaseDirectory();
/** /**
* Method description * Method description
* *
* *
*
* @param type
* @return * @return
*/ */
public RepositoryManager getRepositoryManager(); public GroupManager getGroupManager(String type);
/**
* Method description
*
*
*
* @param type
* @return
*/
public RepositoryManager getRepositoryManager(String type);
} }

View File

@@ -15,4 +15,14 @@ import sonia.scm.Manager;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public interface GroupManager extends Manager<Group, GroupException> {} public interface GroupManager extends Manager<Group, GroupException>
{
/**
* Method description
*
*
* @return
*/
public String getType();
}

View File

@@ -16,4 +16,14 @@ import sonia.scm.Manager;
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public interface RepositoryManager public interface RepositoryManager
extends Manager<Repository, RepositoryException> {} extends Manager<Repository, RepositoryException>
{
/**
* Method description
*
*
* @return
*/
public RepositoryType getType();
}