Skip to content

Commit 43d57dc

Browse files
committed
Make SortPomStep round-trippable
1 parent d25658c commit 43d57dc

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 DiffPlug
2+
* Copyright 2021-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.
@@ -15,7 +15,6 @@
1515
*/
1616
package com.diffplug.spotless.pom;
1717

18-
import java.io.IOException;
1918
import java.io.Serializable;
2019
import java.lang.reflect.Constructor;
2120
import java.lang.reflect.InvocationTargetException;
@@ -24,27 +23,41 @@
2423
import com.diffplug.spotless.FormatterStep;
2524
import com.diffplug.spotless.JarState;
2625
import com.diffplug.spotless.Provisioner;
26+
import com.diffplug.spotless.RoundedStep;
2727

28-
public class SortPomStep {
28+
public class SortPomStep implements RoundedStep {
29+
private static final long serialVersionUID = 1L;
30+
private static final String MAVEN_COORDINATE = "com.github.ekryd.sortpom:sortpom-sorter:";
2931
public static final String NAME = "sortPom";
30-
static final String PACKAGE = "com.github.ekryd.sortpom";
31-
static final String MAVEN_COORDINATE = PACKAGE + ":sortpom-sorter:";
3232

33-
private SortPomStep() {}
33+
private final JarState.Promised jarState;
34+
private final SortPomCfg cfg;
35+
36+
private SortPomStep(JarState.Promised jarState, SortPomCfg cfg) {
37+
this.jarState = jarState;
38+
this.cfg = cfg;
39+
}
3440

3541
public static FormatterStep create(SortPomCfg cfg, Provisioner provisioner) {
36-
return FormatterStep.createLazy(NAME, () -> new State(cfg, provisioner), State::createFormat);
42+
return FormatterStep.create(NAME,
43+
new SortPomStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + cfg.version, provisioner)), cfg),
44+
SortPomStep::equalityState,
45+
State::createFormat);
46+
}
47+
48+
private State equalityState() {
49+
return new State(jarState.get(), cfg);
3750
}
3851

39-
static class State implements Serializable {
52+
private static class State implements Serializable {
4053
private static final long serialVersionUID = 1;
4154

42-
SortPomCfg cfg;
43-
JarState jarState;
55+
private final SortPomCfg cfg;
56+
private final JarState jarState;
4457

45-
public State(SortPomCfg cfg, Provisioner provisioner) throws IOException {
58+
State(JarState jarState, SortPomCfg cfg) {
59+
this.jarState = jarState;
4660
this.cfg = cfg;
47-
this.jarState = JarState.from(MAVEN_COORDINATE + cfg.version, provisioner);
4861
}
4962

5063
FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected StepHarnessBase(Formatter formatter) {
5151
supportsRoundTrip = true;
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",
54-
"gson", "jacksonJson", "apply-json-patch", "jsonSimple",
54+
"gson", "jacksonJson", "apply-json-patch", "jsonSimple", "sortPom",
5555
"importOrder", "Remove unnecessary semicolons").contains(onlyStepName)) {
5656
supportsRoundTrip = true;
5757
}

0 commit comments

Comments
 (0)