Skip to content

Commit f975457

Browse files
authored
Merge branch 'main' into ktlint-120
2 parents fc6c711 + bceba42 commit f975457

File tree

15 files changed

+357
-12
lines changed

15 files changed

+357
-12
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1818
* Bump default `sortpom` version to latest `3.2.1` -> `3.4.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049))
1919
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
2020
* Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057))
21+
* Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078))
2122
### Removed
2223
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))
2324
* **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954))

PULL_REQUEST_TEMPLATE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Please **DO NOT FORCE PUSH**. Don't worry about messy history, it's easier to do code review if we can tell what happened after the review, and force pushing breaks that.
22

3-
Please make sure that your [PR allows edits from maintainers](https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/). Sometimes its faster for us to just fix something than it is to describe how to fix it.
3+
Please make sure that your [PR allows edits from maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork). Sometimes it's faster for us to just fix something than it is to describe how to fix it.
44

5-
![Allow edits from maintainers](https://help.github.com/assets/images/help/pull_requests/allow-maintainers-to-make-edits-sidebar-checkbox.png)
5+
<img src="https://docs.github.com/assets/cb-87454/images/help/pull_requests/allow-edits-and-access-by-maintainers.png" height="297" alt="Allow edits from maintainers">
66

77
After creating the PR, please add a commit that adds a bullet-point under the `[Unreleased]` section of [CHANGES.md](https://github.com/diffplug/spotless/blob/main/CHANGES.md), [plugin-gradle/CHANGES.md](https://github.com/diffplug/spotless/blob/main/plugin-gradle/CHANGES.md), and [plugin-maven/CHANGES.md](https://github.com/diffplug/spotless/blob/main/plugin-maven/CHANGES.md) which includes:
88

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ lib('markdown.FlexmarkStep') +'{{yes}} | {{yes}}
100100
lib('npm.EslintFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
101101
lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
102102
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
103-
lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
103+
lib('pom.SortPomStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
104104
lib('protobuf.BufStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
105105
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
106106
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
@@ -154,7 +154,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
154154
| [`npm.EslintFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
155155
| [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
156156
| [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
157-
| [`pom.SortPomStepStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStepStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
157+
| [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
158158
| [`protobuf.BufStep`](lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
159159
| [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
160160
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: |

lib/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ 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.4.0'
131+
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.4.1'
132132
sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.12'
133133
// zjsonPatch
134134
zjsonPatchCompileOnly 'com.flipkart.zjsonpatch:zjsonpatch:0.4.14'

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
public class SortPomCfg implements Serializable {
2222
private static final long serialVersionUID = 1L;
2323

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

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

plugin-gradle/CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
55
## [Unreleased]
66
### Fixed
77
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
8+
* Fixed memory leak introduced in 6.21.0 ([#2067](https://github.com/diffplug/spotless/issues/2067))
89
### Changes
910
* Bump default `ktfmt` version to latest `0.46` -> `0.47`. ([#2045](https://github.com/diffplug/spotless/pull/2045))
1011
* Bump default `sortpom` version to latest `3.2.1` -> `3.4.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049))
1112
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
1213
* Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057))
14+
* Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078))
1315
### Added
1416
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
17+
* Add support for formatting and sorting Maven POMs ([#2082](https://github.com/diffplug/spotless/issues/2082))
1518

1619
## [6.25.0] - 2024-01-23
1720
### Added

plugin-gradle/README.md

+47-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
6565
- [Flexmark](#flexmark) aka markdown
6666
- [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter))
6767
- [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier))
68+
- [Maven POM](#maven-pom) ([sortPom](#sortpom))
6869
- [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Biome](#biome))
6970
- [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Biome](#biome))
7071
- [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [Biome](#biome), [jsonPatch](#jsonPatch))
@@ -676,6 +677,52 @@ sql.formatter.indent.type=space
676677
sql.formatter.indent.size=4
677678
```
678679
680+
## Maven POM
681+
682+
`com.diffplug.gradle.spotless.PomExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.25.0/com/diffplug/gradle/spotless/PomExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PomExtension.java)
683+
684+
```gradle
685+
spotless {
686+
pom {
687+
target('pom.xml') // default value, you can change if you want
688+
689+
sortPom() // has its own section below
690+
}
691+
}
692+
```
693+
694+
### sortPom
695+
696+
[homepage](https://github.com/Ekryd/sortpom).
697+
698+
All configuration settings are optional, they are described in detail [here](https://github.com/Ekryd/sortpom/wiki/Parameters).
699+
700+
```gradle
701+
spotless {
702+
pom {
703+
sortPom('3.4.0')
704+
.encoding('UTF-8') // The encoding of the pom files
705+
.lineSeparator(System.getProperty('line.separator')) // line separator to use
706+
.expandEmptyElements(true) // Should empty elements be expanded
707+
.spaceBeforeCloseEmptyElement(false) // Should a space be added inside self-closing elements
708+
.keepBlankLines(true) // Keep empty lines
709+
.endWithNewline(true) // Whether sorted pom ends with a newline
710+
.nrOfIndentSpace(2) // Indentation
711+
.indentBlankLines(false) // Should empty lines be indented
712+
.indentSchemaLocation(false) // Should schema locations be indented
713+
.predefinedSortOrder('recommended_2008_06') // Sort order of elements: https://github.com/Ekryd/sortpom/wiki/PredefinedSortOrderProfiles
714+
.sortOrderFile(null) // Custom sort order of elements: https://raw.githubusercontent.com/Ekryd/sortpom/master/sorter/src/main/resources/custom_1.xml
715+
.sortDependencies(null) // Sort dependencies: https://github.com/Ekryd/sortpom/wiki/SortDependencies
716+
.sortDependencyManagement(null) // Sort dependency management: https://github.com/Ekryd/sortpom/wiki/SortDependencies
717+
.sortDependencyExclusions(null) // Sort dependency exclusions: https://github.com/Ekryd/sortpom/wiki/SortDependencies
718+
.sortPlugins(null) // Sort plugins: https://github.com/Ekryd/sortpom/wiki/SortPlugins
719+
.sortProperties(false) // Sort properties
720+
.sortModules(false) // Sort modules
721+
.sortExecutions(false) // Sort plugin executions
722+
}
723+
}
724+
```
725+
679726
<a name="applying-to-typescript-source"></a>
680727
681728
## Typescript
@@ -799,8 +846,6 @@ hence you are required to provide resolvable file paths for config files, or alt
799846
The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. In javascript, *no*
800847
`tsconfig.json` is supported.
801848
802-
```gradle
803-
804849
```gradle
805850
spotless {
806851
javascript {

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,9 @@ protected void setupTask(SpotlessTask task) {
10671067
}
10681068
task.setSteps(steps);
10691069
Directory projectDir = getProject().getLayout().getProjectDirectory();
1070+
LineEnding lineEndings = getLineEndings();
10701071
task.setLineEndingsPolicy(
1071-
getProject().provider(() -> getLineEndings().createPolicy(projectDir.getAsFile(), () -> totalTarget)));
1072+
getProject().provider(() -> lineEndings.createPolicy(projectDir.getAsFile(), () -> totalTarget)));
10721073
spotless.getRegisterDependenciesTask().hookSubprojectTask(task);
10731074
task.setupRatchet(getRatchetFrom() != null ? getRatchetFrom() : "");
10741075
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Copyright 2024 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless;
17+
18+
import java.util.Objects;
19+
20+
import javax.inject.Inject;
21+
22+
import com.diffplug.spotless.FormatterStep;
23+
import com.diffplug.spotless.pom.SortPomCfg;
24+
import com.diffplug.spotless.pom.SortPomStep;
25+
26+
public class PomExtension extends FormatExtension {
27+
private static final String POM_FILE = "pom.xml";
28+
29+
static final String NAME = "pom";
30+
31+
@Inject
32+
public PomExtension(SpotlessExtension spotless) {
33+
super(spotless);
34+
}
35+
36+
@Override
37+
protected void setupTask(SpotlessTask task) {
38+
if (target == null) {
39+
target = parseTarget(POM_FILE);
40+
}
41+
super.setupTask(task);
42+
}
43+
44+
public SortPomGradleConfig sortPom() {
45+
return new SortPomGradleConfig();
46+
}
47+
48+
public SortPomGradleConfig sortPom(String version) {
49+
Objects.requireNonNull(version);
50+
return new SortPomGradleConfig(version);
51+
}
52+
53+
public class SortPomGradleConfig {
54+
private final SortPomCfg cfg = new SortPomCfg();
55+
56+
SortPomGradleConfig() {
57+
addStep(createStep());
58+
}
59+
60+
SortPomGradleConfig(String version) {
61+
this();
62+
cfg.version = Objects.requireNonNull(version);
63+
}
64+
65+
public SortPomGradleConfig encoding(String encoding) {
66+
cfg.encoding = encoding;
67+
return this;
68+
}
69+
70+
public SortPomGradleConfig lineSeparator(String lineSeparator) {
71+
cfg.lineSeparator = lineSeparator;
72+
return this;
73+
}
74+
75+
public SortPomGradleConfig expandEmptyElements(boolean expandEmptyElements) {
76+
cfg.expandEmptyElements = expandEmptyElements;
77+
return this;
78+
}
79+
80+
public SortPomGradleConfig spaceBeforeCloseEmptyElement(boolean spaceBeforeCloseEmptyElement) {
81+
cfg.spaceBeforeCloseEmptyElement = spaceBeforeCloseEmptyElement;
82+
return this;
83+
}
84+
85+
public SortPomGradleConfig keepBlankLines(boolean keepBlankLines) {
86+
cfg.keepBlankLines = keepBlankLines;
87+
return this;
88+
}
89+
90+
public SortPomGradleConfig endWithNewline(boolean endWithNewline) {
91+
cfg.endWithNewline = endWithNewline;
92+
return this;
93+
}
94+
95+
public SortPomGradleConfig nrOfIndentSpace(int nrOfIndentSpace) {
96+
cfg.nrOfIndentSpace = nrOfIndentSpace;
97+
return this;
98+
}
99+
100+
public SortPomGradleConfig indentBlankLines(boolean indentBlankLines) {
101+
cfg.indentBlankLines = indentBlankLines;
102+
return this;
103+
}
104+
105+
public SortPomGradleConfig indentSchemaLocation(boolean indentSchemaLocation) {
106+
cfg.indentSchemaLocation = indentSchemaLocation;
107+
return this;
108+
}
109+
110+
public SortPomGradleConfig predefinedSortOrder(String predefinedSortOrder) {
111+
cfg.predefinedSortOrder = predefinedSortOrder;
112+
return this;
113+
}
114+
115+
public SortPomGradleConfig sortOrderFile(String sortOrderFile) {
116+
cfg.sortOrderFile = sortOrderFile;
117+
return this;
118+
}
119+
120+
public SortPomGradleConfig sortDependencies(String sortDependencies) {
121+
cfg.sortDependencies = sortDependencies;
122+
return this;
123+
}
124+
125+
public SortPomGradleConfig sortDependencyManagement(String sortDependencyManagement) {
126+
cfg.sortDependencyManagement = sortDependencyManagement;
127+
return this;
128+
}
129+
130+
public SortPomGradleConfig sortDependencyExclusions(String sortDependencyExclusions) {
131+
cfg.sortDependencyExclusions = sortDependencyExclusions;
132+
return this;
133+
}
134+
135+
public SortPomGradleConfig sortPlugins(String sortPlugins) {
136+
cfg.sortPlugins = sortPlugins;
137+
return this;
138+
}
139+
140+
public SortPomGradleConfig sortProperties(boolean sortProperties) {
141+
cfg.sortProperties = sortProperties;
142+
return this;
143+
}
144+
145+
public SortPomGradleConfig sortModules(boolean sortModules) {
146+
cfg.sortModules = sortModules;
147+
return this;
148+
}
149+
150+
public SortPomGradleConfig sortExecutions(boolean sortExecutions) {
151+
cfg.sortExecutions = sortExecutions;
152+
return this;
153+
}
154+
155+
private FormatterStep createStep() {
156+
return SortPomStep.create(cfg, provisioner());
157+
}
158+
}
159+
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java

+6
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ public void go(Action<GoExtension> closure) {
228228
format(GoExtension.NAME, GoExtension.class, closure);
229229
}
230230

231+
/** Configures the special POM-specific extension. */
232+
public void pom(Action<PomExtension> closure) {
233+
requireNonNull(closure);
234+
format(PomExtension.NAME, PomExtension.class, closure);
235+
}
236+
231237
/** Configures a custom extension. */
232238
public void format(String name, Action<FormatExtension> closure) {
233239
requireNonNull(name, "name");

0 commit comments

Comments
 (0)