elharo commented on code in PR #1737:
URL: https://github.com/apache/maven-site/pull/1737#discussion_r4383557723


##########
src/test/java/org/apache/maven/site/MarkdownDocsTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.site;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+
+import com.vladsch.flexmark.ext.wikilink.WikiLink;
+import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension;
+import com.vladsch.flexmark.parser.Parser;
+import com.vladsch.flexmark.util.ast.Node;
+import com.vladsch.flexmark.util.ast.NodeVisitor;
+import com.vladsch.flexmark.util.ast.VisitHandler;
+import com.vladsch.flexmark.util.data.MutableDataSet;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class MarkdownDocsTest {
+    private static final Pattern PARENTHESIZED_DESTINATION = 
Pattern.compile("^\\([^)\\s]+\\)");
+
+    private static final Parser MARKDOWN_PARSER = Parser.builder(
+                    new MutableDataSet().set(Parser.EXTENSIONS, 
List.of(WikiLinkExtension.create())))
+            .build();
+
+    @Test
+    void markdownDocsHaveWellFormedLinks() throws IOException {
+        Path contentDirectory = Paths.get("content/markdown");
+        List<Path> files;
+        try (Stream<Path> stream = Files.walk(contentDirectory)) {
+            files = 
stream.filter(MarkdownDocsTest::isMarkdownSource).sorted().toList();

Review Comment:
   Moved the loop into the try-with-resources block and declared the filtered 
file list inside it.



##########
src/test/java/org/apache/maven/site/MarkdownDocsTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.site;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+
+import com.vladsch.flexmark.ext.wikilink.WikiLink;
+import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension;
+import com.vladsch.flexmark.parser.Parser;
+import com.vladsch.flexmark.util.ast.Node;
+import com.vladsch.flexmark.util.ast.NodeVisitor;
+import com.vladsch.flexmark.util.ast.VisitHandler;
+import com.vladsch.flexmark.util.data.MutableDataSet;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class MarkdownDocsTest {
+    private static final Pattern PARENTHESIZED_DESTINATION = 
Pattern.compile("^\\([^)\\s]+\\)");
+
+    private static final Parser MARKDOWN_PARSER = Parser.builder(
+                    new MutableDataSet().set(Parser.EXTENSIONS, 
List.of(WikiLinkExtension.create())))
+            .build();
+
+    @Test
+    void markdownDocsHaveWellFormedLinks() throws IOException {
+        Path contentDirectory = Paths.get("content/markdown");
+        List<Path> files;
+        try (Stream<Path> stream = Files.walk(contentDirectory)) {
+            files = 
stream.filter(MarkdownDocsTest::isMarkdownSource).sorted().toList();
+        }
+
+        List<String> violations = new ArrayList<>();
+        for (Path file : files) {
+            collectViolations(contentDirectory, file, violations);
+        }
+
+        assertTrue(
+                violations.isEmpty(),
+                () -> "Markdown docs must escape square brackets in link 
labels, "
+                        + "otherwise the generated link target is the issue 
key instead of the URL. "

Review Comment:
   Split the assertion message into shorter sentences.



##########
src/test/java/org/apache/maven/site/MarkdownDocsTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.site;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+
+import com.vladsch.flexmark.ext.wikilink.WikiLink;
+import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension;
+import com.vladsch.flexmark.parser.Parser;
+import com.vladsch.flexmark.util.ast.Node;
+import com.vladsch.flexmark.util.ast.NodeVisitor;
+import com.vladsch.flexmark.util.ast.VisitHandler;
+import com.vladsch.flexmark.util.data.MutableDataSet;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class MarkdownDocsTest {
+    private static final Pattern PARENTHESIZED_DESTINATION = 
Pattern.compile("^\\([^)\\s]+\\)");
+
+    private static final Parser MARKDOWN_PARSER = Parser.builder(
+                    new MutableDataSet().set(Parser.EXTENSIONS, 
List.of(WikiLinkExtension.create())))
+            .build();
+
+    @Test
+    void markdownDocsHaveWellFormedLinks() throws IOException {
+        Path contentDirectory = Paths.get("content/markdown");
+        List<Path> files;
+        try (Stream<Path> stream = Files.walk(contentDirectory)) {
+            files = 
stream.filter(MarkdownDocsTest::isMarkdownSource).sorted().toList();
+        }
+
+        List<String> violations = new ArrayList<>();
+        for (Path file : files) {
+            collectViolations(contentDirectory, file, violations);
+        }
+
+        assertTrue(
+                violations.isEmpty(),
+                () -> "Markdown docs must escape square brackets in link 
labels, "
+                        + "otherwise the generated link target is the issue 
key instead of the URL. "
+                        + "Use 
[\\[MNG-1234\\]](https://issues.apache.org/jira/browse/MNG-1234).\n"

Review Comment:
   Replaced the example with MNG-1, a real Maven JIRA issue.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to