Skip to content

Commit

Permalink
Minor renaming to condense SpotlessApplyMojo.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Jan 31, 2023
1 parent d7ff074 commit eeee68a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ public int getCleaned() {
return nbCleaned;
}

public int getTotal() {
return nbskippedAsCleanCache + nbCheckedButAlreadyClean + nbCleaned;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo {

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

for (File file : files) {
if (upToDateChecker.isUpToDate(file.toPath())) {
impactedFilesTracker.skippedAsCleanCache();
counter.skippedAsCleanCache();
if (getLog().isDebugEnabled()) {
getLog().debug("Spotless will not format an up-to-date file: " + file);
}
Expand All @@ -50,9 +50,9 @@ protected void process(Iterable<File> files, Formatter formatter, UpToDateChecke
getLog().info(String.format("Writing clean file: %s", file));
dirtyState.writeCanonicalTo(file);
buildContext.refresh(file);
impactedFilesTracker.cleaned();
counter.cleaned();
} else {
impactedFilesTracker.checkedButAlreadyClean();
counter.checkedButAlreadyClean();
}
} catch (IOException e) {
throw new MojoExecutionException("Unable to format file " + file, e);
Expand All @@ -62,13 +62,9 @@ protected void process(Iterable<File> files, Formatter formatter, UpToDateChecke
}

// We print the number of considered files which is useful when ratchetFrom is setup
int skippedAsCleanCache = impactedFilesTracker.getSkippedAsCleanCache();
int checkedButAlreadyClean = impactedFilesTracker.getCheckedButAlreadyClean();
int cleaned = impactedFilesTracker.getCleaned();
int totalProcessed = skippedAsCleanCache + checkedButAlreadyClean + cleaned;
if (totalProcessed > 0) {
if (counter.getTotal() > 0) {
getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean",
formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache));
formatter.getName(), counter.getTotal(), counter.getCleaned(), counter.getCheckedButAlreadyClean(), counter.getSkippedAsCleanCache()));
} else {
getLog().warn(String.format("Spotless.%s has no target files. Examine your `<includes>`: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName()));
}
Expand Down

0 comments on commit eeee68a

Please sign in to comment.