Skip to content

Commit 5a05beb

Browse files
committed
Merge branch 'main' into serializable-refactor
2 parents 4e54fc2 + 6579264 commit 5a05beb

File tree

10 files changed

+55
-11
lines changed

10 files changed

+55
-11
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ 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+
### Added
14+
* New static method to `DiffMessageFormatter` which allows to retrieve diffs with their line numbers ([#1960](https://github.com/diffplug/spotless/issues/1960))
15+
### Changes
16+
* Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948))
1317

1418
## [2.43.1] - 2023-12-04
1519
### Fixed

lib-extra/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = rootProject.spotlessChangelog.versionNext
77
apply from: rootProject.file('gradle/java-setup.gradle')
88
apply from: rootProject.file('gradle/java-publish.gradle')
99

10-
String VER_SOLSTICE = '1.7.4'
10+
String VER_SOLSTICE = '1.7.5'
1111
dependencies {
1212
api projects.lib
1313
// misc useful utilities

lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import java.nio.file.Path;
2525
import java.util.List;
2626
import java.util.ListIterator;
27+
import java.util.Map;
2728
import java.util.Objects;
2829

2930
import org.eclipse.jgit.diff.DiffFormatter;
31+
import org.eclipse.jgit.diff.Edit;
3032
import org.eclipse.jgit.diff.EditList;
3133
import org.eclipse.jgit.diff.MyersDiff;
3234
import org.eclipse.jgit.diff.RawText;
@@ -234,6 +236,19 @@ private void addIntendedLine(String indent, String line) {
234236
* sequence (\n, \r, \r\n).
235237
*/
236238
private String diff(File file) throws IOException {
239+
return diff(formatter, file).getValue();
240+
}
241+
242+
/**
243+
* Returns a map entry with value being a git-style diff between the contents of the given file and what those contents would
244+
* look like if formatted using the given formatter. Does not end with any newline
245+
* sequence (\n, \r, \r\n). The key of the map entry is the 0-based line where the first difference occurred.
246+
*/
247+
public static Map.Entry<Integer, String> diff(Formatter formatter, File file) throws IOException {
248+
return diff(new CleanProviderFormatter(formatter), file);
249+
}
250+
251+
private static Map.Entry<Integer, String> diff(CleanProvider formatter, File file) throws IOException {
237252
String raw = new String(Files.readAllBytes(file.toPath()), formatter.getEncoding());
238253
String rawUnix = LineEnding.toUnix(raw);
239254
String formatted = formatter.getFormatted(file, rawUnix);
@@ -248,13 +263,13 @@ private String diff(File file) throws IOException {
248263
}
249264

250265
/**
251-
* Returns a git-style diff between the two unix strings.
266+
* Returns a map entry with value being a git-style diff between the two unix strings and key being the 0-based line of the first difference (in the dirty string)
252267
* <p>
253268
* Output has no trailing newlines.
254269
* <p>
255270
* Boolean args determine whether whitespace or line endings will be visible.
256271
*/
257-
private static String diffWhitespaceLineEndings(String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException {
272+
private static Map.Entry<Integer, String> diffWhitespaceLineEndings(String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException {
258273
dirty = visibleWhitespaceLineEndings(dirty, whitespace, lineEndings);
259274
clean = visibleWhitespaceLineEndings(clean, whitespace, lineEndings);
260275

@@ -271,7 +286,11 @@ private static String diffWhitespaceLineEndings(String dirty, String clean, bool
271286

272287
// we don't need the diff to show this, since we display newlines ourselves
273288
formatted = formatted.replace("\\ No newline at end of file\n", "");
274-
return NEWLINE_MATCHER.trimTrailingFrom(formatted);
289+
return Map.entry(getLineOfFirstDifference(edits), NEWLINE_MATCHER.trimTrailingFrom(formatted));
290+
}
291+
292+
private static int getLineOfFirstDifference(EditList edits) {
293+
return edits.stream().mapToInt(Edit::getBeginA).min().getAsInt();
275294
}
276295

277296
private static final CharMatcher NEWLINE_MATCHER = CharMatcher.is('\n');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private PalantirJavaFormatStep() {}
3030
private static final String DEFAULT_STYLE = "PALANTIR";
3131
private static final String NAME = "palantir-java-format";
3232
public static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:";
33-
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "1.1.0").add(11, "2.28.0").add(21, "2.38.0");
33+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "1.1.0").add(11, "2.28.0").add(21, "2.39.0");
3434

3535
/** Creates a step which formats everything - code, import order, and unused imports. */
3636
public static FormatterStep create(Provisioner provisioner) {

plugin-gradle/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Changes
7+
* Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948))
68

79
## [6.23.3] - 2023-12-04
810
**BREAKING CHANGE** `6.23.0` made breaking changes to the ABI of the `KotlinExtension` and `GroovyExtension`. Those are reflected retroactively now.

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ protected GradleRunner gradleRunner() throws IOException {
119119
return GradleRunner.create()
120120
.withGradleVersion(GradleVersionSupport.MINIMUM.version)
121121
.withProjectDir(rootFolder())
122+
.withTestKitDir(getTestKitDir())
122123
.withPluginClasspath();
123124
}
124125

@@ -221,4 +222,12 @@ static String buildResultToString(BuildResult result) {
221222
}
222223
});
223224
}
225+
226+
private static File getTestKitDir() {
227+
String gradleUserHome = System.getenv("GRADLE_USER_HOME");
228+
if (gradleUserHome == null || gradleUserHome.isEmpty()) {
229+
gradleUserHome = new File(System.getProperty("user.home"), ".gradle").getAbsolutePath();
230+
}
231+
return new File(gradleUserHome, "testkit");
232+
}
224233
}

