Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Sep 21, 2022
2 parents f543614 + fbbcdf8 commit ddf57dd
Show file tree
Hide file tree
Showing 14 changed files with 369 additions and 136 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0] - 2022-09-21

### Added

- Add Maven Plugin [#5](https://github.com/nbbrd/heylogs/issues/5)

## [0.1.0] - 2022-09-08

### Added

- Initial release

[Unreleased]: https://github.com/nbbrd/heylogs/compare/v0.1.0...HEAD
[Unreleased]: https://github.com/nbbrd/heylogs/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/nbbrd/heylogs/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/nbbrd/heylogs/releases/tag/v0.1.0
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.1.0</version>
<version>0.2.0</version>
</parent>

<artifactId>heylogs-api</artifactId>
Expand Down
12 changes: 12 additions & 0 deletions heylogs-api/src/main/java/nbbrd/heylogs/Rule.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package nbbrd.heylogs;

import com.vladsch.flexmark.util.ast.Node;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public interface Rule {

String getName();

Failure validate(Node node);

@NotNull
static List<Rule> getDefault() {
return Stream.concat(Stream.of(GuidingPrinciples.values()), Stream.of(ExtendedRules.values()))
.map(Rule.class::cast)
.collect(Collectors.toList());
}
}
93 changes: 93 additions & 0 deletions heylogs-api/src/main/java/nbbrd/heylogs/VersionFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package nbbrd.heylogs;

import com.vladsch.flexmark.ast.Heading;
import com.vladsch.flexmark.ast.RefNode;
import com.vladsch.flexmark.ast.Reference;
import com.vladsch.flexmark.util.ast.Document;
import com.vladsch.flexmark.util.ast.Node;

import java.time.LocalDate;
import java.time.Year;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.List;

@lombok.Value
@lombok.Builder
public class VersionFilter {

@lombok.NonNull
@lombok.Builder.Default
String ref = "";

@lombok.NonNull
@lombok.Builder.Default
LocalDate from = LocalDate.MIN;

@lombok.NonNull
@lombok.Builder.Default
LocalDate to = LocalDate.MAX;

@lombok.Builder.Default
int limit = Integer.MAX_VALUE;

public boolean contains(Heading heading) {
return contains(Version.parse(heading));
}

public boolean contains(Version version) {
return version.getRef().contains(ref)
&& from.compareTo(version.getDate()) <= 0
&& (to.isAfter(version.getDate()) || (to.equals(LocalDate.MAX) && version.isUnreleased()));
}

public void apply(Document root) {
int found = 0;
boolean keep = false;

List<String> refNodes = new ArrayList<>();
List<Reference> references = new ArrayList<>();

for (Node current : root.getChildren()) {

if (current instanceof Heading && Version.isVersionLevel((Heading) current)) {
if (found >= getLimit() || !contains((Heading) current)) {
keep = false;
} else {
found++;
keep = true;
}
}

if (keep) {
Nodes.of(RefNode.class)
.descendants(current)
.map(node -> node.getReference().toString())
.forEach(refNodes::add);
} else {
if (current instanceof Reference) {
references.add((Reference) current);
} else {
current.unlink();
}
}
}

references
.stream()
.filter(reference -> !refNodes.contains(reference.getReference().toString()))
.forEach(Node::unlink);
}

public static LocalDate parseLocalDate(CharSequence input) {
try {
return Year.parse(input).atDay(1);
} catch (Exception ex1) {
try {
return YearMonth.parse(input).atDay(1);
} catch (Exception ex2) {
return LocalDate.parse(input);
}
}
}
}
53 changes: 11 additions & 42 deletions 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.1.0</version>
<version>0.2.0</version>
</parent>

<artifactId>heylogs-cli</artifactId>
Expand Down Expand Up @@ -84,7 +84,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -119,53 +119,22 @@
</configuration>
</plugin>

<!-- Check that CHANGELOG.md complies with the keep-a-changelog format -->
<!-- Extract the latest version from CHANGELOG.md -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<!-- Check that CHANGELOG.md complies with the keep-a-changelog format -->
<execution>
<id>check-changelog</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>${project.x.mainClass}</argument>
<argument>check</argument>
<argument>-i</argument>
<argument>${project.parent.basedir}/CHANGELOG.md</argument>
</arguments>
<useMavenLogger>true</useMavenLogger>
</configuration>
</execution>
<!-- Extract the latest version from CHANGELOG.md -->
<execution>
<id>extract-changelog</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
<goal>check</goal>
<goal>extract</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>${project.x.mainClass}</argument>
<argument>extract</argument>
<argument>-i</argument>
<argument>${project.parent.basedir}/CHANGELOG.md</argument>
<argument>-o</argument>
<argument>${project.build.directory}/CHANGELOG.md</argument>
<argument>--limit</argument>
<argument>1</argument>
</arguments>
<useMavenLogger>true</useMavenLogger>
<inputFile>${project.parent.basedir}/CHANGELOG.md</inputFile>
<limit>1</limit>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package internal.heylogs.cli;

import com.vladsch.flexmark.ast.Heading;
import nbbrd.heylogs.Version;
import nbbrd.heylogs.VersionFilter;
import picocli.CommandLine;

import java.time.LocalDate;
import java.time.Year;
import java.time.YearMonth;

@lombok.Getter
@lombok.Setter
public class VersionFilter {
public class VersionFilterOptions {

@CommandLine.Option(
names = {"--ref"},
Expand Down Expand Up @@ -41,29 +38,21 @@ public class VersionFilter {
)
private int limit = Integer.MAX_VALUE;

public boolean contains(Heading heading) {
return contains(Version.parse(heading));
}

public boolean contains(Version version) {
return version.getRef().contains(ref)
&& from.compareTo(version.getDate()) <= 0
&& (to.isAfter(version.getDate()) || (to.equals(LocalDate.MAX) && version.isUnreleased()));
public VersionFilter get() {
return VersionFilter
.builder()
.ref(ref)
.from(from)
.to(to)
.limit(limit)
.build();
}

private static final class CustomConverter implements CommandLine.ITypeConverter<LocalDate> {

@Override
public LocalDate convert(String value) throws Exception {
try {
return Year.parse(value).atDay(1);
} catch (Exception ex1) {
try {
return YearMonth.parse(value).atDay(1);
} catch (Exception ex2) {
return LocalDate.parse(value);
}
}
public LocalDate convert(String value) {
return VersionFilter.parseLocalDate(value);
}
}
}
14 changes: 1 addition & 13 deletions heylogs-cli/src/main/java/nbbrd/heylogs/cli/CheckCommand.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package nbbrd.heylogs.cli;

import internal.heylogs.cli.MarkdownInputOptions;
import nbbrd.heylogs.ExtendedRules;
import nbbrd.heylogs.Failure;
import nbbrd.heylogs.GuidingPrinciples;
import nbbrd.heylogs.Rule;
import org.jetbrains.annotations.NotNull;
import picocli.CommandLine;
import picocli.CommandLine.Command;

import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Command(name = "check")
public final class CheckCommand implements Callable<Integer> {
Expand All @@ -23,7 +18,7 @@ public final class CheckCommand implements Callable<Integer> {

@Override
public Integer call() throws Exception {
List<Rule> rules = getRules();
List<Rule> rules = Rule.getDefault();

List<Failure> failures = Failure.allOf(input.read(), rules);

Expand All @@ -32,13 +27,6 @@ public Integer call() throws Exception {
return failures.isEmpty() ? CommandLine.ExitCode.OK : CommandLine.ExitCode.USAGE;
}

@NotNull
private static List<Rule> getRules() {
return Stream.concat(Stream.of(GuidingPrinciples.values()), Stream.of(ExtendedRules.values()))
.map(Rule.class::cast)
.collect(Collectors.toList());
}

// https://eslint.org/docs/latest/user-guide/formatters/#stylish
private static void printStylish(Path inputFile, List<Failure> failures) {
if (inputFile != null) {
Expand Down
Loading

0 comments on commit ddf57dd

Please sign in to comment.