From 2a3f5d99ce2ae9e677e7fed458ca19df39c2a984 Mon Sep 17 00:00:00 2001 From: Elyes Cherfa Date: Fri, 5 Jul 2024 09:56:19 +0200 Subject: [PATCH 1/4] Issue #47: Add a new column to indicate if a connector is enterprise * Extracted the Enterprise Connectors Manifest to retrieve the Enterprise Connectors Ids. * Added a Enterprise column on `Connector Reference` page to know if a connector is a CC or EC. * Updated maven skin tools version * Refactored many methods to exculde their parameters. --- src/it/metricshub-connectors/pom.xml | 2 +- .../connector/AbstractConnectorReport.java | 60 +++++++++++++++++++ .../metricshub/connector/ReferenceReport.java | 22 +++---- .../producer/MainPageReferenceProducer.java | 24 +++++++- .../connector/producer/SinkHelper.java | 11 ++++ 5 files changed, 101 insertions(+), 18 deletions(-) diff --git a/src/it/metricshub-connectors/pom.xml b/src/it/metricshub-connectors/pom.xml index 3229298..660879f 100644 --- a/src/it/metricshub-connectors/pom.xml +++ b/src/it/metricshub-connectors/pom.xml @@ -53,7 +53,7 @@ org.sentrysoftware.maven maven-skin-tools - 1.2.00 + 1.3.00 diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/AbstractConnectorReport.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/AbstractConnectorReport.java index 1d9ae15..babef0f 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/AbstractConnectorReport.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/AbstractConnectorReport.java @@ -23,8 +23,17 @@ import com.fasterxml.jackson.databind.JsonNode; import java.io.File; import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.stream.Collectors; +import lombok.Getter; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.Parameter; @@ -47,6 +56,8 @@ public abstract class AbstractConnectorReport extends AbstractMavenReport { protected Map connectors; + protected List enterpriseConnectorIds = new ArrayList<>(); + @Override protected void executeReport(Locale locale) throws MavenReportException { // Get and set the logger @@ -75,10 +86,59 @@ protected void executeReport(Locale locale) throws MavenReportException { // Parse the connector library connectors = parseConnectors(); + // Retrieve the enterprise connector identifiers from the manifest file. + try { + enterpriseConnectorIds = detectEnterpriseConnectors(); + } catch (IOException e) { + final String message = "Could not read the eneterprise connectors manifest: enterprise-connectors-manifest.txt"; + logger.error(message); + throw new MavenReportException(message); + } + // Produce the report doReport(); } + /** + * Detect the enterprise connector identifiers. + * + * @return List of string values containing the connector identifiers. + * @throws IOException If any I/O error occurs. + */ + private List detectEnterpriseConnectors() throws IOException { + final EnterpriseManifestVisitor fileVisitor = new EnterpriseManifestVisitor(); + + Files.walkFileTree(sourceDirectory.toPath(), fileVisitor); + + return fileVisitor.getConnectorEnterpriseList(); + } + + /** + * This inner class allows to visit the files in order to extract the enterprise manifest file content + */ + private static class EnterpriseManifestVisitor extends SimpleFileVisitor { + + @Getter + private List connectorEnterpriseList = new ArrayList<>(); + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + // Skip this path if it is a directory or not a YAML file + if (!Files.isDirectory(file) && "enterprise-connectors-manifest.txt".equals(file.toFile().getName())) { + connectorEnterpriseList = + Files + .readAllLines(file) + .stream() + .map(filename -> filename.substring(0, filename.lastIndexOf('.'))) + .collect(Collectors.toCollection(ArrayList::new)); + + return FileVisitResult.TERMINATE; + } + + return FileVisitResult.CONTINUE; + } + } + /** * Performs the main logic of generating the report. Subclasses should implement this method to define * the specific report generation logic. diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/ReferenceReport.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/ReferenceReport.java index 84b8e14..33c4472 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/ReferenceReport.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/ReferenceReport.java @@ -85,20 +85,19 @@ protected void doReport() throws MavenReportException { } // Main page - produceMainPage(connectors); + produceMainPage(); // Connector pages - produceConnectorPages(connectors, connectorSubdirectory, buildSupersededMap(connectors)); + produceConnectorPages(connectorSubdirectory, buildSupersededMap()); } /** * Builds a map representing the superseded relationships between connectors. * - * @param connectors A map of connector IDs to JsonNode objects representing connectors. * @return A map where each key is a connector ID that is superseded by one or more connectors, * and the associated value is a list of connectors that supersede it. */ - private Map> buildSupersededMap(final Map connectors) { + private Map> buildSupersededMap() { final Map> supersededMap = new HashMap<>(); connectors.forEach((connectorId, connector) -> @@ -115,16 +114,12 @@ private Map> buildSupersededMap(final Map /** * Produces individual connector pages for the Maven report * - * @param connectors A map of connector IDs to their corresponding JSON nodes. * @param connectorSubdirectory The subdirectory where individual connector pages are located. * @param supersededMap A map representing the superseded relationships among connectors. * @throws MavenReportException If an error occurs while producing the connector pages. */ - private void produceConnectorPages( - final Map connectors, - final File connectorSubdirectory, - final Map> supersededMap - ) throws MavenReportException { + private void produceConnectorPages(final File connectorSubdirectory, final Map> supersededMap) + throws MavenReportException { for (Entry connectorEntry : connectors.entrySet()) { final String connectorId = connectorEntry.getKey(); // Create a new sink! @@ -149,13 +144,12 @@ private void produceConnectorPages( /** * Produces the main page for the Maven report - * - * @param connectors A map of connector IDs to their corresponding JSON nodes. */ - private void produceMainPage(final Map connectors) throws MavenReportException { + private void produceMainPage() throws MavenReportException { final Sink mainSink = getMainSink(); - new MainPageReferenceProducer(CONNECTOR_SUBDIRECTORY_NAME, logger).produce(mainSink, connectors); + new MainPageReferenceProducer(CONNECTOR_SUBDIRECTORY_NAME, logger) + .produce(mainSink, connectors, enterpriseConnectorIds); } @Override diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/MainPageReferenceProducer.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/MainPageReferenceProducer.java index 2c210ed..5cbe41e 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/MainPageReferenceProducer.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/MainPageReferenceProducer.java @@ -21,12 +21,17 @@ */ import com.fasterxml.jackson.databind.JsonNode; +import java.io.File; +import java.util.Arrays; import java.util.Comparator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import lombok.AllArgsConstructor; import org.apache.maven.doxia.sink.Sink; +import org.apache.maven.doxia.sink.SinkEventAttributes; +import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; import org.apache.maven.plugin.logging.Log; import org.sentrysoftware.maven.metricshub.connector.ReferenceReport; import org.sentrysoftware.maven.metricshub.connector.producer.model.common.OsType; @@ -45,10 +50,15 @@ public class MainPageReferenceProducer { /** * Produces the main page reference that lists all the connectors. * - * @param mainSink The main sink used for generating content. - * @param connectors The map of connector identifiers to their corresponding JsonNodes. + * @param mainSink The main sink used for generating content. + * @param connectors The map of connector identifiers to their corresponding JsonNodes. + * @param enterpriseConnectorIds The enterprise connector identifiers. */ - public void produce(final Sink mainSink, final Map connectors) { + public void produce( + final Sink mainSink, + final Map connectors, + final List enterpriseConnectorIds + ) { Objects.requireNonNull(connectorSubdirectoryName, () -> "connectorSubdirectoryName cannot be null."); Objects.requireNonNull(mainSink, () -> "mainSink cannot be null."); Objects.requireNonNull(logger, () -> "logger cannot be null."); @@ -94,6 +104,9 @@ public void produce(final Sink mainSink, final Map connectors) mainSink.tableHeaderCell(SinkHelper.setClass(BOOTSTRAP_MEDIUM_3_CLASS)); mainSink.text("Operating Systems"); mainSink.tableHeaderCell_(); + mainSink.tableHeaderCell(SinkHelper.setClass(BOOTSTRAP_MEDIUM_3_CLASS)); + mainSink.text("Enterprise"); + mainSink.tableHeaderCell_(); mainSink.tableRow_(); // A comparison function which compare connectors by display name @@ -143,6 +156,11 @@ public void produce(final Sink mainSink, final Map connectors) mainSink.text(String.join(", ", OsType.mapToDisplayNames(connectorJsonNodeReader.getAppliesTo()))); mainSink.tableCell_(); + SinkEventAttributes attributes = new SinkEventAttributeSet(SinkEventAttributes.ALIGN, "center"); + mainSink.tableCell(attributes); + mainSink.text(enterpriseConnectorIds.contains(connectorId) ? "\u2713" : ""); + mainSink.tableCell_(); + mainSink.tableRow_(); }); 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 6fa6617..c6a8d3f 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 @@ -24,6 +24,7 @@ import java.util.regex.Pattern; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import lombok.NonNull; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.SinkEventAttributes; import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; @@ -120,6 +121,16 @@ public static String glyphIcon(final String iconName) { return String.format("", glyphIconName); } + /** + * Create a bootstrap badge with the following content. + * + * @param content text of the badge. + * @return the HTML code for this badge. + */ + public static String bootstrapBadge(@NonNull final String content) { + return String.format("%s", content); + } + /** * Builds the HTML page file name corresponding to the specified connector identifier. * From 4114e4ff3547471f2ff26e37bf96820a60825878 Mon Sep 17 00:00:00 2001 From: Elyes Cherfa Date: Fri, 5 Jul 2024 17:28:28 +0200 Subject: [PATCH 2/4] Issue #47: Add a new column to indicate if a connector is enterprise * Added an `Enterprise` label on each Enterprise's `ConnectorPageReference` page. * Tested on MetricsHub Enterprise Documentation. --- .../maven/metricshub/connector/ReferenceReport.java | 2 +- .../producer/ConnectorPageReferenceProducer.java | 6 +++++- .../connector/producer/MainPageReferenceProducer.java | 2 -- .../maven/metricshub/connector/producer/SinkHelper.java | 9 +++++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/ReferenceReport.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/ReferenceReport.java index 33c4472..d0d4f78 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/ReferenceReport.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/ReferenceReport.java @@ -138,7 +138,7 @@ private void produceConnectorPages(final File connectorSubdirectory, final Map> supersededMap) { + public void produce(final Sink sink, final Map> supersededMap, final List enterpriseConnectorIds) { Objects.requireNonNull(connectorId, () -> "connectorId cannot be null."); Objects.requireNonNull(connector, () -> "connector cannot be null."); Objects.requireNonNull(supersededMap, () -> "supersededMap cannot be null."); @@ -95,6 +95,10 @@ public void produce(final Sink sink, final Map> supersededM sink.section1(); sink.sectionTitle1(); sink.text(displayName); + // If the connector is Enterprise + if (enterpriseConnectorIds.contains(connectorId)) { + sink.rawText(SinkHelper.bootstrapLabel("Enterprise", "metricshub-enterprise-label")); + } sink.sectionTitle1_(); // Description diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/MainPageReferenceProducer.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/MainPageReferenceProducer.java index 5cbe41e..509b106 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/MainPageReferenceProducer.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/MainPageReferenceProducer.java @@ -21,8 +21,6 @@ */ import com.fasterxml.jackson.databind.JsonNode; -import java.io.File; -import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Map; 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 c6a8d3f..0ddb93f 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 @@ -127,8 +127,13 @@ public static String glyphIcon(final String iconName) { * @param content text of the badge. * @return the HTML code for this badge. */ - public static String bootstrapBadge(@NonNull final String content) { - return String.format("%s", content); + public static String bootstrapLabel(@NonNull final String content, String customClassname) { + if (customClassname == null) { + customClassname = ""; + } else { + customClassname = customClassname.trim() + " "; + } + return String.format(" %s", customClassname, content); } /** From 2338ef1f39f603a3de47213398b37fb6f74d4ca2 Mon Sep 17 00:00:00 2001 From: Elyes Cherfa Date: Mon, 8 Jul 2024 10:44:50 +0200 Subject: [PATCH 3/4] Issue #47: Add a new column to indicate if a connector is enterprise Updated Javadoc --- .../connector/producer/ConnectorPageReferenceProducer.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageReferenceProducer.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageReferenceProducer.java index 9e846db..20fcc8c 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageReferenceProducer.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/producer/ConnectorPageReferenceProducer.java @@ -59,8 +59,11 @@ public class ConnectorPageReferenceProducer { /** * Produces a page reference for the current connector and generates the corresponding sink for documentation output. * - * @param sink The sink used for generating content. - * @param supersededMap Map of superseded connectors. + * This method generates a table with connector information, adding a new column to indicate if a connector is an enterprise connector. + * + * @param sink The sink used for generating content. + * @param supersededMap Map of superseded connectors. + * @param enterpriseConnectorIds List of IDs for enterprise connectors. */ public void produce(final Sink sink, final Map> supersededMap, final List enterpriseConnectorIds) { Objects.requireNonNull(connectorId, () -> "connectorId cannot be null."); From abb8d03730f7d333d0d3482387661349d108ffca Mon Sep 17 00:00:00 2001 From: Elyes Cherfa Date: Mon, 8 Jul 2024 11:19:34 +0200 Subject: [PATCH 4/4] Issue #47: Add a new column to indicate if a connector is enterprise * Added a stream filter to exclude empty and blank lines. --- .../maven/metricshub/connector/AbstractConnectorReport.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/sentrysoftware/maven/metricshub/connector/AbstractConnectorReport.java b/src/main/java/org/sentrysoftware/maven/metricshub/connector/AbstractConnectorReport.java index babef0f..64b6d61 100644 --- a/src/main/java/org/sentrysoftware/maven/metricshub/connector/AbstractConnectorReport.java +++ b/src/main/java/org/sentrysoftware/maven/metricshub/connector/AbstractConnectorReport.java @@ -129,6 +129,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO Files .readAllLines(file) .stream() + .map(String::trim) + .filter(line -> !line.isEmpty()) .map(filename -> filename.substring(0, filename.lastIndexOf('.'))) .collect(Collectors.toCollection(ArrayList::new));