From 90e13dcdd45c9676fff99be1ea1b98903cc39f53 Mon Sep 17 00:00:00 2001 From: Elyes Cherfa Date: Tue, 1 Oct 2024 19:23:00 +0200 Subject: [PATCH 1/4] Issue #58: Add Community Connector GitHub link * Added community connectors github link. * Tested on the metricshub-doc & metricshub-enterprise doc. --- .../parser/ConnectorLibraryParser.java | 11 ++++++++++- .../producer/ConnectorJsonNodeReader.java | 4 ++++ .../producer/ConnectorPageProducer.java | 10 ++++++++++ .../connector/producer/SinkHelper.java | 18 +++++++++++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/parser/ConnectorLibraryParser.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/parser/ConnectorLibraryParser.java index 989e44b..18a0009 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/parser/ConnectorLibraryParser.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/parser/ConnectorLibraryParser.java @@ -23,6 +23,7 @@ import static org.sentrysoftware.maven.metricshub.connector.Constants.YAML_OBJECT_MAPPER; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -48,6 +49,12 @@ private static class ConnectorFileVisitor extends SimpleFileVisitor { @Getter private final Map connectorsMap = new HashMap<>(); + private final Path sourceDirectory; + + public ConnectorFileVisitor(final Path sourceDirectory) { + this.sourceDirectory = sourceDirectory; + } + @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { // Skip this path if it is a directory or not a YAML file @@ -62,6 +69,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO final JsonNode connector = ConnectorParser.withNodeProcessor(file.getParent()).parse(file.toFile()); + ((ObjectNode) connector).put("relativePath", sourceDirectory.relativize(file).toString()); + final Path fileNamePath = file.getFileName(); if (fileNamePath != null) { @@ -107,7 +116,7 @@ private boolean isYamlFile(final String fileName) { * @throws IOException if the file does not exist */ public Map parse(@NonNull final Path sourceDirectory) throws IOException { - final ConnectorFileVisitor fileVisitor = new ConnectorFileVisitor(); + final ConnectorFileVisitor fileVisitor = new ConnectorFileVisitor(sourceDirectory); Files.walkFileTree(sourceDirectory, fileVisitor); diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java index 5a76d56..7a321e6 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java @@ -663,4 +663,8 @@ public Map getDefaultVariables() { } return defaultVariables; } + + public String getRelativePath() { + return connector.get("relativePath").asText(); + } } diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java index 4d5634f..bb0f1f7 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java @@ -56,6 +56,7 @@ public class ConnectorPageProducer { private final String connectorId; private final JsonNode connector; private final Log logger; + private String connectorDirectory; /** * Produces a report page for the current connector and generates the corresponding sink for documentation output. @@ -121,6 +122,15 @@ public void produce( produceSupersedesContent(sink, supersededMap, connectorJsonNodeReader); + // The GitHub link will be generated only for community connectors + if (!enterpriseConnectorIds.contains(connectorId)) { + connectorDirectory = connectorJsonNodeReader.getRelativePath().replace("\\", "/"); + // Add a link to the connector source. + sink.paragraph(); + sink.rawText(SinkHelper.gitHubHyperlinkRef(connectorDirectory, "Source")); + sink.paragraph_(); + } + // End of the second heading element sink.section2_(); diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/SinkHelper.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/SinkHelper.java index becca22..93234b8 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/SinkHelper.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/SinkHelper.java @@ -171,9 +171,25 @@ public static String replaceWithHtmlCode(final String value) { } /** - * Creates an HTML hyperlink reference with the given content + * Creates an HTML hyperlink reference with the given content. */ public static String hyperlinkRef(final String link, final String content) { return String.format("%s", link, content); } + + /** + * Creates an HTMP hyperlink reference with the given content and the specified classes. + */ + public static String gitHubHyperlinkRef(final String link, final String content) { + return String.format( + "" + + "" + + "" + + " %s" + + "", + link, + content + ); + } } From 6d551381fddf811aafc3a4f08fb880a048dc2095 Mon Sep 17 00:00:00 2001 From: Elyes Cherfa Date: Wed, 2 Oct 2024 17:42:40 +0200 Subject: [PATCH 2/4] Issue #58: Add Community Connector GitHub link * Added javadoc. --- .../connector/producer/ConnectorJsonNodeReader.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java index 7a321e6..a7afc8d 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorJsonNodeReader.java @@ -664,6 +664,12 @@ public Map getDefaultVariables() { return defaultVariables; } + /** + * Retrieves the relative path of the connector that was saved during parsing. + * This path is used to generate a link to the connector's source code. + * + * @return The saved relative path as a string. + */ public String getRelativePath() { return connector.get("relativePath").asText(); } From 12fe71772f48389f8789b2ef8e7234a8653b5b40 Mon Sep 17 00:00:00 2001 From: Elyes Cherfa Date: Wed, 2 Oct 2024 17:48:46 +0200 Subject: [PATCH 3/4] Issue #58: Add Community Connector GitHub link * Removed `public` modifier from the `ConnectorLibraryParser` constructor. --- .../metricshub/connector/parser/ConnectorLibraryParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/parser/ConnectorLibraryParser.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/parser/ConnectorLibraryParser.java index 18a0009..7c8a869 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/parser/ConnectorLibraryParser.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/parser/ConnectorLibraryParser.java @@ -51,7 +51,7 @@ private static class ConnectorFileVisitor extends SimpleFileVisitor { private final Path sourceDirectory; - public ConnectorFileVisitor(final Path sourceDirectory) { + ConnectorFileVisitor(final Path sourceDirectory) { this.sourceDirectory = sourceDirectory; } From f89169e5da176dd034e2b9926748e566700a40e3 Mon Sep 17 00:00:00 2001 From: Elyes Cherfa Date: Thu, 3 Oct 2024 11:52:46 +0200 Subject: [PATCH 4/4] Issue #58: Add Community Connector GitHub link * Added tags on each connector page. * Tested the update on Metricshub community & Enterprise documentations. --- .../producer/ConnectorPageProducer.java | 22 +++++++++++++++++++ .../connector/producer/SinkHelper.java | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java index bb0f1f7..12b4e6d 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageProducer.java @@ -21,11 +21,13 @@ */ import static org.sentrysoftware.maven.metricshub.connector.ConnectorsDirectoryReport.CONNECTORS_DIRECTORY_OUTPUT_NAME; +import static org.sentrysoftware.maven.metricshub.connector.Constants.TAG_SUBDIRECTORY_NAME; import com.fasterxml.jackson.databind.JsonNode; import java.text.ChoiceFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -122,6 +124,26 @@ public void produce( produceSupersedesContent(sink, supersededMap, connectorJsonNodeReader); + // Display the connector tags + final List connectorTags = connectorJsonNodeReader.getTags(); + sink.paragraph(); + connectorTags + .stream() + .sorted(String.CASE_INSENSITIVE_ORDER) + .collect(Collectors.toCollection(LinkedHashSet::new)) + .forEach(tag -> + sink.rawText( + SinkHelper.bootstrapLabel( + SinkHelper.hyperlinkRef( + String.format("%s/%s.html", TAG_SUBDIRECTORY_NAME, tag.toLowerCase().replace(" ", "-")), + tag + ), + "metricshub-tag" + ) + ) + ); + sink.paragraph_(); + // The GitHub link will be generated only for community connectors if (!enterpriseConnectorIds.contains(connectorId)) { connectorDirectory = connectorJsonNodeReader.getRelativePath().replace("\\", "/"); diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/SinkHelper.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/SinkHelper.java index 93234b8..cecfd74 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/SinkHelper.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/SinkHelper.java @@ -183,7 +183,7 @@ public static String hyperlinkRef(final String link, final String content) { public static String gitHubHyperlinkRef(final String link, final String content) { return String.format( "" + - "" + "" + " %s" +