Skip to content

Commit eb783cd

Browse files
committed
Integrate paddedcell into maven.
1 parent 19ad28d commit eb783cd

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

plugin-maven/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
55
## [Unreleased]
66
### Added
77
* Support for google-java-format 1.8 (requires you to run build on Java 11) ([#562](https://github.com/diffplug/spotless/issues/562))
8+
* `mvn spotless:apply` is now guaranteed to be idempotent, even if some of the formatters are not. See [`PADDEDCELL.md` for details](https://github.com/diffplug/spotless/blob/master/PADDEDCELL.md) if you're curious. ([#565](https://github.com/diffplug/spotless/pull/565))
89
* Updated a bunch of dependencies, most notably jgit `5.5.0.201909110433-r` -> `5.7.0.202003110725-r`. ([#564](https://github.com/diffplug/spotless/pull/564))
910

1011
## [1.30.0] - 2020-04-10

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.maven.plugins.annotations.Parameter;
2525

2626
import com.diffplug.spotless.Formatter;
27+
import com.diffplug.spotless.PaddedCell;
2728

2829
/**
2930
* Performs formatting of all source files according to configured formatters.
@@ -42,7 +43,10 @@ protected void process(List<File> files, Formatter formatter) throws MojoExecuti
4243

4344
for (File file : files) {
4445
try {
45-
formatter.applyTo(file);
46+
PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file);
47+
if (!dirtyState.isClean() && !dirtyState.didNotConverge()) {
48+
dirtyState.writeCanonicalTo(file);
49+
}
4650
} catch (IOException e) {
4751
throw new MojoExecutionException("Unable to format file " + file, e);
4852
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.maven.plugins.annotations.Parameter;
2727

2828
import com.diffplug.spotless.Formatter;
29+
import com.diffplug.spotless.PaddedCell;
2930
import com.diffplug.spotless.extra.integration.DiffMessageFormatter;
3031

3132
/**
@@ -48,7 +49,8 @@ protected void process(List<File> files, Formatter formatter) throws MojoExecuti
4849
List<File> problemFiles = new ArrayList<>();
4950
for (File file : files) {
5051
try {
51-
if (!formatter.isClean(file)) {
52+
PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file);
53+
if (!dirtyState.isClean() && !dirtyState.didNotConverge()) {
5254
problemFiles.add(file);
5355
}
5456
} catch (IOException e) {
@@ -59,7 +61,6 @@ protected void process(List<File> files, Formatter formatter) throws MojoExecuti
5961
if (!problemFiles.isEmpty()) {
6062
throw new MojoExecutionException(DiffMessageFormatter.builder()
6163
.runToFix("Run 'mvn spotless:apply' to fix these violations.")
62-
.isPaddedCell(false)
6364
.formatter(formatter)
6465
.problemFiles(problemFiles)
6566
.getMessage());

0 commit comments

Comments
 (0)