Skip to content

Commit 1d515e7

Browse files
authored
Merge branch 'main' into 1984-npm-install-cache-and-clean
2 parents dda3a8e + 231e215 commit 1d515e7

File tree

19 files changed

+103
-35
lines changed

19 files changed

+103
-35
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1919
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
2020
* Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057))
2121
* Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078))
22-
* Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096))
22+
* Bump default `sortpom` version to latest `3.4.1` -> `4.0.0` and support versions back to `3.2.1`. ([#2115](https://github.com/diffplug/spotless/pull/2115))
2323
### Removed
2424
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))
2525
* **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954))
2626
### Fixed
2727
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
2828
* Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052))
29+
* Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096))
2930

3031
## [2.45.0] - 2024-01-23
3132
### Added

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ dependencies {
128128
// scalafmt
129129
scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:3.7.3"
130130
// sortPom
131-
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.4.1'
131+
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:4.0.0'
132132
sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.12'
133133
// zjsonPatch
134134
zjsonPatchCompileOnly 'com.flipkart.zjsonpatch:zjsonpatch:0.4.14'

lib/src/main/java/com/diffplug/spotless/DelegateFormatterStep.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 DiffPlug
2+
* Copyright 2022-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.
@@ -29,4 +29,9 @@ abstract class DelegateFormatterStep implements FormatterStep {
2929
public final String getName() {
3030
return delegateStep.getName();
3131
}
32+
33+
@Override
34+
public void close() throws Exception {
35+
delegateStep.close();
36+
}
3237
}

lib/src/main/java/com/diffplug/spotless/Formatter.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535

3636
import javax.annotation.Nullable;
3737

38-
import com.diffplug.spotless.generic.FenceStep;
39-
4038
/** Formatter which performs the full formatting. */
4139
public final class Formatter implements Serializable, AutoCloseable {
4240
private static final long serialVersionUID = 1L;
@@ -304,15 +302,10 @@ public boolean equals(Object obj) {
304302
@Override
305303
public void close() {
306304
for (FormatterStep step : steps) {
307-
if (step instanceof DelegateFormatterStep) {
308-
step = ((DelegateFormatterStep) step).delegateStep;
309-
}
310-
if (step instanceof FormatterStepImpl.Standard) {
311-
((FormatterStepImpl.Standard) step).cleanupFormatterFunc();
312-
} else if (step instanceof FormatterStepEqualityOnStateSerialization) {
313-
((FormatterStepEqualityOnStateSerialization) step).cleanupFormatterFunc();
314-
} else if (step instanceof FenceStep.BaseStep) {
315-
((FenceStep.BaseStep) step).cleanup();
305+
try {
306+
step.close();
307+
} catch (Exception e) {
308+
throw ThrowingEx.asRuntime(e);
316309
}
317310
}
318311
}

lib/src/main/java/com/diffplug/spotless/FormatterStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* The input is guaranteed to have unix-style newlines, and the output is required
2828
* to not introduce any windows-style newlines as well.
2929
*/
30-
public interface FormatterStep extends Serializable {
30+
public interface FormatterStep extends Serializable, AutoCloseable {
3131
/** The name of the step, for debugging purposes. */
3232
String getName();
3333

lib/src/main/java/com/diffplug/spotless/FormatterStepEqualityOnStateSerialization.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public int hashCode() {
6464
return Arrays.hashCode(serializedState());
6565
}
6666

67-
void cleanupFormatterFunc() {
67+
@Override
68+
public void close() {
6869
if (formatter instanceof FormatterFunc.Closeable) {
6970
((FormatterFunc.Closeable) formatter).close();
7071
formatter = null;

lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java

Lines changed: 11 additions & 2 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.
@@ -82,7 +82,8 @@ protected String format(State state, String rawUnix, File file) throws Exception
8282
return formatter.apply(rawUnix, file);
8383
}
8484

85-
void cleanupFormatterFunc() {
85+
@Override
86+
public void close() throws Exception {
8687
if (formatter instanceof FormatterFunc.Closeable) {
8788
((FormatterFunc.Closeable) formatter).close();
8889
formatter = null;
@@ -114,6 +115,14 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti
114115
}
115116
return formatter.apply(rawUnix, file);
116117
}
118+
119+
@Override
120+
public void close() throws Exception {
121+
if (formatter instanceof FormatterFunc.Closeable) {
122+
((FormatterFunc.Closeable) formatter).close();
123+
formatter = null;
124+
}
125+
}
117126
}
118127

119128
static void checkNotSentinel(File file) {

lib/src/main/java/com/diffplug/spotless/generic/FenceStep.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ public int hashCode() {
247247
return Objects.hash(name, regex.pattern(), regex.flags(), steps);
248248
}
249249

250-
public void cleanup() {
250+
@Override
251+
public void close() {
251252
if (formatter != null) {
252253
formatter.close();
253254
formatter = null;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
public class SortPomCfg implements Serializable {
2222
private static final long serialVersionUID = 1L;
2323

24-
public String version = "3.4.1";
24+
public String version = "4.0.0";
2525

2626
public String encoding = "UTF-8";
2727

@@ -41,6 +41,8 @@ public class SortPomCfg implements Serializable {
4141

4242
public boolean indentSchemaLocation = false;
4343

44+
public String indentAttribute = null;
45+
4446
public String predefinedSortOrder = "recommended_2008_06";
4547

4648
public String sortOrderFile = null;

lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.diffplug.spotless.glue.pom;
1717

1818
import java.io.*;
19+
import java.lang.reflect.Method;
1920
import java.nio.charset.Charset;
2021
import java.nio.file.Files;
2122

@@ -46,17 +47,45 @@ public String apply(String input) throws Exception {
4647
writer.write(input);
4748
}
4849
SortPomImpl sortPom = new SortPomImpl();
49-
sortPom.setup(new MySortPomLogger(), PluginParameters.builder()
50+
PluginParameters.Builder builder = PluginParameters.builder()
5051
.setPomFile(pom)
5152
.setFileOutput(false, null, null, false)
52-
.setEncoding(cfg.encoding)
53-
.setFormatting(cfg.lineSeparator, cfg.expandEmptyElements, cfg.spaceBeforeCloseEmptyElement, cfg.keepBlankLines, cfg.endWithNewline)
54-
.setIndent(cfg.nrOfIndentSpace, cfg.indentBlankLines, cfg.indentSchemaLocation)
53+
.setEncoding(cfg.encoding);
54+
try {
55+
builder = builder
56+
.setFormatting(cfg.lineSeparator, cfg.expandEmptyElements, cfg.spaceBeforeCloseEmptyElement,
57+
cfg.keepBlankLines, cfg.endWithNewline);
58+
} catch (NoSuchMethodError e) {
59+
try {
60+
Method method = PluginParameters.Builder.class
61+
.getMethod("setFormatting", String.class, boolean.class, boolean.class, boolean.class);
62+
builder = (PluginParameters.Builder) method
63+
.invoke(builder, cfg.lineSeparator, cfg.expandEmptyElements, cfg.spaceBeforeCloseEmptyElement,
64+
cfg.keepBlankLines);
65+
} catch (ReflectiveOperationException | RuntimeException ignore) {
66+
throw e;
67+
}
68+
}
69+
try {
70+
builder = builder
71+
.setIndent(cfg.nrOfIndentSpace, cfg.indentBlankLines, cfg.indentSchemaLocation,
72+
cfg.indentAttribute);
73+
} catch (NoSuchMethodError e) {
74+
try {
75+
Method method = PluginParameters.Builder.class
76+
.getMethod("setIndent", int.class, boolean.class, boolean.class);
77+
builder = (PluginParameters.Builder) method
78+
.invoke(builder, cfg.nrOfIndentSpace, cfg.indentBlankLines, cfg.indentSchemaLocation);
79+
} catch (ReflectiveOperationException | RuntimeException ignore) {
80+
throw e;
81+
}
82+
}
83+
builder = builder
5584
.setSortOrder(cfg.sortOrderFile, cfg.predefinedSortOrder)
5685
.setSortEntities(cfg.sortDependencies, cfg.sortDependencyExclusions, cfg.sortDependencyManagement,
5786
cfg.sortPlugins, cfg.sortProperties, cfg.sortModules, cfg.sortExecutions)
58-
.setIgnoreLineSeparators(false)
59-
.build());
87+
.setIgnoreLineSeparators(false);
88+
sortPom.setup(new MySortPomLogger(), builder.build());
6089
sortPom.sortPom();
6190
return Files.readString(pom.toPath(), Charset.forName(cfg.encoding));
6291
}

0 commit comments

Comments
 (0)