Check feature in "incoming" commands

This commit is contained in:
René Pfeuffer
2018-12-06 11:35:56 +01:00
parent de6d52bad9
commit f447ae437b
6 changed files with 28 additions and 11 deletions

View File

@@ -50,5 +50,5 @@ public enum Feature
* The repository supports computation of incoming changes (either diff or list of changesets) of one branch
* in respect to another target branch.
*/
INCOMING
INCOMING_REVISION
}

View File

@@ -38,6 +38,8 @@ package sonia.scm.repository.api;
import com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.NotSupportedFeatureException;
import sonia.scm.repository.Feature;
import sonia.scm.repository.spi.DiffCommand;
import sonia.scm.repository.spi.DiffCommandRequest;
import sonia.scm.util.IOUtil;
@@ -45,6 +47,7 @@ import sonia.scm.util.IOUtil;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Set;
//~--- JDK imports ------------------------------------------------------------
@@ -85,10 +88,12 @@ public final class DiffCommandBuilder
* only be called from the {@link RepositoryService}.
*
* @param diffCommand implementation of {@link DiffCommand}
* @param supportedFeatures The supported features of the provider
*/
DiffCommandBuilder(DiffCommand diffCommand)
DiffCommandBuilder(DiffCommand diffCommand, Set<Feature> supportedFeatures)
{
this.diffCommand = diffCommand;
this.supportedFeatures = supportedFeatures;
}
//~--- methods --------------------------------------------------------------
@@ -191,12 +196,15 @@ public final class DiffCommandBuilder
/**
* Compute the incoming changes of the branch set with {@link #setRevision(String)} in respect to the changeset given
* here. In other words: What changes would be new to the ancestor changeset given here when the branch would
* be merged into it. Requires feature {@link sonia.scm.repository.Feature#INCOMING}!
* be merged into it. Requires feature {@link sonia.scm.repository.Feature#INCOMING_REVISION}!
*
* @return {@code this}
*/
public DiffCommandBuilder setAncestorChangeset(String revision)
{
if (!supportedFeatures.contains(Feature.INCOMING_REVISION)) {
throw new NotSupportedFeatureException(Feature.INCOMING_REVISION.name());
}
request.setAncestorChangeset(revision);
return this;
@@ -229,6 +237,7 @@ public final class DiffCommandBuilder
/** implementation of the diff command */
private final DiffCommand diffCommand;
private Set<Feature> supportedFeatures;
/** request for the diff command implementation */
private final DiffCommandRequest request = new DiffCommandRequest();

View File

@@ -39,10 +39,12 @@ import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.NotSupportedFeatureException;
import sonia.scm.cache.Cache;
import sonia.scm.cache.CacheManager;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.Feature;
import sonia.scm.repository.PreProcessorUtil;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryCacheKey;
@@ -51,6 +53,7 @@ import sonia.scm.repository.spi.LogCommandRequest;
import java.io.IOException;
import java.io.Serializable;
import java.util.Set;
//~--- JDK imports ------------------------------------------------------------
@@ -104,19 +107,20 @@ public final class LogCommandBuilder
/**
* Constructs a new {@link LogCommandBuilder}, this constructor should
* only be called from the {@link RepositoryService}.
*
* @param cacheManager cache manager
* @param logCommand implementation of the {@link LogCommand}
* @param repository repository to query
* @param preProcessorUtil
* @param supportedFeatures The supported features of the provider
*/
LogCommandBuilder(CacheManager cacheManager, LogCommand logCommand,
Repository repository, PreProcessorUtil preProcessorUtil)
Repository repository, PreProcessorUtil preProcessorUtil, Set<Feature> supportedFeatures)
{
this.cache = cacheManager.getCache(CACHE_NAME);
this.logCommand = logCommand;
this.repository = repository;
this.preProcessorUtil = preProcessorUtil;
this.supportedFeatures = supportedFeatures;
}
//~--- methods --------------------------------------------------------------
@@ -400,11 +404,14 @@ public final class LogCommandBuilder
/**
* Compute the incoming changes of the branch set with {@link #setBranch(String)} in respect to the changeset given
* here. In other words: What changesets would be new to the ancestor changeset given here when the branch would
* be merged into it. Requires feature {@link sonia.scm.repository.Feature#INCOMING}!
* be merged into it. Requires feature {@link sonia.scm.repository.Feature#INCOMING_REVISION}!
*
* @return {@code this}
*/
public LogCommandBuilder setAncestorChangeset(String ancestorChangeset) {
if (!supportedFeatures.contains(Feature.INCOMING_REVISION)) {
throw new NotSupportedFeatureException(Feature.INCOMING_REVISION.name());
}
request.setAncestorChangeset(ancestorChangeset);
return this;
}
@@ -534,6 +541,7 @@ public final class LogCommandBuilder
/** Field description */
private final PreProcessorUtil preProcessorUtil;
private Set<Feature> supportedFeatures;
/** repository to query */
private final Repository repository;

View File

@@ -221,7 +221,7 @@ public final class RepositoryService implements Closeable {
logger.debug("create diff command for repository {}",
repository.getNamespaceAndName());
return new DiffCommandBuilder(provider.getDiffCommand());
return new DiffCommandBuilder(provider.getDiffCommand(), provider.getSupportedFeatures());
}
/**
@@ -253,7 +253,7 @@ public final class RepositoryService implements Closeable {
repository.getNamespaceAndName());
return new LogCommandBuilder(cacheManager, provider.getLogCommand(),
repository, preProcessorUtil);
repository, preProcessorUtil, provider.getSupportedFeatures());
}
/**

View File

@@ -67,7 +67,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
Command.PULL,
Command.MERGE
);
public static final Set<Feature> FEATURES = EnumSet.of(Feature.INCOMING);
public static final Set<Feature> FEATURES = EnumSet.of(Feature.INCOMING_REVISION);
//J+
//~--- constructors ---------------------------------------------------------

View File

@@ -56,7 +56,7 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
if (repositoryService.isSupported(Command.BRANCHES)) {
linksBuilder.single(link("branches", resourceLinks.branchCollection().self(target.getNamespace(), target.getName())));
}
if (repositoryService.isSupported(Feature.INCOMING)) {
if (repositoryService.isSupported(Feature.INCOMING_REVISION)) {
linksBuilder.single(link("incomingChangesets", resourceLinks.incoming().changesets(target.getNamespace(), target.getName())));
linksBuilder.single(link("incomingDiff", resourceLinks.incoming().diff(target.getNamespace(), target.getName())));
}