Move isSingleProjectMatch() to RemoteConfiguration interface The logic used to identify whether a configuration is related to a single project as opposed to a family of project, is the same across destination or source targets. Provide a default isSingleProjectMatch method so that it can be leveraged by both replication (for DestinationConfiguration) and by pull-replication (for SourceConfiguration) Change-Id: I1a366841e77755a1d17cfd9f68fe235a7a099f48
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/DestinationConfiguration.java b/src/main/java/com/googlesource/gerrit/plugins/replication/DestinationConfiguration.java index d12abc4..4b757ea 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/DestinationConfiguration.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/DestinationConfiguration.java
@@ -17,7 +17,6 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import com.google.gerrit.server.config.ConfigUtil; -import java.util.List; import java.util.concurrent.TimeUnit; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.transport.RemoteConfig; @@ -167,24 +166,6 @@ return cfg.getInt("remote", rc.getName(), name, defValue); } - boolean isSingleProjectMatch() { - List<String> projects = getProjects(); - boolean ret = (projects.size() == 1); - if (ret) { - String projectMatch = projects.get(0); - if (ReplicationFilter.getPatternType(projectMatch) - != ReplicationFilter.PatternType.EXACT_MATCH) { - // projectMatch is either regular expression, or wild-card. - // - // Even though they might refer to a single project now, they need not - // after new projects have been created. Hence, we do not treat them as - // matching a single project. - ret = false; - } - } - return ret; - } - @Override public int getSlowLatencyThreshold() { return slowLatencyThreshold;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/RemoteConfiguration.java b/src/main/java/com/googlesource/gerrit/plugins/replication/RemoteConfiguration.java index aa683ff..b66e73c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/RemoteConfiguration.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/RemoteConfiguration.java
@@ -14,6 +14,7 @@ package com.googlesource.gerrit.plugins.replication; import com.google.common.collect.ImmutableList; +import java.util.List; import org.eclipse.jgit.transport.RemoteConfig; /** Remote configuration for a replication endpoint */ @@ -95,4 +96,27 @@ * @return the slow latency threshold */ int getSlowLatencyThreshold(); + + /** + * Whether the remote configuration is for a single project only + * + * @return true, when configuration is for a single project, false otherwise + */ + default boolean isSingleProjectMatch() { + List<String> projects = getProjects(); + boolean ret = (projects.size() == 1); + if (ret) { + String projectMatch = projects.get(0); + if (ReplicationFilter.getPatternType(projectMatch) + != ReplicationFilter.PatternType.EXACT_MATCH) { + // projectMatch is either regular expression, or wild-card. + // + // Even though they might refer to a single project now, they need not + // after new projects have been created. Hence, we do not treat them as + // matching a single project. + ret = false; + } + } + return ret; + } }