From 5a8288337b391a18be5d7d58ff42e4c30ea93068 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 8 Sep 2010 17:08:34 +0200 Subject: [PATCH] added scm-hg-plugin --- plugins/scm-hg-plugin/pom.xml | 18 ++ .../java/sonia/scm/repository/HgConfig.java | 85 +++++++ .../scm/repository/HgRepositoryManager.java | 208 ++++++++++++++++++ .../sonia.scm.repository.RepositoryManager | 1 + .../sonia/scm/ConfigurationException.java | 64 ++++++ scm-core/src/main/java/sonia/scm/Manager.java | 8 + 6 files changed, 384 insertions(+) create mode 100644 plugins/scm-hg-plugin/pom.xml create mode 100644 plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java create mode 100644 plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryManager.java create mode 100644 plugins/scm-hg-plugin/src/main/resources/META-INF/services/sonia.scm.repository.RepositoryManager create mode 100644 scm-core/src/main/java/sonia/scm/ConfigurationException.java diff --git a/plugins/scm-hg-plugin/pom.xml b/plugins/scm-hg-plugin/pom.xml new file mode 100644 index 0000000000..6e9872b121 --- /dev/null +++ b/plugins/scm-hg-plugin/pom.xml @@ -0,0 +1,18 @@ + + + + 4.0.0 + + + sonia.scm.plugins + scm-plugins + 1.0-SNAPSHOT + + + sonia.scm.plugin + scm-hg-plugin + 1.0-SNAPSHOT + scm-hg-plugin + + diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java new file mode 100644 index 0000000000..4c2be86c65 --- /dev/null +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java @@ -0,0 +1,85 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + + +package sonia.scm.repository; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Sebastian Sdorra + */ +@XmlRootElement(name = "config") +public class HgConfig +{ + + /** + * Constructs ... + * + */ + public HgConfig() {} + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public File getConfigDirectory() + { + return configDirectory; + } + + /** + * Method description + * + * + * @return + */ + public File getRepositoryDirectory() + { + return repositoryDirectory; + } + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param configDirectory + */ + public void setConfigDirectory(File configDirectory) + { + this.configDirectory = configDirectory; + } + + /** + * Method description + * + * + * @param repositoryDirectory + */ + public void setRepositoryDirectory(File repositoryDirectory) + { + this.repositoryDirectory = repositoryDirectory; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private File configDirectory; + + /** Field description */ + private File repositoryDirectory; +} diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryManager.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryManager.java new file mode 100644 index 0000000000..f0e9831ee1 --- /dev/null +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryManager.java @@ -0,0 +1,208 @@ +/* + * 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.AssertUtil; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.IOException; + +import java.util.Collection; + +import javax.xml.bind.JAXB; + +/** + * + * @author Sebastian Sdorra + */ +public class HgRepositoryManager implements RepositoryManager +{ + + /** Field description */ + public static final String TYPE_DISPLAYNAME = "Mercurial"; + + /** Field description */ + public static final String TYPE_NAME = "hg"; + + /** Field description */ + public static final RepositoryType TYPE = new RepositoryType(TYPE_NAME, + TYPE_DISPLAYNAME); + + /** Field description */ + public static final String DEFAULT_CONFIGPATH = + "repositories".concat(File.separator).concat(TYPE_NAME); + + /** Field description */ + public static final String CONFIG_FILE = + "config".concat(File.separator).concat("hg.xml"); + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @throws IOException + */ + @Override + public void close() throws IOException {} + + /** + * Method description + * + * + * @param repository + * + * @throws IOException + * @throws RepositoryException + */ + @Override + public void create(Repository repository) + throws RepositoryException, IOException + { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Method description + * + * + * @param repository + * + * @throws IOException + * @throws RepositoryException + */ + @Override + public void delete(Repository repository) + throws RepositoryException, IOException + { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Method description + * + * + * @param context + */ + @Override + public void init(SCMContextProvider context) + { + File baseDirectory = context.getBaseDirectory(); + + AssertUtil.assertIsNotNull(baseDirectory); + + File configFile = new File(baseDirectory, CONFIG_FILE); + + if (configFile.exists()) + { + config = JAXB.unmarshal(configFile, HgConfig.class); + + if (config.getConfigDirectory() == null) + { + File configDirectory = new File(baseDirectory, DEFAULT_CONFIGPATH); + + config.setConfigDirectory(configDirectory); + } + } + } + + /** + * Method description + * + * + * @param repository + * + * @throws IOException + * @throws RepositoryException + */ + @Override + public void modify(Repository repository) + throws RepositoryException, IOException + { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Method description + * + * + * @param repository + * + * @throws IOException + * @throws RepositoryException + */ + @Override + public void refresh(Repository repository) + throws RepositoryException, IOException + { + throw new UnsupportedOperationException("Not supported yet."); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param name + * + * @return + */ + @Override + public Repository get(String name) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Method description + * + * + * @return + */ + @Override + public Collection getAll() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Method description + * + * + * @return + */ + @Override + public RepositoryType getType() + { + return TYPE; + } + + /** + * Method description + * + * + * @return + */ + @Override + public boolean isConfigured() + { + return config != null; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private HgConfig config; +} diff --git a/plugins/scm-hg-plugin/src/main/resources/META-INF/services/sonia.scm.repository.RepositoryManager b/plugins/scm-hg-plugin/src/main/resources/META-INF/services/sonia.scm.repository.RepositoryManager new file mode 100644 index 0000000000..f975333410 --- /dev/null +++ b/plugins/scm-hg-plugin/src/main/resources/META-INF/services/sonia.scm.repository.RepositoryManager @@ -0,0 +1 @@ +sonia.scm.repository.HgRepositoryManager \ No newline at end of file diff --git a/scm-core/src/main/java/sonia/scm/ConfigurationException.java b/scm-core/src/main/java/sonia/scm/ConfigurationException.java new file mode 100644 index 0000000000..3fec176177 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/ConfigurationException.java @@ -0,0 +1,64 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + + +package sonia.scm; + +/** + * + * @author Sebastian Sdorra + */ +public class ConfigurationException extends RuntimeException +{ + + /** Field description */ + private static final long serialVersionUID = 3462977946341972841L; + + //~--- constructors --------------------------------------------------------- + + /** + * Constructs ... + * + */ + public ConfigurationException() + { + super(); + } + + /** + * Constructs ... + * + * + * @param message + */ + public ConfigurationException(String message) + { + super(message); + } + + /** + * Constructs ... + * + * + * @param cause + */ + public ConfigurationException(Throwable cause) + { + super(cause); + } + + /** + * Constructs ... + * + * + * @param message + * @param cause + */ + public ConfigurationException(String message, Throwable cause) + { + super(message, cause); + } +} diff --git a/scm-core/src/main/java/sonia/scm/Manager.java b/scm-core/src/main/java/sonia/scm/Manager.java index d964c6bc45..41276842f0 100644 --- a/scm-core/src/main/java/sonia/scm/Manager.java +++ b/scm-core/src/main/java/sonia/scm/Manager.java @@ -87,4 +87,12 @@ public interface Manager extends Initable, Closeable * @return */ public Collection getAll(); + + /** + * Method description + * + * + * @return + */ + public boolean isConfigured(); }