mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
Remove old property for default branch
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
package sonia.scm.api.v2.resources;
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sonia.scm.event.ScmEventBus;
|
||||||
|
import sonia.scm.repository.ClearRepositoryCacheEvent;
|
||||||
import sonia.scm.repository.GitRepositoryConfig;
|
import sonia.scm.repository.GitRepositoryConfig;
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
@@ -22,15 +26,17 @@ import static sonia.scm.NotFoundException.notFound;
|
|||||||
|
|
||||||
public class GitRepositoryConfigResource {
|
public class GitRepositoryConfigResource {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(GitRepositoryConfigResource.class);
|
||||||
|
|
||||||
private final GitRepositoryConfigMapper repositoryConfigMapper;
|
private final GitRepositoryConfigMapper repositoryConfigMapper;
|
||||||
private final RepositoryManager repositoryManager;
|
private final RepositoryManager repositoryManager;
|
||||||
private final ConfigurationStoreFactory configurationStoreFactory;
|
private final GitRepositoryConfigStoreProvider gitRepositoryConfigStoreProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GitRepositoryConfigResource(GitRepositoryConfigMapper repositoryConfigMapper, RepositoryManager repositoryManager, ConfigurationStoreFactory configurationStoreFactory) {
|
public GitRepositoryConfigResource(GitRepositoryConfigMapper repositoryConfigMapper, RepositoryManager repositoryManager, GitRepositoryConfigStoreProvider gitRepositoryConfigStoreProvider) {
|
||||||
this.repositoryConfigMapper = repositoryConfigMapper;
|
this.repositoryConfigMapper = repositoryConfigMapper;
|
||||||
this.repositoryManager = repositoryManager;
|
this.repositoryManager = repositoryManager;
|
||||||
this.configurationStoreFactory = configurationStoreFactory;
|
this.gitRepositoryConfigStoreProvider = gitRepositoryConfigStoreProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -55,9 +61,15 @@ public class GitRepositoryConfigResource {
|
|||||||
ConfigurationStore<GitRepositoryConfig> repositoryConfigStore = getStore(repository);
|
ConfigurationStore<GitRepositoryConfig> repositoryConfigStore = getStore(repository);
|
||||||
GitRepositoryConfig config = repositoryConfigMapper.map(dto);
|
GitRepositoryConfig config = repositoryConfigMapper.map(dto);
|
||||||
repositoryConfigStore.set(config);
|
repositoryConfigStore.set(config);
|
||||||
|
LOG.info("git default branch of repository {} has changed, sending clear cache event", repository.getNamespaceAndName());
|
||||||
|
sendClearRepositoryCacheEvent(repository);
|
||||||
return Response.noContent().build();
|
return Response.noContent().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendClearRepositoryCacheEvent(Repository repository) {
|
||||||
|
ScmEventBus.getInstance().post(new ClearRepositoryCacheEvent(repository));
|
||||||
|
}
|
||||||
|
|
||||||
private Repository getRepository(@PathParam("namespace") String namespace, @PathParam("name") String name) {
|
private Repository getRepository(@PathParam("namespace") String namespace, @PathParam("name") String name) {
|
||||||
NamespaceAndName namespaceAndName = new NamespaceAndName(namespace, name);
|
NamespaceAndName namespaceAndName = new NamespaceAndName(namespace, name);
|
||||||
Repository repository = repositoryManager.get(namespaceAndName);
|
Repository repository = repositoryManager.get(namespaceAndName);
|
||||||
@@ -68,6 +80,6 @@ public class GitRepositoryConfigResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ConfigurationStore<GitRepositoryConfig> getStore(Repository repository) {
|
private ConfigurationStore<GitRepositoryConfig> getStore(Repository repository) {
|
||||||
return configurationStoreFactory.withType(GitRepositoryConfig.class).withName("gitConfig").forRepository(repository).build();
|
return gitRepositoryConfigStoreProvider.get(repository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
|
import sonia.scm.repository.GitRepositoryConfig;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.store.ConfigurationStore;
|
||||||
|
import sonia.scm.store.ConfigurationStoreFactory;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
public class GitRepositoryConfigStoreProvider {
|
||||||
|
|
||||||
|
private final ConfigurationStoreFactory configurationStoreFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public GitRepositoryConfigStoreProvider(ConfigurationStoreFactory configurationStoreFactory) {
|
||||||
|
this.configurationStoreFactory = configurationStoreFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationStore<GitRepositoryConfig> get(Repository repository) {
|
||||||
|
return configurationStoreFactory.withType(GitRepositoryConfig.class).withName("gitConfig").forRepository(repository).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014, 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.repository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constants for Git.
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
* @since 1.50
|
|
||||||
*/
|
|
||||||
public final class GitConstants {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default branch repository property.
|
|
||||||
*/
|
|
||||||
public static final String PROPERTY_DEFAULT_BRANCH = "git.default-branch";
|
|
||||||
|
|
||||||
private GitConstants() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,13 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
public class GitRepositoryConfig {
|
public class GitRepositoryConfig {
|
||||||
|
|
||||||
|
public GitRepositoryConfig() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GitRepositoryConfig(String defaultBranch) {
|
||||||
|
this.defaultBranch = defaultBranch;
|
||||||
|
}
|
||||||
|
|
||||||
private String defaultBranch;
|
private String defaultBranch;
|
||||||
|
|
||||||
public String getDefaultBranch() {
|
public String getDefaultBranch() {
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014, 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.repository;
|
|
||||||
|
|
||||||
import com.github.legman.Subscribe;
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.base.Objects;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import sonia.scm.EagerSingleton;
|
|
||||||
import sonia.scm.HandlerEventType;
|
|
||||||
import sonia.scm.event.ScmEventBus;
|
|
||||||
import sonia.scm.plugin.Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Repository listener which handles git related repository events.
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
* @since 1.50
|
|
||||||
*/
|
|
||||||
@Extension
|
|
||||||
@EagerSingleton
|
|
||||||
public class GitRepositoryModifyListener {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for GitRepositoryModifyListener
|
|
||||||
*/
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GitRepositoryModifyListener.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Receives {@link RepositoryModificationEvent} and fires a {@link ClearRepositoryCacheEvent} if
|
|
||||||
* the default branch of a git repository was modified.
|
|
||||||
*
|
|
||||||
* @param event repository modification event
|
|
||||||
*/
|
|
||||||
@Subscribe
|
|
||||||
public void handleEvent(RepositoryModificationEvent event){
|
|
||||||
Repository repository = event.getItem();
|
|
||||||
|
|
||||||
if ( isModifyEvent(event) &&
|
|
||||||
isGitRepository(event.getItem()) &&
|
|
||||||
hasDefaultBranchChanged(event.getItemBeforeModification(), repository))
|
|
||||||
{
|
|
||||||
logger.info("git default branch of repository {} has changed, sending clear cache event", repository.getId());
|
|
||||||
sendClearRepositoryCacheEvent(repository);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected void sendClearRepositoryCacheEvent(Repository repository) {
|
|
||||||
ScmEventBus.getInstance().post(new ClearRepositoryCacheEvent(repository));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isModifyEvent(RepositoryEvent event) {
|
|
||||||
return event.getEventType() == HandlerEventType.MODIFY;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isGitRepository(Repository repository) {
|
|
||||||
return GitRepositoryHandler.TYPE_NAME.equals(repository.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasDefaultBranchChanged(Repository old, Repository current) {
|
|
||||||
return !Objects.equal(
|
|
||||||
old.getProperty(GitConstants.PROPERTY_DEFAULT_BRANCH),
|
|
||||||
current.getProperty(GitConstants.PROPERTY_DEFAULT_BRANCH)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -40,7 +40,6 @@ import org.eclipse.jgit.lib.Ref;
|
|||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.repository.GitConstants;
|
|
||||||
import sonia.scm.repository.GitUtil;
|
import sonia.scm.repository.GitUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -110,7 +109,7 @@ public class AbstractGitCommand
|
|||||||
|
|
||||||
protected Ref getBranchOrDefault(Repository gitRepository, String requestedBranch) throws IOException {
|
protected Ref getBranchOrDefault(Repository gitRepository, String requestedBranch) throws IOException {
|
||||||
if ( Strings.isNullOrEmpty(requestedBranch) ) {
|
if ( Strings.isNullOrEmpty(requestedBranch) ) {
|
||||||
String defaultBranchName = repository.getProperty(GitConstants.PROPERTY_DEFAULT_BRANCH);
|
String defaultBranchName = context.getConfig().getDefaultBranch();
|
||||||
if (!Strings.isNullOrEmpty(defaultBranchName)) {
|
if (!Strings.isNullOrEmpty(defaultBranchName)) {
|
||||||
return GitUtil.getBranchId(gitRepository, defaultBranchName);
|
return GitUtil.getBranchId(gitRepository, defaultBranchName);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ package sonia.scm.repository.spi;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
|
import sonia.scm.repository.GitRepositoryConfig;
|
||||||
import sonia.scm.repository.GitUtil;
|
import sonia.scm.repository.GitUtil;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
|
|
||||||
@@ -68,10 +70,11 @@ public class GitContext implements Closeable
|
|||||||
* @param directory
|
* @param directory
|
||||||
* @param repository
|
* @param repository
|
||||||
*/
|
*/
|
||||||
public GitContext(File directory, Repository repository)
|
public GitContext(File directory, Repository repository, GitRepositoryConfigStoreProvider storeProvider)
|
||||||
{
|
{
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
this.storeProvider = storeProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -117,11 +120,25 @@ public class GitContext implements Closeable
|
|||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GitRepositoryConfig getConfig() {
|
||||||
|
GitRepositoryConfig config = storeProvider.get(repository).get();
|
||||||
|
if (config == null) {
|
||||||
|
return new GitRepositoryConfig();
|
||||||
|
} else {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setConfig(GitRepositoryConfig newConfig) {
|
||||||
|
storeProvider.get(repository).set(newConfig);
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private final File directory;
|
private final File directory;
|
||||||
private final Repository repository;
|
private final Repository repository;
|
||||||
|
private final GitRepositoryConfigStoreProvider storeProvider;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private org.eclipse.jgit.lib.Repository gitRepository;
|
private org.eclipse.jgit.lib.Repository gitRepository;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
import sonia.scm.repository.Feature;
|
import sonia.scm.repository.Feature;
|
||||||
import sonia.scm.repository.GitRepositoryHandler;
|
import sonia.scm.repository.GitRepositoryHandler;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
@@ -73,10 +74,10 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
public GitRepositoryServiceProvider(GitRepositoryHandler handler, Repository repository) {
|
public GitRepositoryServiceProvider(GitRepositoryHandler handler, Repository repository, GitRepositoryConfigStoreProvider storeProvider) {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.context = new GitContext(handler.getDirectory(repository.getId()), repository);
|
this.context = new GitContext(handler.getDirectory(repository.getId()), repository, storeProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ package sonia.scm.repository.spi;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
import sonia.scm.plugin.Extension;
|
import sonia.scm.plugin.Extension;
|
||||||
import sonia.scm.repository.GitRepositoryHandler;
|
import sonia.scm.repository.GitRepositoryHandler;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
@@ -47,10 +48,12 @@ import sonia.scm.repository.Repository;
|
|||||||
public class GitRepositoryServiceResolver implements RepositoryServiceResolver {
|
public class GitRepositoryServiceResolver implements RepositoryServiceResolver {
|
||||||
|
|
||||||
private final GitRepositoryHandler handler;
|
private final GitRepositoryHandler handler;
|
||||||
|
private final GitRepositoryConfigStoreProvider storeProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GitRepositoryServiceResolver(GitRepositoryHandler handler) {
|
public GitRepositoryServiceResolver(GitRepositoryHandler handler, GitRepositoryConfigStoreProvider storeProvider) {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
this.storeProvider = storeProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,7 +61,7 @@ public class GitRepositoryServiceResolver implements RepositoryServiceResolver {
|
|||||||
GitRepositoryServiceProvider provider = null;
|
GitRepositoryServiceProvider provider = null;
|
||||||
|
|
||||||
if (GitRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
|
if (GitRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
|
||||||
provider = new GitRepositoryServiceProvider(handler, repository);
|
provider = new GitRepositoryServiceProvider(handler, repository, storeProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider;
|
return provider;
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class GitConfigResourceTest {
|
|||||||
public void prepareEnvironment() {
|
public void prepareEnvironment() {
|
||||||
GitConfig gitConfig = createConfiguration();
|
GitConfig gitConfig = createConfiguration();
|
||||||
when(repositoryHandler.getConfig()).thenReturn(gitConfig);
|
when(repositoryHandler.getConfig()).thenReturn(gitConfig);
|
||||||
GitRepositoryConfigResource gitRepositoryConfigResource = new GitRepositoryConfigResource(repositoryConfigMapper, repositoryManager, configurationStoreFactory);
|
GitRepositoryConfigResource gitRepositoryConfigResource = new GitRepositoryConfigResource(repositoryConfigMapper, repositoryManager, new GitRepositoryConfigStoreProvider(configurationStoreFactory));
|
||||||
GitConfigResource gitConfigResource = new GitConfigResource(dtoToConfigMapper, configToDtoMapper, repositoryHandler, of(gitRepositoryConfigResource));
|
GitConfigResource gitConfigResource = new GitConfigResource(dtoToConfigMapper, configToDtoMapper, repositoryHandler, of(gitRepositoryConfigResource));
|
||||||
dispatcher.getRegistry().addSingletonResource(gitConfigResource);
|
dispatcher.getRegistry().addSingletonResource(gitConfigResource);
|
||||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ import static org.mockito.Mockito.when;
|
|||||||
/**
|
/**
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||||
public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
|||||||
@@ -1,163 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014, 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.repository;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Before;
|
|
||||||
import sonia.scm.HandlerEventType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit tests for {@link GitRepositoryModifyListener}.
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class GitRepositoryModifyListenerTest {
|
|
||||||
|
|
||||||
private GitRepositoryModifyTestListener repositoryModifyListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up test object.
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUpObjectUnderTest(){
|
|
||||||
repositoryModifyListener = new GitRepositoryModifyTestListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests happy path.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testHandleEvent() {
|
|
||||||
Repository old = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
old.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
|
|
||||||
Repository current = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "develop");
|
|
||||||
|
|
||||||
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
|
|
||||||
repositoryModifyListener.handleEvent(event);
|
|
||||||
|
|
||||||
assertNotNull(repositoryModifyListener.repository);
|
|
||||||
assertSame(current, repositoryModifyListener.repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests with new default branch.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testWithNewDefaultBranch() {
|
|
||||||
Repository old = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
Repository current = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "develop");
|
|
||||||
|
|
||||||
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
|
|
||||||
repositoryModifyListener.handleEvent(event);
|
|
||||||
|
|
||||||
assertNotNull(repositoryModifyListener.repository);
|
|
||||||
assertSame(current, repositoryModifyListener.repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests with non git repositories.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testNonGitRepository(){
|
|
||||||
Repository old = RepositoryTestData.createHeartOfGold("hg");
|
|
||||||
old.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
|
|
||||||
Repository current = RepositoryTestData.createHeartOfGold("hg");
|
|
||||||
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "develop");
|
|
||||||
|
|
||||||
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
|
|
||||||
repositoryModifyListener.handleEvent(event);
|
|
||||||
|
|
||||||
assertNull(repositoryModifyListener.repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests without default branch.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testWithoutDefaultBranch(){
|
|
||||||
Repository old = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
Repository current = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
|
|
||||||
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
|
|
||||||
repositoryModifyListener.handleEvent(event);
|
|
||||||
|
|
||||||
assertNull(repositoryModifyListener.repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests with non modify event.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testNonModifyEvent(){
|
|
||||||
Repository old = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
old.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
|
|
||||||
Repository current = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "develop");
|
|
||||||
|
|
||||||
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.CREATE, current, old);
|
|
||||||
repositoryModifyListener.handleEvent(event);
|
|
||||||
|
|
||||||
assertNull(repositoryModifyListener.repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests with non git repositories.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testNoModification(){
|
|
||||||
Repository old = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
old.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
|
|
||||||
Repository current = RepositoryTestData.createHeartOfGold("git");
|
|
||||||
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
|
|
||||||
|
|
||||||
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
|
|
||||||
repositoryModifyListener.handleEvent(event);
|
|
||||||
|
|
||||||
assertNull(repositoryModifyListener.repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class GitRepositoryModifyTestListener extends GitRepositoryModifyListener {
|
|
||||||
|
|
||||||
private Repository repository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void sendClearRepositoryCacheEvent(Repository repository) {
|
|
||||||
this.repository = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -35,6 +35,9 @@ package sonia.scm.repository.spi;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
|
import sonia.scm.repository.GitRepositoryConfig;
|
||||||
|
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -51,6 +54,7 @@ public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase
|
|||||||
public void close()
|
public void close()
|
||||||
{
|
{
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
|
context.setConfig(new GitRepositoryConfig());
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +69,7 @@ public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase
|
|||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
context = new GitContext(repositoryDirectory, repository);
|
context = new GitContext(repositoryDirectory, repository, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
|||||||
@@ -35,9 +35,11 @@ package sonia.scm.repository.spi;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
import sonia.scm.repository.BlameLine;
|
import sonia.scm.repository.BlameLine;
|
||||||
import sonia.scm.repository.BlameResult;
|
import sonia.scm.repository.BlameResult;
|
||||||
import sonia.scm.repository.GitConstants;
|
import sonia.scm.repository.GitRepositoryConfig;
|
||||||
|
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -73,7 +75,7 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
|
|||||||
assertEquals("fcd0ef1831e4002ac43ea539f4094334c79ea9ec", result.getLine(1).getRevision());
|
assertEquals("fcd0ef1831e4002ac43ea539f4094334c79ea9ec", result.getLine(1).getRevision());
|
||||||
|
|
||||||
// set default branch and test again
|
// set default branch and test again
|
||||||
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
|
createContext().setConfig(new GitRepositoryConfig("test-branch"));
|
||||||
result = createCommand().getBlameResult(request);
|
result = createCommand().getBlameResult(request);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(1, result.getTotal());
|
assertEquals(1, result.getTotal());
|
||||||
|
|||||||
@@ -32,9 +32,11 @@
|
|||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
import sonia.scm.repository.BrowserResult;
|
import sonia.scm.repository.BrowserResult;
|
||||||
import sonia.scm.repository.FileObject;
|
import sonia.scm.repository.FileObject;
|
||||||
import sonia.scm.repository.GitConstants;
|
import sonia.scm.repository.GitRepositoryConfig;
|
||||||
|
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -78,7 +80,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitDefaultBranch() throws IOException {
|
public void testExplicitDefaultBranch() throws IOException {
|
||||||
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
|
createContext().setConfig(new GitRepositoryConfig("test-branch"));
|
||||||
|
|
||||||
FileObject root = createCommand().getBrowserResult(new BrowseCommandRequest()).getFile();
|
FileObject root = createCommand().getBrowserResult(new BrowseCommandRequest()).getFile();
|
||||||
assertNotNull(root);
|
assertNotNull(root);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import org.junit.Rule;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
import sonia.scm.NotFoundException;
|
import sonia.scm.NotFoundException;
|
||||||
import sonia.scm.repository.GitConstants;
|
import sonia.scm.repository.GitRepositoryConfig;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -67,7 +67,7 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase {
|
|||||||
assertEquals("a\nline for blame", execute(request));
|
assertEquals("a\nline for blame", execute(request));
|
||||||
|
|
||||||
// set default branch for repository and check again
|
// set default branch for repository and check again
|
||||||
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
|
createContext().setConfig(new GitRepositoryConfig("test-branch"));
|
||||||
assertEquals("a and b", execute(request));
|
assertEquals("a and b", execute(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ import org.eclipse.jgit.api.errors.GitAPIException;
|
|||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
|
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -103,7 +105,7 @@ public class GitIncomingCommandTest
|
|||||||
|
|
||||||
commit(outgoing, "added a");
|
commit(outgoing, "added a");
|
||||||
|
|
||||||
GitPullCommand pull = new GitPullCommand(handler, new GitContext(incomingDirectory, null), incomingRepository);
|
GitPullCommand pull = new GitPullCommand(handler, new GitContext(incomingDirectory, null, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())), incomingRepository);
|
||||||
PullCommandRequest req = new PullCommandRequest();
|
PullCommandRequest req = new PullCommandRequest();
|
||||||
req.setRemoteRepository(outgoingRepository);
|
req.setRemoteRepository(outgoingRepository);
|
||||||
pull.pull(req);
|
pull.pull(req);
|
||||||
@@ -187,7 +189,7 @@ public class GitIncomingCommandTest
|
|||||||
*/
|
*/
|
||||||
private GitIncomingCommand createCommand()
|
private GitIncomingCommand createCommand()
|
||||||
{
|
{
|
||||||
return new GitIncomingCommand(handler, new GitContext(incomingDirectory, null),
|
return new GitIncomingCommand(handler, new GitContext(incomingDirectory, null, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())),
|
||||||
incomingRepository);
|
incomingRepository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,11 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import sonia.scm.event.ScmEventBus;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
import sonia.scm.repository.GitConstants;
|
import sonia.scm.repository.ClearRepositoryCacheEvent;
|
||||||
|
import sonia.scm.repository.GitRepositoryConfig;
|
||||||
import sonia.scm.repository.Modifications;
|
import sonia.scm.repository.Modifications;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -78,7 +80,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
assertTrue(result.getChangesets().stream().allMatch(r -> r.getBranches().isEmpty()));
|
assertTrue(result.getChangesets().stream().allMatch(r -> r.getBranches().isEmpty()));
|
||||||
|
|
||||||
// set default branch and fetch again
|
// set default branch and fetch again
|
||||||
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
|
createContext().setConfig(new GitRepositoryConfig("test-branch"));
|
||||||
|
|
||||||
result = createCommand().getChangesets(new LogCommandRequest());
|
result = createCommand().getChangesets(new LogCommandRequest());
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
incomingModificationsCommand = new GitModificationsCommand(new GitContext(incomingDirectory, null), incomingRepository);
|
incomingModificationsCommand = new GitModificationsCommand(new GitContext(incomingDirectory, null, null), incomingRepository);
|
||||||
outgoingModificationsCommand = new GitModificationsCommand(new GitContext(outgoingDirectory, null), outgoingRepository);
|
outgoingModificationsCommand = new GitModificationsCommand(new GitContext(outgoingDirectory, null, null), outgoingRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -63,12 +63,12 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pushOutgoingAndPullIncoming() throws IOException {
|
void pushOutgoingAndPullIncoming() throws IOException {
|
||||||
GitPushCommand cmd = new GitPushCommand(handler, new GitContext(outgoingDirectory, null),
|
GitPushCommand cmd = new GitPushCommand(handler, new GitContext(outgoingDirectory, null, null),
|
||||||
outgoingRepository);
|
outgoingRepository);
|
||||||
PushCommandRequest request = new PushCommandRequest();
|
PushCommandRequest request = new PushCommandRequest();
|
||||||
request.setRemoteRepository(incomingRepository);
|
request.setRemoteRepository(incomingRepository);
|
||||||
cmd.push(request);
|
cmd.push(request);
|
||||||
GitPullCommand pullCommand = new GitPullCommand(handler, new GitContext(incomingDirectory, null),
|
GitPullCommand pullCommand = new GitPullCommand(handler, new GitContext(incomingDirectory, null, null),
|
||||||
incomingRepository);
|
incomingRepository);
|
||||||
PullCommandRequest pullRequest = new PullCommandRequest();
|
PullCommandRequest pullRequest = new PullCommandRequest();
|
||||||
pullRequest.setRemoteRepository(incomingRepository);
|
pullRequest.setRemoteRepository(incomingRepository);
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ package sonia.scm.repository.spi;
|
|||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
|
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -104,7 +106,7 @@ public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase
|
|||||||
commit(outgoing, "added a");
|
commit(outgoing, "added a");
|
||||||
|
|
||||||
GitPushCommand push = new GitPushCommand(handler,
|
GitPushCommand push = new GitPushCommand(handler,
|
||||||
new GitContext(outgoingDirectory, null),
|
new GitContext(outgoingDirectory, null, null),
|
||||||
outgoingRepository);
|
outgoingRepository);
|
||||||
PushCommandRequest req = new PushCommandRequest();
|
PushCommandRequest req = new PushCommandRequest();
|
||||||
|
|
||||||
@@ -158,7 +160,7 @@ public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase
|
|||||||
*/
|
*/
|
||||||
private GitOutgoingCommand createCommand()
|
private GitOutgoingCommand createCommand()
|
||||||
{
|
{
|
||||||
return new GitOutgoingCommand(handler, new GitContext(outgoingDirectory, null),
|
return new GitOutgoingCommand(handler, new GitContext(outgoingDirectory, null, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())),
|
||||||
outgoingRepository);
|
outgoingRepository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class GitPushCommandTest extends AbstractRemoteCommandTestBase
|
|||||||
*/
|
*/
|
||||||
private GitPushCommand createCommand()
|
private GitPushCommand createCommand()
|
||||||
{
|
{
|
||||||
return new GitPushCommand(handler, new GitContext(outgoingDirectory, null),
|
return new GitPushCommand(handler, new GitContext(outgoingDirectory, null, null),
|
||||||
outgoingRepository);
|
outgoingRepository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ package sonia.scm.store;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In memory configuration store factory for testing purposes.
|
* In memory configuration store factory for testing purposes.
|
||||||
*
|
*
|
||||||
@@ -42,8 +46,44 @@ package sonia.scm.store;
|
|||||||
*/
|
*/
|
||||||
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
|
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
|
||||||
|
|
||||||
|
private static final Map<Key, InMemoryConfigurationStore> STORES = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigurationStore getStore(TypedStoreParameters storeParameters) {
|
public ConfigurationStore getStore(TypedStoreParameters storeParameters) {
|
||||||
return new InMemoryConfigurationStore<>();
|
Key key = new Key(storeParameters.getType(), storeParameters.getName(), storeParameters.getRepository() == null? "-": storeParameters.getRepository().getId());
|
||||||
|
if (STORES.containsKey(key)) {
|
||||||
|
return STORES.get(key);
|
||||||
|
} else {
|
||||||
|
InMemoryConfigurationStore<Object> store = new InMemoryConfigurationStore<>();
|
||||||
|
STORES.put(key, store);
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Key {
|
||||||
|
private final Class type;
|
||||||
|
private final String name;
|
||||||
|
private final String id;
|
||||||
|
|
||||||
|
public Key(Class type, String name, String id) {
|
||||||
|
this.type = type;
|
||||||
|
this.name = name;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Key key = (Key) o;
|
||||||
|
return Objects.equals(type, key.type) &&
|
||||||
|
Objects.equals(name, key.name) &&
|
||||||
|
Objects.equals(id, key.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(type, name, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user