Skip to content

Suggested feature - Adding a synthesis at the end of spotlessApply #1506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.diffplug.spotless.maven;

import java.util.concurrent.atomic.AtomicInteger;

public class ImpactedFilesTracker {
protected final AtomicInteger nbChecked = new AtomicInteger();
protected final AtomicInteger nbCleaned = new AtomicInteger();

public void checked() {
nbChecked.incrementAndGet();
}

public int getChecked() {
return nbChecked.get();
}

public void cleaned() {
nbCleaned.incrementAndGet();
}

public int getCleaned() {
return nbCleaned.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo {

@Override
protected void process(Iterable<File> files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException {
ImpactedFilesTracker impactedFilesTracker = new ImpactedFilesTracker();

for (File file : files) {
if (upToDateChecker.isUpToDate(file.toPath())) {
if (getLog().isDebugEnabled()) {
Expand All @@ -42,16 +44,22 @@ protected void process(Iterable<File> files, Formatter formatter, UpToDateChecke
}

try {
impactedFilesTracker.checked();
PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file);
if (!dirtyState.isClean() && !dirtyState.didNotConverge()) {
getLog().info(String.format("Writing clean file: %s", file));
dirtyState.writeCanonicalTo(file);
buildContext.refresh(file);
impactedFilesTracker.cleaned();
}
} catch (IOException e) {
throw new MojoExecutionException("Unable to format file " + file, e);
}

upToDateChecker.setUpToDate(file.toPath());
}

// We print the number of considered files which is useful when ratchetFrom is setup
getLog().info(String.format("A formatter with %s steps cleaned: %s files (for %s considered)", formatter.getSteps().size(), impactedFilesTracker.getCleaned(), impactedFilesTracker.getChecked()));
}
}