Skip to content

Commit 5d77810

Browse files
authored
Updates for the Rome -> Biome transition (#1817 fixes #1804)
2 parents 87cb4ae + a1b2e82 commit 5d77810

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2272
-706
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1313
### Added
1414
* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).
1515

16+
* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
17+
The configuration is still the same, but you should switch to the new `biome` tag / function and adjust
18+
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).
19+
1620
### Fixed
1721
* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
1822

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}}
101101
lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
102102
lib('protobuf.BufStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
103103
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
104-
lib('rome.RomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
104+
lib('biome.BiomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
105105
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
106106
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
107107
extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
@@ -153,7 +153,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
153153
| [`pom.SortPomStepStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStepStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
154154
| [`protobuf.BufStep`](lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
155155
| [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
156-
| [`rome.RomeStep`](lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
156+
| [`biome.BiomeStep`](lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
157157
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
158158
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
159159
| [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2023 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.rome;
17+
18+
/**
19+
* The flavor of Biome to use. Exists for compatibility reason, may be removed
20+
* shortly.
21+
* <p>
22+
* Will be removed once the old Rome project is not supported anymore.
23+
*/
24+
public enum BiomeFlavor {
25+
/** The new forked Biome project. */
26+
BIOME("biome", "1.2.0", "biome.json", "biome-%s-%s-%s",
27+
"https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s"),
28+
29+
/**
30+
* The old deprecated Rome project.
31+
*
32+
* @deprecated Will be removed once the old Rome project is not supported
33+
* anymore.
34+
*/
35+
@Deprecated
36+
ROME("rome", "12.0.0", "rome.json", "rome-%s-%s-%s",
37+
"https://github.com/rome/tools/releases/download/cli%%2Fv%s/rome-%s");
38+
39+
private final String configName;
40+
private final String defaultVersion;
41+
private final String downloadFilePattern;
42+
private final String shortName;
43+
private final String urlPattern;
44+
45+
BiomeFlavor(String shortName, String defaultVersion, String configName, String downloadFilePattern,
46+
String urlPattern) {
47+
this.shortName = shortName;
48+
this.defaultVersion = defaultVersion;
49+
this.configName = configName;
50+
this.downloadFilePattern = downloadFilePattern;
51+
this.urlPattern = urlPattern;
52+
}
53+
54+
/**
55+
* @return The name of the default config file.
56+
*/
57+
public String configName() {
58+
return configName;
59+
}
60+
61+
/**
62+
* @return Default version to use when no version was set explicitly.
63+
*/
64+
public String defaultVersion() {
65+
return defaultVersion;
66+
}
67+
68+
/**
69+
* @return The pattern for {@link String#format(String, Object...)
70+
* String.format()} for the file name of a Biome executable for a
71+
* certain version and architecure. The first parameter is the platform,
72+
* the second is the OS, the third is the architecture.
73+
*/
74+
public String getDownloadFilePattern() {
75+
return downloadFilePattern;
76+
}
77+
78+
/**
79+
* @return The pattern for {@link String#format(String, Object...)
80+
* String.format()} for the URL where the executables can be downloaded.
81+
* The first parameter is the version, the second parameter is the OS /
82+
* platform.
83+
*/
84+
public String getUrlPattern() {
85+
return urlPattern;
86+
}
87+
88+
/**
89+
* @return The short name of this flavor, i.e. <code>rome</code> or
90+
* <code>biome</code>.
91+
*/
92+
public String shortName() {
93+
return shortName;
94+
}
95+
}

lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
import org.slf4j.LoggerFactory;
3939

4040
/**
41-
* Downloader for the Rome executable:
42-
* <a href="https://github.com/rome/tools">https://github.com/rome/tools</a>.
41+
* Downloader for the Biome executable:
42+
* <a href="https://github.com/biomejs/biome">https://github.com/biomejs/biome</a>.
4343
*/
4444
final class RomeExecutableDownloader {
4545
private static final Logger logger = LoggerFactory.getLogger(RomeExecutableDownloader.class);
@@ -51,15 +51,7 @@ final class RomeExecutableDownloader {
5151

5252
/**
5353
* The pattern for {@link String#format(String, Object...) String.format()} for
54-
* the file name of a Rome executable for a certain version and architecure. The
55-
* first parameter is the platform, the second is the OS, the third is the
56-
* architecture.
57-
*/
58-
private static final String DOWNLOAD_FILE_PATTERN = "rome-%s-%s-%s";
59-
60-
/**
61-
* The pattern for {@link String#format(String, Object...) String.format()} for
62-
* the platform part of the Rome executable download URL. First parameter is the
54+
* the platform part of the Biome executable download URL. First parameter is the
6355
* OS, second parameter the architecture, the third the file extension.
6456
*/
6557
private static final String PLATFORM_PATTERN = "%s-%s%s";
@@ -70,39 +62,36 @@ final class RomeExecutableDownloader {
7062
*/
7163
private static final OpenOption[] READ_OPTIONS = {StandardOpenOption.READ};
7264

73-
/**
74-
* The pattern for {@link String#format(String, Object...) String.format()} for
75-
* the URL where the Rome executables can be downloaded. The first parameter is
76-
* the version, the second parameter is the OS / platform.
77-
*/
78-
private static final String URL_PATTERN = "https://github.com/rome/tools/releases/download/cli%%2Fv%s/rome-%s";
79-
8065
/**
8166
* {@link OpenOption Open options} for creating a new file, overwriting the
8267
* existing file if present.
8368
*/
8469
private static final OpenOption[] WRITE_OPTIONS = {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING,
8570
StandardOpenOption.WRITE};
8671

87-
private Path downloadDir;
72+
private final Path downloadDir;
73+
74+
private final BiomeFlavor flavor;
8875

8976
/**
90-
* Creates a new downloader for the Rome executable. The executable files are
77+
* Creates a new downloader for the Biome executable. The executable files are
9178
* stored in the given download directory.
9279
*
93-
* @param downloadDir Directory where
80+
* @param flavor Flavor of Biome to use.
81+
* @param downloadDir Directory where to store the downloaded executable.
9482
*/
95-
public RomeExecutableDownloader(Path downloadDir) {
83+
public RomeExecutableDownloader(BiomeFlavor flavor, Path downloadDir) {
84+
this.flavor = flavor;
9685
this.downloadDir = downloadDir;
9786
}
9887

9988
/**
100-
* Downloads the Rome executable for the current platform from the network to
89+
* Downloads the Biome executable for the current platform from the network to
10190
* the download directory. When the executable exists already, it is
10291
* overwritten.
10392
*
104-
* @param version Desired Rome version.
105-
* @return The path to the Rome executable.
93+
* @param version Desired Biome version.
94+
* @return The path to the Biome executable.
10695
* @throws IOException When the executable cannot be downloaded from
10796
* the network or the file system could not be
10897
* accessed.
@@ -121,7 +110,7 @@ public Path download(String version) throws IOException, InterruptedException {
121110
if (executableDir != null) {
122111
Files.createDirectories(executableDir);
123112
}
124-
logger.info("Attempting to download Rome from '{}' to '{}'", url, executablePath);
113+
logger.info("Attempting to download Biome from '{}' to '{}'", url, executablePath);
125114
var request = HttpRequest.newBuilder(URI.create(url)).GET().build();
126115
var handler = BodyHandlers.ofFile(executablePath, WRITE_OPTIONS);
127116
var response = HttpClient.newBuilder().followRedirects(Redirect.NORMAL).build().send(request, handler);
@@ -133,19 +122,19 @@ public Path download(String version) throws IOException, InterruptedException {
133122
throw new IOException("Failed to download file from " + url + ", file is empty or does not exist");
134123
}
135124
writeChecksumFile(downloadedFile, checksumPath);
136-
logger.debug("Rome was downloaded successfully to '{}'", downloadedFile);
125+
logger.debug("Biome was downloaded successfully to '{}'", downloadedFile);
137126
return downloadedFile;
138127
}
139128

140129
/**
141-
* Ensures that the Rome executable for the current platform exists in the
130+
* Ensures that the Biome executable for the current platform exists in the
142131
* download directory. When the executable does not exist in the download
143-
* directory, an attempt is made to download the Rome executable from the
132+
* directory, an attempt is made to download the Biome executable from the
144133
* network. When the executable exists already, no attempt to download it again
145134
* is made.
146135
*
147-
* @param version Desired Rome version.
148-
* @return The path to the Rome executable.
136+
* @param version Desired Biome version.
137+
* @return The path to the Biome executable.
149138
* @throws IOException When the executable cannot be downloaded from
150139
* the network or the file system could not be
151140
* accessed.
@@ -157,23 +146,23 @@ public Path download(String version) throws IOException, InterruptedException {
157146
*/
158147
public Path ensureDownloaded(String version) throws IOException, InterruptedException {
159148
var platform = Platform.guess();
160-
logger.debug("Ensuring that Rome for platform '{}' is downloaded", platform);
149+
logger.debug("Ensuring that Biome for platform '{}' is downloaded", platform);
161150
var existing = findDownloaded(version);
162151
if (existing.isPresent()) {
163-
logger.debug("Rome was already downloaded, using executable at '{}'", existing.get());
152+
logger.debug("Biome was already downloaded, using executable at '{}'", existing.get());
164153
return existing.get();
165154
} else {
166-
logger.debug("Rome was not yet downloaded, attempting to download executable");
155+
logger.debug("Biome was not yet downloaded, attempting to download executable");
167156
return download(version);
168157
}
169158
}
170159

171160
/**
172-
* Attempts to find the Rome executable for the current platform in the download
161+
* Attempts to find the Biome executable for the current platform in the download
173162
* directory. No attempt is made to download the executable from the network.
174163
*
175-
* @param version Desired Rome version.
176-
* @return The path to the Rome executable.
164+
* @param version Desired Biome version.
165+
* @return The path to the Biome executable.
177166
* @throws IOException When the executable does not exists in the
178167
* download directory, or when the file system
179168
* could not be accessed.
@@ -184,7 +173,7 @@ public Path ensureDownloaded(String version) throws IOException, InterruptedExce
184173
public Optional<Path> findDownloaded(String version) throws IOException {
185174
var platform = Platform.guess();
186175
var executablePath = getExecutablePath(version, platform);
187-
logger.debug("Checking rome executable at {}", executablePath);
176+
logger.debug("Checking Biome executable at {}", executablePath);
188177
return checkFileWithChecksum(executablePath) ? Optional.ofNullable(executablePath) : Optional.empty();
189178
}
190179

@@ -248,12 +237,12 @@ private String computeChecksum(Path file, String algorithm) throws IOException {
248237
}
249238

250239
/**
251-
* Finds the code name for the given operating system used by the Rome
240+
* Finds the code name for the given operating system used by the Biome
252241
* executable download URL.
253242
*
254243
* @param os Desired operating system.
255-
* @return Code name for the Rome download URL.
256-
* @throws IOException When the given OS is not supported by Rome.
244+
* @return Code name for the Biome download URL.
245+
* @throws IOException When the given OS is not supported by Biome.
257246
*/
258247
private String getArchitectureCodeName(Architecture architecture) throws IOException {
259248
switch (architecture) {
@@ -281,28 +270,28 @@ private Path getChecksumPath(Path file) {
281270
}
282271

283272
/**
284-
* Finds the URL from which the Rome executable can be downloaded.
273+
* Finds the URL from which the Biome executable can be downloaded.
285274
*
286-
* @param version Desired Rome version.
275+
* @param version Desired Biome version.
287276
* @param platform Desired platform.
288-
* @return The URL for the Rome executable.
289-
* @throws IOException When the platform is not supported by Rome.
277+
* @return The URL for the Biome executable.
278+
* @throws IOException When the platform is not supported by Biome.
290279
*/
291280
private String getDownloadUrl(String version, Platform platform) throws IOException {
292281
var osCodeName = getOsCodeName(platform.getOs());
293282
var architectureCodeName = getArchitectureCodeName(platform.getArchitecture());
294283
var extension = getDownloadUrlExtension(platform.getOs());
295284
var platformString = String.format(PLATFORM_PATTERN, osCodeName, architectureCodeName, extension);
296-
return String.format(URL_PATTERN, version, platformString);
285+
return String.format(flavor.getUrlPattern(), version, platformString);
297286
}
298287

299288
/**
300-
* Finds the file extension of the Rome download URL for the given operating
289+
* Finds the file extension of the Biome download URL for the given operating
301290
* system.
302291
*
303292
* @param os Desired operating system.
304-
* @return Extension for the Rome download URL.
305-
* @throws IOException When the given OS is not supported by Rome.
293+
* @return Extension for the Biome download URL.
294+
* @throws IOException When the given OS is not supported by Biome.
306295
*/
307296
private String getDownloadUrlExtension(OS os) throws IOException {
308297
switch (os) {
@@ -318,27 +307,27 @@ private String getDownloadUrlExtension(OS os) throws IOException {
318307
}
319308

320309
/**
321-
* Finds the path on the file system for the Rome executable with a given
310+
* Finds the path on the file system for the Biome executable with a given
322311
* version and platform.
323312
*
324-
* @param version Desired Rome version.
313+
* @param version Desired Biome version.
325314
* @param platform Desired platform.
326-
* @return The path for the Rome executable.
315+
* @return The path for the Biome executable.
327316
*/
328317
private Path getExecutablePath(String version, Platform platform) {
329318
var os = platform.getOs().name().toLowerCase(Locale.ROOT);
330319
var arch = platform.getArchitecture().name().toLowerCase(Locale.ROOT);
331-
var fileName = String.format(DOWNLOAD_FILE_PATTERN, os, arch, version);
320+
var fileName = String.format(flavor.getDownloadFilePattern(), os, arch, version);
332321
return downloadDir.resolve(fileName);
333322
}
334323

335324
/**
336-
* Finds the code name for the given operating system used by the Rome
325+
* Finds the code name for the given operating system used by the Biome
337326
* executable download URL.
338327
*
339328
* @param os Desired operating system.
340-
* @return Code name for the Rome download URL.
341-
* @throws IOException When the given OS is not supported by Rome.
329+
* @return Code name for the Biome download URL.
330+
* @throws IOException When the given OS is not supported by Biome.
342331
*/
343332
private String getOsCodeName(OS os) throws IOException {
344333
switch (os) {

0 commit comments

Comments
 (0)