Skip to content

Commit fed3ffc

Browse files
committed
First commit to discuss the idea
1 parent bba3ea1 commit fed3ffc

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.diffplug.spotless.maven;
2+
3+
import java.util.concurrent.atomic.AtomicInteger;
4+
5+
public class ImpactedFilesTracker {
6+
protected final AtomicInteger nbChecked = new AtomicInteger();
7+
protected final AtomicInteger nbCleaned = new AtomicInteger();
8+
9+
public void checked() {
10+
nbChecked.incrementAndGet();
11+
}
12+
13+
public int getChecked() {
14+
return nbChecked.get();
15+
}
16+
17+
public void cleaned() {
18+
nbCleaned.incrementAndGet();
19+
}
20+
21+
public int getCleaned() {
22+
return nbCleaned.get();
23+
}
24+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo {
3333

3434
@Override
3535
protected void process(Iterable<File> files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException {
36+
ImpactedFilesTracker impactedFilesTracker = new ImpactedFilesTracker();
37+
3638
for (File file : files) {
3739
if (upToDateChecker.isUpToDate(file.toPath())) {
3840
if (getLog().isDebugEnabled()) {
@@ -42,16 +44,22 @@ protected void process(Iterable<File> files, Formatter formatter, UpToDateChecke
4244
}
4345

4446
try {
47+
impactedFilesTracker.checked();
4548
PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file);
4649
if (!dirtyState.isClean() && !dirtyState.didNotConverge()) {
50+
getLog().info(String.format("Writing clean file: %s", file));
4751
dirtyState.writeCanonicalTo(file);
4852
buildContext.refresh(file);
53+
impactedFilesTracker.cleaned();
4954
}
5055
} catch (IOException e) {
5156
throw new MojoExecutionException("Unable to format file " + file, e);
5257
}
5358

5459
upToDateChecker.setUpToDate(file.toPath());
5560
}
61+
62+
// We print the number of considered files which is useful when ratchetFrom is setup
63+
getLog().info(String.format("A formatter with %s steps cleaned: %s files (for %s considered)", formatter.getSteps().size(), impactedFilesTracker.getCleaned(), impactedFilesTracker.getChecked()));
5664
}
5765
}

0 commit comments

Comments
 (0)