This is an automated email from the ASF dual-hosted git repository. jhyde pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 1eb6551324e3c6734f1e2dbfb223b7453f5a28e9 Author: Julian Hyde <[email protected]> AuthorDate: Tue Oct 31 13:39:20 2023 -0700 [CALCITE-6083] On web site, ensure contributors file is sorted This commit adds a lint test to check the contributors file; the previous commit (by Mihai Budiu) sorts the contributors file, so that lint succeeds. --- .../java/org/apache/calcite/test/LintTest.java | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/core/src/test/java/org/apache/calcite/test/LintTest.java b/core/src/test/java/org/apache/calcite/test/LintTest.java index 591ccb0f61..01e283efb5 100644 --- a/core/src/test/java/org/apache/calcite/test/LintTest.java +++ b/core/src/test/java/org/apache/calcite/test/LintTest.java @@ -22,12 +22,22 @@ import org.apache.calcite.util.Sources; import org.apache.calcite.util.TestUnsafe; import org.apache.calcite.util.Util; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; + +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.jupiter.api.Test; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -35,11 +45,16 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; +import static com.google.common.collect.Iterables.getOnlyElement; + +import static org.apache.calcite.util.Util.filter; + import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; /** Various automated checks on the code and git history. */ @@ -373,6 +388,40 @@ class LintTest { } } + /** Ensures that the {@code contributors.yml} file is sorted by name. */ + @Test void testContributorsFileIsSorted() throws IOException { + final ObjectMapper mapper = new YAMLMapper(); + final List<File> files = TestUnsafe.getTextFiles(); + final File contributorsFile = + getOnlyElement( + filter(files, f -> f.getName().equals("contributors.yml"))); + JavaType listType = + mapper.getTypeFactory() + .constructCollectionType(List.class, Contributor.class); + List<Contributor> contributors = + mapper.readValue(contributorsFile, listType); + Contributor contributor = + firstOutOfOrder(contributors, + Comparator.comparing(c -> c.name, String.CASE_INSENSITIVE_ORDER)); + if (contributor != null) { + fail("contributor '" + contributor.name + "' is out of order"); + } + } + + /** Returns the first element in a list that is out of order, or null if the + * list is sorted. */ + private static <E> @Nullable E firstOutOfOrder(Iterable<E> elements, + Comparator<E> comparator) { + E previous = null; + for (E e : elements) { + if (previous != null && comparator.compare(previous, e) > 0) { + return e; + } + previous = e; + } + return null; + } + /** Warning that code is not as it should be. */ private static class Message { final Source source; @@ -419,4 +468,14 @@ class LintTest { return javadocEndLine < javadocStartLine; } } + + /** Contributor element in "contributors.yaml" file. */ + @JsonIgnoreProperties(ignoreUnknown = true) + private static class Contributor { + final String name; + + @JsonCreator Contributor(@JsonProperty("name") String name) { + this.name = name; + } + } }
