From 58c43eef6555f2557848fa392101a2d975f99c53 Mon Sep 17 00:00:00 2001 From: Philippe Charles Date: Wed, 28 Aug 2024 13:53:07 +0200 Subject: [PATCH] Add json extension --- heylogs-api/pom.xml | 5 -- .../internal/heylogs/ExtendedRulesTest.java | 13 ++-- .../heylogs/GuidingPrinciplesTest.java | 11 ++- .../internal/heylogs/StylishFormatTest.java | 8 ++- .../java/tests/heylogs/spi/FormatAssert.java | 53 ++++++++++++++ heylogs-bom/pom.xml | 5 ++ heylogs-cli/pom.xml | 5 ++ heylogs-ext-json/pom.xml | 71 +++++++++++++++++++ .../nbbrd/heylogs/ext/json}/JsonFormat.java | 2 +- .../heylogs/ext/json}/JsonFormatTest.java | 27 ++++--- .../src/test/resources}/check1.json | 0 .../src/test/resources}/check2.json | 0 .../src/test/resources}/check3.json | 0 .../src/test/resources}/resource1.json | 0 .../src/test/resources}/resource2.json | 0 .../src/test/resources}/resource3.json | 0 .../src/test/resources}/scan1.json | 0 .../src/test/resources}/scan2.json | 0 heylogs-maven-plugin/pom.xml | 5 ++ pom.xml | 1 + 20 files changed, 170 insertions(+), 36 deletions(-) create mode 100644 heylogs-api/src/test/java/tests/heylogs/spi/FormatAssert.java create mode 100644 heylogs-ext-json/pom.xml rename {heylogs-api/src/main/java/internal/heylogs => heylogs-ext-json/src/main/java/nbbrd/heylogs/ext/json}/JsonFormat.java (99%) rename {heylogs-api/src/test/java/internal/heylogs => heylogs-ext-json/src/test/java/nbbrd/heylogs/ext/json}/JsonFormatTest.java (80%) rename {heylogs-api/src/test/resources/internal/heylogs => heylogs-ext-json/src/test/resources}/check1.json (100%) rename {heylogs-api/src/test/resources/internal/heylogs => heylogs-ext-json/src/test/resources}/check2.json (100%) rename {heylogs-api/src/test/resources/internal/heylogs => heylogs-ext-json/src/test/resources}/check3.json (100%) rename {heylogs-api/src/test/resources/internal/heylogs => heylogs-ext-json/src/test/resources}/resource1.json (100%) rename {heylogs-api/src/test/resources/internal/heylogs => heylogs-ext-json/src/test/resources}/resource2.json (100%) rename {heylogs-api/src/test/resources/internal/heylogs => heylogs-ext-json/src/test/resources}/resource3.json (100%) rename {heylogs-api/src/test/resources/internal/heylogs => heylogs-ext-json/src/test/resources}/scan1.json (100%) rename {heylogs-api/src/test/resources/internal/heylogs => heylogs-ext-json/src/test/resources}/scan2.json (100%) diff --git a/heylogs-api/pom.xml b/heylogs-api/pom.xml index 5badb80..c0219a2 100644 --- a/heylogs-api/pom.xml +++ b/heylogs-api/pom.xml @@ -73,11 +73,6 @@ com.github.nbbrd.java-io-util java-io-http - - com.google.code.gson - gson - 2.11.0 - diff --git a/heylogs-api/src/test/java/internal/heylogs/ExtendedRulesTest.java b/heylogs-api/src/test/java/internal/heylogs/ExtendedRulesTest.java index 0b79c04..9268d7b 100644 --- a/heylogs-api/src/test/java/internal/heylogs/ExtendedRulesTest.java +++ b/heylogs-api/src/test/java/internal/heylogs/ExtendedRulesTest.java @@ -1,31 +1,28 @@ package internal.heylogs; -import tests.heylogs.api.Sample; import com.vladsch.flexmark.ast.LinkNodeBase; import com.vladsch.flexmark.util.ast.Node; import nbbrd.heylogs.Nodes; -import nbbrd.heylogs.spi.Rule; import nbbrd.heylogs.spi.RuleIssue; -import nbbrd.heylogs.spi.RuleLoader; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import tests.heylogs.api.Sample; import java.util.Objects; -import static tests.heylogs.api.Sample.using; import static internal.heylogs.ExtendedRules.NO_RULE_ISSUE; import static internal.heylogs.ExtendedRules.validateConsistentSeparator; import static nbbrd.heylogs.Nodes.of; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Index.atIndex; +import static tests.heylogs.api.Sample.using; +import static tests.heylogs.spi.RuleAssert.assertRuleCompliance; public class ExtendedRulesTest { @Test - public void testIdPattern() { - assertThat(ExtendedRules.values()) - .extracting(Rule::getRuleId) - .allMatch(RuleLoader.ID_PATTERN.asPredicate()); + public void testCompliance() { + assertRuleCompliance(new ExtendedRules.Batch()); } @Test diff --git a/heylogs-api/src/test/java/internal/heylogs/GuidingPrinciplesTest.java b/heylogs-api/src/test/java/internal/heylogs/GuidingPrinciplesTest.java index 5b7de9f..73a2967 100644 --- a/heylogs-api/src/test/java/internal/heylogs/GuidingPrinciplesTest.java +++ b/heylogs-api/src/test/java/internal/heylogs/GuidingPrinciplesTest.java @@ -2,28 +2,25 @@ import com.vladsch.flexmark.ast.Heading; import com.vladsch.flexmark.util.ast.Node; -import nbbrd.heylogs.spi.Rule; import nbbrd.heylogs.spi.RuleIssue; -import nbbrd.heylogs.spi.RuleLoader; import org.junit.jupiter.api.Test; import java.util.Objects; -import static tests.heylogs.api.Sample.using; import static internal.heylogs.GuidingPrinciples.validateForHumans; import static internal.heylogs.GuidingPrinciples.validateLatestVersionFirst; import static nbbrd.heylogs.Nodes.of; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Index.atIndex; +import static tests.heylogs.api.Sample.using; +import static tests.heylogs.spi.RuleAssert.assertRuleCompliance; public class GuidingPrinciplesTest { @Test - public void testIdPattern() { - assertThat(GuidingPrinciples.values()) - .extracting(Rule::getRuleId) - .allMatch(RuleLoader.ID_PATTERN.asPredicate()); + public void testCompliance() { + assertRuleCompliance(new GuidingPrinciples.Batch()); } @Test diff --git a/heylogs-api/src/test/java/internal/heylogs/StylishFormatTest.java b/heylogs-api/src/test/java/internal/heylogs/StylishFormatTest.java index d7187e4..5bd3c1d 100644 --- a/heylogs-api/src/test/java/internal/heylogs/StylishFormatTest.java +++ b/heylogs-api/src/test/java/internal/heylogs/StylishFormatTest.java @@ -5,14 +5,20 @@ import nbbrd.heylogs.spi.FormatType; import org.junit.jupiter.api.Test; -import static tests.heylogs.api.Sample.*; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; +import static tests.heylogs.api.Sample.*; +import static tests.heylogs.spi.FormatAssert.assertFormatCompliance; class StylishFormatTest { + @Test + public void testCompliance() { + assertFormatCompliance(new StylishFormat()); + } + @Test public void testIdPattern() { assertThat(new StylishFormat().getFormatId()) diff --git a/heylogs-api/src/test/java/tests/heylogs/spi/FormatAssert.java b/heylogs-api/src/test/java/tests/heylogs/spi/FormatAssert.java new file mode 100644 index 0000000..bfe32f5 --- /dev/null +++ b/heylogs-api/src/test/java/tests/heylogs/spi/FormatAssert.java @@ -0,0 +1,53 @@ +package tests.heylogs.spi; + +import lombok.NonNull; +import nbbrd.heylogs.spi.Format; + +import static java.util.Collections.emptyList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; + +public final class FormatAssert { + + private FormatAssert() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } + + @SuppressWarnings("DataFlowIssue") + public static void assertFormatCompliance(@NonNull Format x) { + assertThat(x.getFormatId()) + .matches(nbbrd.heylogs.spi.FormatLoader.ID_PATTERN); + + assertThat(x.getFormatName()) + .isNotEmpty() + .isNotNull(); + + assertThat(x.getFormatCategory()) + .isNotEmpty() + .isNotNull(); + + assertThat(x.getSupportedFormatTypes()) + .isNotNull(); + + assertThatNullPointerException() + .isThrownBy(() -> x.formatStatus(null, emptyList())); + + assertThatNullPointerException() + .isThrownBy(() -> x.formatStatus(new StringBuilder(), null)); + + assertThatNullPointerException() + .isThrownBy(() -> x.formatResources(null, emptyList())); + + assertThatNullPointerException() + .isThrownBy(() -> x.formatResources(new StringBuilder(), null)); + + assertThatNullPointerException() + .isThrownBy(() -> x.formatProblems(null, emptyList())); + + assertThatNullPointerException() + .isThrownBy(() -> x.formatProblems(new StringBuilder(), null)); + + assertThat(x.getClass()) + .isFinal(); + } +} diff --git a/heylogs-bom/pom.xml b/heylogs-bom/pom.xml index 30abacf..34e8986 100644 --- a/heylogs-bom/pom.xml +++ b/heylogs-bom/pom.xml @@ -41,6 +41,11 @@ ${project.groupId} ${project.version} + + heylogs-ext-json + ${project.groupId} + ${project.version} + heylogs-ext-semver ${project.groupId} diff --git a/heylogs-cli/pom.xml b/heylogs-cli/pom.xml index 34cfe2e..ce8eca2 100644 --- a/heylogs-cli/pom.xml +++ b/heylogs-cli/pom.xml @@ -51,6 +51,11 @@ ${project.groupId} ${project.version} + + heylogs-ext-json + ${project.groupId} + ${project.version} + heylogs-ext-semver ${project.groupId} diff --git a/heylogs-ext-json/pom.xml b/heylogs-ext-json/pom.xml new file mode 100644 index 0000000..ed25080 --- /dev/null +++ b/heylogs-ext-json/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + + com.github.nbbrd.heylogs + heylogs-parent + 0.8.2-SNAPSHOT + + + heylogs-ext-json + jar + + + + + org.checkerframework + checker-qual + provided + + + org.projectlombok + lombok + provided + + + com.github.nbbrd.java-design-util + java-design-processor + provided + + + com.github.nbbrd.java-service-util + java-service-processor + provided + + + + + heylogs-api + ${project.groupId} + ${project.version} + + + com.google.code.gson + gson + 2.11.0 + + + + + heylogs-api + ${project.groupId} + ${project.version} + tests + test-jar + test + + + org.junit.jupiter + junit-jupiter + test + + + org.assertj + assertj-core + test + + + \ No newline at end of file diff --git a/heylogs-api/src/main/java/internal/heylogs/JsonFormat.java b/heylogs-ext-json/src/main/java/nbbrd/heylogs/ext/json/JsonFormat.java similarity index 99% rename from heylogs-api/src/main/java/internal/heylogs/JsonFormat.java rename to heylogs-ext-json/src/main/java/nbbrd/heylogs/ext/json/JsonFormat.java index e4c2448..b16130b 100644 --- a/heylogs-api/src/main/java/internal/heylogs/JsonFormat.java +++ b/heylogs-ext-json/src/main/java/nbbrd/heylogs/ext/json/JsonFormat.java @@ -1,4 +1,4 @@ -package internal.heylogs; +package nbbrd.heylogs.ext.json; import com.google.gson.*; import lombok.NonNull; diff --git a/heylogs-api/src/test/java/internal/heylogs/JsonFormatTest.java b/heylogs-ext-json/src/test/java/nbbrd/heylogs/ext/json/JsonFormatTest.java similarity index 80% rename from heylogs-api/src/test/java/internal/heylogs/JsonFormatTest.java rename to heylogs-ext-json/src/test/java/nbbrd/heylogs/ext/json/JsonFormatTest.java index 7199b5d..6e16a1d 100644 --- a/heylogs-api/src/test/java/internal/heylogs/JsonFormatTest.java +++ b/heylogs-ext-json/src/test/java/nbbrd/heylogs/ext/json/JsonFormatTest.java @@ -1,21 +1,20 @@ -package internal.heylogs; +package nbbrd.heylogs.ext.json; import nbbrd.heylogs.spi.Format; -import nbbrd.heylogs.spi.FormatLoader; import org.junit.jupiter.api.Test; -import static tests.heylogs.api.Sample.*; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; +import static tests.heylogs.api.Sample.*; +import static tests.heylogs.spi.FormatAssert.assertFormatCompliance; class JsonFormatTest { @Test - public void testIdPattern() { - assertThat(new JsonFormat().getFormatId()) - .matches(FormatLoader.ID_PATTERN); + public void testCompliance() { + assertFormatCompliance(new JsonFormat()); } @Test @@ -23,13 +22,13 @@ public void testFormatProblems() { Format x = new JsonFormat(); assertThat(writing(appendable -> x.formatProblems(appendable, singletonList(CHECK1)))) - .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "check1.json")); + .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/check1.json")); assertThat(writing(appendable -> x.formatProblems(appendable, singletonList(CHECK2)))) - .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "check2.json")); + .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/check2.json")); assertThat(writing(appendable -> x.formatProblems(appendable, singletonList(CHECK3)))) - .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "check3.json")); + .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/check3.json")); } @Test @@ -37,10 +36,10 @@ public void testFormatStatus() { Format x = new JsonFormat(); assertThat(writing(appendable -> x.formatStatus(appendable, singletonList(SCAN1)))) - .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "scan1.json")); + .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/scan1.json")); assertThat(writing(appendable -> x.formatStatus(appendable, singletonList(SCAN2)))) - .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "scan2.json")); + .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/scan2.json")); } @Test @@ -48,13 +47,13 @@ public void testFormatResource() { Format x = new JsonFormat(); assertThat(writing(appendable -> x.formatResources(appendable, emptyList()))) - .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "resource1.json")); + .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/resource1.json")); assertThat(writing(appendable -> x.formatResources(appendable, singletonList(RESOURCE1)))) - .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "resource2.json")); + .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/resource2.json")); assertThat(writing(appendable -> x.formatResources(appendable, asList(RESOURCE1, RESOURCE2)))) - .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "resource3.json")); + .isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/resource3.json")); } } \ No newline at end of file diff --git a/heylogs-api/src/test/resources/internal/heylogs/check1.json b/heylogs-ext-json/src/test/resources/check1.json similarity index 100% rename from heylogs-api/src/test/resources/internal/heylogs/check1.json rename to heylogs-ext-json/src/test/resources/check1.json diff --git a/heylogs-api/src/test/resources/internal/heylogs/check2.json b/heylogs-ext-json/src/test/resources/check2.json similarity index 100% rename from heylogs-api/src/test/resources/internal/heylogs/check2.json rename to heylogs-ext-json/src/test/resources/check2.json diff --git a/heylogs-api/src/test/resources/internal/heylogs/check3.json b/heylogs-ext-json/src/test/resources/check3.json similarity index 100% rename from heylogs-api/src/test/resources/internal/heylogs/check3.json rename to heylogs-ext-json/src/test/resources/check3.json diff --git a/heylogs-api/src/test/resources/internal/heylogs/resource1.json b/heylogs-ext-json/src/test/resources/resource1.json similarity index 100% rename from heylogs-api/src/test/resources/internal/heylogs/resource1.json rename to heylogs-ext-json/src/test/resources/resource1.json diff --git a/heylogs-api/src/test/resources/internal/heylogs/resource2.json b/heylogs-ext-json/src/test/resources/resource2.json similarity index 100% rename from heylogs-api/src/test/resources/internal/heylogs/resource2.json rename to heylogs-ext-json/src/test/resources/resource2.json diff --git a/heylogs-api/src/test/resources/internal/heylogs/resource3.json b/heylogs-ext-json/src/test/resources/resource3.json similarity index 100% rename from heylogs-api/src/test/resources/internal/heylogs/resource3.json rename to heylogs-ext-json/src/test/resources/resource3.json diff --git a/heylogs-api/src/test/resources/internal/heylogs/scan1.json b/heylogs-ext-json/src/test/resources/scan1.json similarity index 100% rename from heylogs-api/src/test/resources/internal/heylogs/scan1.json rename to heylogs-ext-json/src/test/resources/scan1.json diff --git a/heylogs-api/src/test/resources/internal/heylogs/scan2.json b/heylogs-ext-json/src/test/resources/scan2.json similarity index 100% rename from heylogs-api/src/test/resources/internal/heylogs/scan2.json rename to heylogs-ext-json/src/test/resources/scan2.json diff --git a/heylogs-maven-plugin/pom.xml b/heylogs-maven-plugin/pom.xml index cb11639..cf0c04f 100644 --- a/heylogs-maven-plugin/pom.xml +++ b/heylogs-maven-plugin/pom.xml @@ -64,6 +64,11 @@ ${project.groupId} ${project.version} + + heylogs-ext-json + ${project.groupId} + ${project.version} + heylogs-ext-semver ${project.groupId} diff --git a/pom.xml b/pom.xml index 0290694..f0390ac 100644 --- a/pom.xml +++ b/pom.xml @@ -244,6 +244,7 @@ heylogs-maven-plugin heylogs-bom heylogs-ext-github + heylogs-ext-json heylogs-ext-semver