Skip to content

Commit e7f259e

Browse files
author
Björn Ekryd
committed
Updated SortPom from 3.2.1 to 3.4.0 with support for endWithNewline
1 parent 63ff3b3 commit e7f259e

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

lib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ dependencies {
128128
// scalafmt
129129
scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:3.7.3"
130130
// sortPom
131-
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.2.1'
132-
sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0'
131+
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.4.0'
132+
sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.12'
133133
// zjsonPatch
134134
zjsonPatchCompileOnly 'com.flipkart.zjsonpatch:zjsonpatch:0.4.14'
135135
}

lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 DiffPlug
2+
* Copyright 2021-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
2121
public class SortPomCfg implements Serializable {
2222
private static final long serialVersionUID = 1L;
2323

24-
public String version = "3.2.1";
24+
public String version = "3.4.0";
2525

2626
public String encoding = "UTF-8";
2727

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

3434
public boolean keepBlankLines = true;
3535

36+
public boolean endWithNewline = true;
37+
3638
public int nrOfIndentSpace = 2;
3739

3840
public boolean indentBlankLines = false;

lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 DiffPlug
2+
* Copyright 2021-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public String apply(String input) throws Exception {
5050
.setPomFile(pom)
5151
.setFileOutput(false, null, null, false)
5252
.setEncoding(cfg.encoding)
53-
.setFormatting(cfg.lineSeparator, cfg.expandEmptyElements, cfg.spaceBeforeCloseEmptyElement, cfg.keepBlankLines)
53+
.setFormatting(cfg.lineSeparator, cfg.expandEmptyElements, cfg.spaceBeforeCloseEmptyElement, cfg.keepBlankLines, cfg.endWithNewline)
5454
.setIndent(cfg.nrOfIndentSpace, cfg.indentBlankLines, cfg.indentSchemaLocation)
5555
.setSortOrder(cfg.sortOrderFile, cfg.predefinedSortOrder)
5656
.setSortEntities(cfg.sortDependencies, cfg.sortDependencyExclusions, cfg.sortDependencyManagement,

plugin-maven/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ All configuration settings are optional, they are described in detail [here](htt
659659

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

662+
<endWithNewline>true</endWithNewline> <!-- Whether sorted pom ends with a newline -->
663+
662664
<nrOfIndentSpace>2</nrOfIndentSpace> <!-- Indentation -->
663665

664666
<indentBlankLines>false</indentBlankLines> <!-- Should empty lines be indented -->

plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 DiffPlug
2+
* Copyright 2021-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,9 @@ public class SortPom implements FormatterStepFactory {
4444
@Parameter
4545
boolean keepBlankLines = defaultValues.keepBlankLines;
4646

47+
@Parameter
48+
boolean endWithNewline = defaultValues.endWithNewline;
49+
4750
@Parameter
4851
int nrOfIndentSpace = defaultValues.nrOfIndentSpace;
4952

@@ -89,6 +92,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
8992
cfg.expandEmptyElements = expandEmptyElements;
9093
cfg.spaceBeforeCloseEmptyElement = spaceBeforeCloseEmptyElement;
9194
cfg.keepBlankLines = keepBlankLines;
95+
cfg.endWithNewline = endWithNewline;
9296
cfg.nrOfIndentSpace = nrOfIndentSpace;
9397
cfg.indentBlankLines = indentBlankLines;
9498
cfg.indentSchemaLocation = indentSchemaLocation;

testlib/src/test/java/com/diffplug/spotless/pom/SortPomTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 DiffPlug
2+
* Copyright 2021-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,16 +21,16 @@
2121

2222
public class SortPomTest extends ResourceHarness {
2323
@Test
24-
public void testSortPomWithDefaultConfig() throws Exception {
24+
public void testSortPomWithDefaultConfig() {
2525
SortPomCfg cfg = new SortPomCfg();
2626
FormatterStep step = SortPomStep.create(cfg, TestProvisioner.mavenCentral());
2727
StepHarness.forStep(step).testResource("pom/pom_dirty.xml", "pom/pom_clean_default.xml");
2828
}
2929

3030
@Test
31-
public void testSortPomWithVersion() throws Exception {
31+
public void testSortPomWithVersion() {
3232
SortPomCfg cfg = new SortPomCfg();
33-
cfg.version = "3.2.1";
33+
cfg.version = "3.4.0";
3434
FormatterStep step = SortPomStep.create(cfg, TestProvisioner.mavenCentral());
3535
StepHarness.forStep(step).testResource("pom/pom_dirty.xml", "pom/pom_clean_default.xml");
3636
}

0 commit comments

Comments
 (0)