Refactor the repository store implementation in order to store repositories in specific paths.

This commit is contained in:
Mohamed Karray
2018-11-15 10:04:16 +01:00
parent 2cd2cfbde2
commit f8ae7cedf7
51 changed files with 628 additions and 594 deletions

View File

@@ -37,7 +37,6 @@ package sonia.scm.repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.AlreadyExistsException;
import sonia.scm.repository.ImportResult.Builder;
import java.io.File;
@@ -230,49 +229,10 @@ public abstract class AbstactImportHandler implements AdvancedImportHandler
// }
}
/**
* Method description
*
*
* @param manager
* @param repositoryName
*
*
* @return
* @throws IOException
*/
private void importRepository(RepositoryManager manager,
String repositoryName)
throws IOException, AlreadyExistsException {
Repository repository =
createRepository(getRepositoryDirectory(repositoryName), repositoryName);
if (logger.isInfoEnabled())
{
logger.info("import repository {} of type {}", repositoryName,
getTypeName());
}
manager.importRepository(repository);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repositoryName
*
* @return
*/
private File getRepositoryDirectory(String repositoryName)
{
return new File(
getRepositoryHandler().getConfig().getRepositoryDirectory(),
repositoryName);
}
/**
* Method description
*

View File

@@ -44,7 +44,6 @@ import sonia.scm.io.CommandResult;
import sonia.scm.io.ExtendedCommand;
import sonia.scm.io.FileSystem;
import sonia.scm.store.ConfigurationStoreFactory;
import sonia.scm.util.IOUtil;
import java.io.File;
import java.io.IOException;
@@ -61,8 +60,6 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
public static final String DEFAULT_VERSION_INFORMATION = "unknown";
public static final String DIRECTORY_REPOSITORY = "repositories";
public static final String DOT = ".";
/**
@@ -72,19 +69,20 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
LoggerFactory.getLogger(AbstractSimpleRepositoryHandler.class);
private FileSystem fileSystem;
private final RepositoryLocationResolver repositoryLocationResolver;
public AbstractSimpleRepositoryHandler(ConfigurationStoreFactory storeFactory,
FileSystem fileSystem) {
FileSystem fileSystem, RepositoryLocationResolver repositoryLocationResolver) {
super(storeFactory);
this.fileSystem = fileSystem;
this.repositoryLocationResolver = repositoryLocationResolver;
}
@Override
public Repository create(Repository repository) throws AlreadyExistsException {
File directory = getDirectory(repository);
if (directory.exists()) {
File directory = repositoryLocationResolver.getInitialNativeDirectory(repository);
if (directory != null && directory.exists()) {
throw new AlreadyExistsException();
}
@@ -96,7 +94,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
postCreate(repository, directory);
return repository;
} catch (Exception ex) {
if (directory.exists()) {
if (directory != null && directory.exists()) {
logger.warn("delete repository directory {}, because of failed repository creation", directory);
try {
fileSystem.destroy(directory);
@@ -122,18 +120,15 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
@Override
public void delete(Repository repository) {
File directory = getDirectory(repository);
if (directory.exists()) {
try {
try {
File directory = repositoryLocationResolver.getRepositoryDirectory(repository);
if (directory.exists()) {
fileSystem.destroy(directory);
} catch (IOException e) {
throw new InternalRepositoryException("could not delete repository directory", e);
} else {
logger.warn("repository {} not found", repository.getNamespaceAndName());
}
cleanupEmptyDirectories(config.getRepositoryDirectory(),
directory.getParentFile());
} else {
logger.warn("repository {} not found", repository.getNamespaceAndName());
} catch (IOException e) {
throw new InternalRepositoryException("could not delete repository directory", e);
}
}
@@ -143,21 +138,6 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
if (config == null) {
config = createInitialConfig();
if (config != null) {
File repositoryDirectory = config.getRepositoryDirectory();
if (repositoryDirectory == null) {
repositoryDirectory = new File(
baseDirectory,
DIRECTORY_REPOSITORY.concat(File.separator).concat(
getType().getName()));
config.setRepositoryDirectory(repositoryDirectory);
}
IOUtil.mkdirs(repositoryDirectory);
storeConfig();
}
}
}
@@ -169,27 +149,24 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
@Override
public File getDirectory(Repository repository) {
File directory = null;
File directory;
if (isConfigured()) {
File repositoryDirectory = config.getRepositoryDirectory();
directory = new File(repositoryDirectory, repository.getId());
if (!IOUtil.isChild(repositoryDirectory, directory)) {
StringBuilder msg = new StringBuilder(directory.getPath());
msg.append("is not a child of ").append(repositoryDirectory.getPath());
throw new ConfigurationException(msg.toString());
try {
directory = repositoryLocationResolver.getNativeDirectory(repository);
} catch (IOException e) {
throw new ConfigurationException("Error on getting the current repository directory");
}
} else {
throw new ConfigurationException("RepositoryHandler is not configured");
}
return directory;
}
@Override
public File getInitialBaseDirectory() {
return repositoryLocationResolver.getInitialBaseDirectory();
}
@Override
public String getVersionInformation() {
return DEFAULT_VERSION_INFORMATION;
@@ -259,7 +236,10 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
* @throws AlreadyExistsException
*/
private void checkPath(File directory) throws AlreadyExistsException {
File repositoryDirectory = config.getRepositoryDirectory();
if (directory == null) {
return;
}
File repositoryDirectory = getInitialBaseDirectory();
File parent = directory.getParentFile();
while ((parent != null) && !repositoryDirectory.equals(parent)) {
@@ -275,25 +255,5 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
}
}
private void cleanupEmptyDirectories(File baseDirectory, File directory) {
if (IOUtil.isChild(baseDirectory, directory)) {
if (IOUtil.isEmpty(directory)) {
// TODO use filesystem
if (directory.delete()) {
logger.info("successfully deleted directory {}", directory);
cleanupEmptyDirectories(baseDirectory, directory.getParentFile());
} else {
logger.warn("could not delete directory {}", directory);
}
} else {
logger.debug("could not remove non empty directory {}", directory);
}
} else {
logger.warn("directory {} is not a child of {}", directory, baseDirectory);
}
}
}

View File

@@ -0,0 +1,58 @@
package sonia.scm.repository;
import sonia.scm.SCMContextProvider;
import sonia.scm.io.FileSystem;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
/**
*
* A Location Resolver for File based Repository Storage.
*
* WARNING: The Locations provided with this class may not be used from the plugins to store any plugin specific files.
*
* Please use the {@link sonia.scm.store.DataStoreFactory } and the {@link sonia.scm.store.DataStore} classes to store data
* Please use the {@link sonia.scm.store.BlobStoreFactory } and the {@link sonia.scm.store.BlobStore} classes to store binary files
* Please use the {@link sonia.scm.store.ConfigurationStoreFactory} and the {@link sonia.scm.store.ConfigurationStore} classes to store configurations
*
* @author Mohamed Karray
* @since 2.0.0
*/
public final class InitialRepositoryLocationResolver {
private static final String REPOSITORIES_DIRECTORY = "repositories";
public static final String REPOSITORIES_NATIVE_DIRECTORY = "data";
private SCMContextProvider context;
private FileSystem fileSystem;
@Inject
public InitialRepositoryLocationResolver(SCMContextProvider context, FileSystem fileSystem) {
this.context = context;
this.fileSystem = fileSystem;
}
public static File getNativeDirectory(File repositoriesDirectory, String repositoryId) {
return new File(repositoriesDirectory, repositoryId
.concat(File.separator)
.concat(REPOSITORIES_NATIVE_DIRECTORY));
}
public File getBaseDirectory() {
return new File(context.getBaseDirectory(), REPOSITORIES_DIRECTORY);
}
public File createDirectory(Repository repository) throws IOException {
File initialRepoFolder = getDirectory(repository);
fileSystem.create(initialRepoFolder);
return initialRepoFolder;
}
public File getDirectory(Repository repository) {
return new File(context.getBaseDirectory(), REPOSITORIES_DIRECTORY
.concat(File.separator)
.concat(repository.getId()));
}
}

