|
1 | 1 | /*
|
2 |
| - * Copyright 2021-2023 DiffPlug |
| 2 | + * Copyright 2021-2024 DiffPlug |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
15 | 15 | */
|
16 | 16 | package com.diffplug.spotless.pom;
|
17 | 17 |
|
18 |
| -import java.io.IOException; |
19 | 18 | import java.io.Serializable;
|
20 | 19 | import java.lang.reflect.Constructor;
|
21 | 20 | import java.lang.reflect.InvocationTargetException;
|
|
24 | 23 | import com.diffplug.spotless.FormatterStep;
|
25 | 24 | import com.diffplug.spotless.JarState;
|
26 | 25 | import com.diffplug.spotless.Provisioner;
|
| 26 | +import com.diffplug.spotless.RoundedStep; |
27 | 27 |
|
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:"; |
29 | 31 | public static final String NAME = "sortPom";
|
30 |
| - static final String PACKAGE = "com.github.ekryd.sortpom"; |
31 |
| - static final String MAVEN_COORDINATE = PACKAGE + ":sortpom-sorter:"; |
32 | 32 |
|
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 | + } |
34 | 40 |
|
35 | 41 | 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); |
37 | 50 | }
|
38 | 51 |
|
39 |
| - static class State implements Serializable { |
| 52 | + private static class State implements Serializable { |
40 | 53 | private static final long serialVersionUID = 1;
|
41 | 54 |
|
42 |
| - SortPomCfg cfg; |
43 |
| - JarState jarState; |
| 55 | + private final SortPomCfg cfg; |
| 56 | + private final JarState jarState; |
44 | 57 |
|
45 |
| - public State(SortPomCfg cfg, Provisioner provisioner) throws IOException { |
| 58 | + State(JarState jarState, SortPomCfg cfg) { |
| 59 | + this.jarState = jarState; |
46 | 60 | this.cfg = cfg;
|
47 |
| - this.jarState = JarState.from(MAVEN_COORDINATE + cfg.version, provisioner); |
48 | 61 | }
|
49 | 62 |
|
50 | 63 | FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
|
0 commit comments