Skip to content

Commit bebeed3

Browse files
authored
Merge branch 'main' into renovate/com.google.googlejavaformat-google-java-format-1.x
2 parents 574b260 + c326efd commit bebeed3

File tree

14 files changed

+222
-13
lines changed

14 files changed

+222
-13
lines changed

CHANGES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Added
1414
* Support for `rdf` ([#2261](https://github.com/diffplug/spotless/pull/2261))
15+
* Support for `buf` on maven plugin ([#2291](https://github.com/diffplug/spotless/pull/2291))
1516
### Changed
1617
* Support configuring the Equo P2 cache. ([#2238](https://github.com/diffplug/spotless/pull/2238))
1718
* Add explicit support for JSONC / CSS via biome, via the file extensions `.css` and `.jsonc`.
1819
([#2259](https://github.com/diffplug/spotless/pull/2259))
19-
* Bump default `jackson` version to latest `2.17.2` -> `2.18.0`. ([#2279](https://github.com/diffplug/spotless/pull/2279))
20+
* Bump default `buf` version to latest `1.24.0` -> `1.44.0`. ([#2291](https://github.com/diffplug/spotless/pull/2291))
2021
* Bump default `google-java-format` version to latest `1.23.0` -> `1.24.0`. ([#2294](https://github.com/diffplug/spotless/pull/2294))
22+
* Bump default `jackson` version to latest `2.17.2` -> `2.18.0`. ([#2279](https://github.com/diffplug/spotless/pull/2279))
23+
### Fixed
24+
* Java import order, ignore duplicate group entries. ([#2293](https://github.com/diffplug/spotless/pull/2293))
2125

2226
## [3.0.0.BETA2] - 2024-08-25
2327
### Changed

lib-extra/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = rootProject.spotlessChangelog.versionNext
77
apply from: rootProject.file('gradle/java-setup.gradle')
88
apply from: rootProject.file('gradle/java-publish.gradle')
99

10-
String VER_SOLSTICE = '1.7.7'
10+
String VER_SOLSTICE = '1.8.0'
1111
dependencies {
1212
api projects.lib
1313
// misc useful utilities

lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public FormatterStep build() {
116116
}
117117
var classpath = new ArrayList<File>();
118118
var mavenDeps = new ArrayList<String>();
119-
mavenDeps.add("dev.equo.ide:solstice:1.7.7");
119+
mavenDeps.add("dev.equo.ide:solstice:1.8.0");
120120
mavenDeps.add("com.diffplug.durian:durian-swt.os:4.2.0");
121121
mavenDeps.addAll(query.getJarsOnMavenCentral());
122122
classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps));

lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-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.
@@ -33,6 +33,7 @@ final class ImportSorterImpl {
3333
private static final String SUBGROUP_SEPARATOR = "|";
3434

3535
private final List<ImportsGroup> importsGroups;
36+
private final Set<String> knownGroupings = new HashSet<>();
3637
private final Map<String, List<String>> matchingImports = new HashMap<>();
3738
private final List<String> notMatching = new ArrayList<>();
3839
private final Set<String> allImportOrderItems = new HashSet<>();
@@ -44,10 +45,12 @@ private static class ImportsGroup {
4445

4546
private final List<String> subGroups;
4647

47-
public ImportsGroup(String importOrder) {
48+
public ImportsGroup(String importOrder, Set<String> knownGroupings) {
4849
this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR, -1))
4950
.map(this::normalizeStatic)
51+
.filter(group -> !knownGroupings.contains(group))
5052
.collect(Collectors.toList());
53+
knownGroupings.addAll(this.subGroups);
5154
}
5255

5356
private String normalizeStatic(String subgroup) {
@@ -80,7 +83,7 @@ private List<String> sort(List<String> imports, String lineFormat) {
8083

8184
private ImportSorterImpl(List<String> importOrder, boolean wildcardsLast, boolean semanticSort,
8285
Set<String> treatAsPackage, Set<String> treatAsClass) {
83-
importsGroups = importOrder.stream().filter(Objects::nonNull).map(ImportsGroup::new).collect(Collectors.toList());
86+
importsGroups = importOrder.stream().filter(Objects::nonNull).map(order -> new ImportsGroup(order, knownGroupings)).collect(Collectors.toList());
8487
putStaticItemIfNotExists(importsGroups);
8588
putCatchAllGroupIfNotExists(importsGroups);
8689

@@ -107,13 +110,13 @@ private void putStaticItemIfNotExists(List<ImportsGroup> importsGroups) {
107110
indexOfFirstStatic = i;
108111
}
109112
}
110-
importsGroups.add(indexOfFirstStatic, new ImportsGroup(STATIC_KEYWORD));
113+
importsGroups.add(indexOfFirstStatic, new ImportsGroup(STATIC_KEYWORD, this.knownGroupings));
111114
}
112115

113116
private void putCatchAllGroupIfNotExists(List<ImportsGroup> importsGroups) {
114117
boolean catchAllSubGroupExist = importsGroups.stream().anyMatch(group -> group.getSubGroups().contains(CATCH_ALL_SUBGROUP));
115118
if (!catchAllSubGroupExist) {
116-
importsGroups.add(new ImportsGroup(CATCH_ALL_SUBGROUP));
119+
importsGroups.add(new ImportsGroup(CATCH_ALL_SUBGROUP, this.knownGroupings));
117120
}
118121
}
119122

lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static String name() {
3838
}
3939

4040
public static String defaultVersion() {
41-
return "1.24.0";
41+
return "1.44.0";
4242
}
4343

4444
private final String version;

plugin-gradle/CHANGES.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Added
67
### Changed
78
* Use the Gradle user home directory by default for the download directory for the biome executable. Previously, the
89
plugin tried to use Maven's home directory, which is not always accessible by a Gradle plugin. ([#2187](https://github.com/diffplug/spotless/issues/2187))
910
* Add explicit support for CSS via biome. Formatting CSS via biome was already supported as a general
1011
formatting step. Biome supports formatting CSS as of 1.8.0 (experimental, opt-in) and 1.9.0 (stable).
1112
([#2259](https://github.com/diffplug/spotless/pull/2259))
12-
* Bump default `jackson` version to latest `2.17.2` -> `2.18.0`. ([#2279](https://github.com/diffplug/spotless/pull/2279))
13+
### Changed
14+
* Bump default `buf` version to latest `1.24.0` -> `1.44.0`. ([#2291](https://github.com/diffplug/spotless/pull/2291))
1315
* Bump default `google-java-format` version to latest `1.23.0` -> `1.24.0`. ([#2294](https://github.com/diffplug/spotless/pull/2294))
16+
* Bump default `jackson` version to latest `2.17.2` -> `2.18.0`. ([#2279](https://github.com/diffplug/spotless/pull/2279))
17+
### Fixed
18+
* Java import order, ignore duplicate group entries. ([#2293](https://github.com/diffplug/spotless/pull/2293))
1419

1520
## [7.0.0.BETA2] - 2024-08-25
1621
### Changed

plugin-maven/CHANGES.md

Lines changed: 4 additions & 1 deletion
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
### Added
77
* Support for `rdf` ([#2261](https://github.com/diffplug/spotless/pull/2261))
8+
* Support for `buf` ([#2291](https://github.com/diffplug/spotless/pull/2291))
89
### Changed
910
* Leverage local repository for Equo P2 cache. ([#2238](https://github.com/diffplug/spotless/pull/2238))
1011
* Add explicit support for CSS via biome. Formatting CSS via biome was already supported as a general
1112
formatting step. Biome supports formatting CSS as of 1.8.0 (experimental, opt-in) and 1.9.0 (stable).
1213
([#2259](https://github.com/diffplug/spotless/pull/2259))
13-
* Bump default `jackson` version to latest `2.17.2` -> `2.18.0`. ([#2279](https://github.com/diffplug/spotless/pull/2279))
1414
* Bump default `google-java-format` version to latest `1.23.0` -> `1.24.0`. ([#2294](https://github.com/diffplug/spotless/pull/2294))
15+
* Bump default `jackson` version to latest `2.17.2` -> `2.18.0`. ([#2279](https://github.com/diffplug/spotless/pull/2279))
16+
### Fixed
17+
* Java import order, ignore duplicate group entries. ([#2293](https://github.com/diffplug/spotless/pull/2293))
1518

1619
## [2.44.0.BETA2] - 2024-08-25
1720
### Changed

plugin-maven/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ user@machine repo % mvn spotless:check
5656
- [Gherkin](#gherkin)
5757
- [Go](#go)
5858
- [RDF](#RDF)
59+
- [Protobuf](#protobuf) ([buf](#buf))
5960
- Multiple languages
6061
- [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection), [caching `npm install` results](#caching-results-of-npm-install))
6162
- [eclipse web tools platform](#eclipse-web-tools-platform)
@@ -1177,6 +1178,36 @@ Configuring some generic and TTL options:
11771178
RDF parsing is done via [Apache Jena](https://jena.apache.org/) in the version that
11781179
[turtle-formatter](https://github.com/atextor/turtle-formatter) depends on (not necessarily the latest).
11791180

1181+
## Protobuf
1182+
1183+
[code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/protobuf/Protobuf.java). [available steps](https://github.com/diffplug/spotless/tree/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/protobuf).
1184+
```xml
1185+
<configuration>
1186+
<includes> <!-- optiona: default is **/*.proto -->
1187+
<include>proto/*.proto<include>
1188+
<includes>
1189+
1190+
<excludes> <!-- optiona: if you want to ignore auto generated protos -->
1191+
<include>target/**/<include>
1192+
<excludes>
1193+
1194+
<protobuf>
1195+
<buf /> <!-- has its own section below -->
1196+
</css>
1197+
</configuration>
1198+
```
1199+
1200+
### buf
1201+
1202+
[homepage](https://buf.build/) [buf repo](https://github.com/bufbuild/buf).
1203+
```xml
1204+
<buf>
1205+
<version>1.44.0</version> <!-- optional -->
1206+
<pathToExe>/path/to/buf</pathToExe> <!-- optional: if buf isn't in your path -->
1207+
</buf>
1208+
```
1209+
1210+
11801211
## CSS
11811212

11821213
[code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/css/Css.java). [available steps](https://github.com/diffplug/spotless/tree/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/css).

plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import com.diffplug.spotless.maven.kotlin.Kotlin;
7474
import com.diffplug.spotless.maven.markdown.Markdown;
7575
import com.diffplug.spotless.maven.pom.Pom;
76+
import com.diffplug.spotless.maven.protobuf.Protobuf;
7677
import com.diffplug.spotless.maven.python.Python;
7778
import com.diffplug.spotless.maven.rdf.Rdf;
7879
import com.diffplug.spotless.maven.scala.Scala;
@@ -200,6 +201,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
200201
@Parameter
201202
private Rdf rdf;
202203

204+
@Parameter
205+
private Protobuf protobuf;
206+
203207
@Parameter(property = "spotlessFiles")
204208
private String filePatterns;
205209

@@ -385,7 +389,7 @@ private FileLocator getFileLocator() {
385389
}
386390

387391
private List<FormatterFactory> getFormatterFactories() {
388-
return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, css, typescript, javascript, antlr4, pom, sql, python, markdown, json, shell, yaml, gherkin, go, rdf))
392+
return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, css, typescript, javascript, antlr4, pom, sql, python, markdown, json, shell, yaml, gherkin, go, rdf, protobuf))
389393
.filter(Objects::nonNull)
390394
.map(factory -> factory.init(repositorySystemSession))
391395
.collect(toList());
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2016-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.spotless.maven.protobuf;
17+
18+
import org.apache.maven.plugins.annotations.Parameter;
19+
20+
import com.diffplug.spotless.FormatterStep;
21+
import com.diffplug.spotless.maven.FormatterStepConfig;
22+
import com.diffplug.spotless.maven.FormatterStepFactory;
23+
import com.diffplug.spotless.protobuf.BufStep;
24+
25+
public class Buf implements FormatterStepFactory {
26+
27+
@Parameter
28+
private String version;
29+
30+
@Parameter
31+
private String pathToExe;
32+
33+
@Override
34+
public FormatterStep newFormatterStep(FormatterStepConfig config) {
35+
BufStep buf = BufStep.withVersion(version == null ? BufStep.defaultVersion() : version);
36+
37+
if (pathToExe != null) {
38+
buf = buf.withPathToExe(pathToExe);
39+
}
40+
41+
return buf.create();
42+
}
43+
44+
}

0 commit comments

Comments
 (0)