Skip to content

Commit b5f1251

Browse files
committed
Ensure support for version 2.x of biome
The download path changed slightly for version 2.x. Add tests for version 2.x.
1 parent 9ed6289 commit b5f1251

File tree

5 files changed

+82
-13
lines changed

5 files changed

+82
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private String getDownloadUrl(String version, Platform platform) throws IOExcept
278278
var architectureCodeName = getArchitectureCodeName(platform.getArchitecture());
279279
var extension = getDownloadUrlExtension(platform.getOs());
280280
var platformString = String.format(PLATFORM_PATTERN, osCodeName, architectureCodeName, extension);
281-
return String.format(flavor.getUrlPattern(), version, platformString);
281+
return String.format(BiomeSettings.getUrlPattern(version), version, platformString);
282282
}
283283

284284
/**
@@ -313,7 +313,7 @@ private String getDownloadUrlExtension(OS os) throws IOException {
313313
private Path getExecutablePath(String version, Platform platform) {
314314
var os = platform.getOs().name().toLowerCase(Locale.ROOT);
315315
var arch = platform.getArchitecture().name().toLowerCase(Locale.ROOT);
316-
var fileName = String.format(flavor.getDownloadFilePattern(), os, arch, version);
316+
var fileName = String.format(BiomeSettings.getDownloadFilePattern(), os, arch, version);
317317
return downloadDir.resolve(fileName);
318318
}
319319

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,27 @@
1919
* Settings and constants for Biome to use.
2020
*/
2121
public final class BiomeSettings {
22-
private final static String configName= "biome.json";
23-
private final static String defaultVersion = "1.2.0";
24-
private final static String downloadFilePattern = "biome-%s-%s-%s";
25-
private final static String shortName = "biome";
26-
private final static String urlPattern = "https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s";
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";
2728

2829
private BiomeSettings() {}
2930

3031
/**
3132
* @return The name of the default config file.
3233
*/
3334
public static String configName() {
34-
return configName;
35+
return CONFIG_NAME;
3536
}
3637

3738
/**
3839
* @return Default version to use when no version was set explicitly.
3940
*/
4041
public static String defaultVersion() {
41-
return defaultVersion;
42+
return DEFAULT_VERSION;
4243
}
4344

4445
/**
@@ -48,23 +49,27 @@ public static String defaultVersion() {
4849
* the second is the OS, the third is the architecture.
4950
*/
5051
public static String getDownloadFilePattern() {
51-
return downloadFilePattern;
52+
return DOWNLOAD_FILE_PATTERN;
5253
}
5354

5455
/**
56+
* @param version The biome version for which to get the URL pattern, e.g. 1.2.0 or 2.0.6.
5557
* @return The pattern for {@link String#format(String, Object...)
5658
* String.format()} for the URL where the executables can be downloaded.
5759
* The first parameter is the version, the second parameter is the OS /
5860
* platform.
5961
*/
60-
public static String getUrlPattern() {
61-
return urlPattern;
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;
6267
}
6368

6469
/**
6570
* @return The short name of this flavor, e.g. <code>biome</code>.
6671
*/
6772
public static String shortName() {
68-
return shortName;
73+
return SHORT_NAME;
6974
}
7075
}

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,29 @@ void preservesIgnoredFiles() throws Exception {
424424
assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
425425
assertFile("package.json").sameAsResource("biome/json/packageAfter.json");
426426
}
427+
428+
/**
429+
* Tests that the Gradle plugin works with version 2.x of biome.
430+
*
431+
* @throws Exception When a test failure occurs.
432+
*/
433+
@Test
434+
void version2x() throws Exception {
435+
setFile("build.gradle").toLines(
436+
"plugins {",
437+
" id 'com.diffplug.spotless'",
438+
"}",
439+
"repositories { mavenCentral() }",
440+
"spotless {",
441+
" format 'mybiome', {",
442+
" target '**/*.js'",
443+
" biome('2.0.6')",
444+
" }",
445+
"}");
446+
setFile("biome_test.js").toResource("biome/js/fileBefore.js");
447+
448+
var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
449+
assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
450+
assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js");
451+
}
427452
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,17 @@ void preservesIgnoredFiles() throws Exception {
248248
mavenRunner().withArguments("spotless:apply").runNoError();
249249
assertFile("package.json").sameAsResource("biome/json/packageAfter.json");
250250
}
251+
252+
/**
253+
* Tests that the Maven plugin works with version 2.x of biome.
254+
*
255+
* @throws Exception When a test failure occurs.
256+
*/
257+
@Test
258+
void version2X() throws Exception {
259+
writePomWithBiomeSteps("**/*.js", "<biome><version>2.0.6</version></biome>");
260+
setFile("biome_test.js").toResource("biome/js/fileBefore.js");
261+
mavenRunner().withArguments("spotless:apply").runNoError();
262+
assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js");
263+
}
251264
}

testlib/src/test/java/com/diffplug/spotless/biome/BiomeStepTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,32 @@ void preservesIgnoredFiles() {
194194
}
195195
}
196196

197+
/**
198+
* Tests for the different biome versions.
199+
*/
200+
@Nested
201+
class BiomeVersion {
202+
/**
203+
* Basic test that biome 1.x works.
204+
*/
205+
@Test
206+
void test1x() {
207+
var step = BiomeStep.withExeDownload("1.2.0", downloadDir).create();
208+
var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step);
209+
stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs");
210+
}
211+
212+
/**
213+
* Basic test that biome 2.x works.
214+
*/
215+
@Test
216+
void test2x() {
217+
var step = BiomeStep.withExeDownload("2.0.6", downloadDir).create();
218+
var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step);
219+
stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs");
220+
}
221+
}
222+
197223
@Nested
198224
class ConfigFile {
199225
/**

0 commit comments

Comments
 (0)