mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
Check feature in "incoming" commands
This commit is contained in:
@@ -50,5 +50,5 @@ public enum Feature
|
|||||||
* The repository supports computation of incoming changes (either diff or list of changesets) of one branch
|
* The repository supports computation of incoming changes (either diff or list of changesets) of one branch
|
||||||
* in respect to another target branch.
|
* in respect to another target branch.
|
||||||
*/
|
*/
|
||||||
INCOMING
|
INCOMING_REVISION
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ package sonia.scm.repository.api;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sonia.scm.NotSupportedFeatureException;
|
||||||
|
import sonia.scm.repository.Feature;
|
||||||
import sonia.scm.repository.spi.DiffCommand;
|
import sonia.scm.repository.spi.DiffCommand;
|
||||||
import sonia.scm.repository.spi.DiffCommandRequest;
|
import sonia.scm.repository.spi.DiffCommandRequest;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
@@ -45,6 +47,7 @@ import sonia.scm.util.IOUtil;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -85,10 +88,12 @@ public final class DiffCommandBuilder
|
|||||||
* only be called from the {@link RepositoryService}.
|
* only be called from the {@link RepositoryService}.
|
||||||
*
|
*
|
||||||
* @param diffCommand implementation of {@link DiffCommand}
|
* @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.diffCommand = diffCommand;
|
||||||
|
this.supportedFeatures = supportedFeatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- 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
|
* 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
|
* 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}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
public DiffCommandBuilder setAncestorChangeset(String revision)
|
public DiffCommandBuilder setAncestorChangeset(String revision)
|
||||||
{
|
{
|
||||||
|
if (!supportedFeatures.contains(Feature.INCOMING_REVISION)) {
|
||||||
|
throw new NotSupportedFeatureException(Feature.INCOMING_REVISION.name());
|
||||||
|
}
|
||||||
request.setAncestorChangeset(revision);
|
request.setAncestorChangeset(revision);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@@ -229,6 +237,7 @@ public final class DiffCommandBuilder
|
|||||||
|
|
||||||
/** implementation of the diff command */
|
/** implementation of the diff command */
|
||||||
private final DiffCommand diffCommand;
|
private final DiffCommand diffCommand;
|
||||||
|
private Set<Feature> supportedFeatures;
|
||||||
|
|
||||||
/** request for the diff command implementation */
|
/** request for the diff command implementation */
|
||||||
private final DiffCommandRequest request = new DiffCommandRequest();
|
private final DiffCommandRequest request = new DiffCommandRequest();
|
||||||
|
|||||||
@@ -39,10 +39,12 @@ import com.google.common.base.Objects;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sonia.scm.NotSupportedFeatureException;
|
||||||
import sonia.scm.cache.Cache;
|
import sonia.scm.cache.Cache;
|
||||||
import sonia.scm.cache.CacheManager;
|
import sonia.scm.cache.CacheManager;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
|
import sonia.scm.repository.Feature;
|
||||||
import sonia.scm.repository.PreProcessorUtil;
|
import sonia.scm.repository.PreProcessorUtil;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.RepositoryCacheKey;
|
import sonia.scm.repository.RepositoryCacheKey;
|
||||||
@@ -51,6 +53,7 @@ import sonia.scm.repository.spi.LogCommandRequest;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -104,19 +107,20 @@ public final class LogCommandBuilder
|
|||||||
/**
|
/**
|
||||||
* Constructs a new {@link LogCommandBuilder}, this constructor should
|
* Constructs a new {@link LogCommandBuilder}, this constructor should
|
||||||
* only be called from the {@link RepositoryService}.
|
* only be called from the {@link RepositoryService}.
|
||||||
*
|
|
||||||
* @param cacheManager cache manager
|
* @param cacheManager cache manager
|
||||||
* @param logCommand implementation of the {@link LogCommand}
|
* @param logCommand implementation of the {@link LogCommand}
|
||||||
* @param repository repository to query
|
* @param repository repository to query
|
||||||
* @param preProcessorUtil
|
* @param preProcessorUtil
|
||||||
|
* @param supportedFeatures The supported features of the provider
|
||||||
*/
|
*/
|
||||||
LogCommandBuilder(CacheManager cacheManager, LogCommand logCommand,
|
LogCommandBuilder(CacheManager cacheManager, LogCommand logCommand,
|
||||||
Repository repository, PreProcessorUtil preProcessorUtil)
|
Repository repository, PreProcessorUtil preProcessorUtil, Set<Feature> supportedFeatures)
|
||||||
{
|
{
|
||||||
this.cache = cacheManager.getCache(CACHE_NAME);
|
this.cache = cacheManager.getCache(CACHE_NAME);
|
||||||
this.logCommand = logCommand;
|
this.logCommand = logCommand;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.preProcessorUtil = preProcessorUtil;
|
this.preProcessorUtil = preProcessorUtil;
|
||||||
|
this.supportedFeatures = supportedFeatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- 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
|
* 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
|
* 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}
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
public LogCommandBuilder setAncestorChangeset(String ancestorChangeset) {
|
public LogCommandBuilder setAncestorChangeset(String ancestorChangeset) {
|
||||||
|
if (!supportedFeatures.contains(Feature.INCOMING_REVISION)) {
|
||||||
|
throw new NotSupportedFeatureException(Feature.INCOMING_REVISION.name());
|
||||||
|
}
|
||||||
request.setAncestorChangeset(ancestorChangeset);
|
request.setAncestorChangeset(ancestorChangeset);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -534,6 +541,7 @@ public final class LogCommandBuilder
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private final PreProcessorUtil preProcessorUtil;
|
private final PreProcessorUtil preProcessorUtil;
|
||||||
|
private Set<Feature> supportedFeatures;
|
||||||
|
|
||||||
/** repository to query */
|
/** repository to query */
|
||||||
private final Repository repository;
|
private final Repository repository;
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ public final class RepositoryService implements Closeable {
|
|||||||
logger.debug("create diff command for repository {}",
|
logger.debug("create diff command for repository {}",
|
||||||
repository.getNamespaceAndName());
|
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());
|
repository.getNamespaceAndName());
|
||||||
|
|
||||||
return new LogCommandBuilder(cacheManager, provider.getLogCommand(),
|
return new LogCommandBuilder(cacheManager, provider.getLogCommand(),
|
||||||
repository, preProcessorUtil);
|
repository, preProcessorUtil, provider.getSupportedFeatures());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
Command.PULL,
|
Command.PULL,
|
||||||
Command.MERGE
|
Command.MERGE
|
||||||
);
|
);
|
||||||
public static final Set<Feature> FEATURES = EnumSet.of(Feature.INCOMING);
|
public static final Set<Feature> FEATURES = EnumSet.of(Feature.INCOMING_REVISION);
|
||||||
//J+
|
//J+
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
|||||||
if (repositoryService.isSupported(Command.BRANCHES)) {
|
if (repositoryService.isSupported(Command.BRANCHES)) {
|
||||||
linksBuilder.single(link("branches", resourceLinks.branchCollection().self(target.getNamespace(), target.getName())));
|
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("incomingChangesets", resourceLinks.incoming().changesets(target.getNamespace(), target.getName())));
|
||||||
linksBuilder.single(link("incomingDiff", resourceLinks.incoming().diff(target.getNamespace(), target.getName())));
|
linksBuilder.single(link("incomingDiff", resourceLinks.incoming().diff(target.getNamespace(), target.getName())));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user