mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-04 03:10:50 +01:00
add the interface StoreFactory and refactor storeFactories
This commit is contained in:
@@ -48,6 +48,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.store.ConfigurationStore;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.store.StoreParameters;
|
||||
|
||||
|
||||
/**
|
||||
@@ -72,9 +73,12 @@ public abstract class AbstractRepositoryHandler<C extends RepositoryConfig>
|
||||
*
|
||||
* @param storeFactory
|
||||
*/
|
||||
protected AbstractRepositoryHandler(ConfigurationStoreFactory storeFactory)
|
||||
{
|
||||
this.store = storeFactory.getStore(getConfigClass(), getType().getName());
|
||||
protected AbstractRepositoryHandler(ConfigurationStoreFactory storeFactory) {
|
||||
this.store = storeFactory.getStore(new StoreParameters()
|
||||
.withType(getConfigClass())
|
||||
.withName(getType().getName())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
@@ -6,6 +6,7 @@ import sonia.scm.io.FileSystem;
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -44,7 +45,11 @@ public final class InitialRepositoryLocationResolver {
|
||||
return new File(context.getBaseDirectory(), REPOSITORIES_DIRECTORY);
|
||||
}
|
||||
|
||||
public File createDirectory(Repository repository) throws IOException {
|
||||
File getContextBaseDirectory() {
|
||||
return context.getBaseDirectory();
|
||||
}
|
||||
|
||||
public File createDirectory(Repository repository) throws IOException {
|
||||
File initialRepoFolder = getDirectory(repository);
|
||||
fileSystem.create(initialRepoFolder);
|
||||
return initialRepoFolder;
|
||||
|
||||
@@ -24,6 +24,10 @@ import static sonia.scm.repository.InitialRepositoryLocationResolver.REPOSITORIE
|
||||
@Singleton
|
||||
public class RepositoryLocationResolver {
|
||||
|
||||
private static final String REPOSITORIES_STORES_DIRECTORY = "stores";
|
||||
private static final String REPOSITORIES_CONFIG_DIRECTORY = "config";
|
||||
private static final String GLOBAL_STORE_BASE_DIRECTORY = "var";
|
||||
|
||||
private RepositoryDAO repositoryDAO;
|
||||
private InitialRepositoryLocationResolver initialRepositoryLocationResolver;
|
||||
|
||||
@@ -70,4 +74,22 @@ public class RepositoryLocationResolver {
|
||||
public File getInitialNativeDirectory(Repository repository) {
|
||||
return new File (getInitialDirectory(repository), REPOSITORIES_NATIVE_DIRECTORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the store directory of a specific repository
|
||||
* @param repository
|
||||
* @return the store directory of a specific repository
|
||||
*/
|
||||
public File getStoresDirectory(Repository repository) throws IOException{
|
||||
return new File (getRepositoryDirectory(repository), REPOSITORIES_STORES_DIRECTORY);
|
||||
}
|
||||
|
||||
public File getConfigDirectory(Repository repository) throws IOException {
|
||||
return new File (getRepositoryDirectory(repository), REPOSITORIES_CONFIG_DIRECTORY);
|
||||
}
|
||||
|
||||
public File getGlobalStoreDirectory() {
|
||||
return new File(initialRepositoryLocationResolver.getContextBaseDirectory(),
|
||||
GLOBAL_STORE_BASE_DIRECTORY.concat(File.separator));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,16 +42,6 @@ package sonia.scm.store;
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses sonia.scm.store.BlobStore
|
||||
*/
|
||||
public interface BlobStoreFactory {
|
||||
public interface BlobStoreFactory extends StoreFactory<BlobStore> {
|
||||
|
||||
/**
|
||||
* Returns a {@link BlobStore} with the given name, if the {@link BlobStore}
|
||||
* with the given name does not exists the factory will create a new one.
|
||||
*
|
||||
*
|
||||
* @param name name of the {@link BlobStore}
|
||||
*
|
||||
* @return {@link BlobStore} with the given name
|
||||
*/
|
||||
public BlobStore getBlobStore(String name);
|
||||
}
|
||||
|
||||
@@ -34,10 +34,10 @@ package sonia.scm.store;
|
||||
|
||||
/**
|
||||
* The ConfigurationEntryStoreFactory can be used to create new or get existing
|
||||
* {@link ConfigurationEntryStore}s. <b>Note:</b> the default implementation
|
||||
* uses the same location as the {@link StoreFactory}, so be sure that the
|
||||
* store names are unique for all {@link ConfigurationEntryStore}s and
|
||||
* {@link Store}s.
|
||||
* {@link ConfigurationEntryStore}s.
|
||||
*
|
||||
* <b>Note:</b> the default implementation uses the same location as the {@link ConfigurationStoreFactory}, so be sure that the
|
||||
* store names are unique for all {@link ConfigurationEntryStore}s and {@link ConfigurationStore}s.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.31
|
||||
@@ -45,18 +45,5 @@ package sonia.scm.store;
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses sonia.scm.store.ConfigurationEntryStore
|
||||
*/
|
||||
public interface ConfigurationEntryStoreFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* Get an existing {@link ConfigurationEntryStore} or create a new one.
|
||||
*
|
||||
*
|
||||
* @param type type of the store objects
|
||||
* @param name name of the store
|
||||
* @param <T> type of the store objects
|
||||
*
|
||||
* @return {@link ConfigurationEntryStore} with given name and type
|
||||
*/
|
||||
public <T> ConfigurationEntryStore<T> getStore(Class<T> type, String name);
|
||||
public interface ConfigurationEntryStoreFactory extends StoreFactory<ConfigurationEntryStore> {
|
||||
}
|
||||
|
||||
@@ -37,23 +37,12 @@ package sonia.scm.store;
|
||||
* The ConfigurationStoreFactory can be used to create new or get existing
|
||||
* {@link ConfigurationStore} objects.
|
||||
*
|
||||
* <b>Note:</b> the default implementation uses the same location as the {@link ConfigurationEntryStoreFactory}, so be sure that the
|
||||
* store names are unique for all {@link ConfigurationEntryStore}s and {@link ConfigurationStore}s.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses sonia.scm.store.ConfigurationStore
|
||||
*/
|
||||
public interface ConfigurationStoreFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* Get an existing {@link ConfigurationStore} or create a new one.
|
||||
*
|
||||
*
|
||||
* @param type type of the store objects
|
||||
* @param name name of the store
|
||||
* @param <T> type of the store objects
|
||||
*
|
||||
* @return {@link ConfigurationStore} of the given type and name
|
||||
*/
|
||||
public <T> ConfigurationStore<T> getStore(Class<T> type, String name);
|
||||
}
|
||||
public interface ConfigurationStoreFactory extends StoreFactory<ConfigurationStore>{}
|
||||
|
||||
@@ -42,17 +42,4 @@ package sonia.scm.store;
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses sonia.scm.store.DataStore
|
||||
*/
|
||||
public interface DataStoreFactory {
|
||||
|
||||
/**
|
||||
* Get an existing {@link DataStore} or create a new one.
|
||||
*
|
||||
*
|
||||
* @param type type of the store objects
|
||||
* @param name name of the store
|
||||
* @param <T> type of the store objects
|
||||
*
|
||||
* @return {@link DataStore} with given name and type
|
||||
*/
|
||||
public <T> DataStore<T> getStore(Class<T> type, String name);
|
||||
}
|
||||
public interface DataStoreFactory extends StoreFactory<DataStore>{}
|
||||
|
||||
6
scm-core/src/main/java/sonia/scm/store/StoreFactory.java
Normal file
6
scm-core/src/main/java/sonia/scm/store/StoreFactory.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package sonia.scm.store;
|
||||
|
||||
public interface StoreFactory<STORE> {
|
||||
|
||||
STORE getStore(final StoreParameters storeParameters);
|
||||
}
|
||||
67
scm-core/src/main/java/sonia/scm/store/StoreParameters.java
Normal file
67
scm-core/src/main/java/sonia/scm/store/StoreParameters.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package sonia.scm.store;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
/**
|
||||
* The fields of the {@link StoreParameters} are used from the {@link StoreFactory} to create a store.
|
||||
*
|
||||
* @author Mohamed Karray
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class StoreParameters {
|
||||
|
||||
private Class type;
|
||||
private String name;
|
||||
private Repository repository;
|
||||
|
||||
public Class getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Repository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
public WithType withType(Class type){
|
||||
return new WithType(type);
|
||||
}
|
||||
|
||||
public class WithType {
|
||||
|
||||
private WithType(Class type) {
|
||||
StoreParameters.this.type = type;
|
||||
}
|
||||
|
||||
public WithTypeAndName withName(String name){
|
||||
return new WithTypeAndName(name);
|
||||
}
|
||||
|
||||
}
|
||||
public class WithTypeAndName {
|
||||
|
||||
private WithTypeAndName(String name) {
|
||||
StoreParameters.this.name = name;
|
||||
}
|
||||
|
||||
public WithTypeNameAndRepository forRepository(Repository repository){
|
||||
return new WithTypeNameAndRepository(repository);
|
||||
}
|
||||
public StoreParameters build(){
|
||||
return StoreParameters.this;
|
||||
}
|
||||
}
|
||||
|
||||
public class WithTypeNameAndRepository {
|
||||
|
||||
private WithTypeNameAndRepository(Repository repository) {
|
||||
StoreParameters.this.repository = repository;
|
||||
}
|
||||
public StoreParameters build(){
|
||||
return StoreParameters.this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.group.GroupDAO;
|
||||
import sonia.scm.store.StoreParameters;
|
||||
import sonia.scm.xml.AbstractXmlDAO;
|
||||
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
@@ -64,9 +65,11 @@ public class XmlGroupDAO extends AbstractXmlDAO<Group, XmlGroupDatabase>
|
||||
* @param storeFactory
|
||||
*/
|
||||
@Inject
|
||||
public XmlGroupDAO(ConfigurationStoreFactory storeFactory)
|
||||
{
|
||||
super(storeFactory.getStore(XmlGroupDatabase.class, STORE_NAME));
|
||||
public XmlGroupDAO(ConfigurationStoreFactory storeFactory) {
|
||||
super(storeFactory.getStore(new StoreParameters()
|
||||
.withType(XmlGroupDatabase.class)
|
||||
.withName(STORE_NAME)
|
||||
.build()));
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -36,14 +36,18 @@ package sonia.scm.repository.xml;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.InitialRepositoryLocationResolver;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.PathBasedRepositoryDAO;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryPathNotFoundException;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.store.JAXBConfigurationStore;
|
||||
import sonia.scm.store.StoreConstants;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.xml.AbstractXmlDAO;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collection;
|
||||
@@ -65,14 +69,10 @@ public class XmlRepositoryDAO
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
* @param storeFactory
|
||||
*/
|
||||
@Inject
|
||||
public XmlRepositoryDAO(ConfigurationStoreFactory storeFactory, InitialRepositoryLocationResolver initialRepositoryLocationResolver) {
|
||||
super(storeFactory.getStore(XmlRepositoryDatabase.class, STORE_NAME));
|
||||
public XmlRepositoryDAO(InitialRepositoryLocationResolver initialRepositoryLocationResolver, SCMContextProvider context) {
|
||||
super(new JAXBConfigurationStore<>(XmlRepositoryDatabase.class, new File(context.getBaseDirectory(), StoreConstants.CONFIG_DIRECTORY_NAME + File.separator + STORE_NAME + StoreConstants.FILE_EXTENSION)));
|
||||
IOUtil.mkdirs(new File(context.getBaseDirectory(), StoreConstants.CONFIG_DIRECTORY_NAME + File.separator + STORE_NAME + StoreConstants.FILE_EXTENSION));
|
||||
this.initialRepositoryLocationResolver = initialRepositoryLocationResolver;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,18 +31,23 @@
|
||||
package sonia.scm.store;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Abstract store factory for file based stores.
|
||||
*
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class FileBasedStoreFactory {
|
||||
@@ -51,18 +56,14 @@ public abstract class FileBasedStoreFactory {
|
||||
* the logger for FileBasedStoreFactory
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FileBasedStoreFactory.class);
|
||||
|
||||
private static final String BASE_DIRECTORY = "var";
|
||||
|
||||
private final SCMContextProvider context;
|
||||
private RepositoryLocationResolver repositoryLocationResolver;
|
||||
|
||||
private final String dataDirectoryName;
|
||||
|
||||
private File dataDirectory;
|
||||
|
||||
protected FileBasedStoreFactory(SCMContextProvider context,
|
||||
String dataDirectoryName) {
|
||||
this.context = context;
|
||||
protected FileBasedStoreFactory(RepositoryLocationResolver repositoryLocationResolver, String dataDirectoryName) {
|
||||
this.repositoryLocationResolver = repositoryLocationResolver;
|
||||
this.dataDirectoryName = dataDirectoryName;
|
||||
}
|
||||
|
||||
@@ -76,9 +77,8 @@ public abstract class FileBasedStoreFactory {
|
||||
*/
|
||||
protected File getDirectory(String name) {
|
||||
if (dataDirectory == null) {
|
||||
dataDirectory = new File(context.getBaseDirectory(),
|
||||
BASE_DIRECTORY.concat(File.separator).concat(dataDirectoryName));
|
||||
LOG.debug("create data directory {}", dataDirectory);
|
||||
dataDirectory = new File(repositoryLocationResolver.getGlobalStoreDirectory(), dataDirectoryName);
|
||||
LOG.debug("get data directory {}", dataDirectory);
|
||||
}
|
||||
|
||||
File storeDirectory = new File(dataDirectory, name);
|
||||
@@ -86,4 +86,25 @@ public abstract class FileBasedStoreFactory {
|
||||
return storeDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns data directory for given name.
|
||||
*
|
||||
* @param name name of data directory
|
||||
*
|
||||
* @return data directory
|
||||
*/
|
||||
protected File getDirectory(String name, Repository repository) {
|
||||
if (dataDirectory == null) {
|
||||
try {
|
||||
dataDirectory = new File(repositoryLocationResolver.getStoresDirectory(repository), dataDirectoryName);
|
||||
} catch (IOException e) {
|
||||
throw new InternalRepositoryException(repository, MessageFormat.format("Error on getting the store directory {0} of the repository {1}", dataDirectory.getAbsolutePath(), repository.getNamespaceAndName()), e);
|
||||
}
|
||||
LOG.debug("create data directory {}", dataDirectory);
|
||||
}
|
||||
File storeDirectory = new File(dataDirectory, name);
|
||||
IOUtil.mkdirs(storeDirectory);
|
||||
return storeDirectory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.security.KeyGenerator;
|
||||
|
||||
/**
|
||||
@@ -60,21 +60,21 @@ public class FileBlobStoreFactory extends FileBasedStoreFactory implements BlobS
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param context scm context
|
||||
* @param repositoryLocationResolver
|
||||
* @param keyGenerator key generator
|
||||
*/
|
||||
@Inject
|
||||
public FileBlobStoreFactory(SCMContextProvider context,
|
||||
KeyGenerator keyGenerator) {
|
||||
super(context, DIRECTORY_NAME);
|
||||
public FileBlobStoreFactory(RepositoryLocationResolver repositoryLocationResolver, KeyGenerator keyGenerator) {
|
||||
super(repositoryLocationResolver, DIRECTORY_NAME);
|
||||
this.keyGenerator = keyGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlobStore getBlobStore(String name) {
|
||||
LOG.debug("create new blob with name {}", name);
|
||||
|
||||
return new FileBlobStore(keyGenerator, getDirectory(name));
|
||||
public BlobStore getStore(StoreParameters storeParameters) {
|
||||
if (storeParameters.getRepository() != null) {
|
||||
return new FileBlobStore(keyGenerator, getDirectory(storeParameters.getName(), storeParameters.getRepository()));
|
||||
}
|
||||
return new FileBlobStore(keyGenerator, getDirectory(storeParameters.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.security.KeyGenerator;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
@@ -91,18 +92,16 @@ public class JAXBConfigurationEntryStoreFactory
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public <T> ConfigurationEntryStore<T> getStore(Class<T> type, String name)
|
||||
private ConfigurationEntryStore getStore(Class type, String name)
|
||||
{
|
||||
logger.debug("create new configuration store for type {} with name {}",
|
||||
type, name);
|
||||
|
||||
//J-
|
||||
return new JAXBConfigurationEntryStore<T>(
|
||||
return new JAXBConfigurationEntryStore(
|
||||
new File(directory,name.concat(StoreConstants.FILE_EXTENSION)),
|
||||
keyGenerator,
|
||||
type
|
||||
@@ -117,4 +116,17 @@ public class JAXBConfigurationEntryStoreFactory
|
||||
|
||||
/** Field description */
|
||||
private KeyGenerator keyGenerator;
|
||||
|
||||
@Override
|
||||
public ConfigurationEntryStore getStore(StoreParameters storeParameters) {
|
||||
if (storeParameters.getRepository() != null){
|
||||
return getStore(storeParameters.getType(),storeParameters.getName(),storeParameters.getRepository());
|
||||
}
|
||||
return getStore(storeParameters.getType(),storeParameters.getName());
|
||||
}
|
||||
|
||||
private ConfigurationEntryStore getStore(Class type, String name, Repository repository) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class JAXBConfigurationStore<T> extends AbstractStore<T> {
|
||||
|
||||
private JAXBContext context;
|
||||
|
||||
JAXBConfigurationStore(Class<T> type, File configFile) {
|
||||
public JAXBConfigurationStore(Class<T> type, File configFile) {
|
||||
this.type = type;
|
||||
|
||||
try {
|
||||
|
||||
@@ -32,17 +32,18 @@ package sonia.scm.store;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* JAXB implementation of {@link ConfigurationStoreFactory}.
|
||||
* JAXB implementation of {@link StoreFactory}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@@ -54,33 +55,65 @@ public class JAXBConfigurationStoreFactory implements ConfigurationStoreFactory
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JAXBConfigurationStoreFactory.class);
|
||||
|
||||
private final File configDirectory;
|
||||
private RepositoryLocationResolver repositoryLocationResolver;
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param context scm context
|
||||
* @param repositoryLocationResolver Resolver to get the repository Directory
|
||||
*/
|
||||
@Inject
|
||||
public JAXBConfigurationStoreFactory(SCMContextProvider context) {
|
||||
configDirectory = new File(context.getBaseDirectory(), StoreConstants.CONFIG_DIRECTORY_NAME);
|
||||
IOUtil.mkdirs(configDirectory);
|
||||
public JAXBConfigurationStoreFactory(RepositoryLocationResolver repositoryLocationResolver) {
|
||||
this.repositoryLocationResolver = repositoryLocationResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> JAXBConfigurationStore<T> getStore(Class<T> type, String name) {
|
||||
if (configDirectory == null) {
|
||||
throw new IllegalStateException("store factory is not initialized");
|
||||
}
|
||||
/**
|
||||
* Get or create the global config directory.
|
||||
*
|
||||
* @return the global config directory.
|
||||
*/
|
||||
private File getGlobalConfigDirectory() {
|
||||
File baseDirectory = repositoryLocationResolver.getInitialBaseDirectory();
|
||||
File configDirectory = new File(baseDirectory, StoreConstants.CONFIG_DIRECTORY_NAME);
|
||||
return getOrCreateFile(configDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create the repository specific config directory.
|
||||
*
|
||||
* @return the repository specific config directory.
|
||||
*/
|
||||
private File getRepositoryConfigDirectory(Repository repository) {
|
||||
File baseDirectory = null;
|
||||
try {
|
||||
baseDirectory = repositoryLocationResolver.getConfigDirectory(repository);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
File configDirectory = new File(baseDirectory, StoreConstants.CONFIG_DIRECTORY_NAME);
|
||||
return getOrCreateFile(configDirectory);
|
||||
}
|
||||
|
||||
private File getOrCreateFile(File directory) {
|
||||
if (!directory.exists()) {
|
||||
IOUtil.mkdirs(directory);
|
||||
}
|
||||
return directory;
|
||||
}
|
||||
|
||||
private JAXBConfigurationStore getStore(Class type, String name, File configDirectory) {
|
||||
File configFile = new File(configDirectory, name.concat(StoreConstants.FILE_EXTENSION));
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("create store for {} at {}", type.getName(),
|
||||
configFile.getPath());
|
||||
}
|
||||
|
||||
LOG.debug("create store for {} at {}", type.getName(), configFile.getPath());
|
||||
return new JAXBConfigurationStore<>(type, configFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JAXBConfigurationStore getStore(StoreParameters storeParameters) {
|
||||
try {
|
||||
return getStore(storeParameters.getType(), storeParameters.getName(),repositoryLocationResolver.getRepositoryDirectory(storeParameters.getRepository()));
|
||||
} catch (IOException e) {
|
||||
|
||||
throw new InternalRepositoryException(storeParameters.getRepository(),"Error on getting the store of the repository"+ storeParameters.getRepository().getNamespaceAndName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.security.KeyGenerator;
|
||||
|
||||
/**
|
||||
@@ -52,54 +52,23 @@ public class JAXBDataStoreFactory extends FileBasedStoreFactory
|
||||
implements DataStoreFactory
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final Logger logger = LoggerFactory.getLogger(JAXBDataStoreFactory.class);
|
||||
private static final String DIRECTORY_NAME = "data";
|
||||
private KeyGenerator keyGenerator;
|
||||
|
||||
/**
|
||||
* the logger for JAXBDataStoreFactory
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(JAXBDataStoreFactory.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
* @param keyGenerator
|
||||
*/
|
||||
@Inject
|
||||
public JAXBDataStoreFactory(SCMContextProvider context,
|
||||
KeyGenerator keyGenerator)
|
||||
{
|
||||
super(context, DIRECTORY_NAME);
|
||||
public JAXBDataStoreFactory(RepositoryLocationResolver repositoryLocationResolver, KeyGenerator keyGenerator) {
|
||||
super(repositoryLocationResolver, DIRECTORY_NAME);
|
||||
this.keyGenerator = keyGenerator;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public <T> DataStore<T> getStore(Class<T> type, String name)
|
||||
{
|
||||
logger.debug("create new store for type {} with name {}", type, name);
|
||||
|
||||
return new JAXBDataStore<>(keyGenerator, type, getDirectory(name));
|
||||
@SuppressWarnings("unchecked")
|
||||
public DataStore getStore(StoreParameters storeParameters) {
|
||||
logger.debug("create new store for type {} with name {}", storeParameters.getType(), storeParameters.getName());
|
||||
if (storeParameters.getRepository() != null) {
|
||||
return new JAXBDataStore(keyGenerator, storeParameters.getType(), getDirectory(storeParameters.getName(), storeParameters.getRepository()));
|
||||
}
|
||||
return new JAXBDataStore(keyGenerator, storeParameters.getType(), getDirectory(storeParameters.getName()));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private KeyGenerator keyGenerator;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ package sonia.scm.user.xml;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.store.StoreParameters;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserDAO;
|
||||
import sonia.scm.xml.AbstractXmlDAO;
|
||||
@@ -65,7 +66,10 @@ public class XmlUserDAO extends AbstractXmlDAO<User, XmlUserDatabase>
|
||||
@Inject
|
||||
public XmlUserDAO(ConfigurationStoreFactory storeFactory)
|
||||
{
|
||||
super(storeFactory.getStore(XmlUserDatabase.class, STORE_NAME));
|
||||
super(storeFactory.getStore(new StoreParameters()
|
||||
.withType(XmlUserDatabase.class)
|
||||
.withName(STORE_NAME)
|
||||
.build()));
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -52,6 +52,6 @@ public class FileBlobStoreTest extends BlobStoreTestBase
|
||||
@Override
|
||||
protected BlobStoreFactory createBlobStoreFactory()
|
||||
{
|
||||
return new FileBlobStoreFactory(contextProvider, new UUIDKeyGenerator());
|
||||
return new FileBlobStoreFactory(repositoryLocationResolver, new UUIDKeyGenerator());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,25 +37,22 @@ package sonia.scm.store;
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.security.AssignedPermission;
|
||||
import sonia.scm.security.UUIDKeyGenerator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -132,13 +129,13 @@ public class JAXBConfigurationEntryStoreTest
|
||||
public void testStoreAndLoad() throws IOException
|
||||
{
|
||||
String name = UUID.randomUUID().toString();
|
||||
ConfigurationEntryStore<AssignedPermission> store =
|
||||
createPermissionStore(RESOURCE_FIXED, name);
|
||||
ConfigurationEntryStore<AssignedPermission> store = createPermissionStore(RESOURCE_FIXED, name);
|
||||
|
||||
store.put("a45", new AssignedPermission("tuser4", "repository:create"));
|
||||
store =
|
||||
createConfigurationStoreFactory().getStore(AssignedPermission.class,
|
||||
name);
|
||||
store = createConfigurationStoreFactory().getStore(new StoreParameters()
|
||||
.withType(AssignedPermission.class)
|
||||
.withName(name)
|
||||
.build());
|
||||
|
||||
AssignedPermission ap = store.get("a45");
|
||||
|
||||
@@ -154,10 +151,9 @@ public class JAXBConfigurationEntryStoreTest
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected ConfigurationEntryStoreFactory createConfigurationStoreFactory()
|
||||
protected ConfigurationEntryStoreFactory createConfigurationStoreFactory()
|
||||
{
|
||||
return new JAXBConfigurationEntryStoreFactory(new UUIDKeyGenerator(),
|
||||
contextProvider);
|
||||
return new JAXBConfigurationEntryStoreFactory(new UUIDKeyGenerator(), contextProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,8 +221,9 @@ public class JAXBConfigurationEntryStoreTest
|
||||
}
|
||||
|
||||
copy(resource, name);
|
||||
|
||||
return createConfigurationStoreFactory().getStore(AssignedPermission.class,
|
||||
name);
|
||||
return createConfigurationStoreFactory().getStore(new StoreParameters()
|
||||
.withType(AssignedPermission.class)
|
||||
.withName(name)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ package sonia.scm.store;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JAXBConfigurationStore}.
|
||||
*
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class JAXBConfigurationStoreTest extends StoreTestBase {
|
||||
@@ -42,6 +42,6 @@ public class JAXBConfigurationStoreTest extends StoreTestBase {
|
||||
@Override
|
||||
protected ConfigurationStoreFactory createStoreFactory()
|
||||
{
|
||||
return new JAXBConfigurationStoreFactory(contextProvider);
|
||||
return new JAXBConfigurationStoreFactory(repositoryLocationResolver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,14 +34,14 @@ package sonia.scm.store;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.security.UUIDKeyGenerator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class JAXBDataStoreTest extends DataStoreTestBase
|
||||
{
|
||||
public class JAXBDataStoreTest extends DataStoreTestBase {
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -52,6 +52,25 @@ public class JAXBDataStoreTest extends DataStoreTestBase
|
||||
@Override
|
||||
protected DataStoreFactory createDataStoreFactory()
|
||||
{
|
||||
return new JAXBDataStoreFactory(contextProvider, new UUIDKeyGenerator());
|
||||
return new JAXBDataStoreFactory(repositoryLocationResolver, new UUIDKeyGenerator());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataStore getDataStore(Class type, Repository repository) {
|
||||
StoreParameters params = new StoreParameters()
|
||||
.withType(type)
|
||||
.withName("test")
|
||||
.forRepository(repository)
|
||||
.build();
|
||||
return createDataStoreFactory().getStore(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataStore getDataStore(Class type) {
|
||||
StoreParameters params = new StoreParameters()
|
||||
.withType(type)
|
||||
.withName("test")
|
||||
.build();
|
||||
return createDataStoreFactory().getStore(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,10 @@ package sonia.scm.web.lfs;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.store.Blob;
|
||||
import sonia.scm.store.BlobStore;
|
||||
import sonia.scm.store.BlobStoreFactory;
|
||||
import sonia.scm.store.StoreParameters;
|
||||
|
||||
/**
|
||||
* Creates {@link BlobStore} objects to store lfs objects.
|
||||
@@ -74,7 +76,13 @@ public class LfsBlobStoreFactory {
|
||||
*
|
||||
* @return blob store for the corresponding scm repository
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public BlobStore getLfsBlobStore(Repository repository) {
|
||||
return blobStoreFactory.getBlobStore(repository.getId() + GIT_LFS_REPOSITORY_POSTFIX);
|
||||
return blobStoreFactory.getStore(new StoreParameters()
|
||||
.withType(Blob.class)
|
||||
.withName(repository.getId() + GIT_LFS_REPOSITORY_POSTFIX)
|
||||
.forRepository(repository)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +39,12 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.schedule.Scheduler;
|
||||
import sonia.scm.store.ConfigurationStore;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -40,7 +40,8 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.store.BlobStoreFactory;
|
||||
|
||||
import static org.mockito.Matchers.matches;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
@@ -59,12 +60,17 @@ public class LfsBlobStoreFactoryTest {
|
||||
private LfsBlobStoreFactory lfsBlobStoreFactory;
|
||||
|
||||
@Test
|
||||
public void getBlobStore() throws Exception {
|
||||
lfsBlobStoreFactory.getLfsBlobStore(new Repository("the-id", "GIT", "space", "the-name"));
|
||||
public void getBlobStore() {
|
||||
Repository repository = new Repository("the-id", "GIT", "space", "the-name");
|
||||
lfsBlobStoreFactory.getLfsBlobStore(repository);
|
||||
|
||||
// just make sure the right parameter is passed, as properly validating the return value is nearly impossible with
|
||||
// the return value (and should not be part of this test)
|
||||
verify(blobStoreFactory).getBlobStore(matches("the-id-git-lfs"));
|
||||
verify(blobStoreFactory).getStore(argThat(blobStoreParameters -> {
|
||||
assertThat(blobStoreParameters.getName()).isEqualTo("the-id-git-lfs");
|
||||
assertThat(blobStoreParameters.getRepository()).isEqualTo(repository);
|
||||
return true;
|
||||
}));
|
||||
|
||||
// make sure there have been no further usages of the factory
|
||||
verifyNoMoreInteractions(blobStoreFactory);
|
||||
|
||||
@@ -39,9 +39,12 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.store.ConfigurationStore;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -51,6 +51,7 @@ import sonia.scm.logging.SVNKitLogger;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.spi.HookEventFacade;
|
||||
import sonia.scm.repository.spi.SvnRepositoryServiceProvider;
|
||||
import sonia.scm.store.ConfigurationStore;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
|
||||
@Test
|
||||
public void getDirectory() {
|
||||
when(factory.getStore(any(), any())).thenReturn(store);
|
||||
when(factory.getStore(any())).thenReturn(store);
|
||||
SvnRepositoryHandler repositoryHandler = new SvnRepositoryHandler(factory,
|
||||
new DefaultFileSystem(), facade, repositoryLocationResolver);
|
||||
|
||||
|
||||
@@ -46,10 +46,15 @@ import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.repository.InitialRepositoryLocationResolver;
|
||||
import sonia.scm.repository.RepositoryDAO;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -66,10 +71,29 @@ import java.util.logging.Logger;
|
||||
public class AbstractTestBase
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static ThreadState subjectThreadState;
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
protected SCMContextProvider contextProvider;
|
||||
|
||||
private File tempDirectory;
|
||||
|
||||
protected DefaultFileSystem fileSystem;
|
||||
|
||||
protected RepositoryDAO repositoryDAO = mock(RepositoryDAO.class);
|
||||
protected RepositoryLocationResolver repositoryLocationResolver;
|
||||
|
||||
@Before
|
||||
public void setUpTest() throws Exception
|
||||
{
|
||||
tempDirectory = new File(System.getProperty("java.io.tmpdir"),
|
||||
UUID.randomUUID().toString());
|
||||
assertTrue(tempDirectory.mkdirs());
|
||||
contextProvider = MockUtil.getSCMContextProvider(tempDirectory);
|
||||
fileSystem = new DefaultFileSystem();
|
||||
InitialRepositoryLocationResolver initialRepoLocationResolver = new InitialRepositoryLocationResolver(contextProvider,fileSystem);
|
||||
repositoryLocationResolver = new RepositoryLocationResolver(repositoryDAO, initialRepoLocationResolver);
|
||||
postSetUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -165,25 +189,6 @@ public class AbstractTestBase
|
||||
}
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUpTest() throws Exception
|
||||
{
|
||||
tempDirectory = new File(System.getProperty("java.io.tmpdir"),
|
||||
UUID.randomUUID().toString());
|
||||
assertTrue(tempDirectory.mkdirs());
|
||||
contextProvider = MockUtil.getSCMContextProvider(tempDirectory);
|
||||
postSetUp();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clears Shiro's thread state, ensuring the thread remains clean for
|
||||
@@ -249,12 +254,4 @@ public class AbstractTestBase
|
||||
subjectThreadState = createThreadState(subject);
|
||||
subjectThreadState.bind();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected SCMContextProvider contextProvider;
|
||||
|
||||
/** Field description */
|
||||
private File tempDirectory;
|
||||
}
|
||||
|
||||
@@ -37,10 +37,13 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -54,12 +57,14 @@ public abstract class ManagerTestBase<T extends ModelObject>
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
protected SCMContextProvider contextProvider;
|
||||
|
||||
protected RepositoryLocationResolver locationResolver;
|
||||
|
||||
protected Manager<T> manager;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
contextProvider = MockUtil.getSCMContextProvider(tempFolder.newFolder());
|
||||
locationResolver = mock(RepositoryLocationResolver.class);
|
||||
manager = createManager();
|
||||
manager.init(contextProvider);
|
||||
}
|
||||
|
||||
@@ -35,22 +35,24 @@ package sonia.scm.store;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -58,12 +60,6 @@ import java.util.List;
|
||||
public abstract class BlobStoreTestBase extends AbstractTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract BlobStoreFactory createBlobStoreFactory();
|
||||
|
||||
/**
|
||||
@@ -73,7 +69,12 @@ public abstract class BlobStoreTestBase extends AbstractTestBase
|
||||
@Before
|
||||
public void createBlobStore()
|
||||
{
|
||||
store = createBlobStoreFactory().getBlobStore("test");
|
||||
store = createBlobStoreFactory().getStore(new StoreParameters()
|
||||
.withType(Blob.class)
|
||||
.withName("test")
|
||||
.forRepository(RepositoryTestData.createHeartOfGold())
|
||||
.build()
|
||||
);
|
||||
store.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,12 +32,13 @@
|
||||
|
||||
package sonia.scm.store;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestBase
|
||||
{
|
||||
public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestBase {
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -48,17 +49,22 @@ public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestB
|
||||
protected abstract ConfigurationEntryStoreFactory createConfigurationStoreFactory();
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected ConfigurationEntryStore<StoreObject> getDataStore()
|
||||
{
|
||||
return createConfigurationStoreFactory().getStore(StoreObject.class,
|
||||
"test");
|
||||
protected ConfigurationEntryStore getDataStore(Class type) {
|
||||
StoreParameters params = new StoreParameters()
|
||||
.withType(type)
|
||||
.withName("test")
|
||||
.build();
|
||||
return this.createConfigurationStoreFactory().getStore(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConfigurationEntryStore getDataStore(Class type, Repository repository) {
|
||||
StoreParameters params = new StoreParameters()
|
||||
.withType(type)
|
||||
.withName("test")
|
||||
.forRepository(repository)
|
||||
.build();
|
||||
return this.createConfigurationStoreFactory().getStore(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
|
||||
package sonia.scm.store;
|
||||
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -48,17 +55,33 @@ public abstract class DataStoreTestBase extends KeyValueStoreTestBase
|
||||
*/
|
||||
protected abstract DataStoreFactory createDataStoreFactory();
|
||||
|
||||
|
||||
protected StoreParameters getStoreParametersWithRepository(Repository repository) {
|
||||
return new StoreParameters()
|
||||
.withType(StoreObject.class)
|
||||
.withName("test")
|
||||
.forRepository(repository)
|
||||
.build();
|
||||
}
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected DataStore<StoreObject> getDataStore()
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
// TODO
|
||||
public void shouldStoreRepositorySpecificData()
|
||||
{
|
||||
return createDataStoreFactory().getStore(StoreObject.class, "test");
|
||||
StoreFactory<DataStore > dataStoreFactory = createDataStoreFactory();
|
||||
StoreObject obj = new StoreObject("test-1");
|
||||
Repository repository = RepositoryTestData.createHeartOfGold();
|
||||
|
||||
DataStore<StoreObject> store = dataStoreFactory.getStore(getStoreParametersWithRepository(repository));
|
||||
|
||||
String id = store.put(obj);
|
||||
|
||||
assertNotNull(id);
|
||||
|
||||
assertEquals(obj, store.get(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ package sonia.scm.store;
|
||||
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
|
||||
|
||||
@Override
|
||||
public <T> ConfigurationStore<T> getStore(Class<T> type, String name)
|
||||
{
|
||||
public ConfigurationStore getStore(StoreParameters storeParameters) {
|
||||
return new InMemoryConfigurationStore<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -56,13 +58,19 @@ import java.util.Map;
|
||||
public abstract class KeyValueStoreTestBase extends AbstractTestBase
|
||||
{
|
||||
|
||||
private Repository repository = RepositoryTestData.createHeartOfGold();
|
||||
private DataStore<StoreObject> store;
|
||||
private DataStore<StoreObject> repoStore;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract DataStore<StoreObject> getDataStore();
|
||||
protected abstract <STORE_OBJECT> DataStore<STORE_OBJECT> getDataStore(Class<STORE_OBJECT> type , Repository repository);
|
||||
protected abstract <STORE_OBJECT> DataStore<STORE_OBJECT> getDataStore(Class<STORE_OBJECT> type );
|
||||
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -73,8 +81,10 @@ public abstract class KeyValueStoreTestBase extends AbstractTestBase
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
store = getDataStore();
|
||||
store = getDataStore(StoreObject.class);
|
||||
repoStore = getDataStore(StoreObject.class, repository);
|
||||
store.clear();
|
||||
repoStore.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,8 +225,5 @@ public abstract class KeyValueStoreTestBase extends AbstractTestBase
|
||||
assertNull(store.get("2"));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private DataStore<StoreObject> store;
|
||||
}
|
||||
|
||||
@@ -35,10 +35,12 @@ package sonia.scm.store;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -58,6 +60,13 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
*/
|
||||
protected abstract ConfigurationStoreFactory createStoreFactory();
|
||||
|
||||
protected StoreParameters getStoreParameters() {
|
||||
return new StoreParameters()
|
||||
.withType(StoreObject.class)
|
||||
.withName("test")
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -65,8 +74,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
@Test
|
||||
public void testGet()
|
||||
{
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
|
||||
"test");
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(getStoreParameters());
|
||||
|
||||
assertNotNull(store);
|
||||
|
||||
@@ -82,8 +90,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
@Test
|
||||
public void testSet()
|
||||
{
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
|
||||
"test");
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(getStoreParameters());
|
||||
|
||||
assertNotNull(store);
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.group.GroupEvent;
|
||||
import sonia.scm.store.ConfigurationEntryStore;
|
||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||
import sonia.scm.store.StoreParameters;
|
||||
import sonia.scm.user.UserEvent;
|
||||
import sonia.scm.util.ClassLoaders;
|
||||
|
||||
@@ -108,9 +109,13 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
* @param storeFactory
|
||||
*/
|
||||
@Inject
|
||||
@SuppressWarnings("unchecked")
|
||||
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory)
|
||||
{
|
||||
store = storeFactory.getStore(AssignedPermission.class, NAME);
|
||||
store = storeFactory.getStore(new StoreParameters()
|
||||
.withType(AssignedPermission.class)
|
||||
.withName(NAME)
|
||||
.build());
|
||||
readAvailablePermissions();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.store.ConfigurationEntryStore;
|
||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||
import sonia.scm.store.StoreParameters;
|
||||
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
|
||||
@@ -87,9 +88,13 @@ public class SecureKeyResolver extends SigningKeyResolverAdapter
|
||||
* @param storeFactory store factory
|
||||
*/
|
||||
@Inject
|
||||
@SuppressWarnings("unchecked")
|
||||
public SecureKeyResolver(ConfigurationEntryStoreFactory storeFactory)
|
||||
{
|
||||
this.store = storeFactory.getStore(SecureKey.class, STORE_NAME);
|
||||
store = storeFactory.getStore(new StoreParameters()
|
||||
.withType(SecureKey.class)
|
||||
.withName(STORE_NAME)
|
||||
.build());
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -66,7 +66,7 @@ public class AutoCompleteResourceTest {
|
||||
ConfigurationStore<Object> storeConfig = mock(ConfigurationStore.class);
|
||||
xmlDB = mock(XmlDatabase.class);
|
||||
when(storeConfig.get()).thenReturn(xmlDB);
|
||||
when(storeFactory.getStore(any(), any())).thenReturn(storeConfig);
|
||||
when(storeFactory.getStore(any())).thenReturn(storeConfig);
|
||||
XmlUserDAO userDao = new XmlUserDAO(storeFactory);
|
||||
this.userDao = spy(userDao);
|
||||
XmlGroupDAO groupDAO = new XmlGroupDAO(storeFactory);
|
||||
|
||||
@@ -422,10 +422,10 @@ 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);
|
||||
InitialRepositoryLocationResolver initialRepositoryLocationResolver = new InitialRepositoryLocationResolver(contextProvider, fileSystem);
|
||||
XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(factory, initialRepositoryLocationResolver);
|
||||
XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(initialRepositoryLocationResolver, contextProvider);
|
||||
RepositoryLocationResolver repositoryLocationResolver = new RepositoryLocationResolver(repositoryDAO, initialRepositoryLocationResolver);
|
||||
ConfigurationStoreFactory factory = new JAXBConfigurationStoreFactory(repositoryLocationResolver);
|
||||
handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver));
|
||||
handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver) {
|
||||
@Override
|
||||
|
||||
@@ -36,20 +36,21 @@ package sonia.scm.security;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import io.jsonwebtoken.Jwts;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import sonia.scm.store.ConfigurationEntryStore;
|
||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -122,11 +123,13 @@ public class SecureKeyResolverTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
ConfigurationEntryStoreFactory factory =
|
||||
mock(ConfigurationEntryStoreFactory.class);
|
||||
ConfigurationEntryStoreFactory factory = mock(ConfigurationEntryStoreFactory.class);
|
||||
|
||||
when(factory.getStore(SecureKey.class,
|
||||
SecureKeyResolver.STORE_NAME)).thenReturn(store);
|
||||
when(factory.getStore(argThat(storeParameters -> {
|
||||
assertThat(storeParameters.getName()).isEqualTo(SecureKeyResolver.STORE_NAME);
|
||||
assertThat(storeParameters.getType()).isEqualTo(SecureKey.class);
|
||||
return true;
|
||||
}))).thenReturn(store);
|
||||
resolver = new SecureKeyResolver(factory);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,6 +182,6 @@ public class DefaultUserManagerTest extends UserManagerTestBase
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
private XmlUserDAO createXmlUserDAO() {
|
||||
return new XmlUserDAO(new JAXBConfigurationStoreFactory(contextProvider));
|
||||
return new XmlUserDAO(new JAXBConfigurationStoreFactory(locationResolver));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user