Skip to content

Commit c45e1f2

Browse files
committed
Merge branch 'main' into renovate/gradle-8.x
2 parents deba340 + 88e3736 commit c45e1f2

File tree

25 files changed

+456
-67
lines changed

25 files changed

+456
-67
lines changed

.github/workflows/changelog-print.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
name: changelogPrint
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- name: jdk 11
1414
uses: actions/setup-java@v3
1515
with:

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
buildcachepass: ${{ secrets.BUILDCACHE_PASS }}
2121
steps:
2222
- name: Checkout
23-
uses: actions/checkout@v3
23+
uses: actions/checkout@v4
2424
with:
2525
fetch-depth: 0
2626
- name: Install JDK 11
@@ -59,7 +59,7 @@ jobs:
5959
runs-on: ${{ matrix.os }}
6060
steps:
6161
- name: Checkout
62-
uses: actions/checkout@v3
62+
uses: actions/checkout@v4
6363
- name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }}
6464
uses: actions/setup-java@v3
6565
with:

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
steps:
3939
- name: Checkout repository
40-
uses: actions/checkout@v3
40+
uses: actions/checkout@v4
4141
with:
4242
# We must fetch at least the immediate parents so that if this is
4343
# a pull request then we can checkout the head.

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
3737
ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }}
3838
steps:
39-
- uses: actions/checkout@v3
39+
- uses: actions/checkout@v4
4040
- name: jdk 11
4141
uses: actions/setup-java@v3
4242
with:

.github/workflows/gradle-wrapper-validation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ jobs:
1919
name: "Validation"
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2323
- uses: gradle/wrapper-validation-action@v1

CHANGES.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ This document is intended for Spotless developers.
1010
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
1111

1212
## [Unreleased]
13+
14+
## [2.42.0] - 2023-09-28
1315
### Added
14-
* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
16+
* Support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
1517
The configuration is still the same, but you should switch to the new `biome` tag / function and adjust
1618
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).
17-
* Add support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793))
19+
* Support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793))
20+
* Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)).
21+
* New line endings mode `GIT_ATTRIBUTES_FAST_ALLSAME`. ([#1838](https://github.com/diffplug/spotless/pull/1838))
1822
### Fixed
1923
* Fix support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
24+
* Fix configuration cache issue around `external process started '/usr/bin/git --version'`. ([#1806](https://github.com/diffplug/spotless/issues/1806))
2025
### Changes
2126
* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801))
2227
* Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808))

lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
*/
1616
package com.diffplug.spotless.extra;
1717

18+
import static java.util.stream.Collectors.toMap;
19+
1820
import java.io.File;
1921
import java.io.IOException;
2022
import java.io.Serializable;
2123
import java.util.ArrayList;
24+
import java.util.Collection;
2225
import java.util.List;
2326
import java.util.Map;
2427
import java.util.Properties;
@@ -76,6 +79,10 @@ public void setP2Mirrors(Map<String, String> p2Mirrors) {
7679
this.p2Mirrors = Map.copyOf(p2Mirrors);
7780
}
7881

82+
public void setP2Mirrors(Collection<P2Mirror> p2Mirrors) {
83+
this.p2Mirrors = p2Mirrors.stream().collect(toMap(P2Mirror::getPrefix, P2Mirror::getUrl));
84+
}
85+
7986
/** Returns the FormatterStep (whose state will be calculated lazily). */
8087
public FormatterStep build() {
8188
return FormatterStep.createLazy(formatterName, this::get, stateToFormatter);
@@ -110,7 +117,7 @@ EquoBasedStepBuilder.State get() throws Exception {
110117
}
111118
var classpath = new ArrayList<File>();
112119
var mavenDeps = new ArrayList<String>();
113-
mavenDeps.add("dev.equo.ide:solstice:1.3.1");
120+
mavenDeps.add("dev.equo.ide:solstice:1.7.3");
114121
mavenDeps.add("com.diffplug.durian:durian-swt.os:4.2.0");
115122
mavenDeps.addAll(query.getJarsOnMavenCentral());
116123
classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps));

lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,42 @@ public final class GitAttributesLineEndings {
6868
// prevent direct instantiation
6969
private GitAttributesLineEndings() {}
7070

71+
/**
72+
* Creates a line-endings policy which matches {@link #create(File, Supplier)},
73+
* which is much faster at the cost that every file under the policy
74+
* is assumed to have the same line endings as the first file.
75+
*/
76+
public static LineEnding.Policy createFastAllSame(File projectDir, Supplier<Iterable<File>> toFormat) {
77+
return new LazyAllTheSame(projectDir, toFormat);
78+
}
79+
80+
static class LazyAllTheSame extends LazyForwardingEquality<String> implements LineEnding.Policy {
81+
private static final long serialVersionUID = 727912266173243664L;
82+
transient File projectDir;
83+
transient Supplier<Iterable<File>> toFormat;
84+
85+
public LazyAllTheSame(File projectDir, Supplier<Iterable<File>> toFormat) {
86+
this.projectDir = projectDir;
87+
this.toFormat = toFormat;
88+
}
89+
90+
@Override
91+
protected String calculateState() throws Exception {
92+
var files = toFormat.get().iterator();
93+
if (files.hasNext()) {
94+
Runtime runtime = new RuntimeInit(projectDir).atRuntime();
95+
return runtime.getEndingFor(files.next());
96+
} else {
97+
return LineEnding.UNIX.str();
98+
}
99+
}
100+
101+
@Override
102+
public String getEndingFor(File file) {
103+
return state();
104+
}
105+
}
106+
71107
/**
72108
* Creates a line-endings policy whose serialized state is relativized against projectDir,
73109
* at the cost of eagerly evaluating the line-ending state of every target file when the
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.extra;
17+
18+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19+
20+
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
21+
public class P2Mirror {
22+
23+
private String prefix;
24+
private String url;
25+
26+
public String getPrefix() {
27+
return prefix;
28+
}
29+
30+
public String getUrl() {
31+
return url;
32+
}
33+
}

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 DiffPlug
2+
* Copyright 2016-2023 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.
@@ -19,11 +19,8 @@
1919
import java.io.Serializable;
2020
import java.lang.reflect.Method;
2121
import java.util.Objects;
22-
import java.util.function.BiFunction;
2322
import java.util.function.Supplier;
2423

25-
import javax.annotation.Nullable;
26-
2724
/**
2825
* Represents the line endings which should be written by the tool.
2926
*/
@@ -37,6 +34,14 @@ public Policy createPolicy() {
3734
return super.createPolicy();
3835
}
3936
},
37+
/** Uses the same line endings as Git, and assumes that every single file being formatted will have the same line ending. */
38+
GIT_ATTRIBUTES_FAST_ALLSAME {
39+
/** .gitattributes is path-specific, so you must use {@link LineEnding#createPolicy(File, Supplier)}. */
40+
@Override @Deprecated
41+
public Policy createPolicy() {
42+
return super.createPolicy();
43+
}
44+
},
4045
/** {@code \n} on unix systems, {@code \r\n} on windows systems. */
4146
PLATFORM_NATIVE,
4247
/** {@code \r\n} */
@@ -51,33 +56,31 @@ public Policy createPolicy() {
5156
public Policy createPolicy(File projectDir, Supplier<Iterable<File>> toFormat) {
5257
Objects.requireNonNull(projectDir, "projectDir");
5358
Objects.requireNonNull(toFormat, "toFormat");
54-
if (this != GIT_ATTRIBUTES) {
55-
return createPolicy();
59+
String gitAttributesMethod;
60+
if (this == GIT_ATTRIBUTES) {
61+
gitAttributesMethod = "create";
62+
} else if (this == GIT_ATTRIBUTES_FAST_ALLSAME) {
63+
gitAttributesMethod = "createFastAllSame";
5664
} else {
57-
if (gitAttributesPolicyCreator == null) {
58-
try {
59-
Class<?> clazz = Class.forName("com.diffplug.spotless.extra.GitAttributesLineEndings");
60-
Method method = clazz.getMethod("create", File.class, Supplier.class);
61-
gitAttributesPolicyCreator = (proj, target) -> ThrowingEx.get(() -> (Policy) method.invoke(null, proj, target));
62-
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) {
63-
throw new IllegalStateException("LineEnding.GIT_ATTRIBUTES requires the spotless-lib-extra library, but it is not on the classpath", e);
64-
}
65-
}
66-
// gitAttributesPolicyCreator will always be nonnull at this point
67-
return gitAttributesPolicyCreator.apply(projectDir, toFormat);
65+
return createPolicy();
66+
}
67+
try {
68+
Class<?> clazz = Class.forName("com.diffplug.spotless.extra.GitAttributesLineEndings");
69+
Method method = clazz.getMethod(gitAttributesMethod, File.class, Supplier.class);
70+
return ThrowingEx.get(() -> (Policy) method.invoke(null, projectDir, toFormat));
71+
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) {
72+
throw new IllegalStateException("LineEnding.GIT_ATTRIBUTES requires the spotless-lib-extra library, but it is not on the classpath", e);
6873
}
6974
}
7075

71-
private static volatile @Nullable BiFunction<File, Supplier<Iterable<File>>, Policy> gitAttributesPolicyCreator;
72-
7376
// @formatter:off
7477
/** Should use {@link #createPolicy(File, Supplier)} instead, but this will work iff its a path-independent LineEnding policy. */
7578
public Policy createPolicy() {
7679
switch (this) {
7780
case PLATFORM_NATIVE: return _platformNativePolicy;
7881
case WINDOWS: return WINDOWS_POLICY;
7982
case UNIX: return UNIX_POLICY;
80-
case MAC_CLASSIC: return MAC_CLASSIC_POLICY;
83+
case MAC_CLASSIC: return MAC_CLASSIC_POLICY;
8184
default: throw new UnsupportedOperationException(this + " is a path-specific line ending.");
8285
}
8386
}
@@ -121,7 +124,7 @@ public String str() {
121124
case PLATFORM_NATIVE: return _platformNative;
122125
case WINDOWS: return "\r\n";
123126
case UNIX: return "\n";
124-
case MAC_CLASSIC: return "\r";
127+
case MAC_CLASSIC: return "\r";
125128
default: throw new UnsupportedOperationException(this + " is a path-specific line ending.");
126129
}
127130
}

0 commit comments

Comments
 (0)