From fed3ffc811da37a30921aa9835627e8ca377c2e2 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 19 Jan 2023 19:42:01 +0400 Subject: [PATCH 1/7] First commit to discuss the idea --- .../spotless/maven/ImpactedFilesTracker.java | 24 +++++++++++++++++++ .../spotless/maven/SpotlessApplyMojo.java | 8 +++++++ 2 files changed, 32 insertions(+) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java new file mode 100644 index 0000000000..6019591e09 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -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(); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 7a15d01b17..b617505826 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -33,6 +33,8 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo { @Override protected void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException { + ImpactedFilesTracker impactedFilesTracker = new ImpactedFilesTracker(); + for (File file : files) { if (upToDateChecker.isUpToDate(file.toPath())) { if (getLog().isDebugEnabled()) { @@ -42,10 +44,13 @@ protected void process(Iterable 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); @@ -53,5 +58,8 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke 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())); } } From b0d16195d45c04a06965217b2bc14bd69d3fe2aa Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sat, 28 Jan 2023 18:39:41 +0400 Subject: [PATCH 2/7] Introduce Formatter.name, Improve synthesis log --- .../java/com/diffplug/spotless/Formatter.java | 26 +++++++++++++--- .../gradle/spotless/SpotlessTask.java | 3 +- .../spotless/maven/FormatterFactory.java | 4 ++- .../spotless/maven/ImpactedFilesTracker.java | 31 +++++++++++++++++++ .../spotless/maven/SpotlessApplyMojo.java | 10 ++++-- .../spotless/StepHarnessWithFile.java | 1 + 6 files changed, 67 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 038e77fa64..bdfe008a61 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,13 +39,16 @@ public final class Formatter implements Serializable, AutoCloseable { private static final long serialVersionUID = 1L; + // The name is used for logging purpose. It does not convey any applicative purpose + private String name; private LineEnding.Policy lineEndingsPolicy; private Charset encoding; private Path rootDir; private List steps; private FormatExceptionPolicy exceptionPolicy; - private Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List steps, FormatExceptionPolicy exceptionPolicy) { + private Formatter(String name, LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List steps, FormatExceptionPolicy exceptionPolicy) { + this.name = name; this.lineEndingsPolicy = Objects.requireNonNull(lineEndingsPolicy, "lineEndingsPolicy"); this.encoding = Objects.requireNonNull(encoding, "encoding"); this.rootDir = Objects.requireNonNull(rootDirectory, "rootDir"); @@ -55,6 +58,7 @@ private Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path ro // override serialize output private void writeObject(ObjectOutputStream out) throws IOException { + out.writeObject(name); out.writeObject(lineEndingsPolicy); out.writeObject(encoding.name()); out.writeObject(rootDir.toString()); @@ -65,6 +69,7 @@ private void writeObject(ObjectOutputStream out) throws IOException { // override serialize input @SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + name = (String) in.readObject(); lineEndingsPolicy = (LineEnding.Policy) in.readObject(); encoding = Charset.forName((String) in.readObject()); rootDir = Paths.get((String) in.readObject()); @@ -78,6 +83,10 @@ private void readObjectNoData() throws ObjectStreamException { throw new UnsupportedOperationException(); } + public String getName() { + return name; + } + public LineEnding.Policy getLineEndingsPolicy() { return lineEndingsPolicy; } @@ -103,6 +112,8 @@ public static Formatter.Builder builder() { } public static class Builder { + // optional parameters + private String name = "misc"; // required parameters private LineEnding.Policy lineEndingsPolicy; private Charset encoding; @@ -112,6 +123,11 @@ public static class Builder { private Builder() {} + public Builder name(String name) { + this.name = name; + return this; + } + public Builder lineEndingsPolicy(LineEnding.Policy lineEndingsPolicy) { this.lineEndingsPolicy = lineEndingsPolicy; return this; @@ -138,7 +154,7 @@ public Builder exceptionPolicy(FormatExceptionPolicy exceptionPolicy) { } public Formatter build() { - return new Formatter(lineEndingsPolicy, encoding, rootDir, steps, + return new Formatter(name, lineEndingsPolicy, encoding, rootDir, steps, exceptionPolicy == null ? FormatExceptionPolicy.failOnlyOnError() : exceptionPolicy); } } @@ -248,6 +264,7 @@ public String compute(String unix, File file) { public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + name.hashCode(); result = prime * result + encoding.hashCode(); result = prime * result + lineEndingsPolicy.hashCode(); result = prime * result + rootDir.hashCode(); @@ -268,7 +285,8 @@ public boolean equals(Object obj) { return false; } Formatter other = (Formatter) obj; - return encoding.equals(other.encoding) && + return name.equals(other.name) && + encoding.equals(other.encoding) && lineEndingsPolicy.equals(other.lineEndingsPolicy) && rootDir.equals(other.rootDir) && steps.equals(other.steps) && diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java index 6f2279b2e0..c23cea0845 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -184,6 +184,7 @@ String formatName() { Formatter buildFormatter() { return Formatter.builder() + .name(formatName()) .lineEndingsPolicy(lineEndingsPolicy.get()) .encoding(Charset.forName(encoding)) .rootDir(getProjectDir().get().getAsFile().toPath()) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java index d5fbe60370..b78e987d34 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -101,7 +101,9 @@ public final Formatter newFormatter(Supplier> filesToFormat, Form formatterSteps.add(pair.out()); } + String formatterName = this.getClass().getSimpleName(); return Formatter.builder() + .name(formatterName) .encoding(formatterEncoding) .lineEndingsPolicy(formatterLineEndingPolicy) .exceptionPolicy(new FormatExceptionPolicyStrict()) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java index 6019591e09..7474c109bc 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -1,11 +1,41 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.maven; import java.util.concurrent.atomic.AtomicInteger; +/** + * Tracks the number of processed files, typically by a single Formatter for a whole repository + */ public class ImpactedFilesTracker { + protected final AtomicInteger nbSkipped = new AtomicInteger(); protected final AtomicInteger nbChecked = new AtomicInteger(); protected final AtomicInteger nbCleaned = new AtomicInteger(); + /** + * Some cache mechanism may indicate some content is clean, without having to execute the cleaning process + */ + public void skippedAsCleanCache() { + nbSkipped.incrementAndGet(); + } + + public int getSkipped() { + return nbSkipped.get(); + } + public void checked() { nbChecked.incrementAndGet(); } @@ -21,4 +51,5 @@ public void cleaned() { public int getCleaned() { return nbCleaned.get(); } + } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index b617505826..0f712ecd12 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke for (File file : files) { if (upToDateChecker.isUpToDate(file.toPath())) { + impactedFilesTracker.skippedAsCleanCache(); if (getLog().isDebugEnabled()) { getLog().debug("Spotless will not format an up-to-date file: " + file); } @@ -60,6 +61,11 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } // 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())); + int nbSkipped = impactedFilesTracker.getSkipped(); + int nbChecked = impactedFilesTracker.getChecked(); + int nbCleaned = impactedFilesTracker.getCleaned(); + int totalProcessed = nbSkipped + nbChecked + nbCleaned; + 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, nbCleaned, nbChecked, nbSkipped)); } } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java index 98a709c59f..9a9eb4042b 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java @@ -38,6 +38,7 @@ private StepHarnessWithFile(ResourceHarness harness, Formatter formatter) { /** Creates a harness for testing steps which do depend on the file. */ public static StepHarnessWithFile forStep(ResourceHarness harness, FormatterStep step) { return new StepHarnessWithFile(harness, Formatter.builder() + .name(step.getName()) .encoding(StandardCharsets.UTF_8) .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) .steps(Collections.singletonList(step)) From 8fcce07eee63e064ad1c8e3583dd6c89c32899fa Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 31 Jan 2023 00:10:27 +0400 Subject: [PATCH 3/7] Apply suggestions --- .../java/com/diffplug/spotless/Formatter.java | 2 +- .../spotless/maven/ImpactedFilesTracker.java | 28 +++++++++---------- .../spotless/maven/SpotlessApplyMojo.java | 13 +++++---- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index bdfe008a61..dede79c1b3 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -113,7 +113,7 @@ public static Formatter.Builder builder() { public static class Builder { // optional parameters - private String name = "misc"; + private String name = "unnamed"; // required parameters private LineEnding.Policy lineEndingsPolicy; private Charset encoding; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java index 7474c109bc..f66802475e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -15,41 +15,39 @@ */ package com.diffplug.spotless.maven; -import java.util.concurrent.atomic.AtomicInteger; - /** * Tracks the number of processed files, typically by a single Formatter for a whole repository */ -public class ImpactedFilesTracker { - protected final AtomicInteger nbSkipped = new AtomicInteger(); - protected final AtomicInteger nbChecked = new AtomicInteger(); - protected final AtomicInteger nbCleaned = new AtomicInteger(); +class ImpactedFilesTracker { + protected int nbskippedAsCleanCache = 0; + protected int nbCheckedButAlreadyClean = 0; + protected int nbCleaned = 0; /** * Some cache mechanism may indicate some content is clean, without having to execute the cleaning process */ public void skippedAsCleanCache() { - nbSkipped.incrementAndGet(); + nbskippedAsCleanCache++; } - public int getSkipped() { - return nbSkipped.get(); + public int getSkippedAsCleanCache() { + return nbskippedAsCleanCache; } - public void checked() { - nbChecked.incrementAndGet(); + public void checkedButAlreadyClean() { + nbCheckedButAlreadyClean++; } - public int getChecked() { - return nbChecked.get(); + public int getCheckedButAlreadyClean() { + return nbCheckedButAlreadyClean; } public void cleaned() { - nbCleaned.incrementAndGet(); + nbCleaned++; } public int getCleaned() { - return nbCleaned.get(); + return nbCleaned; } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 0f712ecd12..0c1cbf8785 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -45,13 +45,14 @@ protected void process(Iterable 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(); + } else { + impactedFilesTracker.checkedButAlreadyClean(); } } catch (IOException e) { throw new MojoExecutionException("Unable to format file " + file, e); @@ -61,11 +62,11 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } // We print the number of considered files which is useful when ratchetFrom is setup - int nbSkipped = impactedFilesTracker.getSkipped(); - int nbChecked = impactedFilesTracker.getChecked(); - int nbCleaned = impactedFilesTracker.getCleaned(); - int totalProcessed = nbSkipped + nbChecked + nbCleaned; + int skippedAsCleanCache = impactedFilesTracker.getSkippedAsCleanCache(); + int checkedButAlreadyClean = impactedFilesTracker.getCheckedButAlreadyClean(); + int cleaned = impactedFilesTracker.getCleaned(); + int totalProcessed = skippedAsCleanCache + checkedButAlreadyClean + cleaned; 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, nbCleaned, nbChecked, nbSkipped)); + formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); } } From c890b89c7fb4430858bac8277bc5cfffad87ebac Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 31 Jan 2023 08:39:13 +0400 Subject: [PATCH 4/7] Add a CHANGES entry. Log only if totalProcessed>0 --- plugin-maven/CHANGES.md | 1 + .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1bb49898f1..2ecb7735ff 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* A synthesis log with the number of considered files is added after each formatter execution [#1507](https://github.com/diffplug/spotless/pull/1507) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 0c1cbf8785..8dd758e84b 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -66,7 +66,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke int checkedButAlreadyClean = impactedFilesTracker.getCheckedButAlreadyClean(); int cleaned = impactedFilesTracker.getCleaned(); int totalProcessed = skippedAsCleanCache + checkedButAlreadyClean + cleaned; - 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)); + if (totalProcessed > 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)); + } } } From 6f6b34fe35753064fdd35e5fcce8b42ec62660fb Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 31 Jan 2023 08:45:30 +0400 Subject: [PATCH 5/7] Add debug log if no concerned filers --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 8dd758e84b..5f99f6a126 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -69,6 +69,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke if (totalProcessed > 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)); + } else { + getLog().debug(String.format("Spotless.%s is not considering a single file", + formatter.getName())); } } } From d7ff074095b4bbcbe1acb6a7e4ad1edf6fccb78f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 30 Jan 2023 22:46:21 -0800 Subject: [PATCH 6/7] Treat empty target as a warning (likely a mistake, e.g. #437). --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 5f99f6a126..440b72c21e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -70,8 +70,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke 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)); } else { - getLog().debug(String.format("Spotless.%s is not considering a single file", - formatter.getName())); + getLog().warn(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); } } } From eeee68aaa9e605d23b0622af7ff2650237c96fa5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 30 Jan 2023 22:48:52 -0800 Subject: [PATCH 7/7] Minor renaming to condense SpotlessApplyMojo. --- .../spotless/maven/ImpactedFilesTracker.java | 3 +++ .../spotless/maven/SpotlessApplyMojo.java | 16 ++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java index f66802475e..60eb8af762 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -50,4 +50,7 @@ public int getCleaned() { return nbCleaned; } + public int getTotal() { + return nbskippedAsCleanCache + nbCheckedButAlreadyClean + nbCleaned; + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 440b72c21e..f7f23d6d75 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -33,11 +33,11 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo { @Override protected void process(Iterable 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); } @@ -50,9 +50,9 @@ protected void process(Iterable 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); @@ -62,13 +62,9 @@ protected void process(Iterable 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 ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); }