From e7f259e7b74fb704a709dc526e8b35aa052ea9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ekryd?= Date: Tue, 20 Feb 2024 10:35:03 +0100 Subject: [PATCH 1/2] Updated SortPom from 3.2.1 to 3.4.0 with support for endWithNewline --- lib/build.gradle | 4 ++-- .../main/java/com/diffplug/spotless/pom/SortPomCfg.java | 6 ++++-- .../diffplug/spotless/glue/pom/SortPomFormatterFunc.java | 4 ++-- plugin-maven/README.md | 2 ++ .../java/com/diffplug/spotless/maven/pom/SortPom.java | 6 +++++- .../test/java/com/diffplug/spotless/pom/SortPomTest.java | 8 ++++---- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 8d313f123a..7b52442f92 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -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' } diff --git a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java index 8315035dc7..c24e91cf80 100644 --- a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java +++ b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java @@ -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. @@ -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"; @@ -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; diff --git a/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java b/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java index 4dcde62bae..57b96d70c7 100644 --- a/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java +++ b/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java @@ -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. @@ -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, diff --git a/plugin-maven/README.md b/plugin-maven/README.md index fbe4248b7b..384d3f78a5 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -659,6 +659,8 @@ All configuration settings are optional, they are described in detail [here](htt true + true + 2 false diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java index 8620427f79..efa2f533b8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java @@ -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. @@ -44,6 +44,9 @@ public class SortPom implements FormatterStepFactory { @Parameter boolean keepBlankLines = defaultValues.keepBlankLines; + @Parameter + boolean endWithNewline = defaultValues.endWithNewline; + @Parameter int nrOfIndentSpace = defaultValues.nrOfIndentSpace; @@ -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; diff --git a/testlib/src/test/java/com/diffplug/spotless/pom/SortPomTest.java b/testlib/src/test/java/com/diffplug/spotless/pom/SortPomTest.java index c88918f505..5a0ad297c5 100644 --- a/testlib/src/test/java/com/diffplug/spotless/pom/SortPomTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/pom/SortPomTest.java @@ -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. @@ -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"); } From 9dec37ac294f4cc71e2c97b9f50785cb51533fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ekryd?= Date: Tue, 20 Feb 2024 10:41:22 +0100 Subject: [PATCH 2/2] Updated change logs --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 1b21b57858..e86f61a3f6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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)) ### Removed * **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945)) * **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a97304f59b..f5d7558a29 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -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)) ### Added * Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 95661d4ebe..b4f1b42e18 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -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)) ### Added * Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))