Skip to content

Commit

Permalink
Updated SortPom from 3.2.1 to 3.4.0 with support for endWithNewline (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Feb 23, 2024
2 parents aceab65 + f7a6e63 commit aa113ff
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
### Changes
* Bump default `ktfmt` version to latest `0.46` -> `0.47`. ([#2045](https://github.com/diffplug/spotless/pull/2045))
* Bump default `sortpom` version to latest `3.2.1` -> `3.4.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049))
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
### Removed
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))
Expand Down
4 changes: 2 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ dependencies {
// scalafmt
scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:3.7.3"
// sortPom
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.2.1'
sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0'
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.4.0'
sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.12'
// zjsonPatch
zjsonPatchCompileOnly 'com.flipkart.zjsonpatch:zjsonpatch:0.4.14'
}
Expand Down
6 changes: 4 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 DiffPlug
* Copyright 2021-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@
public class SortPomCfg implements Serializable {
private static final long serialVersionUID = 1L;

public String version = "3.2.1";
public String version = "3.4.0";

public String encoding = "UTF-8";

Expand All @@ -33,6 +33,8 @@ public class SortPomCfg implements Serializable {

public boolean keepBlankLines = true;

public boolean endWithNewline = true;

public int nrOfIndentSpace = 2;

public boolean indentBlankLines = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 DiffPlug
* Copyright 2021-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,7 +50,7 @@ public String apply(String input) throws Exception {
.setPomFile(pom)
.setFileOutput(false, null, null, false)
.setEncoding(cfg.encoding)
.setFormatting(cfg.lineSeparator, cfg.expandEmptyElements, cfg.spaceBeforeCloseEmptyElement, cfg.keepBlankLines)
.setFormatting(cfg.lineSeparator, cfg.expandEmptyElements, cfg.spaceBeforeCloseEmptyElement, cfg.keepBlankLines, cfg.endWithNewline)
.setIndent(cfg.nrOfIndentSpace, cfg.indentBlankLines, cfg.indentSchemaLocation)
.setSortOrder(cfg.sortOrderFile, cfg.predefinedSortOrder)
.setSortEntities(cfg.sortDependencies, cfg.sortDependencyExclusions, cfg.sortDependencyManagement,
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
### Changes
* Bump default `ktfmt` version to latest `0.46` -> `0.47`. ([#2045](https://github.com/diffplug/spotless/pull/2045))
* Bump default `sortpom` version to latest `3.2.1` -> `3.4.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049))
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
### Added
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
Expand Down
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
### Changes
* Bump default `ktfmt` version to latest `0.46` -> `0.47`. ([#2045](https://github.com/diffplug/spotless/pull/2045))
* Bump default `sortpom` version to latest `3.2.1` -> `3.4.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049))
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
### Added
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
Expand Down
2 changes: 2 additions & 0 deletions plugin-maven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ All configuration settings are optional, they are described in detail [here](htt

<keepBlankLines>true</keepBlankLines> <!-- Keep empty lines -->

<endWithNewline>true</endWithNewline> <!-- Whether sorted pom ends with a newline -->

<nrOfIndentSpace>2</nrOfIndentSpace> <!-- Indentation -->

<indentBlankLines>false</indentBlankLines> <!-- Should empty lines be indented -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 DiffPlug
* Copyright 2021-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +44,9 @@ public class SortPom implements FormatterStepFactory {
@Parameter
boolean keepBlankLines = defaultValues.keepBlankLines;

@Parameter
boolean endWithNewline = defaultValues.endWithNewline;

@Parameter
int nrOfIndentSpace = defaultValues.nrOfIndentSpace;

Expand Down Expand Up @@ -89,6 +92,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
cfg.expandEmptyElements = expandEmptyElements;
cfg.spaceBeforeCloseEmptyElement = spaceBeforeCloseEmptyElement;
cfg.keepBlankLines = keepBlankLines;
cfg.endWithNewline = endWithNewline;
cfg.nrOfIndentSpace = nrOfIndentSpace;
cfg.indentBlankLines = indentBlankLines;
cfg.indentSchemaLocation = indentSchemaLocation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 DiffPlug
* Copyright 2021-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,16 +21,16 @@

public class SortPomTest extends ResourceHarness {
@Test
public void testSortPomWithDefaultConfig() throws Exception {
public void testSortPomWithDefaultConfig() {
SortPomCfg cfg = new SortPomCfg();
FormatterStep step = SortPomStep.create(cfg, TestProvisioner.mavenCentral());
StepHarness.forStep(step).testResource("pom/pom_dirty.xml", "pom/pom_clean_default.xml");
}

@Test
public void testSortPomWithVersion() throws Exception {
public void testSortPomWithVersion() {
SortPomCfg cfg = new SortPomCfg();
cfg.version = "3.2.1";
cfg.version = "3.4.0";
FormatterStep step = SortPomStep.create(cfg, TestProvisioner.mavenCentral());
StepHarness.forStep(step).testResource("pom/pom_dirty.xml", "pom/pom_clean_default.xml");
}
Expand Down

0 comments on commit aa113ff

Please sign in to comment.