View File

@@ -0,0 +1,20 @@
package sonia.scm.repository;
import java.nio.file.Path;
/**
* A DAO used for Repositories accessible by a path
*
* @author Mohamed Karray
* @since 2.0.0
*/
public interface PathBasedRepositoryDAO extends RepositoryDAO {
/**
* get the current path of the repository
*
* @param repository
* @return the current path of the repository
*/
Path getPath(Repository repository) throws RepositoryPathNotFoundException;
}

View File

@@ -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,13 +24,11 @@
* 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;
import sonia.scm.Validateable;
@@ -38,7 +36,6 @@ import sonia.scm.config.Configuration;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.io.File;
/**
* Basic {@link Repository} configuration class.
@@ -46,20 +43,10 @@ import java.io.File;
* @author Sebastian Sdorra
*/
@XmlRootElement
public abstract class RepositoryConfig implements Validateable, Configuration
{
/**
* Returns the directory for the repositories.
*
*
* @return directory for the repositories
*/
public File getRepositoryDirectory()
{
return repositoryDirectory;
}
public abstract class RepositoryConfig implements Validateable, Configuration {
/** true if the plugin is disabled */
private boolean disabled = false;
/**
* Returns true if the plugin is disabled.
*
@@ -67,8 +54,7 @@ public abstract class RepositoryConfig implements Validateable, Configuration
* @return true if the plugin is disabled
* @since 1.13
*/
public boolean isDisabled()
{
public boolean isDisabled() {
return disabled;
}
@@ -79,9 +65,8 @@ public abstract class RepositoryConfig implements Validateable, Configuration
* @return true if the configuration object is valid
*/
@Override
public boolean isValid()
{
return repositoryDirectory != null;
public boolean isValid() {
return true;
}
//~--- set methods ----------------------------------------------------------
@@ -93,29 +78,11 @@ public abstract class RepositoryConfig implements Validateable, Configuration
* @param disabled
* @since 1.13
*/
public void setDisabled(boolean disabled)
{
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
/**
* Sets the directory for the repositories
*
*
* @param repositoryDirectory directory for repositories
*/
public void setRepositoryDirectory(File repositoryDirectory)
{
this.repositoryDirectory = repositoryDirectory;
}
//~--- fields ---------------------------------------------------------------
/** true if the plugin is disabled */
private boolean disabled = false;
/** directory for repositories */
private File repositoryDirectory;
/**
* Specifies the identifier of the concrete {@link RepositoryConfig} when checking permissions of an object.

View File

@@ -40,8 +40,18 @@ import java.io.File;
* @author Sebastian Sdorra
* @since 1.36
*/
public interface RepositoryDirectoryHandler extends RepositoryHandler
{
public interface RepositoryDirectoryHandler extends RepositoryHandler {
public File getDirectory(Repository repository);
/**
* Get the current directory of the given repository
* @param repository
* @return the current directory of the given repository
*/
File getDirectory(Repository repository);
/**
* get the initial directory of all repositories
* @return the initial directory of all repositories
*/
File getInitialBaseDirectory();
}

View File

@@ -0,0 +1,73 @@
package sonia.scm.repository;
import groovy.lang.Singleton;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import static sonia.scm.repository.InitialRepositoryLocationResolver.REPOSITORIES_NATIVE_DIRECTORY;
/**
*
* A Location Resolver for File based Repository Storage.
*
* WARNING: The Locations provided with this class may not be used from the plugins to store any plugin specific files.
*
* Please use the {@link sonia.scm.store.DataStoreFactory } and the {@link sonia.scm.store.DataStore} classes to store data
* Please use the {@link sonia.scm.store.BlobStoreFactory } and the {@link sonia.scm.store.BlobStore} classes to store binary files
* Please use the {@link sonia.scm.store.ConfigurationStoreFactory} and the {@link sonia.scm.store.ConfigurationStore} classes to store configurations
*
* @author Mohamed Karray
* @since 2.0.0
*/
@Singleton
public class RepositoryLocationResolver {
private RepositoryDAO repositoryDAO;
private InitialRepositoryLocationResolver initialRepositoryLocationResolver;
@Inject
public RepositoryLocationResolver(RepositoryDAO repositoryDAO, InitialRepositoryLocationResolver initialRepositoryLocationResolver) {
this.repositoryDAO = repositoryDAO;
this.initialRepositoryLocationResolver = initialRepositoryLocationResolver;
}
/**
* Get the current repository directory from the dao or create the initial directory if the repository does not exists
* @param repository
* @return the current repository directory from the dao or the initial directory if the repository does not exists
* @throws IOException
*/
public File getRepositoryDirectory(Repository repository) throws IOException {
if (repositoryDAO instanceof PathBasedRepositoryDAO) {
PathBasedRepositoryDAO pathBasedRepositoryDAO = (PathBasedRepositoryDAO) repositoryDAO;
try {
return pathBasedRepositoryDAO.getPath(repository).toFile();
} catch (RepositoryPathNotFoundException e) {
return createInitialDirectory(repository);
}
}
return createInitialDirectory(repository);
}
public File getInitialBaseDirectory() {
return initialRepositoryLocationResolver.getBaseDirectory();
}
public File createInitialDirectory(Repository repository) throws IOException {
return initialRepositoryLocationResolver.createDirectory(repository);
}
public File getInitialDirectory(Repository repository) {
return initialRepositoryLocationResolver.getDirectory(repository);
}
public File getNativeDirectory(Repository repository) throws IOException {
return new File (getRepositoryDirectory(repository), REPOSITORIES_NATIVE_DIRECTORY);
}
public File getInitialNativeDirectory(Repository repository) {
return new File (getInitialDirectory(repository), REPOSITORIES_NATIVE_DIRECTORY);
}
}

View File

@@ -0,0 +1,12 @@
package sonia.scm.repository;
public class RepositoryPathNotFoundException extends Exception {
public static final String REPOSITORY_PATH_NOT_FOUND = "Repository path not found";
public RepositoryPathNotFoundException() {
super(REPOSITORY_PATH_NOT_FOUND);
}
}

View File

@@ -66,16 +66,12 @@ public final class RepositoryUtil {
}
@SuppressWarnings("squid:S2083") // ignore, because the path is validated at {@link #getRepositoryId(File, File)}
public static String getRepositoryId(AbstractRepositoryHandler handler, String directoryPath) throws IOException {
return getRepositoryId(handler.getConfig().getRepositoryDirectory(), new File(directoryPath));
public static String getRepositoryId(RepositoryDirectoryHandler handler, String directoryPath) throws IOException {
return getRepositoryId(handler.getInitialBaseDirectory(), new File(directoryPath));
}
public static String getRepositoryId(AbstractRepositoryHandler handler, File directory) throws IOException {
return getRepositoryId(handler.getConfig(), directory);
}
public static String getRepositoryId(RepositoryConfig config, File directory) throws IOException {
return getRepositoryId(config.getRepositoryDirectory(), directory);
public static String getRepositoryId(RepositoryDirectoryHandler handler, File directory) throws IOException {
return getRepositoryId(handler.getInitialBaseDirectory(), directory);
}
public static String getRepositoryId(File baseDirectory, File directory) throws IOException {
@@ -87,7 +83,7 @@ public final class RepositoryUtil {
"repository path %s is not in the main repository path %s", path, basePath
);
String id = IOUtil.trimSeperatorChars(path.substring(basePath.length()));
String id = IOUtil.trimSeperatorChars(path.substring(basePath.length()).replace(InitialRepositoryLocationResolver.REPOSITORIES_NATIVE_DIRECTORY, ""));
Preconditions.checkArgument(
!id.contains("\\") && !id.contains("/"),

View File

@@ -21,25 +21,18 @@ public class RepositoryUtilTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Mock
private AbstractRepositoryHandler<RepositoryConfig> repositoryHandler;
private RepositoryDirectoryHandler repositoryHandler;
private RepositoryConfig repositoryConfig = new RepositoryConfig() {
@Override
public String getId() {
return "repository";
}
};
private File repositoryTypeRoot;
@Before
public void setUpMocks() {
when(repositoryHandler.getConfig()).thenReturn(repositoryConfig);
public void setUpMocks() throws IOException {
repositoryTypeRoot = temporaryFolder.newFolder();
when(repositoryHandler.getInitialBaseDirectory()).thenReturn(repositoryTypeRoot);
}
@Test
public void testGetRepositoryId() throws IOException {
File repositoryTypeRoot = temporaryFolder.newFolder();
repositoryConfig.setRepositoryDirectory(repositoryTypeRoot);
File repository = new File(repositoryTypeRoot, "abc");
String id = RepositoryUtil.getRepositoryId(repositoryHandler, repository.getPath());
assertEquals("abc", id);
@@ -47,9 +40,6 @@ public class RepositoryUtilTest {
@Test(expected = IllegalArgumentException.class)
public void testGetRepositoryIdWithInvalidPath() throws IOException {
File repositoryTypeRoot = temporaryFolder.newFolder();
repositoryConfig.setRepositoryDirectory(repositoryTypeRoot);
File repository = new File("/etc/abc");
String id = RepositoryUtil.getRepositoryId(repositoryHandler, repository.getPath());
assertEquals("abc", id);
@@ -57,9 +47,6 @@ public class RepositoryUtilTest {
@Test(expected = IllegalArgumentException.class)
public void testGetRepositoryIdWithInvalidPathButSameLength() throws IOException {
File repositoryTypeRoot = temporaryFolder.newFolder();
repositoryConfig.setRepositoryDirectory(repositoryTypeRoot);
File repository = new File(temporaryFolder.newFolder(), "abc");
String id = RepositoryUtil.getRepositoryId(repositoryHandler, repository.getPath());
@@ -68,9 +55,6 @@ public class RepositoryUtilTest {
@Test(expected = IllegalArgumentException.class)
public void testGetRepositoryIdWithInvalidId() throws IOException {
File repositoryTypeRoot = temporaryFolder.newFolder();
repositoryConfig.setRepositoryDirectory(repositoryTypeRoot);
File repository = new File(repositoryTypeRoot, "abc/123");
RepositoryUtil.getRepositoryId(repositoryHandler, repository.getPath());
}

View File

@@ -0,0 +1,90 @@
package sonia.scm.repository.xml;
import org.apache.commons.lang.StringUtils;
import sonia.scm.ModelObject;
import sonia.scm.repository.Repository;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
@XmlRootElement(name = "repository-link")
@XmlAccessorType(XmlAccessType.FIELD)
public class RepositoryPath implements ModelObject {
private String path;
private String id;
private Long lastModified;
private Long creationDate;
@XmlTransient
private Repository repository;
/**
* Needed from JAXB
*/
public RepositoryPath() {
}
public RepositoryPath(String path, String id, Repository repository) {
this.path = path;
this.id = id;
this.repository = repository;
}
public Repository getRepository() {
return repository;
}
public void setRepository(Repository repository) {
this.repository = repository;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
@Override
public String getId() {
return id;
}
@Override
public void setLastModified(Long lastModified) {
this.lastModified = lastModified;
}
@Override
public Long getCreationDate() {
return creationDate;
}
@Override
public void setCreationDate(Long creationDate) {
this.creationDate = creationDate;
}
public void setId(String id) {
this.id = id;
}
@Override
public Long getLastModified() {
return lastModified;
}
@Override
public String getType() {
return getRepository()!= null? getRepository().getType():"";
}
@Override
public boolean isValid() {
return StringUtils.isNotEmpty(path);
}
}

View File

@@ -36,80 +36,124 @@ package sonia.scm.repository.xml;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import sonia.scm.repository.InitialRepositoryLocationResolver;
import sonia.scm.repository.NamespaceAndName;
import sonia.scm.repository.PathBasedRepositoryDAO;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryDAO;
import sonia.scm.repository.RepositoryPathNotFoundException;
import sonia.scm.store.ConfigurationStoreFactory;
import sonia.scm.xml.AbstractXmlDAO;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Optional;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class XmlRepositoryDAO
extends AbstractXmlDAO<Repository, XmlRepositoryDatabase>
implements RepositoryDAO
{
extends AbstractXmlDAO<Repository, XmlRepositoryDatabase>
implements PathBasedRepositoryDAO {
/** Field description */
/**
* Field description
*/
public static final String STORE_NAME = "repositories";
private InitialRepositoryLocationResolver initialRepositoryLocationResolver;
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param storeFactory
*/
@Inject
public XmlRepositoryDAO(ConfigurationStoreFactory storeFactory)
{
public XmlRepositoryDAO(ConfigurationStoreFactory storeFactory, InitialRepositoryLocationResolver initialRepositoryLocationResolver) {
super(storeFactory.getStore(XmlRepositoryDatabase.class, STORE_NAME));
this.initialRepositoryLocationResolver = initialRepositoryLocationResolver;
}
//~--- methods --------------------------------------------------------------
@Override
public boolean contains(NamespaceAndName namespaceAndName)
{
public boolean contains(NamespaceAndName namespaceAndName) {
return db.contains(namespaceAndName);
}
//~--- get methods ----------------------------------------------------------
@Override
public Repository get(NamespaceAndName namespaceAndName)
{
public Repository get(NamespaceAndName namespaceAndName) {
return db.get(namespaceAndName);
}
//~--- methods --------------------------------------------------------------
@Override
public void modify(Repository repository) {
db.remove(repository.getId());
add(repository);
}
@Override
public void add(Repository repository) {
String path = initialRepositoryLocationResolver.getDirectory(repository).getAbsolutePath();
RepositoryPath repositoryPath = new RepositoryPath(path, repository.getId(), repository.clone());
synchronized (store) {
db.add(repositoryPath);
storeDB();
}
}
@Override
public Repository get(String id) {
RepositoryPath repositoryPath = db.get(id);
if (repositoryPath != null) {
return repositoryPath.getRepository();
}
return null;
}
@Override
public Collection<Repository> getAll() {
return db.getRepositories();
}
/**
* Method description
*
*
* @param repository
*
* @return
*/
@Override
protected Repository clone(Repository repository)
{
protected Repository clone(Repository repository) {
return repository.clone();
}
/**
* Method description
*
*
* @return
*/
@Override
protected XmlRepositoryDatabase createNewDatabase()
{
protected XmlRepositoryDatabase createNewDatabase() {
return new XmlRepositoryDatabase();
}
@Override
public Path getPath(Repository repository) throws RepositoryPathNotFoundException {
Optional<RepositoryPath> repositoryPath = db.getPaths().stream()
.filter(repoPath -> repoPath.getId().equals(repository.getId()))
.findFirst();
if (!repositoryPath.isPresent()) {
throw new RepositoryPathNotFoundException();
} else {
return Paths.get(repositoryPath.get().getPath());
}
}
}

View File

@@ -44,21 +44,29 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
//~--- JDK imports ------------------------------------------------------------
@XmlRootElement(name = "repository-db")
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlRepositoryDatabase implements XmlDatabase<Repository>
{
public class XmlRepositoryDatabase implements XmlDatabase<RepositoryPath> {
public XmlRepositoryDatabase()
{
private Long creationTime;
private Long lastModified;
@XmlJavaTypeAdapter(XmlRepositoryMapAdapter.class)
@XmlElement(name = "repositories")
private Map<String, RepositoryPath> repositoryPathMap = new LinkedHashMap<>();
public XmlRepositoryDatabase() {
long c = System.currentTimeMillis();
creationTime = c;
lastModified = c;
}
@@ -74,14 +82,14 @@ public class XmlRepositoryDatabase implements XmlDatabase<Repository>
}
@Override
public void add(Repository repository)
public void add(RepositoryPath repositoryPath)
{
repositoryMap.put(createKey(repository), repository);
repositoryPathMap.put(createKey(repositoryPath.getRepository()), repositoryPath);
}
public boolean contains(NamespaceAndName namespaceAndName)
{
return repositoryMap.containsKey(createKey(namespaceAndName));
return repositoryPathMap.containsKey(createKey(namespaceAndName));
}
@Override
@@ -92,61 +100,55 @@ public class XmlRepositoryDatabase implements XmlDatabase<Repository>
public boolean contains(Repository repository)
{
return repositoryMap.containsKey(createKey(repository));
return repositoryPathMap.containsKey(createKey(repository));
}
public void remove(Repository repository)
{
repositoryMap.remove(createKey(repository));
repositoryPathMap.remove(createKey(repository));
}
@Override
public Repository remove(String id)
public RepositoryPath remove(String id)
{
Repository r = get(id);
remove(r);
return r;
return repositoryPathMap.remove(createKey(get(id).getRepository()));
}
@Override
public Collection<Repository> values()
{
return repositoryMap.values();
}
//~--- get methods ----------------------------------------------------------
public Repository get(NamespaceAndName namespaceAndName)
{
return repositoryMap.get(createKey(namespaceAndName));
}
/**
* Method description
*
*
* @param id
*
* @return
*/
@Override
public Repository get(String id)
{
Repository repository = null;
for (Repository r : values())
{
if (r.getId().equals(id))
{
repository = r;
break;
}
public Collection<Repository> getRepositories() {
List<Repository> repositories = new ArrayList<>();
for (RepositoryPath repositoryPath : repositoryPathMap.values()) {
Repository repository = repositoryPath.getRepository();
repositories.add(repository);
}
return repositories;
}
return repository;
@Override
public Collection<RepositoryPath> values()
{
return repositoryPathMap.values();
}
public Collection<RepositoryPath> getPaths() {
return repositoryPathMap.values();
}
public Repository get(NamespaceAndName namespaceAndName) {
RepositoryPath repositoryPath = repositoryPathMap.get(createKey(namespaceAndName));
if (repositoryPath != null) {
return repositoryPath.getRepository();
}
return null;
}
@Override
public RepositoryPath get(String id) {
return values().stream()
.filter(repoPath -> repoPath.getId().equals(id))
.findFirst()
.orElse(null);
}
/**
@@ -198,17 +200,4 @@ public class XmlRepositoryDatabase implements XmlDatabase<Repository>
{
this.lastModified = lastModified;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Long creationTime;
/** Field description */
private Long lastModified;
/** Field description */
@XmlJavaTypeAdapter(XmlRepositoryMapAdapter.class)
@XmlElement(name = "repositories")
private Map<String, Repository> repositoryMap = new LinkedHashMap<>();
}

View File

@@ -54,7 +54,7 @@ import javax.xml.bind.annotation.XmlRootElement;
*/
@XmlRootElement(name = "repositories")
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlRepositoryList implements Iterable<Repository>
public class XmlRepositoryList implements Iterable<RepositoryPath>
{
/**
@@ -70,9 +70,9 @@ public class XmlRepositoryList implements Iterable<Repository>
*
* @param repositoryMap
*/
public XmlRepositoryList(Map<String, Repository> repositoryMap)
public XmlRepositoryList(Map<String, RepositoryPath> repositoryMap)
{
this.repositories = new LinkedList<Repository>(repositoryMap.values());
this.repositories = new LinkedList<>(repositoryMap.values());
}
//~--- methods --------------------------------------------------------------
@@ -84,7 +84,7 @@ public class XmlRepositoryList implements Iterable<Repository>
* @return
*/
@Override
public Iterator<Repository> iterator()
public Iterator<RepositoryPath> iterator()
{
return repositories.iterator();
}
@@ -97,7 +97,7 @@ public class XmlRepositoryList implements Iterable<Repository>
*
* @return
*/
public LinkedList<Repository> getRepositories()
public LinkedList<RepositoryPath> getRepositoryPaths()
{
return repositories;
}
@@ -110,7 +110,7 @@ public class XmlRepositoryList implements Iterable<Repository>
*
* @param repositories
*/
public void setRepositories(LinkedList<Repository> repositories)
public void setRepositories(LinkedList<RepositoryPath> repositories)
{
this.repositories = repositories;
}
@@ -118,6 +118,6 @@ public class XmlRepositoryList implements Iterable<Repository>
//~--- fields ---------------------------------------------------------------
/** Field description */
@XmlElement(name = "repository")
private LinkedList<Repository> repositories;
@XmlElement(name = "repository-path")
private LinkedList<RepositoryPath> repositories;
}

View File

@@ -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,45 +24,76 @@
* 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.xml;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.repository.Repository;
import sonia.scm.store.StoreConstants;
import sonia.scm.store.StoreException;
import sonia.scm.util.IOUtil;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
*/
public class XmlRepositoryMapAdapter extends XmlAdapter<XmlRepositoryList, Map<String, Repository>> {
public class XmlRepositoryMapAdapter extends XmlAdapter<XmlRepositoryList, Map<String, RepositoryPath>> {
@Override
public XmlRepositoryList marshal(Map<String, Repository> repositoryMap) {
return new XmlRepositoryList(repositoryMap);
}
public XmlRepositoryList marshal(Map<String, RepositoryPath> repositoryMap) {
XmlRepositoryList repositoryPaths = new XmlRepositoryList(repositoryMap);
try {
JAXBContext context = JAXBContext.newInstance(Repository.class);
Marshaller marshaller = context.createMarshaller();
@Override
public Map<String, Repository> unmarshal(XmlRepositoryList repositories) {
Map<String, Repository> repositoryMap = new LinkedHashMap<>();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
for (Repository repository : repositories) {
repositoryMap.put(XmlRepositoryDatabase.createKey(repository),
repository);
// marshall the repo_path/metadata.xml files
for (RepositoryPath repositoryPath : repositoryPaths.getRepositoryPaths()) {
File dir = new File(repositoryPath.getPath());
if (!dir.exists()){
IOUtil.mkdirs(dir);
}
marshaller.marshal(repositoryPath.getRepository(), getRepositoryMetadataFile(dir));
}
} catch (JAXBException ex) {
throw new StoreException("failed to marshall repository database", ex);
}
return repositoryMap;
return repositoryPaths;
}
private File getRepositoryMetadataFile(File dir) {
return new File(dir, StoreConstants.REPOSITORY_METADATA.concat(StoreConstants.FILE_EXTENSION));
}
@Override
public Map<String, RepositoryPath> unmarshal(XmlRepositoryList repositories) {
Map<String, RepositoryPath> repositoryPathMap = new LinkedHashMap<>();
try {
JAXBContext context = JAXBContext.newInstance(Repository.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
for (RepositoryPath repositoryPath : repositories) {
Repository repository = (Repository) unmarshaller.unmarshal(getRepositoryMetadataFile(new File(repositoryPath.getPath())));
repositoryPath.setRepository(repository);
repositoryPathMap.put(XmlRepositoryDatabase.createKey(repository), repositoryPath);
}
} catch (JAXBException ex) {
throw new StoreException("failed to unmarshall object", ex);
}
return repositoryPathMap;
}
}

View File

@@ -79,7 +79,7 @@ public class JAXBConfigurationEntryStoreFactory
{
this.keyGenerator = keyGenerator;
directory = new File(context.getBaseDirectory(),
StoreConstants.CONFIGDIRECTORY_NAME);
StoreConstants.CONFIG_DIRECTORY_NAME);
IOUtil.mkdirs(directory);
}

View File

@@ -42,7 +42,7 @@ import sonia.scm.util.IOUtil;
import java.io.File;
/**
* JAXB implementation of {@link JAXBConfigurationStoreFactory}.
* JAXB implementation of {@link ConfigurationStoreFactory}.
*
* @author Sebastian Sdorra
*/
@@ -63,7 +63,7 @@ public class JAXBConfigurationStoreFactory implements ConfigurationStoreFactory
*/
@Inject
public JAXBConfigurationStoreFactory(SCMContextProvider context) {
configDirectory = new File(context.getBaseDirectory(), StoreConstants.CONFIGDIRECTORY_NAME);
configDirectory = new File(context.getBaseDirectory(), StoreConstants.CONFIG_DIRECTORY_NAME);
IOUtil.mkdirs(configDirectory);
}

View File

@@ -37,12 +37,14 @@ package sonia.scm.store;
*
* @author Sebastian Sdorra
*/
public interface StoreConstants
public class StoreConstants
{
/** Field description */
public static final String CONFIGDIRECTORY_NAME = "config";
private StoreConstants() { }
public static final String CONFIG_DIRECTORY_NAME = "config";
public static final String REPOSITORY_METADATA = "metadata";
/** Field description */
public static final String FILE_EXTENSION = ".xml";
}

View File

@@ -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,9 +24,8 @@
* 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
*
*/
@@ -35,18 +34,14 @@ package sonia.scm.xml;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.GenericDAO;
import sonia.scm.ModelObject;
import sonia.scm.group.xml.XmlGroupDAO;
import sonia.scm.store.ConfigurationStore;
import sonia.scm.util.AssertUtil;
import java.util.Collection;
import java.util.stream.Collectors;
//~--- JDK imports ------------------------------------------------------------
@@ -58,7 +53,7 @@ import java.util.stream.Collectors;
* @param <T>
*/
public abstract class AbstractXmlDAO<I extends ModelObject,
T extends XmlDatabase<I>> implements GenericDAO<I>
T extends XmlDatabase> implements GenericDAO<I>
{
/** Field description */
@@ -192,6 +187,7 @@ public abstract class AbstractXmlDAO<I extends ModelObject,
* @param item
*/
@Override
@SuppressWarnings("unchecked")
public void modify(I item)
{
if (logger.isTraceEnabled())
@@ -219,9 +215,10 @@ public abstract class AbstractXmlDAO<I extends ModelObject,
* @return
*/
@Override
@SuppressWarnings("unchecked")
public I get(String id)
{
return db.get(id);
return (I) db.get(id);
}
/**
@@ -293,7 +290,7 @@ public abstract class AbstractXmlDAO<I extends ModelObject,
//~--- fields ---------------------------------------------------------------
/** Field description */
private final ConfigurationStore<T> store;
protected final ConfigurationStore<T> store;
/** Field description */
protected T db;

View File

@@ -6,14 +6,11 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.io.File;
@NoArgsConstructor
@Getter
@Setter
public class GitConfigDto extends HalRepresentation {
private File repositoryDirectory;
private boolean disabled = false;
private String gcExpression;

View File

@@ -98,15 +98,15 @@ public class GitRepositoryHandler
/**
* Constructs ...
*
*
* @param storeFactory
* @param storeFactory
* @param fileSystem
* @param scheduler
* @param repositoryLocationResolver
*/
@Inject
public GitRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem, Scheduler scheduler)
public GitRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem, Scheduler scheduler, RepositoryLocationResolver repositoryLocationResolver)
{
super(storeFactory, fileSystem);
super(storeFactory, fileSystem, repositoryLocationResolver);
this.scheduler = scheduler;
}

View File

@@ -106,7 +106,7 @@ public class GitRepositoryResolver implements RepositoryResolver<HttpServletRequ
if (config.isValid())
{
File gitdir = findRepository(config.getRepositoryDirectory(), repo.getId());
File gitdir = handler.getDirectory(repo);
if (gitdir == null) {
throw new RepositoryNotFoundException(repositoryName);
}
@@ -132,32 +132,6 @@ public class GitRepositoryResolver implements RepositoryResolver<HttpServletRequ
}
}
@VisibleForTesting
File findRepository(File parentDirectory, String repositoryName) {
File repositoryDirectory = new File(parentDirectory, repositoryName);
if (repositoryDirectory.exists()) {
return repositoryDirectory;
}
if (endsWithDotGit(repositoryName)) {
String repositoryNameWithoutDotGit = repositoryNameWithoutDotGit(repositoryName);
repositoryDirectory = new File(parentDirectory, repositoryNameWithoutDotGit);
if (repositoryDirectory.exists()) {
return repositoryDirectory;
}
}
return null;
}
private boolean endsWithDotGit(String repositoryName) {
return repositoryName.endsWith(GitRepositoryHandler.DOT_GIT);
}
private String repositoryNameWithoutDotGit(String repositoryName) {
return repositoryName.substring(0, repositoryName.length() - GitRepositoryHandler.DOT_GIT.length());
}
//~--- fields ---------------------------------------------------------------
private final GitRepositoryHandler handler;

View File

@@ -6,8 +6,6 @@ import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;
import sonia.scm.repository.GitConfig;
import java.io.File;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -22,7 +20,6 @@ public class GitConfigDtoToGitConfigMapperTest {
GitConfigDto dto = createDefaultDto();
GitConfig config = mapper.map(dto);
assertEquals("express", config.getGcExpression());
assertEquals("repository/directory", config.getRepositoryDirectory().getPath());
assertFalse(config.isDisabled());
}
@@ -30,7 +27,6 @@ public class GitConfigDtoToGitConfigMapperTest {
GitConfigDto gitConfigDto = new GitConfigDto();
gitConfigDto.setGcExpression("express");
gitConfigDto.setDisabled(false);
gitConfigDto.setRepositoryDirectory(new File("repository/directory"));
return gitConfigDto;
}
}

View File

@@ -81,7 +81,6 @@ public class GitConfigResourceTest {
ObjectNode responseJson = new ObjectMapper().readValue(responseString, ObjectNode.class);
assertTrue(responseString.contains("\"disabled\":false"));
assertTrue(responseJson.get("repositoryDirectory").asText().endsWith("repository/directory"));
assertTrue(responseString.contains("\"gcExpression\":\"valid Git GC Cron Expression\""));
assertTrue(responseString.contains("\"self\":{\"href\":\"/v2/config/git"));
assertTrue(responseString.contains("\"update\":{\"href\":\"/v2/config/git"));
@@ -152,7 +151,6 @@ public class GitConfigResourceTest {
GitConfig config = new GitConfig();
config.setGcExpression("valid Git GC Cron Expression");
config.setDisabled(false);
config.setRepositoryDirectory(new File("repository/directory"));
return config;
}

View File

@@ -60,7 +60,6 @@ public class GitConfigToGitConfigDtoMapperTest {
assertEquals("express", dto.getGcExpression());
assertFalse(dto.isDisabled());
assertEquals("repository/directory", dto.getRepositoryDirectory().getPath());
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("self").get().getHref());
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("update").get().getHref());
}
@@ -79,7 +78,6 @@ public class GitConfigToGitConfigDtoMapperTest {
private GitConfig createConfiguration() {
GitConfig config = new GitConfig();
config.setDisabled(false);
config.setRepositoryDirectory(new File("repository/directory"));
config.setGcExpression("express");
return config;
}

View File

@@ -42,9 +42,13 @@ import sonia.scm.schedule.Scheduler;
import sonia.scm.store.ConfigurationStoreFactory;
import java.io.File;
import java.nio.file.Path;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
//~--- JDK imports ------------------------------------------------------------
@@ -61,6 +65,9 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
@Mock
private ConfigurationStoreFactory factory;
RepositoryLocationResolver repositoryLocationResolver ;
private Path repoDir;
@Override
protected void checkDirectory(File directory) {
File head = new File(directory, "HEAD");
@@ -82,15 +89,20 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
@Override
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
File directory) {
File directory) throws RepositoryPathNotFoundException {
DefaultFileSystem fileSystem = new DefaultFileSystem();
PathBasedRepositoryDAO repoDao = mock(PathBasedRepositoryDAO.class);
InitialRepositoryLocationResolver initialRepositoryLocationResolver = new InitialRepositoryLocationResolver(contextProvider,fileSystem);
repositoryLocationResolver = new RepositoryLocationResolver(repoDao, initialRepositoryLocationResolver);
GitRepositoryHandler repositoryHandler = new GitRepositoryHandler(factory,
new DefaultFileSystem(), scheduler);
fileSystem, scheduler, repositoryLocationResolver);
repoDir = directory.toPath();
when(repoDao.getPath(any())).thenReturn(repoDir);
repositoryHandler.init(contextProvider);
GitConfig config = new GitConfig();
config.setRepositoryDirectory(directory);
// TODO fix event bus exception
repositoryHandler.setConfig(config);
@@ -98,17 +110,18 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
}
@Test
public void getDirectory() {
public void getDirectory() {
GitRepositoryHandler repositoryHandler = new GitRepositoryHandler(factory,
new DefaultFileSystem(), scheduler);
GitConfig gitConfig = new GitConfig();
gitConfig.setRepositoryDirectory(new File("/path"));
repositoryHandler.setConfig(gitConfig);
new DefaultFileSystem(), scheduler, repositoryLocationResolver);
Repository repository = new Repository("id", "git", "Space", "Name");
GitConfig config = new GitConfig();
config.setDisabled(false);
config.setGcExpression("gc exp");
repositoryHandler.setConfig(config);
File path = repositoryHandler.getDirectory(repository);
assertEquals("/path/id", path.getAbsolutePath());
assertEquals(repoDir.toString()+File.separator+InitialRepositoryLocationResolver.REPOSITORIES_NATIVE_DIRECTORY, path.getAbsolutePath());
}
}

View File

@@ -1,110 +0,0 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* 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.
* 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.
*
* 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
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* 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.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.web;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import sonia.scm.repository.GitConfig;
import sonia.scm.repository.GitRepositoryHandler;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link GitRepositoryResolver}.
*
* @author Sebastian Sdorra
*/
@RunWith(MockitoJUnitRunner.class)
public class GitRepositoryResolverTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private File parentDirectory;
@Mock
private GitRepositoryHandler handler;
@InjectMocks
private GitRepositoryResolver resolver;
@Before
public void setUp() throws IOException {
parentDirectory = temporaryFolder.newFolder();
GitConfig config = new GitConfig();
config.setRepositoryDirectory(parentDirectory);
}
@Test
public void testFindRepositoryWithoutDotGit() {
createRepositories("a", "ab");
File directory = resolver.findRepository(parentDirectory, "a");
assertNotNull(directory);
assertEquals("a", directory.getName());
directory = resolver.findRepository(parentDirectory, "ab");
assertNotNull(directory);
assertEquals("ab", directory.getName());
}
@Test
public void testFindRepositoryWithDotGit() {
createRepositories("a", "ab");
File directory = resolver.findRepository(parentDirectory, "a.git");
assertNotNull(directory);
assertEquals("a", directory.getName());
directory = resolver.findRepository(parentDirectory, "ab.git");
assertNotNull(directory);
assertEquals("ab", directory.getName());
}
private void createRepositories(String... names) {
for (String name : names) {
assertTrue(new File(parentDirectory, name).mkdirs());
}
}
}

View File

@@ -6,15 +6,12 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.io.File;
@NoArgsConstructor
@Getter
@Setter
public class HgConfigDto extends HalRepresentation {
private boolean disabled;
private File repositoryDirectory;
private String encoding;
private String hgBinary;

View File

@@ -52,32 +52,6 @@ import sonia.scm.net.ahc.AdvancedHttpClient;
public abstract class AbstractHgInstaller implements HgInstaller
{
/** Field description */
public static final String DIRECTORY_REPOSITORY = "repositories";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
*
* @param baseDirectory
* @param config
*
* @throws IOException
*/
@Override
public void install(File baseDirectory, HgConfig config) throws IOException
{
File repoDirectory = new File(
baseDirectory,
DIRECTORY_REPOSITORY.concat(File.separator).concat(
HgRepositoryHandler.TYPE_NAME));
IOUtil.mkdirs(repoDirectory);
config.setRepositoryDirectory(repoDirectory);
}
/**
* Method description

View File

@@ -74,8 +74,6 @@ public class UnixHgInstaller extends AbstractHgInstaller
@Override
public void install(File baseDirectory, HgConfig config) throws IOException
{
super.install(baseDirectory, config);
// search mercurial (hg)
if (Util.isEmpty(config.getHgBinary()))
{

View File

@@ -116,8 +116,6 @@ public class WindowsHgInstaller extends AbstractHgInstaller
@Override
public void install(File baseDirectory, HgConfig config) throws IOException
{
super.install(baseDirectory, config);
if (Util.isEmpty(config.getPythonBinary()))
{
String pythonBinary = getPythonBinary();

View File

@@ -111,16 +111,16 @@ public class HgRepositoryHandler
/**
* Constructs ...
*
*
* @param storeFactory
* @param storeFactory
* @param fileSystem
* @param hgContextProvider
* @param repositoryLocationResolver
*/
@Inject
public HgRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem,
Provider<HgContext> hgContextProvider)
Provider<HgContext> hgContextProvider, RepositoryLocationResolver repositoryLocationResolver)
{
super(storeFactory, fileSystem);
super(storeFactory, fileSystem, repositoryLocationResolver);
this.hgContextProvider = hgContextProvider;
try
@@ -566,8 +566,7 @@ public class HgRepositoryHandler
if (c != null)
{
File repositoryDirectroy = c.getRepositoryDirectory();
File repositoryDirectroy = getInitialBaseDirectory();
if (repositoryDirectroy.exists())
{
File lockFile = new File(repositoryDirectroy, PATH_HOOK);

View File

@@ -123,8 +123,9 @@ public class HgHookChangesetProvider implements HookChangesetProvider
*/
private Repository open()
{
File directory = handler.getConfig().getRepositoryDirectory();
File repositoryDirectory = new File(directory, id);
sonia.scm.repository.Repository repo = new sonia.scm.repository.Repository();
repo.setId(id);
File repositoryDirectory = handler.getDirectory(repo);
// use HG_PENDING only for pre receive hooks
boolean pending = type == RepositoryHookType.PRE_RECEIVE;

View File

@@ -23,7 +23,6 @@ public class HgConfigDtoToHgConfigMapperTest {
HgConfig config = mapper.map(dto);
assertTrue(config.isDisabled());
assertEquals("repository/directory", config.getRepositoryDirectory().getPath());
assertEquals("ABC", config.getEncoding());
assertEquals("/etc/hg", config.getHgBinary());
@@ -36,7 +35,6 @@ public class HgConfigDtoToHgConfigMapperTest {
private HgConfigDto createDefaultDto() {
HgConfigDto configDto = new HgConfigDto();
configDto.setDisabled(true);
configDto.setRepositoryDirectory(new File("repository/directory"));
configDto.setEncoding("ABC");
configDto.setHgBinary("/etc/hg");
configDto.setPythonBinary("/py");

View File

@@ -93,7 +93,6 @@ public class HgConfigResourceTest {
ObjectNode responseJson = new ObjectMapper().readValue(responseString, ObjectNode.class);
assertTrue(responseString.contains("\"disabled\":false"));
assertTrue(responseJson.get("repositoryDirectory").asText().endsWith("repository/directory"));
assertTrue(responseString.contains("\"self\":{\"href\":\"/v2/config/hg"));
assertTrue(responseString.contains("\"update\":{\"href\":\"/v2/config/hg"));
}
@@ -162,7 +161,6 @@ public class HgConfigResourceTest {
private HgConfig createConfiguration() {
HgConfig config = new HgConfig();
config.setDisabled(false);
config.setRepositoryDirectory(new File("repository/directory"));
return config;
}

View File

@@ -16,7 +16,6 @@ class HgConfigTests {
static HgConfig createConfiguration() {
HgConfig config = new HgConfig();
config.setDisabled(true);
config.setRepositoryDirectory(new File("repository/directory"));
config.setEncoding("ABC");
config.setHgBinary("/etc/hg");
@@ -30,7 +29,6 @@ class HgConfigTests {
static void assertEqualsConfiguration(HgConfigDto dto) {
assertTrue(dto.isDisabled());
assertEquals("repository/directory", dto.getRepositoryDirectory().getPath());
assertEquals("ABC", dto.getEncoding());
assertEquals("/etc/hg", dto.getHgBinary());

View File

@@ -42,9 +42,13 @@ import sonia.scm.io.DefaultFileSystem;
import sonia.scm.store.ConfigurationStoreFactory;
import java.io.File;
import java.nio.file.Path;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
//~--- JDK imports ------------------------------------------------------------
@@ -61,6 +65,9 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
@Mock
private com.google.inject.Provider<HgContext> provider;
RepositoryLocationResolver repositoryLocationResolver ;
private Path repoDir;
@Override
protected void checkDirectory(File directory) {
File hgDirectory = new File(directory, ".hg");
@@ -77,14 +84,17 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
@Override
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
File directory) {
File directory) throws RepositoryPathNotFoundException {
DefaultFileSystem fileSystem = new DefaultFileSystem();
PathBasedRepositoryDAO repoDao = mock(PathBasedRepositoryDAO.class);
repositoryLocationResolver = new RepositoryLocationResolver(repoDao, new InitialRepositoryLocationResolver(contextProvider,fileSystem));
HgRepositoryHandler handler = new HgRepositoryHandler(factory,
new DefaultFileSystem(),
new HgContextProvider());
new HgContextProvider(), repositoryLocationResolver);
handler.init(contextProvider);
handler.getConfig().setRepositoryDirectory(directory);
repoDir = directory.toPath();
when(repoDao.getPath(any())).thenReturn(repoDir);
HgTestUtil.checkForSkip(handler);
return handler;
@@ -93,17 +103,15 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
@Test
public void getDirectory() {
HgRepositoryHandler repositoryHandler = new HgRepositoryHandler(factory,
new DefaultFileSystem(), provider);
new DefaultFileSystem(), provider, repositoryLocationResolver);
HgConfig hgConfig = new HgConfig();
hgConfig.setRepositoryDirectory(new File("/path"));
hgConfig.setHgBinary("hg");
hgConfig.setPythonBinary("python");
repositoryHandler.setConfig(hgConfig);
Repository repository = new Repository("id", "git", "Space", "Name");
File path = repositoryHandler.getDirectory(repository);
assertEquals("/path/id", path.getAbsolutePath());
assertEquals(repoDir.toString()+File.separator+InitialRepositoryLocationResolver.REPOSITORIES_NATIVE_DIRECTORY, path.getAbsolutePath());
}
}

View File

@@ -46,6 +46,7 @@ import static org.mockito.Mockito.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.nio.file.Path;
import javax.servlet.http.HttpServletRequest;
@@ -95,19 +96,21 @@ public final class HgTestUtil
*
* @return
*/
public static HgRepositoryHandler createHandler(File directory)
{
public static HgRepositoryHandler createHandler(File directory) throws RepositoryPathNotFoundException {
TempSCMContextProvider context =
(TempSCMContextProvider) SCMContext.getContext();
context.setBaseDirectory(directory);
FileSystem fileSystem = mock(FileSystem.class);
PathBasedRepositoryDAO repoDao = mock(PathBasedRepositoryDAO.class);
RepositoryLocationResolver repositoryLocationResolver = new RepositoryLocationResolver(repoDao, new InitialRepositoryLocationResolver(context,fileSystem));
HgRepositoryHandler handler =
new HgRepositoryHandler(new InMemoryConfigurationStoreFactory(), fileSystem,
new HgContextProvider());
new HgContextProvider(), repositoryLocationResolver);
Path repoDir = directory.toPath();
when(repoDao.getPath(any())).thenReturn(repoDir);
handler.init(context);
return handler;

View File

@@ -40,6 +40,7 @@ import org.junit.Before;
import sonia.scm.repository.HgRepositoryHandler;
import sonia.scm.repository.HgTestUtil;
import sonia.scm.repository.RepositoryPathNotFoundException;
import sonia.scm.repository.RepositoryTestData;
import sonia.scm.util.MockUtil;
@@ -76,8 +77,7 @@ public class AbstractHgCommandTestBase extends ZippedRepositoryTestBase
* @throws IOException
*/
@Before
public void initHgHandler() throws IOException
{
public void initHgHandler() throws IOException, RepositoryPathNotFoundException {
this.handler = HgTestUtil.createHandler(tempFolder.newFolder());
HgTestUtil.checkForSkip(handler);

View File

@@ -51,6 +51,7 @@ import sonia.scm.repository.HgConfig;
import sonia.scm.repository.HgContext;
import sonia.scm.repository.HgRepositoryHandler;
import sonia.scm.repository.HgTestUtil;
import sonia.scm.repository.RepositoryPathNotFoundException;
import sonia.scm.user.User;
import sonia.scm.user.UserTestData;
import sonia.scm.util.MockUtil;
@@ -78,8 +79,7 @@ public abstract class IncomingOutgoingTestBase extends AbstractTestBase
* @throws IOException
*/
@Before
public void initHgHandler() throws IOException
{
public void initHgHandler() throws IOException, RepositoryPathNotFoundException {
HgRepositoryHandler temp = HgTestUtil.createHandler(tempFolder.newFolder());
HgTestUtil.checkForSkip(temp);

View File

@@ -25,14 +25,15 @@ public class HgHookCallbackServletTest {
HgHookCallbackServlet servlet = new HgHookCallbackServlet(null, handler, null, null);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
HgConfig config = mock(HgConfig.class);
when(request.getContextPath()).thenReturn("http://example.com/scm");
when(request.getRequestURI()).thenReturn("http://example.com/scm/hook/hg/pretxnchangegroup");
when(request.getParameter(PARAM_REPOSITORYPATH)).thenReturn("/tmp/hg/12345");
String path = "/tmp/hg/12345";
when(request.getParameter(PARAM_REPOSITORYPATH)).thenReturn(path);
when(handler.getConfig()).thenReturn(config);
when(config.getRepositoryDirectory()).thenReturn(new File("/tmp/hg"));
File file = new File(path);
when(handler.getInitialBaseDirectory()).thenReturn(file);
servlet.doPost(request, response);

View File

@@ -7,15 +7,12 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import sonia.scm.repository.Compatibility;
import java.io.File;
@NoArgsConstructor
@Getter
@Setter
public class SvnConfigDto extends HalRepresentation {
private boolean disabled;
private File repositoryDirectory;
private boolean enabledGZip;
private Compatibility compatibility;

View File

@@ -85,9 +85,9 @@ public class SvnRepositoryHandler
@Inject
public SvnRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem,
HookEventFacade eventFacade)
HookEventFacade eventFacade, RepositoryLocationResolver repositoryLocationResolver)
{
super(storeFactory, fileSystem);
super(storeFactory, fileSystem, repositoryLocationResolver);
// register logger
SVNDebugLog.setDefaultLog(new SVNKitLogger());

View File

@@ -7,8 +7,6 @@ import org.mockito.runners.MockitoJUnitRunner;
import sonia.scm.repository.Compatibility;
import sonia.scm.repository.SvnConfig;
import java.io.File;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -24,7 +22,6 @@ public class SvnConfigDtoToSvnConfigMapperTest {
SvnConfig config = mapper.map(dto);
assertTrue(config.isDisabled());
assertEquals("repository/directory", config.getRepositoryDirectory().getPath());
assertEquals(Compatibility.PRE15, config.getCompatibility());
assertTrue(config.isEnabledGZip());
@@ -33,7 +30,6 @@ public class SvnConfigDtoToSvnConfigMapperTest {
private SvnConfigDto createDefaultDto() {
SvnConfigDto configDto = new SvnConfigDto();
configDto.setDisabled(true);
configDto.setRepositoryDirectory(new File("repository/directory"));
configDto.setCompatibility(Compatibility.PRE15);
configDto.setEnabledGZip(true);

View File

@@ -81,7 +81,6 @@ public class SvnConfigResourceTest {
ObjectNode responseJson = new ObjectMapper().readValue(responseString, ObjectNode.class);
assertTrue(responseString.contains("\"disabled\":false"));
assertTrue(responseJson.get("repositoryDirectory").asText().endsWith("repository/directory"));
assertTrue(responseString.contains("\"self\":{\"href\":\"/v2/config/svn"));
assertTrue(responseString.contains("\"update\":{\"href\":\"/v2/config/svn"));
}
@@ -150,7 +149,6 @@ public class SvnConfigResourceTest {
private SvnConfig createConfiguration() {
SvnConfig config = new SvnConfig();
config.setDisabled(false);
config.setRepositoryDirectory(new File("repository/directory"));
return config;
}

View File

@@ -61,7 +61,6 @@ public class SvnConfigToSvnConfigDtoMapperTest {
SvnConfigDto dto = mapper.map(config);
assertTrue(dto.isDisabled());
assertEquals("repository/directory", dto.getRepositoryDirectory().getPath());
assertEquals(Compatibility.PRE15, dto.getCompatibility());
assertTrue(dto.isEnabledGZip());
@@ -84,7 +83,6 @@ public class SvnConfigToSvnConfigDtoMapperTest {
private SvnConfig createConfiguration() {
SvnConfig config = new SvnConfig();
config.setDisabled(true);
config.setRepositoryDirectory(new File("repository/directory"));
config.setCompatibility(Compatibility.PRE15);
config.setEnabledGZip(true);

View File

@@ -43,6 +43,7 @@ import sonia.scm.store.ConfigurationStore;
import sonia.scm.store.ConfigurationStoreFactory;
import java.io.File;
import java.nio.file.Path;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -72,6 +73,9 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
private HookEventFacade facade = new HookEventFacade(repositoryManagerProvider, hookContextFactory);
RepositoryLocationResolver repositoryLocationResolver ;
private Path repoDir;
@Override
protected void checkDirectory(File directory) {
File format = new File(directory, "format");
@@ -87,16 +91,22 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
@Override
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
File directory) {
SvnRepositoryHandler handler = new SvnRepositoryHandler(factory,
new DefaultFileSystem(), null);
File directory) throws RepositoryPathNotFoundException {
DefaultFileSystem fileSystem = new DefaultFileSystem();
PathBasedRepositoryDAO repoDao = mock(PathBasedRepositoryDAO.class);
repositoryLocationResolver = new RepositoryLocationResolver(repoDao, new InitialRepositoryLocationResolver(contextProvider,fileSystem));
SvnRepositoryHandler handler = new SvnRepositoryHandler(factory,
new DefaultFileSystem(), null, repositoryLocationResolver);
repoDir = directory.toPath();
when(repoDao.getPath(any())).thenReturn(repoDir);
handler.init(contextProvider);
SvnConfig config = new SvnConfig();
config.setRepositoryDirectory(directory);
// TODO fix event bus exception
handler.setConfig(config);
@@ -107,15 +117,14 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
public void getDirectory() {
when(factory.getStore(any(), any())).thenReturn(store);
SvnRepositoryHandler repositoryHandler = new SvnRepositoryHandler(factory,
new DefaultFileSystem(), facade);
new DefaultFileSystem(), facade, repositoryLocationResolver);
SvnConfig svnConfig = new SvnConfig();
svnConfig.setRepositoryDirectory(new File("/path"));
repositoryHandler.setConfig(svnConfig);
Repository repository = new Repository("id", "svn", "Space", "Name");
File path = repositoryHandler.getDirectory(repository);
assertEquals("/path/id", path.getAbsolutePath());
assertEquals(repoDir.toString()+File.separator+InitialRepositoryLocationResolver.REPOSITORIES_NATIVE_DIRECTORY, path.getAbsolutePath());
}
}

View File

@@ -46,7 +46,6 @@ import java.util.Set;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
*/
public class DummyRepositoryHandler
@@ -60,8 +59,8 @@ public class DummyRepositoryHandler
private final Set<String> existingRepoNames = new HashSet<>();
public DummyRepositoryHandler(ConfigurationStoreFactory storeFactory) {
super(storeFactory, new DefaultFileSystem());
public DummyRepositoryHandler(ConfigurationStoreFactory storeFactory, RepositoryLocationResolver repositoryLocationResolver) {
super(storeFactory, new DefaultFileSystem(), repositoryLocationResolver);
}
@Override

View File

@@ -41,6 +41,7 @@ import sonia.scm.store.InMemoryConfigurationStoreFactory;
import sonia.scm.util.IOUtil;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -58,7 +59,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
protected abstract void checkDirectory(File directory);
protected abstract RepositoryHandler createRepositoryHandler(
ConfigurationStoreFactory factory, File directory);
ConfigurationStoreFactory factory, File directory) throws IOException, RepositoryPathNotFoundException;
@Test
public void testCreate() throws AlreadyExistsException {
@@ -87,7 +88,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
}
@Override
protected void postSetUp() {
protected void postSetUp() throws IOException, RepositoryPathNotFoundException {
InMemoryConfigurationStoreFactory storeFactory = new InMemoryConfigurationStoreFactory();
baseDirectory = new File(contextProvider.getBaseDirectory(), "repositories");
IOUtil.mkdirs(baseDirectory);
@@ -106,7 +107,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
handler.create(repository);
File directory = new File(baseDirectory, repository.getId());
File directory = new File(new File(baseDirectory, repository.getId()), InitialRepositoryLocationResolver.REPOSITORIES_NATIVE_DIRECTORY);
assertTrue(directory.exists());
assertTrue(directory.isDirectory());

View File

@@ -166,7 +166,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
throw new RepositoryIsNotArchivedException();
}
fireEvent(HandlerEventType.BEFORE_DELETE, toDelete);
// getHandler(toDelete).delete(toDelete);
getHandler(toDelete).delete(toDelete);
}
@Override

View File

@@ -51,6 +51,7 @@ import sonia.scm.ManagerTestBase;
import sonia.scm.NotFoundException;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.event.ScmEventBus;
import sonia.scm.io.DefaultFileSystem;
import sonia.scm.repository.api.HookContext;
import sonia.scm.repository.api.HookContextFactory;
import sonia.scm.repository.api.HookFeature;
@@ -419,23 +420,26 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository> {
}
private DefaultRepositoryManager createRepositoryManager(boolean archiveEnabled, KeyGenerator keyGenerator) {
DefaultFileSystem fileSystem = new DefaultFileSystem();
Set<RepositoryHandler> handlerSet = new HashSet<>();
ConfigurationStoreFactory factory = new JAXBConfigurationStoreFactory(contextProvider);
handlerSet.add(new DummyRepositoryHandler(factory));
handlerSet.add(new DummyRepositoryHandler(factory) {
InitialRepositoryLocationResolver initialRepositoryLocationResolver = new InitialRepositoryLocationResolver(contextProvider, fileSystem);
XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(factory, initialRepositoryLocationResolver);
RepositoryLocationResolver repositoryLocationResolver = new RepositoryLocationResolver(repositoryDAO, initialRepositoryLocationResolver);
handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver));
handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver) {
@Override
public RepositoryType getType() {
return new RepositoryType("hg", "Mercurial", Sets.newHashSet());
}
});
handlerSet.add(new DummyRepositoryHandler(factory) {
handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver) {
@Override
public RepositoryType getType() {
return new RepositoryType("git", "Git", Sets.newHashSet());
}
});
XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(factory);
this.configuration = new ScmConfiguration();