mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
Implemented persisting repositories according to namespace changes
Repository directories are now named after the repo's id instead of it's name
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* 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
|
||||
@@ -24,113 +24,67 @@
|
||||
* 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.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class DummyRepositoryHandler
|
||||
extends AbstractSimpleRepositoryHandler<SimpleRepositoryConfig>
|
||||
{
|
||||
extends AbstractSimpleRepositoryHandler<SimpleRepositoryConfig> {
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE_DISPLAYNAME = "Dummy";
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE_NAME = "dummy";
|
||||
|
||||
/** Field description */
|
||||
public static final Type TYPE = new Type(TYPE_NAME, TYPE_DISPLAYNAME);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
private Set<String> existingRepoNames = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param storeFactory
|
||||
*/
|
||||
public DummyRepositoryHandler(ConfigurationStoreFactory storeFactory)
|
||||
{
|
||||
public DummyRepositoryHandler(ConfigurationStoreFactory storeFactory) {
|
||||
super(storeFactory, new DefaultFileSystem());
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Type getType()
|
||||
{
|
||||
public Type getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param directory
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
protected void create(Repository repository, File directory)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
|
||||
// do nothing
|
||||
throws RepositoryException {
|
||||
if (existingRepoNames.contains(repository.getNamespace() + repository.getName())) {
|
||||
throw new RepositoryAlreadyExistsException("Repo exists");
|
||||
} else {
|
||||
existingRepoNames.add(repository.getNamespace() + repository.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected SimpleRepositoryConfig createInitialConfig()
|
||||
{
|
||||
protected SimpleRepositoryConfig createInitialConfig() {
|
||||
return new SimpleRepositoryConfig();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Class<SimpleRepositoryConfig> getConfigClass()
|
||||
{
|
||||
protected Class<SimpleRepositoryConfig> getConfigClass() {
|
||||
return SimpleRepositoryConfig.class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public final class RepositoryTestData
|
||||
heartOfGold.setName("HeartOfGold");
|
||||
heartOfGold.setDescription(
|
||||
"Heart of Gold is the first prototype ship to successfully utilise the revolutionary Infinite Improbability Drive");
|
||||
|
||||
heartOfGold.setId("hogId");
|
||||
return heartOfGold;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* 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
|
||||
@@ -24,169 +24,94 @@
|
||||
* 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.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase
|
||||
{
|
||||
public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
|
||||
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
protected abstract void checkDirectory(File directory);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param factory
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract RepositoryHandler createRepositoryHandler(
|
||||
ConfigurationStoreFactory factory, File directory);
|
||||
ConfigurationStoreFactory factory, File directory);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testCreate() throws RepositoryException, IOException
|
||||
{
|
||||
public void testCreate() throws RepositoryException, IOException {
|
||||
createRepository();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test(expected = RepositoryAlreadyExistsException.class)
|
||||
public void testCreateExisitingRepository()
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
throws RepositoryException, IOException {
|
||||
createRepository();
|
||||
createRepository();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testCreateResourcePath() throws RepositoryException, IOException
|
||||
{
|
||||
public void testCreateResourcePath() throws RepositoryException, IOException {
|
||||
Repository repository = createRepository();
|
||||
String path = handler.createResourcePath(repository);
|
||||
|
||||
assertNotNull(path);
|
||||
assertTrue(path.trim().length() > 0);
|
||||
assertTrue(path.contains(repository.getName()));
|
||||
assertTrue(path.contains(repository.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testDelete() throws RepositoryException, IOException
|
||||
{
|
||||
public void testDelete() throws RepositoryException, IOException {
|
||||
Repository repository = createRepository();
|
||||
|
||||
handler.delete(repository);
|
||||
|
||||
File directory = new File(baseDirectory, repository.getName());
|
||||
File directory = new File(baseDirectory, repository.getId());
|
||||
|
||||
assertFalse(directory.exists());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void postSetUp() throws Exception
|
||||
{
|
||||
protected void postSetUp() throws Exception {
|
||||
InMemoryConfigurationStoreFactory storeFactory = new InMemoryConfigurationStoreFactory();
|
||||
baseDirectory = new File(contextProvider.getBaseDirectory(), "repositories");
|
||||
IOUtil.mkdirs(baseDirectory);
|
||||
handler = createRepositoryHandler(storeFactory, baseDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void preTearDown() throws Exception
|
||||
{
|
||||
if (handler != null)
|
||||
{
|
||||
protected void preTearDown() throws Exception {
|
||||
if (handler != null) {
|
||||
handler.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private Repository createRepository() throws RepositoryException, IOException
|
||||
{
|
||||
private Repository createRepository() throws RepositoryException, IOException {
|
||||
Repository repository = RepositoryTestData.createHeartOfGold();
|
||||
|
||||
handler.create(repository);
|
||||
|
||||
File directory = new File(baseDirectory, repository.getName());
|
||||
File directory = new File(baseDirectory, repository.getId());
|
||||
|
||||
assertTrue(directory.exists());
|
||||
assertTrue(directory.isDirectory());
|
||||
@@ -195,11 +120,8 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase
|
||||
return repository;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected File baseDirectory;
|
||||
|
||||
/** Field description */
|
||||
private RepositoryHandler handler;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user