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.
3434import com .diffplug .spotless .FormatterStep ;
3535import com .diffplug .spotless .JarState ;
3636import com .diffplug .spotless .Provisioner ;
37- import com .diffplug .spotless .ThrowingEx ;
37+ import com .diffplug .spotless .SerializedFunction ;
3838
3939import dev .equo .solstice .NestedJars ;
4040import dev .equo .solstice .p2 .P2ClientCache ;
4848public abstract class EquoBasedStepBuilder {
4949 private final String formatterName ;
5050 private final Provisioner mavenProvisioner ;
51- private final ThrowingEx . Function <State , FormatterFunc > stateToFormatter ;
51+ private final SerializedFunction <State , FormatterFunc > stateToFormatter ;
5252 private String formatterVersion ;
5353 private Iterable <File > settingsFiles = new ArrayList <>();
5454 private Map <String , String > p2Mirrors = Map .of ();
5555
5656 /** @deprecated if you use this constructor you *must* call {@link #setVersion(String)} before calling {@link #build()} */
5757 @ Deprecated
58- public EquoBasedStepBuilder (String formatterName , Provisioner mavenProvisioner , ThrowingEx . Function <State , FormatterFunc > stateToFormatter ) {
58+ public EquoBasedStepBuilder (String formatterName , Provisioner mavenProvisioner , SerializedFunction <State , FormatterFunc > stateToFormatter ) {
5959 this (formatterName , mavenProvisioner , null , stateToFormatter );
6060 }
6161
6262 /** Initialize valid default configuration, taking latest version */
63- public EquoBasedStepBuilder (String formatterName , Provisioner mavenProvisioner , @ Nullable String defaultVersion , ThrowingEx . Function <State , FormatterFunc > stateToFormatter ) {
63+ public EquoBasedStepBuilder (String formatterName , Provisioner mavenProvisioner , @ Nullable String defaultVersion , SerializedFunction <State , FormatterFunc > stateToFormatter ) {
6464 this .formatterName = formatterName ;
6565 this .mavenProvisioner = mavenProvisioner ;
6666 this .formatterVersion = defaultVersion ;
@@ -83,11 +83,6 @@ public void setP2Mirrors(Collection<P2Mirror> p2Mirrors) {
8383 this .p2Mirrors = p2Mirrors .stream ().collect (toMap (P2Mirror ::getPrefix , P2Mirror ::getUrl ));
8484 }
8585
86- /** Returns the FormatterStep (whose state will be calculated lazily). */
87- public FormatterStep build () {
88- return FormatterStep .createLazy (formatterName , this ::get , stateToFormatter );
89- }
90-
9186 protected abstract P2Model model (String version );
9287
9388 protected void addPlatformRepo (P2Model model , String version ) {
@@ -107,26 +102,28 @@ protected void addPlatformRepo(P2Model model, String version) {
107102 }
108103 }
109104
110- /** Creates the state of the configuration. */
111- EquoBasedStepBuilder .State get () throws Exception {
112- P2QueryResult query ;
113- try {
114- query = createModelWithMirrors ().query (P2ClientCache .PREFER_OFFLINE , P2QueryCache .ALLOW );
115- } catch (Exception x ) {
116- throw new IOException ("Failed to load " + formatterName + ": " + x , x );
117- }
118- var classpath = new ArrayList <File >();
119- var mavenDeps = new ArrayList <String >();
120- mavenDeps .add ("dev.equo.ide:solstice:1.7.4" );
121- mavenDeps .add ("com.diffplug.durian:durian-swt.os:4.2.0" );
122- mavenDeps .addAll (query .getJarsOnMavenCentral ());
123- classpath .addAll (mavenProvisioner .provisionWithTransitives (false , mavenDeps ));
124- classpath .addAll (query .getJarsNotOnMavenCentral ());
125- for (var nested : NestedJars .inFiles (query .getJarsNotOnMavenCentral ()).extractAllNestedJars ()) {
126- classpath .add (nested .getValue ());
127- }
128- var jarState = JarState .preserveOrder (classpath );
129- return new State (formatterVersion , jarState , FileSignature .signAsList (settingsFiles ));
105+ /** Returns the FormatterStep (whose state will be calculated lazily). */
106+ public FormatterStep build () {
107+ var roundtrippableState = new EquoStep (formatterVersion , FileSignature .promise (settingsFiles ), JarState .promise (() -> {
108+ P2QueryResult query ;
109+ try {
110+ query = createModelWithMirrors ().query (P2ClientCache .PREFER_OFFLINE , P2QueryCache .ALLOW );
111+ } catch (Exception x ) {
112+ throw new IOException ("Failed to load " + formatterName + ": " + x , x );
113+ }
114+ var classpath = new ArrayList <File >();
115+ var mavenDeps = new ArrayList <String >();
116+ mavenDeps .add ("dev.equo.ide:solstice:1.7.5" );
117+ mavenDeps .add ("com.diffplug.durian:durian-swt.os:4.2.0" );
118+ mavenDeps .addAll (query .getJarsOnMavenCentral ());
119+ classpath .addAll (mavenProvisioner .provisionWithTransitives (false , mavenDeps ));
120+ classpath .addAll (query .getJarsNotOnMavenCentral ());
121+ for (var nested : NestedJars .inFiles (query .getJarsNotOnMavenCentral ()).extractAllNestedJars ()) {
122+ classpath .add (nested .getValue ());
123+ }
124+ return JarState .preserveOrder (classpath );
125+ }));
126+ return FormatterStep .create (formatterName , roundtrippableState , EquoStep ::state , stateToFormatter );
130127 }
131128
132129 private P2Model createModelWithMirrors () {
@@ -152,12 +149,29 @@ private P2Model createModelWithMirrors() {
152149 return model ;
153150 }
154151
152+ static class EquoStep implements Serializable {
153+ private static final long serialVersionUID = 1 ;
154+ private final String semanticVersion ;
155+ private final FileSignature .Promised settingsPromise ;
156+ private final JarState .Promised jarPromise ;
157+
158+ EquoStep (String semanticVersion , FileSignature .Promised settingsPromise , JarState .Promised jarPromise ) {
159+ this .semanticVersion = semanticVersion ;
160+ this .settingsPromise = settingsPromise ;
161+ this .jarPromise = jarPromise ;
162+ }
163+
164+ private State state () {
165+ return new State (semanticVersion , jarPromise .get (), settingsPromise .get ());
166+ }
167+ }
168+
155169 /**
156170 * State of Eclipse configuration items, providing functionality to derived information
157171 * based on the state.
158172 */
159173 public static class State implements Serializable {
160- private static final long serialVersionUID = 584400372246020995L ;
174+ private static final long serialVersionUID = 1 ;
161175 final String semanticVersion ;
162176 final JarState jarState ;
163177 final FileSignature settingsFiles ;
0 commit comments