mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-03 03:55:51 +01:00
merge + refactor getStoreDirectory
This commit is contained in:
@@ -46,7 +46,11 @@ import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
|
||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
||||
import org.tmatesoft.svn.util.SVNDebugLog;
|
||||
import sonia.scm.io.FileSystem;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.io.INIConfiguration;
|
||||
import sonia.scm.io.INIConfigurationReader;
|
||||
import sonia.scm.io.INIConfigurationWriter;
|
||||
import sonia.scm.io.INISection;
|
||||
import sonia.scm.logging.SVNKitLogger;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.spi.HookEventFacade;
|
||||
@@ -56,6 +60,7 @@ import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
|
||||
@@ -82,15 +87,19 @@ public class SvnRepositoryHandler
|
||||
public static final RepositoryType TYPE = new RepositoryType(TYPE_NAME,
|
||||
TYPE_DISPLAYNAME,
|
||||
SvnRepositoryServiceProvider.COMMANDS);
|
||||
private static final String CONFIG_FILE_NAME = "scm-manager.conf";
|
||||
private static final String CONFIG_SECTION_SCMM = "scmm";
|
||||
private static final String CONFIG_KEY_REPOSITORY_ID = "repositoryid";
|
||||
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(SvnRepositoryHandler.class);
|
||||
|
||||
@Inject
|
||||
public SvnRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem,
|
||||
HookEventFacade eventFacade, RepositoryLocationResolver repositoryLocationResolver)
|
||||
public SvnRepositoryHandler(ConfigurationStoreFactory storeFactory,
|
||||
HookEventFacade eventFacade,
|
||||
RepositoryLocationResolver repositoryLocationResolver)
|
||||
{
|
||||
super(storeFactory, fileSystem, repositoryLocationResolver);
|
||||
super(storeFactory, repositoryLocationResolver);
|
||||
|
||||
// register logger
|
||||
SVNDebugLog.setDefaultLog(new SVNKitLogger());
|
||||
@@ -210,4 +219,21 @@ public class SvnRepositoryHandler
|
||||
{
|
||||
return SvnConfig.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postCreate(Repository repository, File directory) throws IOException {
|
||||
INISection iniSection = new INISection(CONFIG_SECTION_SCMM);
|
||||
iniSection.setParameter(CONFIG_KEY_REPOSITORY_ID, repository.getId());
|
||||
INIConfiguration iniConfiguration = new INIConfiguration();
|
||||
iniConfiguration.addSection(iniSection);
|
||||
new INIConfigurationWriter().write(iniConfiguration, new File(directory, CONFIG_FILE_NAME));
|
||||
}
|
||||
|
||||
String getRepositoryId(File directory) {
|
||||
try {
|
||||
return new INIConfigurationReader().read(new File(directory, CONFIG_FILE_NAME)).getSection(CONFIG_SECTION_SCMM).getParameter(CONFIG_KEY_REPOSITORY_ID);
|
||||
} catch (IOException e) {
|
||||
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity("directory", directory.toString()), "could not read scm configuration file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,16 +70,7 @@ public class SvnRepositoryHook implements FSHook
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param hookEventFacade
|
||||
* @param handler
|
||||
*/
|
||||
public SvnRepositoryHook(HookEventFacade hookEventFacade,
|
||||
SvnRepositoryHandler handler)
|
||||
public SvnRepositoryHook(HookEventFacade hookEventFacade, SvnRepositoryHandler handler)
|
||||
{
|
||||
this.hookEventFacade = hookEventFacade;
|
||||
this.handler = handler;
|
||||
@@ -163,10 +154,10 @@ public class SvnRepositoryHook implements FSHook
|
||||
{
|
||||
try
|
||||
{
|
||||
String id = getRepositoryId(directory);
|
||||
String repositoryId = getRepositoryId(directory);
|
||||
|
||||
//J-
|
||||
hookEventFacade.handle(id)
|
||||
hookEventFacade.handle(repositoryId)
|
||||
.fireHookEvent(
|
||||
changesetProvider.getType(),
|
||||
new SvnHookContextProvider(changesetProvider)
|
||||
@@ -197,18 +188,16 @@ public class SvnRepositoryHook implements FSHook
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private String getRepositoryId(File directory) throws IOException
|
||||
private String getRepositoryId(File directory)
|
||||
{
|
||||
AssertUtil.assertIsNotNull(directory);
|
||||
|
||||
return RepositoryUtil.getRepositoryId(handler, directory);
|
||||
return handler.getRepositoryId(directory);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private SvnRepositoryHandler handler;
|
||||
|
||||
/** Field description */
|
||||
private HookEventFacade hookEventFacade;
|
||||
|
||||
private final SvnRepositoryHandler handler;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { translate } from "react-i18next";
|
||||
import { InputField, Checkbox, Select } from "@scm-manager/ui-components";
|
||||
|
||||
type Configuration = {
|
||||
repositoryDirectory: string,
|
||||
compatibility: string,
|
||||
enabledGZip: boolean,
|
||||
disabled: boolean,
|
||||
@@ -31,14 +30,11 @@ class HgConfigurationForm extends React.Component<Props, State> {
|
||||
this.state = { ...props.initialConfiguration, validationErrors: [] };
|
||||
}
|
||||
|
||||
isValid = () => {
|
||||
return !!this.state.repositoryDirectory;
|
||||
};
|
||||
|
||||
handleChange = (value: any, name: string) => {
|
||||
this.setState({
|
||||
[name]: value
|
||||
}, () => this.props.onConfigurationChange(this.state, this.isValid()));
|
||||
}, () => this.props.onConfigurationChange(this.state, true));
|
||||
};
|
||||
|
||||
compatibilityOptions = (values: string[]) => {
|
||||
@@ -64,16 +60,6 @@ class HgConfigurationForm extends React.Component<Props, State> {
|
||||
|
||||
return (
|
||||
<>
|
||||
<InputField
|
||||
name="repositoryDirectory"
|
||||
label={t("scm-svn-plugin.config.directory")}
|
||||
helpText={t("scm-svn-plugin.config.directoryHelpText")}
|
||||
value={this.state.repositoryDirectory}
|
||||
errorMessage={t("scm-svn-plugin.config.required")}
|
||||
validationError={!this.state.repositoryDirectory}
|
||||
onChange={this.handleChange}
|
||||
disabled={readOnly}
|
||||
/>
|
||||
<Select
|
||||
name="compatibility"
|
||||
label={t("scm-svn-plugin.config.compatibility")}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import { Title, GlobalConfiguration } from "@scm-manager/ui-components";
|
||||
import { Title, Configuration } from "@scm-manager/ui-components";
|
||||
import SvnConfigurationForm from "./SvnConfigurationForm";
|
||||
|
||||
type Props = {
|
||||
@@ -18,7 +18,7 @@ class SvnGlobalConfiguration extends React.Component<Props> {
|
||||
return (
|
||||
<div>
|
||||
<Title title={t("scm-svn-plugin.config.title")}/>
|
||||
<GlobalConfiguration link={link} render={props => <SvnConfigurationForm {...props} />}/>
|
||||
<Configuration link={link} render={props => <SvnConfigurationForm {...props} />}/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
"config": {
|
||||
"link": "Subversion",
|
||||
"title": "Subversion Configuration",
|
||||
"directory": "Repository Directory",
|
||||
"directoryHelpText": "Location of Subversion repositories.",
|
||||
"compatibility": "Version Compatibility",
|
||||
"compatibilityHelpText": "Specifies with which subversion version repositories are compatible.",
|
||||
"compatibility-values": {
|
||||
|
||||
@@ -36,14 +36,12 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.repository.api.HookContextFactory;
|
||||
import sonia.scm.repository.spi.HookEventFacade;
|
||||
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;
|
||||
@@ -69,12 +67,14 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
@Mock
|
||||
private com.google.inject.Provider<RepositoryManager> repositoryManagerProvider;
|
||||
|
||||
@Mock
|
||||
private RepositoryDAO repositoryDAO;
|
||||
|
||||
private HookContextFactory hookContextFactory = new HookContextFactory(mock(PreProcessorUtil.class));
|
||||
|
||||
private HookEventFacade facade = new HookEventFacade(repositoryManagerProvider, hookContextFactory);
|
||||
|
||||
RepositoryLocationResolver repositoryLocationResolver ;
|
||||
private Path repoDir;
|
||||
private RepositoryLocationResolver repositoryLocationResolver;
|
||||
|
||||
@Override
|
||||
protected void checkDirectory(File directory) {
|
||||
@@ -91,18 +91,10 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
|
||||
@Override
|
||||
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
|
||||
File directory) throws RepositoryPathNotFoundException {
|
||||
File directory) {
|
||||
repositoryLocationResolver = new RepositoryLocationResolver(repoDao, new InitialRepositoryLocationResolver(contextProvider));
|
||||
SvnRepositoryHandler handler = new SvnRepositoryHandler(factory, null, repositoryLocationResolver);
|
||||
|
||||
|
||||
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();
|
||||
@@ -117,14 +109,13 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
public void getDirectory() {
|
||||
when(factory.getStore(any())).thenReturn(store);
|
||||
SvnRepositoryHandler repositoryHandler = new SvnRepositoryHandler(factory,
|
||||
new DefaultFileSystem(), facade, repositoryLocationResolver);
|
||||
facade, repositoryLocationResolver);
|
||||
|
||||
SvnConfig svnConfig = new SvnConfig();
|
||||
repositoryHandler.setConfig(svnConfig);
|
||||
|
||||
Repository repository = new Repository("id", "svn", "Space", "Name");
|
||||
|
||||
initRepository();
|
||||
File path = repositoryHandler.getDirectory(repository);
|
||||
assertEquals(repoDir.toString()+File.separator+InitialRepositoryLocationResolver.REPOSITORIES_NATIVE_DIRECTORY, path.getAbsolutePath());
|
||||
assertEquals(repoPath.toString()+File.separator+ AbstractSimpleRepositoryHandler.REPOSITORIES_NATIVE_DIRECTORY, path.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user