Skip to content

Commit efc15b4

Browse files
committed
Make FlexmarkStep round-trippable
1 parent fb4b0ff commit efc15b4

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,15 +23,20 @@
2323
import com.diffplug.spotless.FormatterStep;
2424
import com.diffplug.spotless.JarState;
2525
import com.diffplug.spotless.Provisioner;
26+
import com.diffplug.spotless.RoundedStep;
2627

2728
/** A step for <a href="https://github.com/vsch/flexmark-java">flexmark-java</a>. */
28-
public class FlexmarkStep {
29-
// prevent direct instantiation
30-
private FlexmarkStep() {}
31-
29+
public class FlexmarkStep implements RoundedStep {
30+
private static final long serialVersionUID = 1L;
3231
private static final String DEFAULT_VERSION = "0.64.8";
33-
private static final String NAME = "flexmark-java";
3432
private static final String MAVEN_COORDINATE = "com.vladsch.flexmark:flexmark-all:";
33+
public static final String NAME = "flexmark-java";
34+
35+
private final JarState.Promised jarState;
36+
37+
private FlexmarkStep(JarState.Promised jarState) {
38+
this.jarState = jarState;
39+
}
3540

3641
/** Creates a formatter step for the default version. */
3742
public static FormatterStep create(Provisioner provisioner) {
@@ -42,20 +47,24 @@ public static FormatterStep create(Provisioner provisioner) {
4247
public static FormatterStep create(String version, Provisioner provisioner) {
4348
Objects.requireNonNull(version, "version");
4449
Objects.requireNonNull(provisioner, "provisioner");
45-
return FormatterStep.createLazy(NAME,
46-
() -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner)),
50+
return FormatterStep.create(NAME,
51+
new FlexmarkStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + version, provisioner))),
52+
FlexmarkStep::equalityState,
4753
State::createFormat);
4854
}
4955

5056
public static String defaultVersion() {
5157
return DEFAULT_VERSION;
5258
}
5359

60+
private State equalityState() {
61+
return new State(jarState.get());
62+
}
63+
5464
private static class State implements Serializable {
5565
private static final long serialVersionUID = 1L;
5666

57-
/** The jar that contains the formatter. */
58-
final JarState jarState;
67+
private final JarState jarState;
5968

6069
State(JarState jarState) {
6170
this.jarState = jarState;
@@ -67,6 +76,5 @@ FormatterFunc createFormat() throws Exception {
6776
final Constructor<?> constructor = formatterFunc.getConstructor();
6877
return (FormatterFunc) constructor.newInstance();
6978
}
70-
7179
}
7280
}

testlib/src/main/java/com/diffplug/spotless/StepHarnessBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected StepHarnessBase(Formatter formatter) {
5252
} else if (Set.of("black", "buf", "clang", "ktlint", "ktfmt", "scalafmt", "palantir-java-format", "google-java-format",
5353
"removeUnusedImports", "cleanthat", "No line break between type annotation and type", "antlr4Formatter",
5454
"gson", "jacksonJson", "apply-json-patch", "jsonSimple", "sortPom", "jacksonYaml", "gherkinUtils",
55+
"flexmark-java",
5556
"importOrder", "Remove unnecessary semicolons").contains(onlyStepName)) {
5657
supportsRoundTrip = true;
5758
}

0 commit comments

Comments
 (0)