ConfigEntry: Trim whitespaces on exclude entries
It is natural to add whitespaces after commas in the exclude list.
Trim the result of splitting the entry, so later when we compare the
refs we get the expected results.
Change-Id: I8e49ae482665aa0f456944b5454561e682b84a43
diff --git a/java/com/googlesource/gerrit/plugins/supermanifest/ConfigEntry.java b/java/com/googlesource/gerrit/plugins/supermanifest/ConfigEntry.java
index 788d673..09ac53c 100644
--- a/java/com/googlesource/gerrit/plugins/supermanifest/ConfigEntry.java
+++ b/java/com/googlesource/gerrit/plugins/supermanifest/ConfigEntry.java
@@ -21,9 +21,9 @@
import com.google.gerrit.entities.Project;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
+import java.util.stream.Stream;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Repository;
@@ -106,8 +106,9 @@
}
srcRefsExcluded =
- ImmutableSet.copyOf(
- Arrays.asList(nullToEmpty(cfg.getString(SECTION_NAME, name, "exclude")).split(",")));
+ Stream.of(nullToEmpty(cfg.getString(SECTION_NAME, name, "exclude")).split(","))
+ .map(String::trim)
+ .collect(ImmutableSet.toImmutableSet());
xmlPath = cfg.getString(SECTION_NAME, name, "srcPath");
if (xmlPath == null) {
diff --git a/javatests/com/googlesource/gerrit/plugins/supermanifest/ConfigEntryTest.java b/javatests/com/googlesource/gerrit/plugins/supermanifest/ConfigEntryTest.java
index 61391db..7017680 100644
--- a/javatests/com/googlesource/gerrit/plugins/supermanifest/ConfigEntryTest.java
+++ b/javatests/com/googlesource/gerrit/plugins/supermanifest/ConfigEntryTest.java
@@ -140,6 +140,26 @@
.containsExactly("refs/heads/a", "refs/heads/b", "refs/heads/c");
}
+ @Test
+ public void excluded_whitespace() throws ConfigInvalidException {
+ StringBuilder builder =
+ new StringBuilder(
+ getBasicConf(
+ "superproject",
+ "refs/heads/*",
+ "manifest",
+ "refs/heads/nyc-src",
+ "default.xml"))
+ .append(" exclude = refs/heads/a, refs/heads/b , refs/heads/c \n");
+ Config cfg = new Config();
+ cfg.fromText(builder.toString());
+
+ ConfigEntry entry = new ConfigEntry(cfg, "superproject:refs/heads/*");
+
+ assertThat(entry.srcRefsExcluded)
+ .containsExactly("refs/heads/a", "refs/heads/b", "refs/heads/c");
+ }
+
private String getBasicConf(
String destRepoKey, String destBranch, String srcRepoKey, String srcRef, String xmlPath) {
return String.format(