Skip to content

Commit

Permalink
Merge branch 'main' into feat/foreign
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Aug 25, 2020
2 parents e106d38 + 6f1177f commit 608e128
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
- It is now much easier for Spotless to [integrate formatters with native executables](../../CONTRIBUTING.md#integrating-outside-the-jvm).
- Added support for [python](../#python), specifically [black](../#black).
- Added support for [clang-format](../#clang-format) for all formats.
### Fixed
* 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).

## [5.1.2] - 2020-08-21
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/
package com.diffplug.gradle.spotless;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand All @@ -32,6 +36,7 @@

import com.diffplug.spotless.FileSignature;
import com.diffplug.spotless.Formatter;
import com.diffplug.spotless.ThrowingEx;
import com.diffplug.spotless.extra.integration.DiffMessageFormatter;

public class SpotlessCheck extends DefaultTask {
Expand Down Expand Up @@ -76,10 +81,33 @@ public void visitDir(FileVisitDetails fileVisitDetails) {
public void visitFile(FileVisitDetails fileVisitDetails) {
String path = fileVisitDetails.getPath();
File originalSource = new File(getProject().getProjectDir(), path);
problemFiles.add(originalSource);
try {
// read the file on disk
byte[] userFile = Files.readAllBytes(originalSource.toPath());
// and the formatted version from spotlessOutDirectory
byte[] formatted;
{
ByteArrayOutputStream clean = new ByteArrayOutputStream();
fileVisitDetails.copyTo(clean);
formatted = clean.toByteArray();
}
// If these two are equal, it means that SpotlessTask left a file
// in its output directory which ought to have been removed. As
// best I can tell, this is a filesytem race which is very hard
// to trigger. GitRatchetGradleTest can *sometimes* reproduce it
// but it's very erratic, and that test writes both to gradle cache
// and git cache very quickly. Either of gradle or jgit might be
// caching something wrong because of the fast repeated writes.
if (!Arrays.equals(userFile, formatted)) {
// If the on-disk content is equal to the formatted content,
// just don't add it as a problem file. Easy!
problemFiles.add(originalSource);
}
} catch (IOException e) {
throw ThrowingEx.asRuntime(e);
}
}
});

if (!problemFiles.isEmpty()) {
try (Formatter formatter = source.buildFormatter()) {
Collections.sort(problemFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.diffplug.spotless.kotlin;

import org.junit.Ignore;
import org.junit.Test;

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

0 comments on commit 608e128

Please sign in to comment.