8080
8181import groovy .lang .Closure ;
8282
83- /** Adds a {@code spotless{Name}Check} and {@code spotless{Name}Apply} task. */
83+ /**
84+ * Adds a {@code spotless{Name}Check} and {@code spotless{Name}Apply} task.
85+ */
8486public class FormatExtension {
8587
8688 private static final Logger LOGGER = LoggerFactory .getLogger (FormatExtension .class );
@@ -150,7 +152,9 @@ public void setEncoding(String name) {
150152
151153 private String ratchetFrom = RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL ;
152154
153- /** @see #setRatchetFrom(String) */
155+ /**
156+ * @see #setRatchetFrom(String)
157+ */
154158 public String getRatchetFrom () {
155159 return ratchetFrom == RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL ? spotless .getRatchetFrom () : ratchetFrom ;
156160 }
@@ -163,7 +167,9 @@ public void setRatchetFrom(String ratchetFrom) {
163167 this .ratchetFrom = ratchetFrom ;
164168 }
165169
166- /** @see #setRatchetFrom(String) */
170+ /**
171+ * @see #setRatchetFrom(String)
172+ */
167173 public void ratchetFrom (String ratchetFrom ) {
168174 setRatchetFrom (ratchetFrom );
169175 }
@@ -178,7 +184,9 @@ public void setEncoding(Charset charset) {
178184
179185 final List <LintSuppression > lintSuppressions = new ArrayList <>();
180186
181- /** Suppresses any lints which meet the supplied criteria. */
187+ /**
188+ * Suppresses any lints which meet the supplied criteria.
189+ */
182190 public void suppressLintsFor (Action <LintSuppression > lintSuppression ) {
183191 LintSuppression suppression = new LintSuppression ();
184192 lintSuppression .execute (suppression );
@@ -216,11 +224,15 @@ public void encoding(String charset) {
216224 setEncoding (charset );
217225 }
218226
219- /** The files to be formatted = (target - targetExclude). */
227+ /**
228+ * The files to be formatted = (target - targetExclude).
229+ */
220230 protected FileCollection target ;
221231 protected FileCollection targetExclude ;
222232
223- /** The value from which files will be excluded if their content contain it. */
233+ /**
234+ * The value from which files will be excluded if their content contain it.
235+ */
224236 @ Nullable protected String targetExcludeContentPattern ;
225237
226238 protected boolean isLicenseHeaderStep (FormatterStep formatterStep ) {
@@ -351,10 +363,14 @@ private static void relativizeIfSubdir(List<String> relativePaths, File root, Fi
351363 }
352364 }
353365
354- /** The steps that need to be added. */
366+ /**
367+ * The steps that need to be added.
368+ */
355369 protected final List <FormatterStep > steps = new ArrayList <>();
356370
357- /** Adds a new step. */
371+ /**
372+ * Adds a new step.
373+ */
358374 public void addStep (FormatterStep newStep ) {
359375 requireNonNull (newStep );
360376 int existingIdx = getExistingStepIdx (newStep .getName ());
@@ -365,7 +381,9 @@ public void addStep(FormatterStep newStep) {
365381 steps .add (newStep );
366382 }
367383
368- /** Adds a new step that requires a Provisioner. */
384+ /**
385+ * Adds a new step that requires a Provisioner.
386+ */
369387 public void addStep (Function <Provisioner , FormatterStep > createStepFn ) {
370388 requireNonNull (createStepFn );
371389 FormatterStep newStep = createStepFn .apply (provisioner ());
@@ -385,7 +403,9 @@ protected int getExistingStepIdx(String stepName) {
385403 return -1 ;
386404 }
387405
388- /** Replaces the given step. */
406+ /**
407+ * Replaces the given step.
408+ */
389409 protected void replaceStep (FormatterStep replacementStep ) {
390410 int existingIdx = getExistingStepIdx (replacementStep .getName ());
391411 if (existingIdx == -1 ) {
@@ -395,7 +415,9 @@ protected void replaceStep(FormatterStep replacementStep) {
395415 steps .set (existingIdx , replacementStep );
396416 }
397417
398- /** Clears all of the existing steps. */
418+ /**
419+ * Clears all of the existing steps.
420+ */
399421 public void clearSteps () {
400422 steps .clear ();
401423 }
@@ -478,32 +500,44 @@ public void custom(String name, FormatterFunc formatter) {
478500 addStep (FormatterStep .createLazy (name , () -> globalState , SerializedFunction .alwaysReturns (formatter )));
479501 }
480502
481- /** Highly efficient find-replace char sequence. */
503+ /**
504+ * Highly efficient find-replace char sequence.
505+ */
482506 public void replace (String name , CharSequence original , CharSequence after ) {
483507 addStep (ReplaceStep .create (name , original , after ));
484508 }
485509
486- /** Highly efficient find-replace regex. */
510+ /**
511+ * Highly efficient find-replace regex.
512+ */
487513 public void replaceRegex (String name , String regex , String replacement ) {
488514 addStep (ReplaceRegexStep .create (name , regex , replacement ));
489515 }
490516
491- /** A regex which generates a lint. */
517+ /**
518+ * A regex which generates a lint.
519+ */
492520 public void forbidRegex (String name , String regex , String lintDetail ) {
493521 addStep (ReplaceRegexStep .lint (name , regex , lintDetail ));
494522 }
495523
496- /** Removes trailing whitespace. */
524+ /**
525+ * Removes trailing whitespace.
526+ */
497527 public void trimTrailingWhitespace () {
498528 addStep (TrimTrailingWhitespaceStep .create ());
499529 }
500530
501- /** Ensures that files end with a single newline. */
531+ /**
532+ * Ensures that files end with a single newline.
533+ */
502534 public void endWithNewline () {
503535 addStep (EndWithNewlineStep .create ());
504536 }
505537
506- /** Ensures that the files are indented using spaces. */
538+ /**
539+ * Ensures that the files are indented using spaces.
540+ */
507541 public void leadingTabsToSpaces (int spacesPerTab ) {
508542 addStep (IndentStep .Type .SPACE .create (spacesPerTab ));
509543 }
@@ -514,7 +548,9 @@ public void indentWithSpaces(int numSpacesPerTab) {
514548 leadingTabsToSpaces (numSpacesPerTab );
515549 }
516550
517- /** Ensures that the files are indented using spaces. */
551+ /**
552+ * Ensures that the files are indented using spaces.
553+ */
518554 public void leadingTabsToSpaces () {
519555 addStep (IndentStep .Type .SPACE .create ());
520556 }
@@ -525,7 +561,9 @@ public void indentWithSpaces() {
525561 leadingTabsToSpaces ();
526562 }
527563
528- /** Ensures that the files are indented using tabs. */
564+ /**
565+ * Ensures that the files are indented using tabs.
566+ */
529567 public void leadingSpacesToTabs (int spacesPerTab ) {
530568 addStep (IndentStep .Type .TAB .create (spacesPerTab ));
531569 }
@@ -536,7 +574,9 @@ public void indentWithTabs(int tabToSpaces) {
536574 leadingSpacesToTabs (tabToSpaces );
537575 }
538576
539- /** Ensures that the files are indented using tabs. */
577+ /**
578+ * Ensures that the files are indented using tabs.
579+ */
540580 public void leadingSpacesToTabs () {
541581 addStep (IndentStep .Type .TAB .create ());
542582 }
@@ -551,7 +591,9 @@ private static void logDeprecation(String methodName, String replacement) {
551591 LOGGER .warn ("'{}' is deprecated, use '{}' in your gradle build script instead." , methodName , replacement );
552592 }
553593
554- /** Ensures formatting of files via native binary. */
594+ /**
595+ * Ensures formatting of files via native binary.
596+ */
555597 public void nativeCmd (String name , String pathToExe , List <String > arguments ) {
556598 addStep (NativeCmdStep .create (name , new File (pathToExe ), arguments ));
557599 }
@@ -630,8 +672,11 @@ public LicenseHeaderConfig updateYearWithLatest(boolean updateYearWithLatest) {
630672
631673 FormatterStep createStep () {
632674 return builder .withYearModeLazy (() -> {
633- if ("true" .equals (spotless .project
634- .findProperty (LicenseHeaderStep .FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY ()))) {
675+ if (spotless .project
676+ .getProviders ()
677+ .gradleProperty (LicenseHeaderStep .FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY ())
678+ .map (Boolean ::parseBoolean )
679+ .getOrElse (false )) {
635680 return YearMode .SET_FROM_GIT ;
636681 } else {
637682 boolean updateYear = updateYearWithLatest == null ? getRatchetFrom () != null : updateYearWithLatest ;
@@ -846,17 +891,23 @@ protected BiomeGeneric getThis() {
846891 }
847892 }
848893
849- /** Uses the default version of prettier. */
894+ /**
895+ * Uses the default version of prettier.
896+ */
850897 public PrettierConfig prettier () {
851898 return prettier (PrettierFormatterStep .defaultDevDependencies ());
852899 }
853900
854- /** Uses the specified version of prettier. */
901+ /**
902+ * Uses the specified version of prettier.
903+ */
855904 public PrettierConfig prettier (String version ) {
856905 return prettier (PrettierFormatterStep .defaultDevDependenciesWithPrettier (version ));
857906 }
858907
859- /** Uses exactly the npm packages specified in the map. */
908+ /**
909+ * Uses exactly the npm packages specified in the map.
910+ */
860911 public PrettierConfig prettier (Map <String , String > devDependencies ) {
861912 PrettierConfig prettierConfig = new PrettierConfig (devDependencies );
862913 addStep (prettierConfig .createStep ());
@@ -872,19 +923,25 @@ public BiomeStepConfig<?> biome() {
872923 return biome (null );
873924 }
874925
875- /** Downloads the given Biome version from the network. */
926+ /**
927+ * Downloads the given Biome version from the network.
928+ */
876929 public BiomeStepConfig <?> biome (String version ) {
877930 var biomeConfig = new BiomeGeneric (version );
878931 addStep (biomeConfig .createStep ());
879932 return biomeConfig ;
880933 }
881934
882- /** Uses the default version of clang-format. */
935+ /**
936+ * Uses the default version of clang-format.
937+ */
883938 public ClangFormatConfig clangFormat () {
884939 return clangFormat (ClangFormatStep .defaultVersion ());
885940 }
886941
887- /** Uses the specified version of clang-format. */
942+ /**
943+ * Uses the specified version of clang-format.
944+ */
888945 public ClangFormatConfig clangFormat (String version ) {
889946 return new ClangFormatConfig (version );
890947 }
@@ -897,7 +954,9 @@ public class ClangFormatConfig {
897954 addStep (createStep ());
898955 }
899956
900- /** Any of: LLVM, Google, Chromium, Mozilla, WebKit. */
957+ /**
958+ * Any of: LLVM, Google, Chromium, Mozilla, WebKit.
959+ */
901960 public ClangFormatConfig style (String style ) {
902961 stepCfg = stepCfg .withStyle (style );
903962 replaceStep (createStep ());
@@ -1051,12 +1110,16 @@ public void toggleOffOnRegex(String regex) {
10511110 this .toggleFence = FenceStep .named (FenceStep .defaultToggleName ()).regex (regex );
10521111 }
10531112
1054- /** Disables formatting between the given tags. */
1113+ /**
1114+ * Disables formatting between the given tags.
1115+ */
10551116 public void toggleOffOn (String off , String on ) {
10561117 this .toggleFence = FenceStep .named (FenceStep .defaultToggleName ()).openClose (off , on );
10571118 }
10581119
1059- /** Disables formatting between {@code spotless:off} and {@code spotless:on}. */
1120+ /**
1121+ * Disables formatting between {@code spotless:off} and {@code spotless:on}.
1122+ */
10601123 public void toggleOffOn () {
10611124 toggleOffOn (FenceStep .defaultToggleOff (), FenceStep .defaultToggleOn ());
10621125 }
@@ -1071,7 +1134,9 @@ public void toggleOffOnDisable() {
10711134
10721135 private @ Nullable FenceStep toggleFence ;
10731136
1074- /** Sets up a format task according to the values in this extension. */
1137+ /**
1138+ * Sets up a format task according to the values in this extension.
1139+ */
10751140 protected void setupTask (SpotlessTask task ) {
10761141 task .setEncoding (getEncoding ().name ());
10771142 task .setLintSuppressions (lintSuppressions );
@@ -1098,12 +1163,16 @@ protected void setupTask(SpotlessTask task) {
10981163 task .setupRatchet (getRatchetFrom () != null ? getRatchetFrom () : "" );
10991164 }
11001165
1101- /** Returns the project that this extension is attached to. */
1166+ /**
1167+ * Returns the project that this extension is attached to.
1168+ */
11021169 protected Project getProject () {
11031170 return spotless .project ;
11041171 }
11051172
1106- /** Eager version of {@link #createIndependentApplyTaskLazy(String)} */
1173+ /**
1174+ * Eager version of {@link #createIndependentApplyTaskLazy(String)}
1175+ */
11071176 public SpotlessApply createIndependentApplyTask (String taskName ) {
11081177 return createIndependentApplyTaskLazy (taskName ).get ();
11091178 }
0 commit comments