Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Aug 30, 2024
2 parents 0debf3e + 51a9e93 commit ce3500a
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 80 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.9.2] - 2024-08-30

- Fix blank line at the end of file [#299](https://github.com/nbbrd/heylogs/issues/299)

## [0.9.1] - 2024-08-28

### Fixed
Expand Down Expand Up @@ -173,7 +177,8 @@ This release improves extension points and also aligns features of Maven plugin

- Initial release

[Unreleased]: https://github.com/nbbrd/heylogs/compare/v0.9.1...HEAD
[Unreleased]: https://github.com/nbbrd/heylogs/compare/v0.9.2...HEAD
[0.9.2]: https://github.com/nbbrd/heylogs/compare/v0.9.1...v0.9.2
[0.9.1]: https://github.com/nbbrd/heylogs/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/nbbrd/heylogs/compare/v0.8.1...v0.9.0
[0.8.1]: https://github.com/nbbrd/heylogs/compare/v0.8.0...v0.8.1
Expand Down
2 changes: 1 addition & 1 deletion heylogs-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-parent</artifactId>
<version>0.9.1</version>
<version>0.9.2</version>
</parent>

<artifactId>heylogs-api</artifactId>
Expand Down
32 changes: 32 additions & 0 deletions heylogs-api/src/main/java/internal/heylogs/FlexmarkIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package internal.heylogs;

import com.vladsch.flexmark.formatter.Formatter;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Document;
import nbbrd.io.text.TextFormatter;
import nbbrd.io.text.TextParser;

public final class FlexmarkIO {

private FlexmarkIO() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

public static Parser newParser() {
return Parser.builder().build();
}

public static TextParser<Document> newTextParser() {
return TextParser.onParsingReader(newParser()::parseReader);
}

public static Formatter newFormatter() {
Formatter.Builder result = Formatter.builder();
result.set(Formatter.MAX_TRAILING_BLANK_LINES, 0);
return result.build();
}

public static TextFormatter<Document> newTextFormatter() {
return TextFormatter.onFormattingWriter(newFormatter()::render);
}
}
17 changes: 8 additions & 9 deletions heylogs-api/src/test/java/nbbrd/heylogs/FilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.time.LocalDate;
import java.util.function.Function;

import static nbbrd.heylogs.Filter.builder;
import static nbbrd.heylogs.Filter.parseLocalDate;
import static nbbrd.heylogs.Version.HYPHEN;
import static org.assertj.core.api.Assertions.*;
Expand All @@ -15,43 +14,43 @@ public class FilterTest {

@Test
public void testRef() {
assertThat(builder().build())
assertThat(Filter.builder().build())
.describedAs("Empty reference")
.is(containing(unreleased))
.is(containing(v1_1_0))
.is(containing(v1_0_0));

assertThat(builder().ref("Unreleased").build())
assertThat(Filter.builder().ref("Unreleased").build())
.describedAs("Full reference")
.is(containing(unreleased))
.isNot(containing(v1_1_0))
.isNot(containing(v1_0_0));

assertThat(builder().ref("1.1.0").build())
assertThat(Filter.builder().ref("1.1.0").build())
.describedAs("Full reference")
.isNot(containing(unreleased))
.is(containing(v1_1_0))
.isNot(containing(v1_0_0));

assertThat(builder().ref("rel").build())
assertThat(Filter.builder().ref("rel").build())
.describedAs("Partial reference")
.is(containing(unreleased))
.isNot(containing(v1_1_0))
.isNot(containing(v1_0_0));

assertThat(builder().ref("1.").build())
assertThat(Filter.builder().ref("1.").build())
.describedAs("Partial reference")
.isNot(containing(unreleased))
.is(containing(v1_1_0))
.is(containing(v1_0_0));

assertThat(builder().ref("other").build())
assertThat(Filter.builder().ref("other").build())
.describedAs("Unknown reference")
.isNot(containing(unreleased))
.isNot(containing(v1_1_0))
.isNot(containing(v1_0_0));

assertThat(builder().ref("other-SNAPSHOT").build())
assertThat(Filter.builder().ref("other-SNAPSHOT").build())
.describedAs("Matching unreleased pattern reference")
.is(containing(unreleased))
.isNot(containing(v1_1_0))
Expand All @@ -60,7 +59,7 @@ public void testRef() {

@Test
public void testTimeRange() {
Function<TimeRange, Filter> onTimeRange = o -> builder().timeRange(o).build();
Function<TimeRange, Filter> onTimeRange = o -> Filter.builder().timeRange(o).build();

assertThat(TimeRange.ALL)
.extracting(onTimeRange)
Expand Down
38 changes: 20 additions & 18 deletions heylogs-api/src/test/java/nbbrd/heylogs/HeylogsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.vladsch.flexmark.util.ast.Document;
import com.vladsch.flexmark.util.ast.Node;
import internal.heylogs.FlexmarkIO;
import internal.heylogs.StylishFormat;
import lombok.NonNull;
import nbbrd.design.MightBePromoted;
Expand All @@ -11,7 +12,6 @@
import nbbrd.heylogs.spi.RuleSeverity;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.jupiter.api.Test;
import tests.heylogs.api.Sample;

import java.io.IOException;
import java.net.URL;
Expand All @@ -21,9 +21,9 @@

import static internal.heylogs.URLExtractor.urlOf;
import static java.util.Collections.singletonList;
import static nbbrd.heylogs.Filter.builder;
import static nbbrd.heylogs.Heylogs.FIRST_FORMAT_AVAILABLE;
import static nbbrd.heylogs.spi.RuleSeverity.ERROR;
import static nbbrd.io.function.IOFunction.unchecked;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.InstanceOfAssertFactories.list;
import static tests.heylogs.api.Sample.using;
Expand Down Expand Up @@ -62,13 +62,9 @@ public void testCheckFormat() {
public void testExtractVersions() {
Heylogs x = Heylogs.ofServiceLoader();

Function<Filter, String> usingMain = extractor -> {
Document doc = using("/Main.md");
x.extractVersions(doc, extractor);
return Sample.FORMATTER.render(doc);
};
Function<Filter, String> usingMain = extractor -> extractVersionsToString(x, using("/Main.md"), extractor);

assertThat(builder().ref("1.1.0").build())
assertThat(Filter.builder().ref("1.1.0").build())
.extracting(usingMain, STRING)
.isEqualTo(
"## [1.1.0] - 2019-02-15\n" +
Expand All @@ -84,18 +80,16 @@ public void testExtractVersions() {
"- Fixed typos in Italian translation from [@lorenzo-arena](https://github.com/lorenzo-arena).\n" +
"- Fixed typos in Indonesian translation from [@ekojs](https://github.com/ekojs).\n" +
"\n" +
"[1.1.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...v1.1.0\n" +
"\n");
"[1.1.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...v1.1.0\n");

assertThat(builder().ref("1.1.0").ignoreContent(true).build())
assertThat(Filter.builder().ref("1.1.0").ignoreContent(true).build())
.extracting(usingMain, STRING)
.isEqualTo(
"## [1.1.0] - 2019-02-15\n" +
"\n" +
"[1.1.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...v1.1.0\n" +
"\n");
"[1.1.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...v1.1.0\n");

assertThat(builder().ref("zzz").build())
assertThat(Filter.builder().ref("zzz").build())
.extracting(usingMain, STRING)
.isEmpty();
}
Expand Down Expand Up @@ -127,23 +121,26 @@ public void testReleaseChanges() {
"## [1.2.3] - 2010-01-01",
"[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.2.3...HEAD",
"[1.2.3]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.0...v1.2.3")
.doesNotContain("[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.0...HEAD");
.doesNotContain("[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.0...HEAD")
.endsWith("[0.0.1]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/v0.0.1\n");

assertThat(releaseChangesToString(x, using("/UnreleasedChanges.md"), v123))
.contains(
"## [Unreleased]",
"## [1.2.3] - 2010-01-01",
"[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.2.3...HEAD",
"[1.2.3]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.0...v1.2.3")
.doesNotContain("[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.0...HEAD");
.doesNotContain("[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.0...HEAD")
.endsWith("[1.1.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...v1.1.0\n");

assertThat(releaseChangesToString(x, using("/FirstRelease.md"), v123))
.contains(
"## [Unreleased]",
"## [1.2.3] - 2010-01-01",
"[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.2.3...HEAD",
"[1.2.3]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.2.3...v1.2.3")
.doesNotContain("[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/HEAD...HEAD");
.doesNotContain("[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/HEAD...HEAD")
.endsWith("[1.2.3]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.2.3...v1.2.3\n");
}

@Test
Expand Down Expand Up @@ -259,9 +256,14 @@ public void testFormatStatus() throws IOException {
);
}

private static String extractVersionsToString(Heylogs heylogs, Document doc, Filter extractor) {
heylogs.extractVersions(doc, extractor);
return unchecked(FlexmarkIO.newTextFormatter()::formatToString).apply(doc);
}

private static String releaseChangesToString(Heylogs heylogs, Document doc, Version version) {
heylogs.releaseChanges(doc, version, "v");
return Sample.FORMATTER.render(doc);
return unchecked(FlexmarkIO.newTextFormatter()::formatToString).apply(doc);
}

private static final class MockedRule implements Rule {
Expand Down
32 changes: 12 additions & 20 deletions heylogs-api/src/test/java/tests/heylogs/api/Sample.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
package tests.heylogs.api;

import com.vladsch.flexmark.ast.Heading;
import com.vladsch.flexmark.formatter.Formatter;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Document;
import com.vladsch.flexmark.util.sequence.BasedSequence;
import internal.heylogs.FlexmarkIO;
import nbbrd.heylogs.*;
import nbbrd.heylogs.spi.RuleIssue;
import nbbrd.io.function.IOConsumer;
import org.assertj.core.util.URLs;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.Objects;

import static java.nio.charset.StandardCharsets.UTF_8;
import static nbbrd.heylogs.spi.RuleSeverity.ERROR;
import static nbbrd.io.function.IOFunction.unchecked;

public class Sample {

public static final Parser PARSER = Parser.builder().build();
public static final Formatter FORMATTER = Formatter.builder().build();

public static Document using(String name) {
try (InputStream stream = Sample.class.getResourceAsStream(name)) {
if (stream == null) {
throw new IllegalArgumentException("Missing resource '" + name + "'");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
return PARSER.parseReader(reader);
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return unchecked((String x) -> FlexmarkIO.newTextParser().parseResource(Sample.class, x, UTF_8))
.apply(name);
}

public static Heading asHeading(String text) {
return (Heading) PARSER.parse(text).getChildOfType(Heading.class);
return unchecked(FlexmarkIO.newTextParser()::parseChars)
.andThen(doc -> (Heading) doc.getChildOfType(Heading.class))
.apply(text);
}

public static String asText(Heading heading) {
Document doc = new Document(null, BasedSequence.NULL);
doc.appendChild(heading);
return FORMATTER.render(doc).trim();
return unchecked(FlexmarkIO.newTextFormatter()::formatToString)
.andThen(String::trim)
.apply(doc);
}

public static final Problem PROBLEM1 = Problem.builder().id("rule1").severity(ERROR).issue(RuleIssue.builder().message("boom").line(5).column(18).build()).build();
Expand Down Expand Up @@ -76,6 +68,6 @@ public static String writing(IOConsumer<? super Appendable> content) {
}

public static String contentOf(Class<?> anchor, String resourceName) {
return URLs.contentOf(Objects.requireNonNull(anchor.getResource(resourceName)), StandardCharsets.UTF_8);
return URLs.contentOf(Objects.requireNonNull(anchor.getResource(resourceName)), UTF_8);
}
}
2 changes: 1 addition & 1 deletion heylogs-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-parent</artifactId>
<version>0.9.1</version>
<version>0.9.2</version>
</parent>

<artifactId>heylogs-bom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion heylogs-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-parent</artifactId>
<version>0.9.1</version>
<version>0.9.2</version>
</parent>

<artifactId>heylogs-cli</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package internal.heylogs.cli;

import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Document;
import internal.heylogs.FlexmarkIO;
import lombok.AccessLevel;
import lombok.NonNull;
import nbbrd.console.picocli.CommandSupporter;
import nbbrd.console.picocli.text.TextInputSupport;
import nbbrd.design.StaticFactoryMethod;

import java.io.IOException;
import java.io.Reader;
import java.nio.file.DirectoryStream;
import java.nio.file.Path;
import java.util.Locale;
Expand All @@ -25,12 +24,8 @@ public class MarkdownInputSupport extends TextInputSupport implements DirectoryS
return CommandSupporter.create(MarkdownInputSupport::new, supporters);
}

private @NonNull Parser parser = Parser.builder().build();

public Document readDocument(Path file) throws IOException {
try (Reader reader = newBufferedReader(file)) {
return parser.parseReader(reader);
}
return FlexmarkIO.newTextParser().parseReader(() -> newBufferedReader(file));
}

public String getName(Path file) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package internal.heylogs.cli;

import com.vladsch.flexmark.formatter.Formatter;
import com.vladsch.flexmark.util.ast.Document;
import internal.heylogs.FlexmarkIO;
import lombok.AccessLevel;
import lombok.NonNull;
import nbbrd.console.picocli.CommandSupporter;
import nbbrd.console.picocli.text.TextOutputSupport;
import nbbrd.design.StaticFactoryMethod;

import java.io.IOException;
import java.io.Writer;
import java.nio.file.Path;

@lombok.Getter
Expand All @@ -23,11 +22,7 @@ public class MarkdownOutputSupport extends TextOutputSupport {
return CommandSupporter.create(MarkdownOutputSupport::new, supporters);
}

private @NonNull Formatter formatter = Formatter.builder().build();

public void writeDocument(Path file, Document document) throws IOException {
try (Writer writer = newBufferedWriter(file)) {
formatter.render(document, writer);
}
FlexmarkIO.newTextFormatter().formatWriter(document, () -> newBufferedWriter(file));
}
}
2 changes: 1 addition & 1 deletion heylogs-ext-github/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-parent</artifactId>
<version>0.9.1</version>
<version>0.9.2</version>
</parent>

<artifactId>heylogs-ext-github</artifactId>
Expand Down
Loading

0 comments on commit ce3500a

Please sign in to comment.