Skip to content

Commit 38989da

Browse files
authored
Update for biome 2.x (#2538 fixes #2537)
2 parents 1ed7249 + dc969c1 commit 38989da

File tree

22 files changed

+236
-234
lines changed

22 files changed

+236
-234
lines changed

CHANGES.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1414
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020), [#2535](https://github.com/diffplug/spotless/pull/2535))
1515
* Add support for removing wildcard imports via `removeWildcardImports` step. ([#2517](https://github.com/diffplug/spotless/pull/2517))
1616
* Use `palantir-java-format` as default formatter in `RemoveUnusedImportsStep`. ([#2541](https://github.com/diffplug/spotless/pull/2541))
17-
17+
* scalafmt: enforce version consistency between the version configured in Spotless and the version declared in Scalafmt config file ([#2460](https://github.com/diffplug/spotless/issues/2460))
1818
### Fixed
19+
* Fix biome formatter for new major release 2.x of biome ([#2537](https://github.com/diffplug/spotless/pull/2537))
1920
* Make sure npm-based formatters use the correct `node_modules` directory when running in parallel. ([#2542](https://github.com/diffplug/spotless/pull/2542))
20-
2121
### Changed
2222
* Bump internal dependencies for npm-based formatters ([#2542](https://github.com/diffplug/spotless/pull/2542))
2323

24-
### Changed
25-
* scalafmt: enforce version consistency between the version configured in Spotless and the version declared in Scalafmt config file ([#2460](https://github.com/diffplug/spotless/issues/2460))
26-
2724
## [3.1.2] - 2025-05-27
2825
### Fixed
2926
* Fix `UnsupportedOperationException` in the Gradle plugin when using `targetExcludeContent[Pattern]` ([#2487](https://github.com/diffplug/spotless/pull/2487))

lib/src/main/java/com/diffplug/spotless/biome/BiomeExecutableDownloader.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 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.
@@ -71,17 +71,13 @@ final class BiomeExecutableDownloader {
7171

7272
private final Path downloadDir;
7373

74-
private final BiomeFlavor flavor;
75-
7674
/**
7775
* Creates a new downloader for the Biome executable. The executable files are
7876
* stored in the given download directory.
7977
*
80-
* @param flavor Flavor of Biome to use.
8178
* @param downloadDir Directory where to store the downloaded executable.
8279
*/
83-
public BiomeExecutableDownloader(BiomeFlavor flavor, Path downloadDir) {
84-
this.flavor = flavor;
80+
public BiomeExecutableDownloader(Path downloadDir) {
8581
this.downloadDir = downloadDir;
8682
}
8783

@@ -240,7 +236,7 @@ private String computeChecksum(Path file, String algorithm) throws IOException {
240236
* Finds the code name for the given operating system used by the Biome
241237
* executable download URL.
242238
*
243-
* @param os Desired operating system.
239+
* @param architecture Desired operating system architecture.
244240
* @return Code name for the Biome download URL.
245241
* @throws IOException When the given OS is not supported by Biome.
246242
*/
@@ -282,7 +278,7 @@ private String getDownloadUrl(String version, Platform platform) throws IOExcept
282278
var architectureCodeName = getArchitectureCodeName(platform.getArchitecture());
283279
var extension = getDownloadUrlExtension(platform.getOs());
284280
var platformString = String.format(PLATFORM_PATTERN, osCodeName, architectureCodeName, extension);
285-
return String.format(flavor.getUrlPattern(), version, platformString);
281+
return String.format(BiomeSettings.getUrlPattern(version), version, platformString);
286282
}
287283

288284
/**
@@ -317,7 +313,7 @@ private String getDownloadUrlExtension(OS os) throws IOException {
317313
private Path getExecutablePath(String version, Platform platform) {
318314
var os = platform.getOs().name().toLowerCase(Locale.ROOT);
319315
var arch = platform.getArchitecture().name().toLowerCase(Locale.ROOT);
320-
var fileName = String.format(flavor.getDownloadFilePattern(), os, arch, version);
316+
var fileName = String.format(BiomeSettings.getDownloadFilePattern(), os, arch, version);
321317
return downloadDir.resolve(fileName);
322318
}
323319

lib/src/main/java/com/diffplug/spotless/biome/BiomeFlavor.java

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2023-2025 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.biome;
17+
18+
/**
19+
* Settings and constants for Biome to use.
20+
*/
21+
public final class BiomeSettings {
22+
private final static String CONFIG_NAME = "biome.json";
23+
private final static String DEFAULT_VERSION = "1.2.0";
24+
private final static String DOWNLOAD_FILE_PATTERN = "biome-%s-%s-%s";
25+
private final static String SHORT_NAME = "biome";
26+
private final static String URL_PATTERN_1X = "https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s";
27+
private final static String URL_PATTERN_2X = "https://github.com/biomejs/biome/releases/download/%%40biomejs%%2Fbiome%%40%s/biome-%s";
28+
29+
private BiomeSettings() {}
30+
31+
/**
32+
* @return The name of the default config file.
33+
*/
34+
public static String configName() {
35+
return CONFIG_NAME;
36+
}
37+
38+
/**
39+
* @return Default version to use when no version was set explicitly.
40+
*/
41+
public static String defaultVersion() {
42+
return DEFAULT_VERSION;
43+
}
44+
45+
/**
46+
* @return The pattern for {@link String#format(String, Object...)
47+
* String.format()} for the file name of a Biome executable for a
48+
* certain version and architecture. The first parameter is the platform,
49+
* the second is the OS, the third is the architecture.
50+
*/
51+
public static String getDownloadFilePattern() {
52+
return DOWNLOAD_FILE_PATTERN;
53+
}
54+
55+
/**
56+
* @param version The biome version for which to get the URL pattern, e.g. 1.2.0 or 2.0.6.
57+
* @return The pattern for {@link String#format(String, Object...)
58+
* String.format()} for the URL where the executables can be downloaded.
59+
* The first parameter is the version, the second parameter is the OS /
60+
* platform.
61+
*/
62+
public static String getUrlPattern(String version) {
63+
if (version != null && version.startsWith("1.")) {
64+
return URL_PATTERN_1X;
65+
}
66+
return URL_PATTERN_2X;
67+
}
68+
69+
/**
70+
* @return The short name of this flavor, e.g. <code>biome</code>.
71+
*/
72+
public static String shortName() {
73+
return SHORT_NAME;
74+
}
75+
}

lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 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.
@@ -72,12 +72,6 @@ public class BiomeStep {
7272
*/
7373
private String language;
7474

75-
/**
76-
* Biome flavor to use. Will be removed once we stop supporting the deprecated Rome project.
77-
*/
78-
@Deprecated
79-
private final BiomeFlavor flavor;
80-
8175
/**
8276
* Path to the Biome executable. Can be <code>null</code>, but either a path to
8377
* the executable of a download directory and version must be given. The path
@@ -103,32 +97,30 @@ public class BiomeStep {
10397
* @return The name of this format step, i.e. <code>biome</code> or <code>rome</code>.
10498
*/
10599
public String name() {
106-
return flavor.shortName();
100+
return BiomeSettings.shortName();
107101
}
108102

109103
/**
110104
* Creates a Biome step that format code by downloading to the given Biome
111105
* version. The executable is downloaded from the network.
112106
*
113-
* @param flavor Flavor of Biome to use.
114107
* @param version Version of the Biome executable to download.
115108
* @param downloadDir Directory where to place the downloaded executable.
116109
* @return A new Biome step that download the executable from the network.
117110
*/
118-
public static BiomeStep withExeDownload(BiomeFlavor flavor, String version, String downloadDir) {
119-
return new BiomeStep(flavor, version, null, downloadDir);
111+
public static BiomeStep withExeDownload(String version, String downloadDir) {
112+
return new BiomeStep(version, null, downloadDir);
120113
}
121114

122115
/**
123116
* Creates a Biome step that formats code by delegating to the Biome executable
124117
* located at the given path.
125118
*
126-
* @param flavor Flavor of Biome to use.
127119
* @param pathToExe Path to the Biome executable to use.
128120
* @return A new Biome step that format with the given executable.
129121
*/
130-
public static BiomeStep withExePath(BiomeFlavor flavor, String pathToExe) {
131-
return new BiomeStep(flavor, null, pathToExe, null);
122+
public static BiomeStep withExePath(String pathToExe) {
123+
return new BiomeStep(null, pathToExe, null);
132124
}
133125

134126
/**
@@ -156,8 +148,8 @@ private static void attemptToAddPosixPermission(Path file, PosixFilePermission p
156148
*
157149
* @return The default version for Biome.
158150
*/
159-
private static String defaultVersion(BiomeFlavor flavor) {
160-
return flavor.defaultVersion();
151+
private static String defaultVersion() {
152+
return BiomeSettings.defaultVersion();
161153
}
162154

163155
/**
@@ -200,12 +192,12 @@ private static String resolveNameAgainstPath(String name) throws IOException, In
200192
* Checks the Biome config path. When the config path does not exist or when it
201193
* does not contain a file named {@code biome.json}, an error is thrown.
202194
*/
203-
private static void validateBiomeConfigPath(BiomeFlavor flavor, String configPath) {
195+
private static void validateBiomeConfigPath(String configPath) {
204196
if (configPath == null) {
205197
return;
206198
}
207199
var path = Paths.get(configPath);
208-
var config = path.resolve(flavor.configName());
200+
var config = path.resolve(BiomeSettings.configName());
209201
if (!Files.exists(path)) {
210202
throw new IllegalArgumentException("Biome config directory does not exist: " + path);
211203
}
@@ -227,14 +219,12 @@ private static void validateBiomeExecutable(String resolvedPathToExe) {
227219
/**
228220
* Creates a new Biome step with the configuration from the given builder.
229221
*
230-
* @param flavor Flavor of Biome to use.
231222
* @param version Version of the Biome executable to download.
232223
* @param pathToExe Path to the Biome executable to use.
233224
* @param downloadDir Directory where to place the downloaded executable.
234225
*/
235-
private BiomeStep(BiomeFlavor flavor, String version, String pathToExe, String downloadDir) {
236-
this.flavor = flavor;
237-
this.version = version != null && !version.isBlank() ? version : defaultVersion(flavor);
226+
private BiomeStep(String version, String pathToExe, String downloadDir) {
227+
this.version = version != null && !version.isBlank() ? version : defaultVersion();
238228
this.pathToExe = pathToExe;
239229
this.downloadDir = downloadDir;
240230
}
@@ -306,7 +296,7 @@ public BiomeStep withLanguage(String language) {
306296
private State createState() throws IOException, InterruptedException {
307297
var resolvedPathToExe = resolveExe();
308298
validateBiomeExecutable(resolvedPathToExe);
309-
validateBiomeConfigPath(flavor, configPath);
299+
validateBiomeConfigPath(configPath);
310300
logger.debug("Using Biome executable located at '{}'", resolvedPathToExe);
311301
var exeSignature = FileSignature.signAsList(Collections.singleton(new File(resolvedPathToExe)));
312302
makeExecutable(resolvedPathToExe);
@@ -337,7 +327,7 @@ private String resolveExe() throws IOException, InterruptedException {
337327
return pathToExe;
338328
}
339329
} else {
340-
var downloader = new BiomeExecutableDownloader(flavor, Paths.get(downloadDir));
330+
var downloader = new BiomeExecutableDownloader(Paths.get(downloadDir));
341331
var downloaded = downloader.ensureDownloaded(version).toString();
342332
makeExecutable(downloaded);
343333
return downloaded;

plugin-gradle/CHANGES.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
66
### Added
77
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020), [#2535](https://github.com/diffplug/spotless/pull/2535))
88
* Add support for removing wildcard imports via `removeWildcardImports` step. ([#2517](https://github.com/diffplug/spotless/pull/2517))
9-
109
### Fixed
10+
* Fix biome formatter for new major release 2.x of biome ([#2537](https://github.com/diffplug/spotless/pull/2537))
1111
* Make sure npm-based formatters use the correct `node_modules` directory when running in parallel. ([#2542](https://github.com/diffplug/spotless/pull/2542))
12-
1312
### Changed
14-
* Bump internal dependencies for npm-based formatters ([#2542](https://github.com/diffplug/spotless/pull/2542))\
13+
* Bump internal dependencies for npm-based formatters ([#2542](https://github.com/diffplug/spotless/pull/2542))
1514

1615
### Changed
1716
* scalafmt: enforce version consistency between the version configured in Spotless and the version declared in Scalafmt config file ([#2460](https://github.com/diffplug/spotless/issues/2460))

0 commit comments

Comments
 (0)