Skip to content

Commit 608e128

Browse files
committed
Merge branch 'main' into feat/foreign
2 parents e106d38 + 6f1177f commit 608e128

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

plugin-gradle/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
77
- It is now much easier for Spotless to [integrate formatters with native executables](../../CONTRIBUTING.md#integrating-outside-the-jvm).
88
- Added support for [python](../#python), specifically [black](../#black).
99
- Added support for [clang-format](../#clang-format) for all formats.
10+
### Fixed
11+
* If you executed `gradlew spotlessCheck` multiple times within a single second (hard in practice, easy for a unit test) you could sometimes get an erroneous failure message. Fixed in [#671](https://github.com/diffplug/spotless/pull/671).
1012

1113
## [5.1.2] - 2020-08-21
1214
### Fixed

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
*/
1616
package com.diffplug.gradle.spotless;
1717

18+
import java.io.ByteArrayOutputStream;
1819
import java.io.File;
20+
import java.io.IOException;
21+
import java.nio.file.Files;
1922
import java.util.ArrayList;
23+
import java.util.Arrays;
2024
import java.util.Collections;
2125
import java.util.List;
2226

@@ -32,6 +36,7 @@
3236

3337
import com.diffplug.spotless.FileSignature;
3438
import com.diffplug.spotless.Formatter;
39+
import com.diffplug.spotless.ThrowingEx;
3540
import com.diffplug.spotless.extra.integration.DiffMessageFormatter;
3641

3742
public class SpotlessCheck extends DefaultTask {
@@ -76,10 +81,33 @@ public void visitDir(FileVisitDetails fileVisitDetails) {
7681
public void visitFile(FileVisitDetails fileVisitDetails) {
7782
String path = fileVisitDetails.getPath();
7883
File originalSource = new File(getProject().getProjectDir(), path);
79-
problemFiles.add(originalSource);
84+
try {
85+
// read the file on disk
86+
byte[] userFile = Files.readAllBytes(originalSource.toPath());
87+
// and the formatted version from spotlessOutDirectory
88+
byte[] formatted;
89+
{
90+
ByteArrayOutputStream clean = new ByteArrayOutputStream();
91+
fileVisitDetails.copyTo(clean);
92+
formatted = clean.toByteArray();
93+
}
94+
// If these two are equal, it means that SpotlessTask left a file
95+
// in its output directory which ought to have been removed. As
96+
// best I can tell, this is a filesytem race which is very hard
97+
// to trigger. GitRatchetGradleTest can *sometimes* reproduce it
98+
// but it's very erratic, and that test writes both to gradle cache
99+
// and git cache very quickly. Either of gradle or jgit might be
100+
// caching something wrong because of the fast repeated writes.
101+
if (!Arrays.equals(userFile, formatted)) {
102+
// If the on-disk content is equal to the formatted content,
103+
// just don't add it as a problem file. Easy!
104+
problemFiles.add(originalSource);
105+
}
106+
} catch (IOException e) {
107+
throw ThrowingEx.asRuntime(e);
108+
}
80109
}
81110
});
82-
83111
if (!problemFiles.isEmpty()) {
84112
try (Formatter formatter = source.buildFormatter()) {
85113
Collections.sort(problemFiles);

testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.diffplug.spotless.kotlin;
1717

18+
import org.junit.Ignore;
1819
import org.junit.Test;
1920

2021
import com.diffplug.spotless.FormatterStep;
@@ -28,6 +29,7 @@
2829
* causes these problems. The root is still a gradle bug, but in the meantime we don't
2930
* need to hold up *every* PR with this: https://github.com/gradle/gradle/issues/11752
3031
*/
32+
@Ignore
3133
public class KtLintStepTest extends ResourceHarness {
3234
@Test
3335
public void behavior() throws Exception {

0 commit comments

Comments
 (0)