Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020), [#2535](https://github.com/diffplug/spotless/pull/2535))
* Add support for removing wildcard imports via `removeWildcardImports` step. ([#2517](https://github.com/diffplug/spotless/pull/2517))
* Use `palantir-java-format` as default formatter in `RemoveUnusedImportsStep`. ([#2541](https://github.com/diffplug/spotless/pull/2541))

* 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))
### Fixed
* Fix biome formatter for new major release 2.x of biome ([#2537](https://github.com/diffplug/spotless/pull/2537))
* Make sure npm-based formatters use the correct `node_modules` directory when running in parallel. ([#2542](https://github.com/diffplug/spotless/pull/2542))

### Changed
* Bump internal dependencies for npm-based formatters ([#2542](https://github.com/diffplug/spotless/pull/2542))

### Changed
* 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))

## [3.1.2] - 2025-05-27
### Fixed
* Fix `UnsupportedOperationException` in the Gradle plugin when using `targetExcludeContent[Pattern]` ([#2487](https://github.com/diffplug/spotless/pull/2487))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,17 +71,13 @@ final class BiomeExecutableDownloader {

private final Path downloadDir;

private final BiomeFlavor flavor;

/**
* Creates a new downloader for the Biome executable. The executable files are
* stored in the given download directory.
*
* @param flavor Flavor of Biome to use.
* @param downloadDir Directory where to store the downloaded executable.
*/
public BiomeExecutableDownloader(BiomeFlavor flavor, Path downloadDir) {
this.flavor = flavor;
public BiomeExecutableDownloader(Path downloadDir) {
this.downloadDir = downloadDir;
}

Expand Down Expand Up @@ -240,7 +236,7 @@ private String computeChecksum(Path file, String algorithm) throws IOException {
* Finds the code name for the given operating system used by the Biome
* executable download URL.
*
* @param os Desired operating system.
* @param architecture Desired operating system architecture.
* @return Code name for the Biome download URL.
* @throws IOException When the given OS is not supported by Biome.
*/
Expand Down Expand Up @@ -282,7 +278,7 @@ private String getDownloadUrl(String version, Platform platform) throws IOExcept
var architectureCodeName = getArchitectureCodeName(platform.getArchitecture());
var extension = getDownloadUrlExtension(platform.getOs());
var platformString = String.format(PLATFORM_PATTERN, osCodeName, architectureCodeName, extension);
return String.format(flavor.getUrlPattern(), version, platformString);
return String.format(BiomeSettings.getUrlPattern(version), version, platformString);
}

/**
Expand Down Expand Up @@ -317,7 +313,7 @@ private String getDownloadUrlExtension(OS os) throws IOException {
private Path getExecutablePath(String version, Platform platform) {
var os = platform.getOs().name().toLowerCase(Locale.ROOT);
var arch = platform.getArchitecture().name().toLowerCase(Locale.ROOT);
var fileName = String.format(flavor.getDownloadFilePattern(), os, arch, version);
var fileName = String.format(BiomeSettings.getDownloadFilePattern(), os, arch, version);
return downloadDir.resolve(fileName);
}

Expand Down
85 changes: 0 additions & 85 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeFlavor.java

This file was deleted.

75 changes: 75 additions & 0 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2023-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.biome;

/**
* Settings and constants for Biome to use.
*/
public final class BiomeSettings {
private final static String CONFIG_NAME = "biome.json";
private final static String DEFAULT_VERSION = "1.2.0";
private final static String DOWNLOAD_FILE_PATTERN = "biome-%s-%s-%s";
private final static String SHORT_NAME = "biome";
private final static String URL_PATTERN_1X = "https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s";
private final static String URL_PATTERN_2X = "https://github.com/biomejs/biome/releases/download/%%40biomejs%%2Fbiome%%40%s/biome-%s";

private BiomeSettings() {}

/**
* @return The name of the default config file.
*/
public static String configName() {
return CONFIG_NAME;
}

/**
* @return Default version to use when no version was set explicitly.
*/
public static String defaultVersion() {
return DEFAULT_VERSION;
}

/**
* @return The pattern for {@link String#format(String, Object...)
* String.format()} for the file name of a Biome executable for a
* certain version and architecture. The first parameter is the platform,
* the second is the OS, the third is the architecture.
*/
public static String getDownloadFilePattern() {
return DOWNLOAD_FILE_PATTERN;
}

/**
* @param version The biome version for which to get the URL pattern, e.g. 1.2.0 or 2.0.6.
* @return The pattern for {@link String#format(String, Object...)
* String.format()} for the URL where the executables can be downloaded.
* The first parameter is the version, the second parameter is the OS /
* platform.
*/
public static String getUrlPattern(String version) {
if (version != null && version.startsWith("1.")) {
return URL_PATTERN_1X;
}
return URL_PATTERN_2X;
}

/**
* @return The short name of this flavor, e.g. <code>biome</code>.
*/
public static String shortName() {
return SHORT_NAME;
}
}
38 changes: 14 additions & 24 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,12 +72,6 @@ public class BiomeStep {
*/
private String language;

/**
* Biome flavor to use. Will be removed once we stop supporting the deprecated Rome project.
*/
@Deprecated
private final BiomeFlavor flavor;

/**
* Path to the Biome executable. Can be <code>null</code>, but either a path to
* the executable of a download directory and version must be given. The path
Expand All @@ -103,32 +97,30 @@ public class BiomeStep {
* @return The name of this format step, i.e. <code>biome</code> or <code>rome</code>.
*/
public String name() {
return flavor.shortName();
return BiomeSettings.shortName();
}

/**
* Creates a Biome step that format code by downloading to the given Biome
* version. The executable is downloaded from the network.
*
* @param flavor Flavor of Biome to use.
* @param version Version of the Biome executable to download.
* @param downloadDir Directory where to place the downloaded executable.
* @return A new Biome step that download the executable from the network.
*/
public static BiomeStep withExeDownload(BiomeFlavor flavor, String version, String downloadDir) {
return new BiomeStep(flavor, version, null, downloadDir);
public static BiomeStep withExeDownload(String version, String downloadDir) {
return new BiomeStep(version, null, downloadDir);
}

/**
* Creates a Biome step that formats code by delegating to the Biome executable
* located at the given path.
*
* @param flavor Flavor of Biome to use.
* @param pathToExe Path to the Biome executable to use.
* @return A new Biome step that format with the given executable.
*/
public static BiomeStep withExePath(BiomeFlavor flavor, String pathToExe) {
return new BiomeStep(flavor, null, pathToExe, null);
public static BiomeStep withExePath(String pathToExe) {
return new BiomeStep(null, pathToExe, null);
}

/**
Expand Down Expand Up @@ -156,8 +148,8 @@ private static void attemptToAddPosixPermission(Path file, PosixFilePermission p
*
* @return The default version for Biome.
*/
private static String defaultVersion(BiomeFlavor flavor) {
return flavor.defaultVersion();
private static String defaultVersion() {
return BiomeSettings.defaultVersion();
}

/**
Expand Down Expand Up @@ -200,12 +192,12 @@ private static String resolveNameAgainstPath(String name) throws IOException, In
* Checks the Biome config path. When the config path does not exist or when it
* does not contain a file named {@code biome.json}, an error is thrown.
*/
private static void validateBiomeConfigPath(BiomeFlavor flavor, String configPath) {
private static void validateBiomeConfigPath(String configPath) {
if (configPath == null) {
return;
}
var path = Paths.get(configPath);
var config = path.resolve(flavor.configName());
var config = path.resolve(BiomeSettings.configName());
if (!Files.exists(path)) {
throw new IllegalArgumentException("Biome config directory does not exist: " + path);
}
Expand All @@ -227,14 +219,12 @@ private static void validateBiomeExecutable(String resolvedPathToExe) {
/**
* Creates a new Biome step with the configuration from the given builder.
*
* @param flavor Flavor of Biome to use.
* @param version Version of the Biome executable to download.
* @param pathToExe Path to the Biome executable to use.
* @param downloadDir Directory where to place the downloaded executable.
*/
private BiomeStep(BiomeFlavor flavor, String version, String pathToExe, String downloadDir) {
this.flavor = flavor;
this.version = version != null && !version.isBlank() ? version : defaultVersion(flavor);
private BiomeStep(String version, String pathToExe, String downloadDir) {
this.version = version != null && !version.isBlank() ? version : defaultVersion();
this.pathToExe = pathToExe;
this.downloadDir = downloadDir;
}
Expand Down Expand Up @@ -306,7 +296,7 @@ public BiomeStep withLanguage(String language) {
private State createState() throws IOException, InterruptedException {
var resolvedPathToExe = resolveExe();
validateBiomeExecutable(resolvedPathToExe);
validateBiomeConfigPath(flavor, configPath);
validateBiomeConfigPath(configPath);
logger.debug("Using Biome executable located at '{}'", resolvedPathToExe);
var exeSignature = FileSignature.signAsList(Collections.singleton(new File(resolvedPathToExe)));
makeExecutable(resolvedPathToExe);
Expand Down Expand Up @@ -337,7 +327,7 @@ private String resolveExe() throws IOException, InterruptedException {
return pathToExe;
}
} else {
var downloader = new BiomeExecutableDownloader(flavor, Paths.get(downloadDir));
var downloader = new BiomeExecutableDownloader(Paths.get(downloadDir));
var downloaded = downloader.ensureDownloaded(version).toString();
makeExecutable(downloaded);
return downloaded;
Expand Down
5 changes: 2 additions & 3 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Added
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020), [#2535](https://github.com/diffplug/spotless/pull/2535))
* Add support for removing wildcard imports via `removeWildcardImports` step. ([#2517](https://github.com/diffplug/spotless/pull/2517))

### Fixed
* Fix biome formatter for new major release 2.x of biome ([#2537](https://github.com/diffplug/spotless/pull/2537))
* Make sure npm-based formatters use the correct `node_modules` directory when running in parallel. ([#2542](https://github.com/diffplug/spotless/pull/2542))

### Changed
* Bump internal dependencies for npm-based formatters ([#2542](https://github.com/diffplug/spotless/pull/2542))\
* Bump internal dependencies for npm-based formatters ([#2542](https://github.com/diffplug/spotless/pull/2542))

### Changed
* 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))
Expand Down
Loading
Loading