Skip to content

Commit

Permalink
Support toning down sortPom (#2185)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Jul 2, 2024
2 parents b456d1c + d0d71d6 commit 7bbe908
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Changed
* Support toning down sortPom logging. ([#2185](https://github.com/diffplug/spotless/pull/2185))
* Bump default `ktlint` version to latest `1.2.1` -> `1.3.0`. ([#2165](https://github.com/diffplug/spotless/pull/2165))
* Bump default `ktfmt` version to latest `0.49` -> `0.51`. ([#2172](https://github.com/diffplug/spotless/pull/2172))
* Rename property `ktfmt` option `removeUnusedImport` -> `removeUnusedImports` to match `ktfmt`. ([#2172](https://github.com/diffplug/spotless/pull/2172))
Expand Down
2 changes: 2 additions & 0 deletions lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class SortPomCfg implements Serializable {

public String predefinedSortOrder = "recommended_2008_06";

public boolean quiet = false;

public String sortOrderFile = null;

public String sortDependencies = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,28 @@ public String apply(String input) throws Exception {
.setSortEntities(cfg.sortDependencies, cfg.sortDependencyExclusions, cfg.sortDependencyManagement,
cfg.sortPlugins, cfg.sortProperties, cfg.sortModules, cfg.sortExecutions)
.setIgnoreLineSeparators(false);
sortPom.setup(new MySortPomLogger(), builder.build());
sortPom.setup(new MySortPomLogger(cfg.quiet), builder.build());
sortPom.sortPom();
return Files.readString(pom.toPath(), Charset.forName(cfg.encoding));
}

private static class MySortPomLogger implements SortPomLogger {
private final boolean quiet;

public MySortPomLogger(boolean quiet) {
this.quiet = quiet;
}

@Override
public void warn(String content) {
logger.warn(content);
}

@Override
public void info(String content) {
logger.info(content);
if (!quiet) {
logger.info(content);
}
}

@Override
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Changed
* Support toning down sortPom logging. ([#2185](https://github.com/diffplug/spotless/pull/2185))
* Bump default `ktlint` version to latest `1.2.1` -> `1.3.0`. ([#2165](https://github.com/diffplug/spotless/pull/2165))
* Bump default `ktfmt` version to latest `0.49` -> `0.51`. ([#2172](https://github.com/diffplug/spotless/pull/2172))
* Rename property `ktfmt` option `removeUnusedImport` -> `removeUnusedImports` to match `ktfmt`. ([#2172](https://github.com/diffplug/spotless/pull/2172))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public SortPomGradleConfig predefinedSortOrder(String predefinedSortOrder) {
return this;
}

public SortPomGradleConfig quiet(boolean quiet) {
cfg.quiet = quiet;
return this;
}

public SortPomGradleConfig sortOrderFile(String sortOrderFile) {
cfg.sortOrderFile = sortOrderFile;
return this;
Expand Down
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Changed
* Support toning down sortPom logging. ([#2185](https://github.com/diffplug/spotless/pull/2185))
* Bump default `ktlint` version to latest `1.2.1` -> `1.3.0`. ([#2165](https://github.com/diffplug/spotless/pull/2165))
* Bump default `ktfmt` version to latest `0.49` -> `0.51`. ([#2172](https://github.com/diffplug/spotless/pull/2172))
* Rename property `ktfmt` option `removeUnusedImport` -> `removeUnusedImports` to match `ktfmt`. ([#2172](https://github.com/diffplug/spotless/pull/2172))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class SortPom implements FormatterStepFactory {
@Parameter
String predefinedSortOrder = defaultValues.predefinedSortOrder;

@Parameter
boolean quiet = defaultValues.quiet;

@Parameter
String sortOrderFile = defaultValues.sortOrderFile;

Expand Down Expand Up @@ -101,6 +104,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
cfg.indentSchemaLocation = indentSchemaLocation;
cfg.indentAttribute = indentAttribute;
cfg.predefinedSortOrder = predefinedSortOrder;
cfg.quiet = quiet;
cfg.sortOrderFile = sortOrderFile;
cfg.sortDependencies = sortDependencies;
cfg.sortDependencyManagement = sortDependencyManagement;
Expand Down

0 comments on commit 7bbe908

Please sign in to comment.