plugin-maven/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
44

55
## [Unreleased]
6+
### Added
7+
* M2E support: Emit file specific errors during incremental build. ([#1960](https://github.com/diffplug/spotless/issues/1960))
8+
### Changes
9+
* Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948))
610

711
## [2.41.1] - 2023-12-04
812
### Fixed

plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessCheckMojo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
import java.io.IOException;
2020
import java.util.ArrayList;
2121
import java.util.List;
22+
import java.util.Map;
2223

2324
import org.apache.maven.plugin.MojoExecutionException;
2425
import org.apache.maven.plugins.annotations.LifecyclePhase;
2526
import org.apache.maven.plugins.annotations.Mojo;
27+
import org.sonatype.plexus.build.incremental.BuildContext;
2628

2729
import com.diffplug.spotless.Formatter;
2830
import com.diffplug.spotless.PaddedCell;
@@ -54,13 +56,17 @@ protected void process(Iterable<File> files, Formatter formatter, UpToDateChecke
5456
PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file);
5557
if (!dirtyState.isClean() && !dirtyState.didNotConverge()) {
5658
problemFiles.add(file);
59+
if (buildContext.isIncremental()) {
60+
Map.Entry<Integer, String> diffEntry = DiffMessageFormatter.diff(formatter, file);
61+
buildContext.addMessage(file, diffEntry.getKey() + 1, 0, diffEntry.getValue(), BuildContext.SEVERITY_ERROR, null);
62+
}
5763
counter.cleaned();
5864
} else {
5965
counter.checkedButAlreadyClean();
6066
upToDateChecker.setUpToDate(file.toPath());
6167
}
6268
} catch (IOException | RuntimeException e) {
63-
throw new MojoExecutionException("Unable to format file " + file, e);
69+
throw new MojoExecutionException("Unable to check file " + file, e);
6470
}
6571
}
6672

plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void specificVersionDefaultStyle() throws Exception {
3434
void specificJava11Version2() throws Exception {
3535
writePomWithJavaSteps(
3636
"<palantirJavaFormat>",
37-
" <version>2.38.0</version>",
37+
" <version>2.39.0</version>",
3838
"</palantirJavaFormat>");
3939

4040
runTest("java/palantirjavaformat/JavaCodeFormatted.test");

settings.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ pluginManagement {
66
}
77

88
plugins {
9-
id 'com.diffplug.spotless' version '6.22.0' apply false
9+
id 'com.diffplug.spotless' version '6.23.3' apply false
1010
// https://plugins.gradle.org/plugin/com.gradle.plugin-publish
1111
id 'com.gradle.plugin-publish' version '1.2.1' apply false
1212
// https://github.com/gradle-nexus/publish-plugin/releases
1313
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0-rc-1' apply false
1414
// https://github.com/spotbugs/spotbugs-gradle-plugin/releases
15-
id 'com.github.spotbugs' version '6.0.1' apply false
15+
id 'com.github.spotbugs' version '6.0.2' apply false
1616
// https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md
1717
id 'com.diffplug.spotless-changelog' version '3.0.2' apply false
1818
// https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md
1919
id 'com.adarshr.test-logger' version '4.0.0' apply false
2020
// https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags
2121
id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false
2222
// https://plugins.gradle.org/plugin/com.gradle.enterprise
23-
id 'com.gradle.enterprise' version '3.15.1'
23+
id 'com.gradle.enterprise' version '3.16'
2424
// https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md
25-
id 'dev.equo.ide' version '1.7.3' apply false
25+
id 'dev.equo.ide' version '1.7.5' apply false
2626
}
2727

2828
dependencyResolutionManagement {

0 commit comments

Comments
 (0)